2017-10-20 05:04:21 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2017-10-23 17:29:26 +00:00
|
|
|
const { Controller, inject, observer, run } = Ember;
|
2017-10-20 05:04:21 +00:00
|
|
|
|
|
|
|
export default Controller.extend({
|
|
|
|
system: inject.service(),
|
|
|
|
|
|
|
|
queryParams: {
|
|
|
|
jobNamespace: 'namespace',
|
|
|
|
},
|
|
|
|
|
2017-10-24 23:07:43 +00:00
|
|
|
isForbidden: false,
|
|
|
|
|
2017-10-20 05:04:21 +00:00
|
|
|
jobNamespace: 'default',
|
|
|
|
|
|
|
|
// The namespace query param should act as an alias to the system active namespace.
|
|
|
|
// But query param defaults can't be CPs: https://github.com/emberjs/ember.js/issues/9819
|
2017-10-23 23:59:30 +00:00
|
|
|
syncNamespaceService: forwardNamespace('jobNamespace', 'system.activeNamespace'),
|
|
|
|
syncNamespaceParam: forwardNamespace('system.activeNamespace', 'jobNamespace'),
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
refreshRoute() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
function forwardNamespace(source, destination) {
|
|
|
|
return observer(source, `${source}.id`, function() {
|
|
|
|
const newNamespace = this.get(`${source}.id`) || this.get(source);
|
|
|
|
const currentNamespace = this.get(`${destination}.id`) || this.get(destination);
|
2017-10-20 05:04:21 +00:00
|
|
|
const bothAreDefault =
|
|
|
|
(currentNamespace == undefined || currentNamespace === 'default') &&
|
|
|
|
(newNamespace == undefined || newNamespace === 'default');
|
|
|
|
|
|
|
|
if (currentNamespace !== newNamespace && !bothAreDefault) {
|
2017-10-23 23:59:30 +00:00
|
|
|
this.set(destination, newNamespace);
|
2017-10-23 17:29:26 +00:00
|
|
|
run.next(() => {
|
|
|
|
this.send('refreshRoute');
|
|
|
|
});
|
2017-10-20 05:04:21 +00:00
|
|
|
}
|
2017-10-23 23:59:30 +00:00
|
|
|
});
|
|
|
|
}
|