mirror of https://github.com/hashicorp/consul
ui: Remove unnecessay reopens from sort and form services (#9146)
parent
97b1d92c17
commit
d561d346a8
|
@ -1,46 +0,0 @@
|
||||||
import { get, set } from '@ember/object';
|
|
||||||
|
|
||||||
import kv from 'consul-ui/forms/kv';
|
|
||||||
import acl from 'consul-ui/forms/acl';
|
|
||||||
import token from 'consul-ui/forms/token';
|
|
||||||
import policy from 'consul-ui/forms/policy';
|
|
||||||
import role from 'consul-ui/forms/role';
|
|
||||||
import intention from 'consul-ui/forms/intention';
|
|
||||||
import nspace from 'consul-ui/forms/nspace';
|
|
||||||
|
|
||||||
export function initialize(application) {
|
|
||||||
// Service-less injection using private properties at a per-project level
|
|
||||||
const FormBuilder = application.resolveRegistration('service:form');
|
|
||||||
const forms = {
|
|
||||||
kv: kv,
|
|
||||||
acl: acl,
|
|
||||||
token: token,
|
|
||||||
policy: policy,
|
|
||||||
role: role,
|
|
||||||
intention: intention,
|
|
||||||
nspace: nspace,
|
|
||||||
};
|
|
||||||
FormBuilder.reopen({
|
|
||||||
form: function(name) {
|
|
||||||
let form = get(this.forms, name);
|
|
||||||
if (!form) {
|
|
||||||
form = set(this.forms, name, forms[name](this));
|
|
||||||
// only do special things for our new things for the moment
|
|
||||||
if (name === 'role' || name === 'policy') {
|
|
||||||
const repo = get(this, name);
|
|
||||||
form.clear(function(obj) {
|
|
||||||
return repo.create(obj);
|
|
||||||
});
|
|
||||||
form.submit(function(obj) {
|
|
||||||
return repo.persist(obj);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return form;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
|
||||||
initialize,
|
|
||||||
};
|
|
|
@ -1,36 +0,0 @@
|
||||||
import service from 'consul-ui/sort/comparators/service';
|
|
||||||
import serviceInstance from 'consul-ui/sort/comparators/service-instance';
|
|
||||||
import kv from 'consul-ui/sort/comparators/kv';
|
|
||||||
import check from 'consul-ui/sort/comparators/check';
|
|
||||||
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';
|
|
||||||
|
|
||||||
export function initialize(container) {
|
|
||||||
// Service-less injection using private properties at a per-project level
|
|
||||||
const Sort = container.resolveRegistration('service:sort');
|
|
||||||
const comparators = {
|
|
||||||
service: service(),
|
|
||||||
serviceInstance: serviceInstance(),
|
|
||||||
kv: kv(),
|
|
||||||
check: check(),
|
|
||||||
intention: intention(),
|
|
||||||
token: token(),
|
|
||||||
role: role(),
|
|
||||||
policy: policy(),
|
|
||||||
nspace: nspace(),
|
|
||||||
node: node(),
|
|
||||||
};
|
|
||||||
Sort.reopen({
|
|
||||||
comparator: function(type) {
|
|
||||||
return comparators[type];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
|
||||||
initialize,
|
|
||||||
};
|
|
|
@ -1,27 +1,56 @@
|
||||||
import Service, { inject as service } from '@ember/service';
|
import Service, { inject as service } from '@ember/service';
|
||||||
import builderFactory from 'consul-ui/utils/form/builder';
|
import builderFactory from 'consul-ui/utils/form/builder';
|
||||||
|
|
||||||
|
import kv from 'consul-ui/forms/kv';
|
||||||
|
import acl from 'consul-ui/forms/acl';
|
||||||
|
import token from 'consul-ui/forms/token';
|
||||||
|
import policy from 'consul-ui/forms/policy';
|
||||||
|
import role from 'consul-ui/forms/role';
|
||||||
|
import intention from 'consul-ui/forms/intention';
|
||||||
|
import nspace from 'consul-ui/forms/nspace';
|
||||||
|
|
||||||
const builder = builderFactory();
|
const builder = builderFactory();
|
||||||
|
|
||||||
|
const forms = {
|
||||||
|
kv: kv,
|
||||||
|
acl: acl,
|
||||||
|
token: token,
|
||||||
|
policy: policy,
|
||||||
|
role: role,
|
||||||
|
intention: intention,
|
||||||
|
nspace: nspace,
|
||||||
|
};
|
||||||
|
|
||||||
export default class FormService extends Service {
|
export default class FormService extends Service {
|
||||||
// a `get` method is added via the form initializer
|
// a `get` method is added via the form initializer
|
||||||
// see initializers/form.js
|
// see initializers/form.js
|
||||||
|
|
||||||
// TODO: Temporarily add these here until something else needs
|
// TODO: Temporarily add these here until something else needs
|
||||||
// dynamic repos
|
// dynamic repos
|
||||||
@service('repository/role')
|
@service('repository/role') role;
|
||||||
role;
|
@service('repository/policy') policy;
|
||||||
|
|
||||||
@service('repository/policy')
|
|
||||||
policy;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
init() {
|
forms = [];
|
||||||
super.init(...arguments);
|
|
||||||
this.forms = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
build(obj, name) {
|
build(obj, name) {
|
||||||
return builder(...arguments);
|
return builder(...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
form() {}
|
form(name) {
|
||||||
|
let form = this.forms[name];
|
||||||
|
if (typeof form === 'undefined') {
|
||||||
|
form = this.forms[name] = forms[name](this);
|
||||||
|
// only do special things for our new things for the moment
|
||||||
|
if (name === 'role' || name === 'policy') {
|
||||||
|
const repo = this[name];
|
||||||
|
form.clear(function(obj) {
|
||||||
|
return repo.create(obj);
|
||||||
|
});
|
||||||
|
form.submit(function(obj) {
|
||||||
|
return repo.persist(obj);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return form;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,29 @@
|
||||||
import Service from '@ember/service';
|
import Service from '@ember/service';
|
||||||
|
import service from 'consul-ui/sort/comparators/service';
|
||||||
|
import serviceInstance from 'consul-ui/sort/comparators/service-instance';
|
||||||
|
import kv from 'consul-ui/sort/comparators/kv';
|
||||||
|
import check from 'consul-ui/sort/comparators/check';
|
||||||
|
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';
|
||||||
|
|
||||||
|
const comparators = {
|
||||||
|
service: service(),
|
||||||
|
serviceInstance: serviceInstance(),
|
||||||
|
kv: kv(),
|
||||||
|
check: check(),
|
||||||
|
intention: intention(),
|
||||||
|
token: token(),
|
||||||
|
role: role(),
|
||||||
|
policy: policy(),
|
||||||
|
nspace: nspace(),
|
||||||
|
node: node(),
|
||||||
|
};
|
||||||
export default class SortService extends Service {
|
export default class SortService extends Service {
|
||||||
comparator(type) {}
|
comparator(type) {
|
||||||
|
return comparators[type];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue