93f41278b1
This is incredibly tricky with query params, since there is a bundle of timing issues, lifecycle issues, missing features, and all around gotchas with query params. This solution has no observers and no instances of the system service being set from the jobs controller. The upside to this is no observers, much easier to follow logic, no more dependent key chain reactions.
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
import { inject as service } from '@ember/service';
|
|
import { next } from '@ember/runloop';
|
|
import Route from '@ember/routing/route';
|
|
import WithForbiddenState from 'nomad-ui/mixins/with-forbidden-state';
|
|
import notifyForbidden from 'nomad-ui/utils/notify-forbidden';
|
|
|
|
export default Route.extend(WithForbiddenState, {
|
|
system: service(),
|
|
store: service(),
|
|
|
|
breadcrumbs: [
|
|
{
|
|
label: 'Jobs',
|
|
args: ['jobs.index'],
|
|
},
|
|
],
|
|
|
|
queryParams: {
|
|
jobNamespace: {
|
|
refreshModel: true,
|
|
},
|
|
},
|
|
|
|
afterSetup(fn) {
|
|
this._afterSetups || (this._afterSetups = []);
|
|
this._afterSetups.push(fn);
|
|
},
|
|
|
|
beforeModel(transition) {
|
|
return this.get('system.namespaces').then(namespaces => {
|
|
const queryParam = transition.queryParams.namespace;
|
|
const activeNamespace = this.get('system.activeNamespace.id');
|
|
|
|
if (!queryParam && activeNamespace !== 'default') {
|
|
this.afterSetup(controller => {
|
|
controller.set('jobNamespace', activeNamespace);
|
|
});
|
|
} else if (queryParam && queryParam !== activeNamespace) {
|
|
this.set('system.activeNamespace', queryParam);
|
|
}
|
|
|
|
return namespaces;
|
|
});
|
|
},
|
|
|
|
setupController(controller) {
|
|
next(() => {
|
|
(this._afterSetups || []).forEach(fn => {
|
|
fn(controller);
|
|
});
|
|
this._afterSetups = [];
|
|
});
|
|
return this._super(...arguments);
|
|
},
|
|
|
|
model() {
|
|
return this.get('store')
|
|
.findAll('job', { reload: true })
|
|
.catch(notifyForbidden(this));
|
|
},
|
|
|
|
actions: {
|
|
refreshRoute() {
|
|
this.refresh();
|
|
},
|
|
},
|
|
});
|