Skip to content

Commit

Permalink
Related-Bug: #1456145 - In policy create/edit window the Source Desti…
Browse files Browse the repository at this point in the history
…nation dropdown is

modified to show only 200 items and the user will need to search using the
search tool to find if there are more no. of records. Limiting the items shown
at once will improve the performance.

Change-Id: I915276fdd5e77b81c3104321b187256660acf79c
  • Loading branch information
manojgn committed May 27, 2015
1 parent 6613d0d commit 72aeda3
Showing 1 changed file with 40 additions and 26 deletions.
66 changes: 40 additions & 26 deletions webroot/config/networkpolicies/ui/js/policy_config.js
Expand Up @@ -1425,32 +1425,10 @@ function setFocusSelectedItem(grpName, term, data) {
function select2Query(query) {
//using predefined process method to make work select2 selection
var t = query.term,filtered = { results: [] }, process;
process = function(datum, collection) {
var group, attr;
datum = datum[0];
if (datum.children) {
group = {};
for (attr in datum) {
if (datum.hasOwnProperty(attr)) group[attr]=datum[attr];
}
group.children=[];
$(datum.children).each2(function(i, childDatum) { process(childDatum, group.children); });
if (group.children.length || query.matcher(t, '', datum)) {
collection.push(group);
}
} else {
if (query.matcher(t, '', datum)) {
collection.push(datum);
}
}
};
if(t != ""){
$(dsSrcDest).each2(function(i, datum) { process(datum, filtered.results); })
}

var data = {results: []};
var grpName = getSelectedGroupName();
if(query.term != undefined && query.term != "") {
var grpName = getSelectedGroupName();

if(query.term != undefined) {
data.results.push({ id : query.term, text : query.term, parent : grpName});
this.data = [];
$.extend(true, this.data, dsSrcDest);
Expand All @@ -1466,8 +1444,44 @@ function select2Query(query) {
data.results.push(this.data[i]);
}
addNewTermDataSource(grpName, query.term, data.results);
} else{
var pageSize =200;
var typeNo = 2;
if(grpName == "Networks") {children = data.results[2]['children']; typeNo = 2;}
else if(grpName == "CIDR") {children = data.results[1]['children'];typeNo = 1;}
else if(grpName == "Policies") {children = data.results[3]['children'];typeNo = 3;}
var more = false;
if (data.results[typeNo]['children'].length >= query.page*pageSize) {
more = true;
}
data.results[typeNo]['children'] = data.results[typeNo]['children'].slice((query.page-1)*pageSize, query.page*pageSize);
if (more) {
data.results[typeNo]['children'].push({id:"search" + typeNo, text:"Search to find more entries", disabled : true})
}
} else {
process = function(datum, collection) {
var group, attr;
datum = datum[0];
if (datum.children) {
group = {};
for (attr in datum) {
if (datum.hasOwnProperty(attr)) group[attr]=datum[attr];
}
group.children=[];
$(datum.children).each2(function(i, childDatum) { process(childDatum, group.children); });
if (group.children.length || query.matcher(t, '', datum)) {
collection.push(group);
}
} else {
if (query.matcher(t, '', datum)) {
collection.push(datum);
}
}
};
if(t != ""){
$(dsSrcDest).each2(function(i, datum) { process(datum, filtered.results); })
}
data.results = dsSrcDest;

}
query.callback(data);
//set focus for a searched item
Expand Down

0 comments on commit 72aeda3

Please sign in to comment.