2020-04-08 17:03:18 +00:00
|
|
|
import Service, { inject as service } from '@ember/service';
|
|
|
|
import { setProperties } from '@ember/object';
|
|
|
|
|
|
|
|
export default Service.extend({
|
|
|
|
settings: service('settings'),
|
|
|
|
intention: service('repository/intention'),
|
|
|
|
prepare: function(sink, data, instance) {
|
|
|
|
const [, dc, nspace, model, slug] = sink.split('/');
|
|
|
|
const repo = this[model];
|
|
|
|
if (slug === '') {
|
|
|
|
instance = repo.create({
|
|
|
|
Datacenter: dc,
|
|
|
|
Namespace: nspace,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (typeof instance === 'undefined') {
|
|
|
|
instance = repo.peek(slug);
|
|
|
|
}
|
|
|
|
}
|
2020-05-01 08:49:33 +00:00
|
|
|
return setProperties(instance, data);
|
2020-04-08 17:03:18 +00:00
|
|
|
},
|
|
|
|
persist: function(sink, instance) {
|
|
|
|
const [, , , /*dc*/ /*nspace*/ model] = sink.split('/');
|
|
|
|
const repo = this[model];
|
|
|
|
return repo.persist(instance);
|
|
|
|
},
|
|
|
|
remove: function(sink, instance) {
|
|
|
|
const [, , , /*dc*/ /*nspace*/ model] = sink.split('/');
|
|
|
|
const repo = this[model];
|
|
|
|
return repo.remove(instance);
|
|
|
|
},
|
|
|
|
});
|