You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rz...@apache.org on 2016/06/09 00:19:17 UTC
ambari git commit: AMBARI-17132 - Typing the whole component name vs
selecting drop down filter in hosts page gives 2 different results (rzang)
Repository: ambari
Updated Branches:
refs/heads/branch-2.4 de85cddbd -> 94038e5c3
AMBARI-17132 - Typing the whole component name vs selecting drop down filter in hosts page gives 2 different results (rzang)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/94038e5c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/94038e5c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/94038e5c
Branch: refs/heads/branch-2.4
Commit: 94038e5c3f7f5d9d6f4df3b653178638eea9beef
Parents: de85cdd
Author: Richard Zang <rz...@apache.org>
Authored: Wed Jun 8 17:17:22 2016 -0700
Committer: Richard Zang <rz...@apache.org>
Committed: Wed Jun 8 17:17:48 2016 -0700
----------------------------------------------------------------------
ambari-web/app/messages.js | 1 +
.../templates/main/host/combo_search_box.hbs | 5 +
.../app/views/main/host/combo_search_box.js | 305 +++++++++++--------
3 files changed, 181 insertions(+), 130 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/94038e5c/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 02da1f6..6f67f8c 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -2574,6 +2574,7 @@ Em.I18n.translations = {
'hosts.passiveMode.popup.version.mismatch': '{0} has components from a stack which is not current. Before bringing this host out of maintenance mode, it is recommended that you upgrade its components to {1}',
'hosts.passiveMode.popup.version.mismatch.multiple': 'Some hosts have components from a stack which is not current. Before bringing these hosts out of maintenance mode, it is recommended that you upgrade their components to {0}',
'hosts.combo.search.placebolder': 'Filter by host and component attributes or search by keyword ...',
+ 'hosts.combo.search.invalidCategory': 'is not a valid category.',
'charts.horizon.chart.showText':'show',
'charts.horizon.chart.hideText':'hide',
'charts.horizon.chart.attributes.cpu':'CPU',
http://git-wip-us.apache.org/repos/asf/ambari/blob/94038e5c/ambari-web/app/templates/main/host/combo_search_box.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host/combo_search_box.hbs b/ambari-web/app/templates/main/host/combo_search_box.hbs
index 6ff9640..6b118a9 100644
--- a/ambari-web/app/templates/main/host/combo_search_box.hbs
+++ b/ambari-web/app/templates/main/host/combo_search_box.hbs
@@ -17,5 +17,10 @@
}}
{{#if App.supports.hostComboSearchBox}}
<br/>
+{{#if view.errMsg}}
+<div class="alert alert-error">
+ {{view.errMsg}}
+</div>
+{{/if}}
<div id="combo_search_box"></div>
{{/if}}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/94038e5c/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 c6ac3bd..54c2df4 100644
--- a/ambari-web/app/views/main/host/combo_search_box.js
+++ b/ambari-web/app/views/main/host/combo_search_box.js
@@ -21,6 +21,7 @@ var App = require('app');
App.MainHostComboSearchBoxView = Em.View.extend({
templateName: require('templates/main/host/combo_search_box'),
healthStatusCategories: require('data/host/categories'),
+ errMsg: '',
didInsertElement: function () {
this.initVS();
@@ -28,6 +29,179 @@ App.MainHostComboSearchBoxView = Em.View.extend({
this.showHideClearButton();
},
+ initVS: function() {
+ this.setupLabelMap();
+ window.visualSearch = VS.init({
+ container: $('#combo_search_box'),
+ query: '',
+ showFacets: true,
+ delay: 1000,
+ placeholder: Em.I18n.t('hosts.combo.search.placebolder'),
+ unquotable: [
+ 'text'
+ ],
+ callbacks: {
+ search: this.search.bind(this),
+ facetMatches: this.facetMatches.bind(this),
+ valueMatches: this.valueMatches.bind(this)
+ }
+ });
+ },
+
+ /**
+ * 'search' call back for visualsearch.js
+ * @param query
+ * @param searchCollection
+ */
+ search: function (query, searchCollection) {
+ this.clearErrMsg();
+ var invalidFacet = this.findInvalidFacet(searchCollection);
+ if (invalidFacet) {
+ this.showErrMsg(invalidFacet);
+ }
+ var tableView = this.get('parentView').get('parentView');
+ App.db.setComboSearchQuery(tableView.get('controller.name'), query);
+ var filterConditions = this.createFilterConditions(searchCollection);
+ tableView.updateComboFilter(filterConditions);
+ },
+
+ /**
+ * 'facetMatches' callback for visualsearch.js
+ * @param callback
+ */
+ facetMatches: function (callback) {
+ this.showHideClearButton();
+ var list = [
+ {label: 'Host Name', category: 'Host'},
+ {label: 'IP', category: 'Host'},
+ {label: 'Host Status', category: 'Host'},
+ {label: 'Cores', category: 'Host'},
+ {label: 'RAM', category: 'Host'},
+ {label: 'Stack Version', category: 'Host'},
+ {label: 'Version State', category: 'Host'},
+ {label: 'Rack', category: 'Host'},
+ {label: 'Service', category: 'Service'}
+ ];
+ var hostComponentList = this.getHostComponentList();
+ // Add host component facets only when there isn't any component filter
+ // with value other than ALL yet
+ var currentComponentFacets = this.getComponentStateFacets(hostComponentList, false);
+ if (currentComponentFacets.length == 0) {
+ list = list.concat(hostComponentList);
+ }
+ list = this.filterOutOneFacetOnlyOptions(list);
+ // Append host components
+ callback(list, {preserveOrder: true});
+ },
+
+ /**
+ * 'valueMatches' callback for visualsearch.js
+ * @param facet
+ * @param searchTerm
+ * @param callback
+ */
+ valueMatches: function (facet, searchTerm, callback) {
+ var controller = App.router.get('mainHostComboSearchBoxController');
+ this.showHideClearButton();
+ var map = App.router.get('mainHostController.labelValueMap');
+ var facetValue = map[facet] || facet;
+ if (controller.isComponentStateFacet(facetValue)) {
+ facetValue = 'componentState'
+ }
+ switch (facetValue) {
+ case 'hostName':
+ case 'ip':
+ controller.getPropertySuggestions(facetValue, searchTerm).done(function() {
+ 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().reject(function (item) {
+ return visualSearch.searchQuery.values(facet).indexOf(item) >= 0;
+ }));
+ break;
+ case 'version':
+ 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) {
+ map[App.HostStackVersion.formatStatus(status)] = status;
+ return App.HostStackVersion.formatStatus(status);
+ }).reject(function (item) {
+ return visualSearch.searchQuery.values(facet).indexOf(item) >= 0;
+ }));
+ break;
+ case 'healthClass':
+ var category_mocks = this.healthStatusCategories;
+ callback(category_mocks.slice(1).map(function (category) {
+ map[category.value] = category.healthStatus;
+ return category.value;
+ }).reject(function (item) {
+ return visualSearch.searchQuery.values(facet).indexOf(item) >= 0;
+ }), {preserveOrder: true});
+ break;
+ case 'services':
+ callback(App.Service.find().toArray().map(function (service) {
+ map[App.format.role(service.get('serviceName'), true)] = service.get('serviceName');
+ return App.format.role(service.get('serviceName'), true);
+ }).reject(function (item) {
+ return visualSearch.searchQuery.values(facet).indexOf(item) >= 0;
+ }), {preserveOrder: true});
+ break;
+ case 'componentState':
+ var list = [ "All" ];
+ // client only have "ALL" state
+ if (facet.toLowerCase().indexOf("client") == -1)
+ {
+ var currentComponentFacets = this.getComponentStateFacets(null, true);
+ if (currentComponentFacets.length == 0) {
+ list = list.concat(App.HostComponentStatus.getStatusesList()
+ .reject(function(status){return status == "UPGRADE_FAILED"}) // take out 'UPGRADE_FAILED'
+ .map(function (status) {
+ map[App.HostComponentStatus.getTextStatus(status)] = status;
+ return App.HostComponentStatus.getTextStatus(status);
+ }))
+ .concat([
+ "Inservice",
+ "Decommissioned",
+ "Decommissioning",
+ "RS Decommissioned",
+ "Maintenance Mode On",
+ "Maintenance Mode Off"
+ ]);
+ }
+ }
+ callback(list, {preserveOrder: true});
+ break;
+ }
+ },
+
+ findInvalidFacet: function(searchCollection) {
+ var result = null;
+ var map = App.router.get('mainHostController.labelValueMap');
+ for (var i = 0; i < searchCollection.models.length; i++) {
+ var facet = searchCollection.models[i];
+ if (!map[facet.attributes.category]) {
+ result = facet;
+ break;
+ }
+ }
+ return result;
+ },
+
+ showErrMsg: function(category) {
+ this.set('errMsg', category+ " " + Em.I18n.t('hosts.combo.search.invalidCategory'));
+ },
+
+ clearErrMsg: function() {
+ this.set('errMsg', '')
+ },
+
showHideClearButton: function() {
if(visualSearch.searchQuery.toJSON().length > 0) {
$('.VS-cancel-search-box').removeClass('hide');
@@ -93,6 +267,7 @@ App.MainHostComboSearchBoxView = Em.View.extend({
setupLabelMap: function() {
var map = App.router.get('mainHostController.labelValueMap');
+ map['All'] = 'ALL';
map['Host Name'] = 'hostName';
map['IP'] = 'ip';
map['Host Status'] = 'healthClass';
@@ -171,135 +346,5 @@ App.MainHostComboSearchBoxView = Em.View.extend({
filterValue = this.get('healthStatusCategories').findProperty('healthStatus', value).filterValue;
}
return filterValue;
- },
-
- initVS: function() {
- var self = this;
- var controller = App.router.get('mainHostComboSearchBoxController');
- this.setupLabelMap();
- window.visualSearch = VS.init({
- container: $('#combo_search_box'),
- query: '',
- showFacets: true,
- delay: 1000,
- placeholder: Em.I18n.t('hosts.combo.search.placebolder'),
- unquotable: [
- 'text'
- ],
- callbacks: {
- search: function (query, searchCollection) {
- var tableView = self.get('parentView').get('parentView');
- App.db.setComboSearchQuery(tableView.get('controller.name'), query);
- var filterConditions = self.createFilterConditions(searchCollection);
- tableView.updateComboFilter(filterConditions);
- },
-
- facetMatches: function (callback) {
- self.showHideClearButton();
- var list = [
- {label: 'Host Name', category: 'Host'},
- {label: 'IP', category: 'Host'},
- {label: 'Host Status', category: 'Host'},
- {label: 'Cores', category: 'Host'},
- {label: 'RAM', category: 'Host'},
- {label: 'Stack Version', category: 'Host'},
- {label: 'Version State', category: 'Host'},
- {label: 'Rack', category: 'Host'},
- {label: 'Service', category: 'Service'}
- ];
- 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);
- }
- list = self.filterOutOneFacetOnlyOptions(list);
- // Append host components
- callback(list, {preserveOrder: true});
- },
-
- valueMatches: function (facet, searchTerm, callback) {
- self.showHideClearButton();
- var map = App.router.get('mainHostController.labelValueMap');
- var facetValue = map[facet] || facet;
- if (controller.isComponentStateFacet(facetValue)) {
- facetValue = 'componentState'
- }
- switch (facetValue) {
- case 'hostName':
- case 'ip':
- controller.getPropertySuggestions(facetValue, searchTerm).done(function() {
- 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().reject(function (item) {
- return visualSearch.searchQuery.values(facet).indexOf(item) >= 0;
- }));
- break;
- case 'version':
- 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) {
- map[App.HostStackVersion.formatStatus(status)] = status;
- return App.HostStackVersion.formatStatus(status);
- }).reject(function (item) {
- return visualSearch.searchQuery.values(facet).indexOf(item) >= 0;
- }));
- break;
- case 'healthClass':
- var category_mocks = self.healthStatusCategories;
- callback(category_mocks.slice(1).map(function (category) {
- map[category.value] = category.healthStatus;
- return category.value;
- }).reject(function (item) {
- return visualSearch.searchQuery.values(facet).indexOf(item) >= 0;
- }), {preserveOrder: true});
- break;
- case 'services':
- callback(App.Service.find().toArray().map(function (service) {
- map[App.format.role(service.get('serviceName'), true)] = service.get('serviceName');
- return App.format.role(service.get('serviceName'), true);
- }).reject(function (item) {
- return visualSearch.searchQuery.values(facet).indexOf(item) >= 0;
- }), {preserveOrder: true});
- break;
- case 'componentState':
- var list = [ "All" ];
- map['All'] = 'ALL';
- // client only have "ALL" state
- if (facet.toLowerCase().indexOf("client") == -1)
- {
- var currentComponentFacets = self.getComponentStateFacets(null, true);
- if (currentComponentFacets.length == 0) {
- list = list.concat(App.HostComponentStatus.getStatusesList()
- .reject(function(status){return status == "UPGRADE_FAILED"}) // take out 'UPGRADE_FAILED'
- .map(function (status) {
- map[App.HostComponentStatus.getTextStatus(status)] = status;
- return App.HostComponentStatus.getTextStatus(status);
- }))
- .concat([
- "Inservice",
- "Decommissioned",
- "Decommissioning",
- "RS Decommissioned",
- "Maintenance Mode On",
- "Maintenance Mode Off"
- ]);
- }
- }
- callback(list, {preserveOrder: true});
- break;
- }
- }
- }
- });
}
});
\ No newline at end of file