91383269b9
This sounds a bit 'backwards' as the end goal here is to add an improved UX to partitions, not namespaces. The reason for doing it this way is that Namespaces already has a type of 'improved UX' CRUD in that it has one to many relationship in the form when saving your namespaces (the end goal for partitions). In moving Namespaces to use the same approach as partitions we: - Ensure the new approach works with one-to-many forms. - Test the new approach without writing a single test (we already have a bunch of tests for namespaces which are now testing the approach used by both namespaces and partitions) Additionally: - Fixes issue with missing default nspace in the nspace selector - In doing when checking to see that things where consistent between the two, I found a few little minor problems with the Admin Partition CRUD so fixed those up here also. - Removed the old style Nspace notifications
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import Service, { inject as service } from '@ember/service';
|
|
import builderFactory from 'consul-ui/utils/form/builder';
|
|
|
|
import kv from 'consul-ui/forms/kv';
|
|
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';
|
|
|
|
const builder = builderFactory();
|
|
|
|
const forms = {
|
|
kv: kv,
|
|
token: token,
|
|
policy: policy,
|
|
role: role,
|
|
intention: intention,
|
|
};
|
|
|
|
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;
|
|
//
|
|
forms = [];
|
|
|
|
build(obj, name) {
|
|
return builder(...arguments);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|