John Cowen 97b645a745 ui: Run Ember native class code mod (#9093)
* ui: Apply native class codemod to all services

* ui: Apply native class codemod to routes

* ui: Apply native class codemod to controllers

* Fix up ember proxy `content` issue

* Add a CreateTime on policy creation

* Minor formatting

* Convert child based saving to use ec instead of custom approach

* Remove custom event source repo wrapping initializer

* Repos here are no longer proxy objects revert to using them normally

* Remove areas of code that were used to set up source backed repos
2020-11-09 09:26:20 +00:00

52 lines
1.3 KiB
JavaScript

import { inject as service } from '@ember/service';
import RepositoryService from 'consul-ui/services/repository';
import { get } from '@ember/object';
import Error from '@ember/error';
const modelName = 'dc';
export default class DcService extends RepositoryService {
@service('settings')
settings;
getModelName() {
return modelName;
}
findAll() {
return this.store.query(this.getModelName(), {});
}
findBySlug(name, items) {
if (name != null) {
const item = items.findBy('Name', name);
if (item) {
return this.settings.persist({ dc: get(item, 'Name') }).then(function() {
// TODO: create a model
return { Name: get(item, 'Name') };
});
}
}
const e = new Error();
e.status = '404';
e.detail = 'Page not found';
return Promise.reject({ errors: [e] });
}
getActive(name, items) {
const settings = this.settings;
return Promise.all([name || settings.findBySlug('dc'), items || this.findAll()]).then(
([name, items]) => {
return this.findBySlug(name, items).catch(function() {
const item = get(items, 'firstObject');
settings.persist({ dc: get(item, 'Name') });
return item;
});
}
);
}
clearActive() {
return this.settings.delete('dc');
}
}