2019-12-17 18:47:37 +00:00
|
|
|
import Route from '@ember/routing/route';
|
2020-01-21 17:52:40 +00:00
|
|
|
import { env } from 'consul-ui/env';
|
2019-12-17 18:47:37 +00:00
|
|
|
|
|
|
|
import { routes } from 'consul-ui/router';
|
|
|
|
import flat from 'flat';
|
|
|
|
|
|
|
|
let initialize = function() {};
|
|
|
|
Route.reopen(
|
|
|
|
['modelFor', 'transitionTo', 'replaceWith', 'paramsFor'].reduce(function(prev, item) {
|
|
|
|
prev[item] = function(routeName, ...rest) {
|
|
|
|
const isNspaced = this.routeName.startsWith('nspace.');
|
|
|
|
if (routeName === 'nspace') {
|
|
|
|
if (isNspaced || this.routeName === 'nspace') {
|
|
|
|
return this._super(...arguments);
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
nspace: '~',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isNspaced && routeName.startsWith('dc')) {
|
|
|
|
return this._super(...[`nspace.${routeName}`, ...rest]);
|
|
|
|
}
|
|
|
|
return this._super(...arguments);
|
|
|
|
};
|
|
|
|
return prev;
|
|
|
|
}, {})
|
|
|
|
);
|
2020-01-21 17:52:40 +00:00
|
|
|
if (env('CONSUL_NSPACES_ENABLED')) {
|
2019-12-17 18:47:37 +00:00
|
|
|
const dotRe = /\./g;
|
|
|
|
initialize = function(container) {
|
2020-04-08 09:56:36 +00:00
|
|
|
const register = function(route, path) {
|
|
|
|
route.reopen({
|
|
|
|
templateName: path
|
|
|
|
.replace('/root-create', '/create')
|
|
|
|
.replace('/create', '/edit')
|
|
|
|
.replace('/folder', '/index'),
|
|
|
|
});
|
|
|
|
container.register(`route:nspace/${path}`, route);
|
|
|
|
const controller = container.resolveRegistration(`controller:${path}`);
|
|
|
|
if (controller) {
|
|
|
|
container.register(`controller:nspace/${path}`, controller);
|
|
|
|
}
|
|
|
|
};
|
2019-12-17 18:47:37 +00:00
|
|
|
const all = Object.keys(flat(routes))
|
|
|
|
.filter(function(item) {
|
|
|
|
return item.startsWith('dc');
|
|
|
|
})
|
|
|
|
.map(function(item) {
|
|
|
|
return item.replace('._options.path', '').replace(dotRe, '/');
|
|
|
|
});
|
|
|
|
all.forEach(function(item) {
|
|
|
|
let route = container.resolveRegistration(`route:${item}`);
|
2020-04-08 09:56:36 +00:00
|
|
|
let indexed;
|
|
|
|
// if the route doesn't exist it probably has an index route instead
|
2019-12-17 18:47:37 +00:00
|
|
|
if (!route) {
|
|
|
|
item = `${item}/index`;
|
|
|
|
route = container.resolveRegistration(`route:${item}`);
|
2020-04-08 09:56:36 +00:00
|
|
|
} else {
|
|
|
|
// if the route does exists
|
|
|
|
// then check to see if it also has an index route
|
|
|
|
indexed = `${item}/index`;
|
|
|
|
const index = container.resolveRegistration(`route:${indexed}`);
|
|
|
|
if (typeof index !== 'undefined') {
|
|
|
|
register(index, indexed);
|
|
|
|
}
|
2019-12-17 18:47:37 +00:00
|
|
|
}
|
2020-04-08 09:56:36 +00:00
|
|
|
register(route, item);
|
2019-12-17 18:47:37 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
export default {
|
|
|
|
initialize,
|
|
|
|
};
|