open-nomad/ui/app/controllers/jobs.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

import Ember from 'ember';
2017-10-23 17:29:26 +00:00
const { Controller, inject, observer, run } = Ember;
export default Controller.extend({
system: inject.service(),
queryParams: {
jobNamespace: 'namespace',
},
isForbidden: false,
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
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);
const bothAreDefault =
(currentNamespace == undefined || currentNamespace === 'default') &&
(newNamespace == undefined || newNamespace === 'default');
if (currentNamespace !== newNamespace && !bothAreDefault) {
this.set(destination, newNamespace);
2017-10-23 17:29:26 +00:00
run.next(() => {
this.send('refreshRoute');
});
}
});
}