open-consul/ui-v2/app/mixins/intention/with-actions.js
John Cowen 96ea5b799a WIP: First draft intentions
1. Listing, filtering by action and searching by source name and
destination name
2. Edit/Create page, edits ping the API double fine, need to work through
creates and deletes
3. Currently uses a `Precedence` intention keyname that doesn't yet
exist in the real API
2018-06-25 12:25:14 -07:00

60 lines
1.7 KiB
JavaScript

import Mixin from '@ember/object/mixin';
import { get } from '@ember/object';
import WithFeedback from 'consul-ui/mixins/with-feedback';
export default Mixin.create(WithFeedback, {
actions: {
create: function(item) {
get(this, 'feedback').execute(
() => {
return get(this, 'repo')
.persist(item)
.then(item => {
return this.transitionTo('dc.intentions');
});
},
`Your intention has been added.`,
`There was an error adding your intention.`
);
},
update: function(item) {
get(this, 'feedback').execute(
() => {
return get(this, 'repo')
.persist(item)
.then(() => {
return this.transitionTo('dc.intentions');
});
},
`Your intention was saved.`,
`There was an error saving your intention.`
);
},
delete: function(item) {
get(this, 'feedback').execute(
() => {
return (
get(this, 'repo')
// ember-changeset doesn't support `get`
// and `data` returns an object not a model
.remove(item)
.then(() => {
switch (this.routeName) {
case 'dc.intentions.index':
return this.refresh();
default:
return this.transitionTo('dc.intentions');
}
})
);
},
`Your intention was deleted.`,
`There was an error deleting your intention.`
);
},
cancel: function(item) {
this.transitionTo('dc.intentions');
},
},
});