Repository: ambari Updated Branches: refs/heads/trunk 5e3c40f37 -> 7ade22258
AMBARI-15307 Combo Search: Apply existing filter conditions when creating new filter (rzang) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7ade2225 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7ade2225 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7ade2225 Branch: refs/heads/trunk Commit: 7ade22258e09bbc50e1186619cd89f4dd06497f5 Parents: 5e3c40f Author: Richard Zang <[email protected]> Authored: Fri Mar 4 15:37:41 2016 -0800 Committer: Richard Zang <[email protected]> Committed: Fri Mar 4 15:37:41 2016 -0800 ---------------------------------------------------------------------- .../controllers/main/host/combo_search_box.js | 1 + .../app/views/main/host/combo_search_box.js | 78 +++++++++++++++----- 2 files changed, 59 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/7ade2225/ambari-web/app/controllers/main/host/combo_search_box.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/host/combo_search_box.js b/ambari-web/app/controllers/main/host/combo_search_box.js index 6c75c7a..9fa6851 100644 --- a/ambari-web/app/controllers/main/host/combo_search_box.js +++ b/ambari-web/app/controllers/main/host/combo_search_box.js @@ -23,6 +23,7 @@ App.MainHostComboSearchBoxController = Em.Controller.extend({ currentSuggestion: [], page_size: 10, getPropertySuggestions: function(facet, searchTerm) { + facet = (facet == 'hostName')? 'host_name' : facet; return App.ajax.send({ name: 'hosts.with_searchTerm', sender: this, http://git-wip-us.apache.org/repos/asf/ambari/blob/7ade2225/ambari-web/app/views/main/host/combo_search_box.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/host/combo_search_box.js b/ambari-web/app/views/main/host/combo_search_box.js index e8f21f0..17c0a6d 100644 --- a/ambari-web/app/views/main/host/combo_search_box.js +++ b/ambari-web/app/views/main/host/combo_search_box.js @@ -32,6 +32,33 @@ App.MainHostComboSearchBoxView = Em.View.extend({ } }, + getHostComponentList: function() { + var controller = App.router.get('mainHostComboSearchBoxController'); + var hostComponentList = []; + App.HostComponent.find().toArray().forEach(function(component) { + var displayName = component.get('displayName'); + var name = component.get('componentName'); + if (displayName != null && !controller.isClientComponent(name)) { + hostComponentList.push({label: displayName, value: name, category: 'Component'}); + } + }); + return hostComponentList; + }, + + getComponentStateFacets: function(hostComponentList, includeAllValue) { + if (!hostComponentList) { + hostComponentList = this.getHostComponentList(); + } + var currentComponentFacets = visualSearch.searchQuery.toJSON().filter(function (facet) { + var result = !!(hostComponentList.findProperty('value', facet.category) && facet.value); + if (!includeAllValue) { + result &= (facet.value != 'ALL'); + } + return result; + }); + return currentComponentFacets; + }, + initVS: function() { var self = this; var controller = App.router.get('mainHostComboSearchBoxController'); @@ -62,16 +89,12 @@ App.MainHostComboSearchBoxView = Em.View.extend({ {label: 'Rack', value: 'rack', category: 'Host'}, {label: 'Service', value: 'services', category: 'Service'}, ]; - var hostComponentHash = {}; - App.HostComponent.find().toArray().forEach(function(component) { - hostComponentHash[component.get('displayName')] = component; - }); - for (key in hostComponentHash) { - var name = hostComponentHash[key].get('componentName'); - var displayName = hostComponentHash[key].get('displayName'); - if (displayName != null && !controller.isClientComponent(name)) { - list.push({label: displayName, value: name, category: 'Component'}); - } + var hostComponentList = self.getHostComponentList(); + // Add host component facets only when there isn't any component filter + // with value other than ALL yet + var currentComponentFacets = self.getComponentStateFacets(hostComponentList, false); + if (currentComponentFacets.length == 0) { + list = list.concat(hostComponentList); } // Append host components callback(list, {preserveOrder: true}); @@ -84,46 +107,61 @@ App.MainHostComboSearchBoxView = Em.View.extend({ switch (facet) { case 'hostName': case 'ip': - facet = (facet == 'hostName')? 'host_name' : facet; controller.getPropertySuggestions(facet, searchTerm).done(function() { - callback(controller.get('currentSuggestion'), {preserveMatches: true}); + callback(controller.get('currentSuggestion').reject(function (item) { + return visualSearch.searchQuery.values(facet).indexOf(item) >= 0; // reject the ones already in search + }), {preserveMatches: true}); }); break; case 'rack': - callback(App.Host.find().toArray().mapProperty('rack').uniq()); + callback(App.Host.find().toArray().mapProperty('rack').uniq().reject(function (item) { + return visualSearch.searchQuery.values(facet).indexOf(item) >= 0; + }), {preserveMatches: true}); break; case 'version': - callback(App.HostStackVersion.find().toArray().filterProperty('isVisible', true).mapProperty('displayName').uniq()); + callback(App.HostStackVersion.find().toArray() + .filterProperty('isVisible', true).mapProperty('displayName').uniq().reject(function (item) { + return visualSearch.searchQuery.values(facet).indexOf(item) >= 0; + })); break; case 'versionState': callback(App.HostStackVersion.statusDefinition.map(function (status) { return {label: App.HostStackVersion.formatStatus(status), value: status}; + }).reject(function (item) { + return visualSearch.searchQuery.values(facet).indexOf(item.value) >= 0; })); break; case 'healthClass': var category_mocks = require('data/host/categories'); callback(category_mocks.slice(1).map(function (category) { return {label: category.value, value: category.healthStatus} + }).reject(function (item) { + return visualSearch.searchQuery.values(facet).indexOf(item.value) >= 0; }), {preserveOrder: true}); break; case 'services': callback(App.Service.find().toArray().map(function (service) { return {label: App.format.role(service.get('serviceName')), value: service.get('serviceName')}; + }).reject(function (item) { + return visualSearch.searchQuery.values(facet).indexOf(item.value) >= 0; }), {preserveOrder: true}); break; case 'componentState': - callback([{label: "All", value: "ALL"}] - .concat(App.HostComponentStatus.getStatusesList().map(function (status) { - return {label: App.HostComponentStatus.getTextStatus(status), value: status}; - })) - .concat([ + var list = [{label: "All", value: "ALL"}]; + var currentComponentFacets = self.getComponentStateFacets(null, true); + if (currentComponentFacets.length == 0) { + list = list.concat(App.HostComponentStatus.getStatusesList().map(function (status) { + return {label: App.HostComponentStatus.getTextStatus(status), value: status}; + })).concat([ {label: "Inservice", value: "INSERVICE"}, {label: "Decommissioned", value: "DECOMMISSIONED"}, {label: "Decommissioning", value: "DECOMMISSIONING"}, {label: "RS Decommissioned", value: "RS_DECOMMISSIONED"}, {label: "Maintenance Mode On", value: "ON"}, {label: "Maintenance Mode Off", value: "OFF"} - ]), {preserveOrder: true}); + ]); + } + callback(list, {preserveOrder: true}); break; } }
