github.com/hernad/nomad@v1.6.112/ui/app/controllers/csi/volumes/index.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { inject as service } from '@ember/service'; 7 import { action, computed } from '@ember/object'; 8 import { alias, readOnly } from '@ember/object/computed'; 9 import { scheduleOnce } from '@ember/runloop'; 10 import Controller, { inject as controller } from '@ember/controller'; 11 import SortableFactory from 'nomad-ui/mixins/sortable-factory'; 12 import Searchable from 'nomad-ui/mixins/searchable'; 13 import { lazyClick } from 'nomad-ui/helpers/lazy-click'; 14 import { serialize } from 'nomad-ui/utils/qp-serialize'; 15 import classic from 'ember-classic-decorator'; 16 17 @classic 18 export default class IndexController extends Controller.extend( 19 SortableFactory([ 20 'id', 21 'schedulable', 22 'controllersHealthyProportion', 23 'nodesHealthyProportion', 24 'provider', 25 ]), 26 Searchable 27 ) { 28 @service system; 29 @service userSettings; 30 @service keyboard; 31 @controller('csi/volumes') volumesController; 32 33 @alias('volumesController.isForbidden') 34 isForbidden; 35 36 queryParams = [ 37 { 38 currentPage: 'page', 39 }, 40 { 41 searchTerm: 'search', 42 }, 43 { 44 sortProperty: 'sort', 45 }, 46 { 47 sortDescending: 'desc', 48 }, 49 { 50 qpNamespace: 'namespace', 51 }, 52 ]; 53 54 currentPage = 1; 55 @readOnly('userSettings.pageSize') pageSize; 56 57 sortProperty = 'id'; 58 sortDescending = false; 59 60 @computed 61 get searchProps() { 62 return ['name']; 63 } 64 65 @computed 66 get fuzzySearchProps() { 67 return ['name']; 68 } 69 70 fuzzySearchEnabled = true; 71 72 @computed('qpNamespace', 'model.namespaces.[]') 73 get optionsNamespaces() { 74 const availableNamespaces = this.model.namespaces.map((namespace) => ({ 75 key: namespace.name, 76 label: namespace.name, 77 })); 78 79 availableNamespaces.unshift({ 80 key: '*', 81 label: 'All (*)', 82 }); 83 84 // Unset the namespace selection if it was server-side deleted 85 if (!availableNamespaces.mapBy('key').includes(this.qpNamespace)) { 86 // eslint-disable-next-line ember/no-incorrect-calls-with-inline-anonymous-functions 87 scheduleOnce('actions', () => { 88 // eslint-disable-next-line ember/no-side-effects 89 this.set('qpNamespace', '*'); 90 }); 91 } 92 93 return availableNamespaces; 94 } 95 96 /** 97 Visible volumes are those that match the selected namespace 98 */ 99 @computed('model.volumes.@each.parent', 'system.{namespaces.length}') 100 get visibleVolumes() { 101 if (!this.model.volumes) return []; 102 return this.model.volumes.compact(); 103 } 104 105 @alias('visibleVolumes') listToSort; 106 @alias('listSorted') listToSearch; 107 @alias('listSearched') sortedVolumes; 108 109 setFacetQueryParam(queryParam, selection) { 110 this.set(queryParam, serialize(selection)); 111 } 112 113 @action 114 gotoVolume(volume, event) { 115 lazyClick([ 116 () => 117 this.transitionToRoute( 118 'csi.volumes.volume', 119 volume.get('idWithNamespace') 120 ), 121 event, 122 ]); 123 } 124 }