2019-05-01 18:09:29 +00:00
|
|
|
import Service, { inject as service } from '@ember/service';
|
2018-10-19 15:17:02 +00:00
|
|
|
import builderFactory from 'consul-ui/utils/form/builder';
|
2020-11-10 14:36:27 +00:00
|
|
|
|
|
|
|
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';
|
|
|
|
|
2018-10-19 15:17:02 +00:00
|
|
|
const builder = builderFactory();
|
2020-11-10 14:36:27 +00:00
|
|
|
|
|
|
|
const forms = {
|
|
|
|
kv: kv,
|
|
|
|
acl: acl,
|
|
|
|
token: token,
|
|
|
|
policy: policy,
|
|
|
|
role: role,
|
|
|
|
intention: intention,
|
|
|
|
nspace: nspace,
|
|
|
|
};
|
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class FormService extends Service {
|
2018-10-19 15:17:02 +00:00
|
|
|
// a `get` method is added via the form initializer
|
|
|
|
// see initializers/form.js
|
2019-05-01 18:09:29 +00:00
|
|
|
|
|
|
|
// TODO: Temporarily add these here until something else needs
|
|
|
|
// dynamic repos
|
2020-11-10 14:36:27 +00:00
|
|
|
@service('repository/role') role;
|
|
|
|
@service('repository/policy') policy;
|
2019-05-01 18:09:29 +00:00
|
|
|
//
|
2020-11-10 14:36:27 +00:00
|
|
|
forms = [];
|
2020-11-09 09:25:35 +00:00
|
|
|
|
|
|
|
build(obj, name) {
|
2018-10-19 15:17:02 +00:00
|
|
|
return builder(...arguments);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 14:36:27 +00:00
|
|
|
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;
|
|
|
|
}
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|