open-consul/ui-v2/app/controllers/dc/intentions/index.js
John Cowen 96ea5b799a WIP: First draft intentions
1. Listing, filtering by action and searching by source name and
destination name
2. Edit/Create page, edits ping the API double fine, need to work through
creates and deletes
3. Currently uses a `Precedence` intention keyname that doesn't yet
exist in the real API
2018-06-25 12:25:14 -07:00

46 lines
1.3 KiB
JavaScript

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 = '' }) {
return (
(get(item, 'SourceName')
.toLowerCase()
.indexOf(s.toLowerCase()) !== -1 ||
get(item, 'DestinationName')
.toLowerCase()
.indexOf(s.toLowerCase()) !== -1) &&
(action === '' || get(item, 'Action') === action)
);
},
});