open-nomad/ui/app/routes/jobs/job.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.5 KiB
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import RSVP from 'rsvp';
2017-09-28 17:06:13 +00:00
import notifyError from 'nomad-ui/utils/notify-error';
import classic from 'ember-classic-decorator';
2017-09-19 14:47:10 +00:00
@classic
export default class JobRoute extends Route {
@service can;
@service store;
@service token;
@service router;
2017-09-19 14:47:10 +00:00
2017-10-23 17:27:22 +00:00
serialize(model) {
return { job_name: model.get('idWithNamespace') };
}
2017-10-23 17:27:22 +00:00
model(params) {
let name,
namespace = 'default';
const { job_name } = params;
const delimiter = job_name.lastIndexOf('@');
if (delimiter !== -1) {
name = job_name.slice(0, delimiter);
namespace = job_name.slice(delimiter + 1);
} else {
name = job_name;
}
const fullId = JSON.stringify([name, namespace]);
2019-03-26 07:46:44 +00:00
return this.store
2017-10-23 17:27:22 +00:00
.findRecord('job', fullId, { reload: true })
2021-12-28 14:45:20 +00:00
.then((job) => {
const relatedModelsQueries = [
job.get('allocations'),
job.get('evaluations'),
this.store.query('job', { namespace }),
this.store.findAll('namespace'),
];
if (this.can.can('accept recommendation')) {
relatedModelsQueries.push(job.get('recommendationSummaries'));
}
// Optimizing future node look ups by preemptively loading everything
if (job.get('hasClientStatus') && this.can.can('read client')) {
relatedModelsQueries.push(this.store.findAll('node'));
}
return RSVP.all(relatedModelsQueries).then(() => job);
2017-10-23 17:27:22 +00:00
})
2017-09-28 17:06:13 +00:00
.catch(notifyError(this));
}
}