github.com/DerekStrickland/consul@v1.4.5/ui-v2/app/controllers/dc/intentions/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 // TODO: DRY out in acls at least 6 const createCounter = function(prop) { 7 return function(items, val) { 8 return val === '' ? get(items, 'length') : items.filterBy(prop, val).length; 9 }; 10 }; 11 const countAction = createCounter('Action'); 12 export default Controller.extend(WithFiltering, { 13 queryParams: { 14 action: { 15 as: 'action', 16 }, 17 s: { 18 as: 'filter', 19 replace: true, 20 }, 21 }, 22 actionFilters: computed('items', function() { 23 const items = get(this, 'items'); 24 return ['', 'allow', 'deny'].map(function(item) { 25 return { 26 label: `${item === '' ? 'All' : ucfirst(item)} (${countAction( 27 items, 28 item 29 ).toLocaleString()})`, 30 value: item, 31 }; 32 }); 33 }), 34 filter: function(item, { s = '', action = '' }) { 35 const source = get(item, 'SourceName').toLowerCase(); 36 const destination = get(item, 'DestinationName').toLowerCase(); 37 const sLower = s.toLowerCase(); 38 const allLabel = 'All Services (*)'.toLowerCase(); 39 return ( 40 (source.indexOf(sLower) !== -1 || 41 destination.indexOf(sLower) !== -1 || 42 (source === '*' && allLabel.indexOf(sLower) !== -1) || 43 (destination === '*' && allLabel.indexOf(sLower) !== -1)) && 44 (action === '' || get(item, 'Action') === action) 45 ); 46 }, 47 });