2018-05-22 15:03:45 +00:00
|
|
|
import Controller from '@ember/controller';
|
|
|
|
import { computed, get } from '@ember/object';
|
|
|
|
import WithFiltering from 'consul-ui/mixins/with-filtering';
|
|
|
|
import ucfirst from 'consul-ui/utils/ucfirst';
|
|
|
|
import numeral from 'numeral';
|
|
|
|
// TODO: DRY out in acls at least
|
|
|
|
const createCounter = function(prop) {
|
|
|
|
return function(items, val) {
|
|
|
|
return val === '' ? get(items, 'length') : items.filterBy(prop, val).length;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const countAction = createCounter('Action');
|
|
|
|
export default Controller.extend(WithFiltering, {
|
|
|
|
queryParams: {
|
|
|
|
action: {
|
|
|
|
as: 'action',
|
|
|
|
},
|
|
|
|
s: {
|
|
|
|
as: 'filter',
|
|
|
|
replace: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
actionFilters: computed('items', function() {
|
|
|
|
const items = get(this, 'items');
|
|
|
|
return ['', 'allow', 'deny'].map(function(item) {
|
|
|
|
return {
|
|
|
|
label: `${item === '' ? 'All' : ucfirst(item)} (${numeral(
|
|
|
|
countAction(items, item)
|
|
|
|
).format()})`,
|
|
|
|
value: item,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
filter: function(item, { s = '', action = '' }) {
|
2018-06-22 13:29:18 +00:00
|
|
|
const source = get(item, 'SourceName').toLowerCase();
|
|
|
|
const destination = get(item, 'DestinationName').toLowerCase();
|
|
|
|
const sLower = s.toLowerCase();
|
|
|
|
const allLabel = 'All Services (*)'.toLowerCase();
|
2018-05-22 15:03:45 +00:00
|
|
|
return (
|
2018-06-22 13:29:18 +00:00
|
|
|
(source.indexOf(sLower) !== -1 ||
|
|
|
|
destination.indexOf(sLower) !== -1 ||
|
|
|
|
(source === '*' && allLabel.indexOf(sLower) !== -1) ||
|
|
|
|
(destination === '*' && allLabel.indexOf(sLower) !== -1)) &&
|
2018-05-22 15:03:45 +00:00
|
|
|
(action === '' || get(item, 'Action') === action)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|