github.com/aminovpavel/nomad@v0.11.8/ui/app/controllers/csi/plugins/plugin/allocations.js (about) 1 import Controller from '@ember/controller'; 2 import { inject as service } from '@ember/service'; 3 import { computed } from '@ember/object'; 4 import { alias, readOnly } from '@ember/object/computed'; 5 import SortableFactory from 'nomad-ui/mixins/sortable-factory'; 6 import { lazyClick } from 'nomad-ui/helpers/lazy-click'; 7 import { serialize, deserializedQueryParam as selection } from 'nomad-ui/utils/qp-serialize'; 8 9 export default Controller.extend(SortableFactory(['updateTime', 'healthy']), { 10 userSettings: service(), 11 12 queryParams: { 13 currentPage: 'page', 14 sortProperty: 'sort', 15 sortDescending: 'desc', 16 qpHealth: 'healthy', 17 qpType: 'type', 18 }, 19 20 currentPage: 1, 21 pageSize: readOnly('userSettings.pageSize'), 22 23 sortProperty: 'updateTime', 24 sortDescending: false, 25 26 qpType: '', 27 qpHealth: '', 28 29 selectionType: selection('qpType'), 30 selectionHealth: selection('qpHealth'), 31 32 optionsType: computed(() => [ 33 { key: 'controller', label: 'Controller' }, 34 { key: 'node', label: 'Node' }, 35 ]), 36 37 optionsHealth: computed(() => [ 38 { key: 'true', label: 'Healthy' }, 39 { key: 'false', label: 'Unhealthy' }, 40 ]), 41 42 combinedAllocations: computed('model.controllers.[]', 'model.nodes.[]', function() { 43 return this.model.controllers.toArray().concat(this.model.nodes.toArray()); 44 }), 45 46 filteredAllocations: computed( 47 'combinedAllocations.[]', 48 'model.controllers.[]', 49 'model.nodes.[]', 50 'selectionType', 51 'selectionHealth', 52 function() { 53 const { selectionType: types, selectionHealth: healths } = this; 54 55 // Instead of filtering the combined list, revert back to one of the two 56 // pre-existing lists. 57 let listToFilter = this.combinedAllocations; 58 if (types.length === 1 && types[0] === 'controller') { 59 listToFilter = this.model.controllers; 60 } else if (types.length === 1 && types[0] === 'node') { 61 listToFilter = this.model.nodes; 62 } 63 64 if (healths.length === 1 && healths[0] === 'true') return listToFilter.filterBy('healthy'); 65 if (healths.length === 1 && healths[0] === 'false') 66 return listToFilter.filterBy('healthy', false); 67 return listToFilter; 68 } 69 ), 70 71 listToSort: alias('filteredAllocations'), 72 sortedAllocations: alias('listSorted'), 73 74 resetPagination() { 75 if (this.currentPage != null) { 76 this.set('currentPage', 1); 77 } 78 }, 79 80 setFacetQueryParam(queryParam, selection) { 81 this.set(queryParam, serialize(selection)); 82 }, 83 84 actions: { 85 gotoAllocation(allocation, event) { 86 lazyClick([() => this.transitionToRoute('allocations.allocation', allocation), event]); 87 }, 88 }, 89 });