consul/ui-v2/app/services/intentions.js
John Cowen b38e5df630 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

49 lines
1.3 KiB
JavaScript

import Service, { inject as service } from '@ember/service';
import { get, set } from '@ember/object';
import { typeOf } from '@ember/utils';
import { PRIMARY_KEY } from 'consul-ui/models/intention';
export default Service.extend({
store: service('store'),
findAllByDatacenter: function(dc) {
return get(this, 'store')
.query('intention', { dc: dc })
.then(function(items) {
return items.forEach(function(item, i, arr) {
set(item, 'Datacenter', dc);
});
});
},
findBySlug: function(slug, dc) {
return get(this, 'store')
.queryRecord('intention', {
id: slug,
dc: dc,
})
.then(function(item) {
set(item, 'Datacenter', dc);
return item;
});
},
create: function() {
return get(this, 'store').createRecord('intention');
},
persist: function(item) {
return item.save();
},
remove: function(obj) {
let item = obj;
if (typeof obj.destroyRecord === 'undefined') {
item = obj.get('data');
}
if (typeOf(item) === 'object') {
item = get(this, 'store').peekRecord('intention', item[PRIMARY_KEY]);
}
return item.destroyRecord().then(item => {
return get(this, 'store').unloadRecord(item);
});
},
invalidate: function() {
return get(this, 'store').unloadAll('intention');
},
});