github.com/DerekStrickland/consul@v1.4.5/ui-v2/app/controllers/dc/acls/index.js (about) 1 import Controller from '@ember/controller'; 2 import { computed, get } from '@ember/object'; 3 import WithFiltering from 'consul-ui/mixins/with-filtering'; 4 import ucfirst from 'consul-ui/utils/ucfirst'; 5 const countType = function(items, type) { 6 return type === '' ? get(items, 'length') : items.filterBy('Type', type).length; 7 }; 8 export default Controller.extend(WithFiltering, { 9 queryParams: { 10 type: { 11 as: 'type', 12 }, 13 s: { 14 as: 'filter', 15 replace: true, 16 }, 17 }, 18 typeFilters: computed('items', function() { 19 const items = get(this, 'items'); 20 return ['', 'management', 'client'].map(function(item) { 21 return { 22 label: `${item === '' ? 'All' : ucfirst(item)} (${countType( 23 items, 24 item 25 ).toLocaleString()})`, 26 value: item, 27 }; 28 }); 29 }), 30 filter: function(item, { s = '', type = '' }) { 31 const sLower = s.toLowerCase(); 32 return ( 33 (get(item, 'Name') 34 .toLowerCase() 35 .indexOf(sLower) !== -1 || 36 get(item, 'ID') 37 .toLowerCase() 38 .indexOf(sLower) !== -1) && 39 (type === '' || get(item, 'Type') === type) 40 ); 41 }, 42 actions: { 43 sendClone: function(item) { 44 this.send('clone', item); 45 }, 46 }, 47 });