2019-12-17 18:47:37 +00:00
|
|
|
import Helper from '@ember/component/helper';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { hrefTo } from 'consul-ui/helpers/href-to';
|
|
|
|
|
|
|
|
const getRouteParams = function(route, params = {}) {
|
|
|
|
return route.paramNames.map(function(item) {
|
|
|
|
if (typeof params[item] !== 'undefined') {
|
|
|
|
return params[item];
|
|
|
|
}
|
|
|
|
return route.params[item];
|
|
|
|
});
|
|
|
|
};
|
|
|
|
export default Helper.extend({
|
|
|
|
router: service('router'),
|
|
|
|
compute([params], hash) {
|
|
|
|
let current = this.router.currentRoute;
|
|
|
|
let parent;
|
|
|
|
let atts = getRouteParams(current, params);
|
|
|
|
// walk up the entire route/s replacing any instances
|
|
|
|
// of the specified params with the values specified
|
|
|
|
while ((parent = current.parent)) {
|
|
|
|
atts = atts.concat(getRouteParams(parent, params));
|
|
|
|
current = parent;
|
|
|
|
}
|
2020-03-09 09:10:47 +00:00
|
|
|
let route = this.router.currentRoute.name;
|
2019-12-17 18:47:37 +00:00
|
|
|
// TODO: this is specific to consul/nspaces
|
|
|
|
// 'ideally' we could try and do this elsewhere
|
|
|
|
// not super important though.
|
|
|
|
// This will turn an URL that has no nspace (/ui/dc-1/nodes) into one
|
|
|
|
// that does have a namespace (/ui/~nspace/dc-1/nodes) if you href-mut with
|
|
|
|
// a nspace parameter
|
2019-12-18 18:27:54 +00:00
|
|
|
if (typeof params.nspace !== 'undefined' && route.startsWith('dc.')) {
|
2019-12-17 18:47:37 +00:00
|
|
|
route = `nspace.${route}`;
|
|
|
|
atts.push(params.nspace);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
return hrefTo(this, this.router, [route, ...atts.reverse()], hash);
|
|
|
|
},
|
|
|
|
});
|