2020-06-03 16:07:49 +00:00
|
|
|
import Service from '@ember/service';
|
2020-11-10 14:36:27 +00:00
|
|
|
import service from 'consul-ui/sort/comparators/service';
|
|
|
|
import serviceInstance from 'consul-ui/sort/comparators/service-instance';
|
2020-11-12 18:45:11 +00:00
|
|
|
import upstreamInstance from 'consul-ui/sort/comparators/upstream-instance';
|
2020-12-02 09:16:55 +00:00
|
|
|
import acl from 'consul-ui/sort/comparators/acl';
|
2020-11-10 14:36:27 +00:00
|
|
|
import kv from 'consul-ui/sort/comparators/kv';
|
2020-12-07 09:14:30 +00:00
|
|
|
import healthCheck from 'consul-ui/sort/comparators/health-check';
|
2020-11-10 14:36:27 +00:00
|
|
|
import intention from 'consul-ui/sort/comparators/intention';
|
|
|
|
import token from 'consul-ui/sort/comparators/token';
|
|
|
|
import role from 'consul-ui/sort/comparators/role';
|
|
|
|
import policy from 'consul-ui/sort/comparators/policy';
|
|
|
|
import nspace from 'consul-ui/sort/comparators/nspace';
|
|
|
|
import node from 'consul-ui/sort/comparators/node';
|
|
|
|
|
2020-11-19 16:06:39 +00:00
|
|
|
// returns an array of Property:asc, Property:desc etc etc
|
|
|
|
const directionify = arr => {
|
|
|
|
return arr.reduce((prev, item) => prev.concat([`${item}:asc`, `${item}:desc`]), []);
|
|
|
|
};
|
|
|
|
// Specify a list of sortable properties, when called with a property
|
|
|
|
// returns an array ready to be passed to ember @sort
|
|
|
|
// properties(['Potential', 'Sortable', 'Properties'])('Sortable:asc') => ['Sortable:asc']
|
2020-12-02 09:16:55 +00:00
|
|
|
export const properties = (props = []) => key => {
|
2020-11-19 16:06:39 +00:00
|
|
|
const comparables = directionify(props);
|
|
|
|
return [comparables.find(item => item === key) || comparables[0]];
|
|
|
|
};
|
|
|
|
const options = {
|
|
|
|
properties,
|
|
|
|
directionify,
|
|
|
|
};
|
2020-11-10 14:36:27 +00:00
|
|
|
const comparators = {
|
2020-11-19 16:06:39 +00:00
|
|
|
service: service(options),
|
2020-12-02 09:16:55 +00:00
|
|
|
['service-instance']: serviceInstance(options),
|
2020-11-19 16:06:39 +00:00
|
|
|
['upstream-instance']: upstreamInstance(options),
|
2020-12-07 09:14:30 +00:00
|
|
|
['health-check']: healthCheck(options),
|
2020-12-02 09:16:55 +00:00
|
|
|
acl: acl(options),
|
2020-11-19 16:06:39 +00:00
|
|
|
kv: kv(options),
|
|
|
|
intention: intention(options),
|
|
|
|
token: token(options),
|
|
|
|
role: role(options),
|
|
|
|
policy: policy(options),
|
|
|
|
nspace: nspace(options),
|
|
|
|
node: node(options),
|
2020-11-10 14:36:27 +00:00
|
|
|
};
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class SortService extends Service {
|
2020-11-10 14:36:27 +00:00
|
|
|
comparator(type) {
|
|
|
|
return comparators[type];
|
|
|
|
}
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|