1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | 1 1 1 2 2 2 2 2 2 3 3 3 3 3 2 3 3 8 8 8 8 8 1 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 7 7 7 1 1 2 2 2 1 1 2 2 2 3 3 2 2 1 2 1 1 3 1 1 6 6 3 3 1 1 5 1 5 15 15 6 15 1 2 3 3 3 6 6 4 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 4 4 4 4 4 4 4 2 2 2 3 3 3 1 3 1 3 3 3 1 2 1 1 3 3 3 1 2 1 3 | 'use strict'; ;require.register("views/main/host/combo_search_box", function (exports, require, module) { /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var App = require('app'); App.MainHostComboSearchBoxView = App.SearchBoxView.extend({ healthStatusCategories: require('data/host/categories'), serviceMap: {}, controllerBinding: 'App.router.mainHostComboSearchBoxController', initVS: function initVS() { 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'], remainder: 'Host Name', 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 search(query, searchCollection) { var tableView = this.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 facetMatches(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 valueMatches(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': this.searchByHostname(facetValue, searchTerm, facet, callback); break; case 'rack': this.searchByRack(facet, callback); break; case 'version': this.searchByVersion(facet, callback); break; case 'versionState': this.searchByVersionState(facet, callback, map); break; case 'healthClass': this.searchByHealthClass(facet, callback, map); break; case 'services': this.searchByServices(facet, callback); break; case 'componentState': this.searchByComponentState(facet, callback, map); break; } }, /** * * @param {string} facetValue * @param {string} searchTerm * @param {string} facet * @param {Function} callback */ searchByHostname: function searchByHostname(facetValue, searchTerm, facet, callback) { var controller = App.router.get('mainHostComboSearchBoxController'); 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 }); }); }, /** * * @param {string} facet * @param {Function} callback */ searchByRack: function searchByRack(facet, callback) { callback(App.Host.find().toArray().mapProperty('rack').uniq().reject(function (item) { return visualSearch.searchQuery.values(facet).indexOf(item) >= 0; })); }, /** * * @param {string} facet * @param {Function} callback */ searchByVersion: function searchByVersion(facet, callback) { callback(App.HostStackVersion.find().toArray().filterProperty('isVisible', true).mapProperty('displayName').uniq().reject(function (item) { return visualSearch.searchQuery.values(facet).indexOf(item) >= 0; })); }, /** * * @param {string} facet * @param {Function} callback * @param {object} map */ searchByVersionState: function searchByVersionState(facet, callback, map) { 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; })); }, /** * * @param {string} facet * @param {Function} callback * @param {object} map */ searchByHealthClass: function searchByHealthClass(facet, callback, map) { //exclude "All" category var category_mocks = this.get('healthStatusCategories').slice(1); callback(category_mocks.map(function (category) { map[category.value] = category.healthStatus; return category.value; }).reject(function (item) { return visualSearch.searchQuery.values(facet).indexOf(item) >= 0; }), { preserveOrder: true }); }, /** * * @param {string} facet * @param {Function} callback */ searchByServices: function searchByServices(facet, callback) { var serviceMap = this.get('serviceMap'); callback(App.Service.find().toArray().map(function (service) { serviceMap[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 }); }, /** * * @param {string} facet * @param {Function} callback * @param {object} map */ searchByComponentState: function searchByComponentState(facet, callback, map) { 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 }); }, getHostComponentList: function getHostComponentList() { var hostComponentList = []; App.MasterComponent.find().rejectProperty('totalCount', 0).toArray().concat(App.SlaveComponent.find().rejectProperty('totalCount', 0).toArray().concat(App.ClientComponent.find().rejectProperty('totalCount', 0).toArray())).forEach(function (component) { var displayName = component.get('displayName'); if (displayName) { hostComponentList.push({ label: displayName, category: 'Component' }); App.router.get('mainHostController.labelValueMap')[displayName] = component.get('componentName'); } }); hostComponentList = hostComponentList.sortProperty('label'); return hostComponentList; }, /** * * @param {Array} hostComponentList * @param {boolean} includeAllValue * @returns {Array} */ getComponentStateFacets: function getComponentStateFacets(hostComponentList, includeAllValue) { if (!hostComponentList) { hostComponentList = this.getHostComponentList(); } return visualSearch.searchQuery.toJSON().filter(function (facet) { var result = Boolean(hostComponentList.findProperty('label', facet.category) && facet.value); if (!includeAllValue) { result &= facet.value !== 'All'; } return result; }); }, /** * * @param {string} name * @returns {Array} */ getFacetsByName: function getFacetsByName(name) { return visualSearch.searchQuery.toJSON().filter(function (facet) { return facet.category === name; }); }, filterOutOneFacetOnlyOptions: function filterOutOneFacetOnlyOptions(options) { var self = this; var oneFacetOnlyLables = ['Cores', 'RAM']; oneFacetOnlyLables.forEach(function (label) { var facets = self.getFacetsByName(label); if (facets.length > 0) { options = options.rejectProperty('label', label); } }); return options; }, setupLabelMap: function setupLabelMap() { var map = App.router.get('mainHostController.labelValueMap'); map['All'] = 'ALL'; map['Host Name'] = 'hostName'; map['IP'] = 'ip'; map['Host Status'] = 'healthClass'; map['Cores'] = 'cpu'; map['RAM'] = 'memoryFormatted'; map['Stack Version'] = 'version'; map['Version State'] = 'versionState'; map['Rack'] = 'rack'; map['Service'] = 'services'; map['Inservice'] = 'INSERVICE'; map['Decommissioned'] = 'DECOMMISSIONED'; map['Decommissioning'] = 'DECOMMISSIONING'; map['RS Decommissioned'] = 'RS_DECOMMISSIONED'; map['Maintenance Mode On'] = 'ON'; map['Maintenance Mode Off'] = 'OFF'; }, createFilterConditions: function createFilterConditions(searchCollection) { var map = App.router.get('mainHostController.labelValueMap'); var serviceMap = this.get('serviceMap'); var filterConditions = Em.A(); searchCollection.models.forEach(function (model) { var tag = model.attributes; var category = map[tag.category] || tag.category; var value = category === 'services' ? serviceMap[tag.value] || tag.value : map[tag.value] || tag.value; var iColumn = this.getFilterColumn(category, value); var filterValue = this.getFilterValue(category, value); var condition = filterConditions.findProperty('iColumn', iColumn); if (condition) { // handle multiple facets with same category Eif (typeof condition.value === 'string') { condition.value = [condition.value, filterValue]; } else if (Em.isArray(condition.value) && condition.value.indexOf(filterValue) === -1) { condition.value.push(filterValue); } } else { filterConditions.push(this.createCondition(category, iColumn, filterValue)); } }, this); return filterConditions; }, /** * * @param {string} category * @param {number} iColumn * @param {string} filterValue * @returns {{skipFilter: boolean, iColumn: number, value: string, type: string}} */ createCondition: function createCondition(category, iColumn, filterValue) { var type = 'string'; if (category === 'cpu') { type = 'number'; } if (category === 'memoryFormatted') { type = 'ambari-bandwidth'; } return { skipFilter: false, iColumn: iColumn, value: filterValue, type: type }; }, /** * * @param {string} category * @param {string} value * @returns {number} */ getFilterColumn: function getFilterColumn(category, value) { var iColumn; if (this.get('controller').isComponentStateFacet(category)) { iColumn = App.router.get('mainHostController.colPropAssoc').indexOf('componentState'); } else if (this.get('controller').isComplexHealthStatusFacet(value)) { iColumn = this.get('healthStatusCategories').findProperty('healthStatus', value).column; } else { iColumn = App.router.get('mainHostController.colPropAssoc').indexOf(category); } return iColumn; }, /** * * @param {string} category * @param {string} value * @returns {string} */ getFilterValue: function getFilterValue(category, value) { var filterValue = value; if (this.get('controller').isComponentStateFacet(category)) { filterValue = category + ':' + value; } else if (this.get('controller').isComplexHealthStatusFacet(value)) { filterValue = this.get('healthStatusCategories').findProperty('healthStatus', value).filterValue; } return filterValue; } }); }); |