github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/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 { action, 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 import classic from 'ember-classic-decorator'; 9 10 @classic 11 export default class AllocationsController extends Controller.extend( 12 SortableFactory(['updateTime', 'healthy']) 13 ) { 14 @service userSettings; 15 16 queryParams = [ 17 { 18 currentPage: 'page', 19 }, 20 { 21 sortProperty: 'sort', 22 }, 23 { 24 sortDescending: 'desc', 25 }, 26 { 27 qpHealth: 'healthy', 28 }, 29 { 30 qpType: 'type', 31 }, 32 ]; 33 34 currentPage = 1; 35 @readOnly('userSettings.pageSize') pageSize; 36 37 sortProperty = 'updateTime'; 38 sortDescending = false; 39 40 qpType = ''; 41 qpHealth = ''; 42 43 @selection('qpType') selectionType; 44 @selection('qpHealth') selectionHealth; 45 46 @computed 47 get optionsType() { 48 return [{ key: 'controller', label: 'Controller' }, { key: 'node', label: 'Node' }]; 49 } 50 51 @computed 52 get optionsHealth() { 53 return [{ key: 'true', label: 'Healthy' }, { key: 'false', label: 'Unhealthy' }]; 54 } 55 56 @computed('model.{controllers.[],nodes.[]}') 57 get combinedAllocations() { 58 return this.model.controllers.toArray().concat(this.model.nodes.toArray()); 59 } 60 61 @computed( 62 'combinedAllocations.[]', 63 'model.{controllers.[],nodes.[]}', 64 'selectionType', 65 'selectionHealth' 66 ) 67 get filteredAllocations() { 68 const { selectionType: types, selectionHealth: healths } = this; 69 70 // Instead of filtering the combined list, revert back to one of the two 71 // pre-existing lists. 72 let listToFilter = this.combinedAllocations; 73 if (types.length === 1 && types[0] === 'controller') { 74 listToFilter = this.model.controllers; 75 } else if (types.length === 1 && types[0] === 'node') { 76 listToFilter = this.model.nodes; 77 } 78 79 if (healths.length === 1 && healths[0] === 'true') return listToFilter.filterBy('healthy'); 80 if (healths.length === 1 && healths[0] === 'false') 81 return listToFilter.filterBy('healthy', false); 82 return listToFilter; 83 } 84 85 @alias('filteredAllocations') listToSort; 86 @alias('listSorted') sortedAllocations; 87 88 resetPagination() { 89 if (this.currentPage != null) { 90 this.set('currentPage', 1); 91 } 92 } 93 94 setFacetQueryParam(queryParam, selection) { 95 this.set(queryParam, serialize(selection)); 96 } 97 98 @action 99 gotoAllocation(allocation, event) { 100 lazyClick([() => this.transitionToRoute('allocations.allocation', allocation), event]); 101 } 102 }