8cb402eae7
* Add uri identifiers to all data source things and make them the same 1. Add uri identitifer to data-source service 2. Make <EventSource /> and <DataSource /> as close as possible 3. Add extra `.closed` method to get a list of inactive/closed/closing data-sources from elsewhere * Make the connections cleanup the least worst connection when required * Pass the uri/request id through all the things * Better user erroring * Make event sources close on error * Allow <DataLoader /> data slot to be configurable * Allow the <DataWriter /> removed state to be configurable * Don't error if meta is undefined * Stitch together all the repositories into the data-source/sink * Use data.source over repositories * Add missing <EventSource /> components * Fix up the views/templates * Disable all the old route based blocking query things * We still need the repo for the mixin for the moment * Don't default to default, default != ''
82 lines
2.5 KiB
JavaScript
82 lines
2.5 KiB
JavaScript
import { inject as service } from '@ember/service';
|
|
import { get } from '@ember/object';
|
|
import { env } from 'consul-ui/env';
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/nspace';
|
|
|
|
const modelName = 'nspace';
|
|
export default RepositoryService.extend({
|
|
router: service('router'),
|
|
settings: service('settings'),
|
|
getPrimaryKey: function() {
|
|
return PRIMARY_KEY;
|
|
},
|
|
getSlugKey: function() {
|
|
return SLUG_KEY;
|
|
},
|
|
getModelName: function() {
|
|
return modelName;
|
|
},
|
|
findAll: function(configuration = {}) {
|
|
const query = {};
|
|
if (typeof configuration.cursor !== 'undefined') {
|
|
query.index = configuration.cursor;
|
|
query.uri = configuration.uri;
|
|
}
|
|
return this.store.query(this.getModelName(), query);
|
|
},
|
|
authorize: function(dc, nspace) {
|
|
if (!env('CONSUL_ACLS_ENABLED')) {
|
|
return Promise.resolve([
|
|
{
|
|
Resource: 'operator',
|
|
Access: 'write',
|
|
Allow: true,
|
|
},
|
|
]);
|
|
}
|
|
return this.store.authorize(this.getModelName(), { dc: dc, ns: nspace }).catch(function(e) {
|
|
return [];
|
|
});
|
|
},
|
|
getActive: function() {
|
|
let routeParams = {};
|
|
// this is only populated before the model hook as fired,
|
|
// it is then deleted after the model hook has finished
|
|
const infos = get(this, 'router._router.currentState.router.activeTransition.routeInfos');
|
|
if (typeof infos !== 'undefined') {
|
|
infos.forEach(function(item) {
|
|
Object.keys(item.params).forEach(function(prop) {
|
|
routeParams[prop] = item.params[prop];
|
|
});
|
|
});
|
|
} else {
|
|
// this is only populated after the model hook has finished
|
|
//
|
|
const current = get(this, 'router.currentRoute');
|
|
if (current) {
|
|
const nspacedRoute = current.find(function(item, i, arr) {
|
|
return item.paramNames.includes('nspace');
|
|
});
|
|
if (typeof nspacedRoute !== 'undefined') {
|
|
routeParams.nspace = nspacedRoute.params.nspace;
|
|
}
|
|
}
|
|
}
|
|
return this.settings
|
|
.findBySlug('nspace')
|
|
.then(function(nspace) {
|
|
// If we can't figure out the nspace from the URL use
|
|
// the previously saved nspace and if thats not there
|
|
// then just use default
|
|
return routeParams.nspace || nspace || '~default';
|
|
})
|
|
.then(nspace => this.settings.persist({ nspace: nspace }))
|
|
.then(function(item) {
|
|
return {
|
|
Name: item.nspace.substr(1),
|
|
};
|
|
});
|
|
},
|
|
});
|