8b5b2116ec
Without this, visiting any job detail page on Nomad OSS would crash with an error like this: Error: Ember Data Request GET /v1/recommendations?job=ping%F0%9F%A5%B3&namespace=default returned a 404 Payload (text/xml) The problem was twofold. 1. The recommendation ability didn’t include anything about checking whether the feature was present. This adds a request to /v1/operator/license on application load to determine which features are present and store them in the system service. The ability now looks for 'Dynamic Application Sizing' in that feature list. 2. Second, I didn’t check permissions at all in the job-fetching or job detail templates.
101 lines
2.4 KiB
JavaScript
101 lines
2.4 KiB
JavaScript
import { inject as service } from '@ember/service';
|
|
import { next } from '@ember/runloop';
|
|
import Route from '@ember/routing/route';
|
|
import { AbortError } from '@ember-data/adapter/error';
|
|
import RSVP from 'rsvp';
|
|
import { action } from '@ember/object';
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
@classic
|
|
export default class ApplicationRoute extends Route {
|
|
@service config;
|
|
@service system;
|
|
@service store;
|
|
@service token;
|
|
|
|
queryParams = {
|
|
region: {
|
|
refreshModel: true,
|
|
},
|
|
};
|
|
|
|
resetController(controller, isExiting) {
|
|
if (isExiting) {
|
|
controller.set('error', null);
|
|
}
|
|
}
|
|
|
|
beforeModel(transition) {
|
|
const fetchSelfTokenAndPolicies = this.get('token.fetchSelfTokenAndPolicies')
|
|
.perform()
|
|
.catch();
|
|
|
|
const fetchLicense = this.get('system.fetchLicense')
|
|
.perform()
|
|
.catch();
|
|
|
|
return RSVP.all([
|
|
this.get('system.regions'),
|
|
this.get('system.defaultRegion'),
|
|
fetchLicense,
|
|
fetchSelfTokenAndPolicies,
|
|
]).then(promises => {
|
|
if (!this.get('system.shouldShowRegions')) return promises;
|
|
|
|
const queryParam = transition.to.queryParams.region;
|
|
const defaultRegion = this.get('system.defaultRegion.region');
|
|
const currentRegion = this.get('system.activeRegion') || defaultRegion;
|
|
|
|
// Only reset the store if the region actually changed
|
|
if (
|
|
(queryParam && queryParam !== currentRegion) ||
|
|
(!queryParam && currentRegion !== defaultRegion)
|
|
) {
|
|
this.system.reset();
|
|
this.store.unloadAll();
|
|
}
|
|
|
|
this.set('system.activeRegion', queryParam || defaultRegion);
|
|
|
|
return promises;
|
|
});
|
|
}
|
|
|
|
// Model is being used as a way to transfer the provided region
|
|
// query param to update the controller state.
|
|
model(params) {
|
|
return params.region;
|
|
}
|
|
|
|
setupController(controller, model) {
|
|
const queryParam = model;
|
|
|
|
if (queryParam === this.get('system.defaultRegion.region')) {
|
|
next(() => {
|
|
controller.set('region', null);
|
|
});
|
|
}
|
|
|
|
return super.setupController(...arguments);
|
|
}
|
|
|
|
@action
|
|
didTransition() {
|
|
if (!this.get('config.isTest')) {
|
|
window.scrollTo(0, 0);
|
|
}
|
|
}
|
|
|
|
@action
|
|
willTransition() {
|
|
this.controllerFor('application').set('error', null);
|
|
}
|
|
|
|
@action
|
|
error(error) {
|
|
if (!(error instanceof AbortError)) {
|
|
this.controllerFor('application').set('error', error);
|
|
}
|
|
}
|
|
}
|