mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 22:34:55 +00:00
b025319756
* ui: Surface 'detail' of API errors in the error page * Make UI generated 404s look less bare
51 lines
1.3 KiB
JavaScript
51 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('Page not found');
|
|
e.status = '404';
|
|
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');
|
|
}
|
|
}
|