ui: Remove unnecessay reopens from sort and form services (#9146)

This commit is contained in:
John Cowen 2020-11-10 14:36:27 +00:00 committed by GitHub
parent 97b1d92c17
commit d561d346a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 94 deletions

View File

@ -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,
};

View File

@ -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,
};

View File

@ -1,27 +1,56 @@
import Service, { inject as service } from '@ember/service';
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 forms = {
kv: kv,
acl: acl,
token: token,
policy: policy,
role: role,
intention: intention,
nspace: nspace,
};
export default class FormService extends Service {
// a `get` method is added via the form initializer
// see initializers/form.js
// TODO: Temporarily add these here until something else needs
// dynamic repos
@service('repository/role')
role;
@service('repository/policy')
policy;
@service('repository/role') role;
@service('repository/policy') policy;
//
init() {
super.init(...arguments);
this.forms = [];
}
forms = [];
build(obj, name) {
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;
}
}

View File

@ -1,4 +1,29 @@
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 {
comparator(type) {}
comparator(type) {
return comparators[type];
}
}