open-consul/ui-v2/app/routes/dc/intentions/create.js
John Cowen 651c0b2c33 ui: Moves intentions listing and form into components (#7549)
Whilst we tried to do this with the smallest amount of changes possible,
our acceptance tests for trying to submit a blank form started failing
due to usage of `destroyRecord`, its seems that the correct way to
achieve the same thing is to use `rollbackAttributes` instead. We
changed that here and the tests pass once again. Furture work related to
this will involve change the rest of the UI where we use `destroyRecord`
to achieve the same thing, to use `rollbackAttributes` instead
2020-05-12 17:14:21 +00:00

49 lines
1.4 KiB
JavaScript

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { hash } from 'rsvp';
import { get } from '@ember/object';
import WithIntentionActions from 'consul-ui/mixins/intention/with-actions';
// TODO: This route and the edit Route need merging somehow
export default Route.extend(WithIntentionActions, {
templateName: 'dc/intentions/edit',
repo: service('repository/intention'),
servicesRepo: service('repository/service'),
nspacesRepo: service('repository/nspace/disabled'),
beforeModel: function() {
this.repo.invalidate();
},
model: function(params) {
const dc = this.modelFor('dc').dc.Name;
const nspace = '*';
this.item = this.repo.create({
Datacenter: dc,
});
return hash({
create: true,
isLoading: false,
item: this.item,
services: this.servicesRepo.findAllByDatacenter(dc, nspace),
nspaces: this.nspacesRepo.findAll(),
}).then(function(model) {
return {
...model,
...{
services: [{ Name: '*' }].concat(
model.services.toArray().filter(item => get(item, 'Kind') !== 'connect-proxy')
),
nspaces: [{ Name: '*' }].concat(model.nspaces.toArray()),
},
};
});
},
setupController: function(controller, model) {
controller.setProperties(model);
},
deactivate: function() {
if (get(this.item, 'isNew')) {
this.item.rollbackAttributes();
}
},
});