2017-12-15 21:39:18 +00:00
|
|
|
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';
|
2020-06-22 15:48:53 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-22 15:48:53 +00:00
|
|
|
@classic
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class JobRoute extends Route {
|
2020-11-06 14:21:38 +00:00
|
|
|
@service can;
|
2020-06-10 13:49:16 +00:00
|
|
|
@service store;
|
|
|
|
@service token;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-10-23 17:27:22 +00:00
|
|
|
serialize(model) {
|
2022-01-14 15:11:22 +00:00
|
|
|
return { job_name: JSON.parse(model.get('id')).join('@') };
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-10-23 17:27:22 +00:00
|
|
|
|
2022-02-10 15:55:32 +00:00
|
|
|
model(params) {
|
2022-02-16 14:03:02 +00:00
|
|
|
const [name, namespace = 'default'] = params.job_name.split('@');
|
2022-02-10 15:55:32 +00:00
|
|
|
|
2022-02-16 14:03:02 +00:00
|
|
|
const fullId = JSON.stringify([name, namespace]);
|
2021-12-13 15:29:25 +00:00
|
|
|
|
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) => {
|
2020-11-06 14:21:38 +00:00
|
|
|
const relatedModelsQueries = [
|
2020-10-29 12:46:42 +00:00
|
|
|
job.get('allocations'),
|
|
|
|
job.get('evaluations'),
|
2021-04-29 20:00:59 +00:00
|
|
|
this.store.query('job', { namespace }),
|
|
|
|
this.store.findAll('namespace'),
|
2020-11-06 14:21:38 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if (this.can.can('accept recommendation')) {
|
|
|
|
relatedModelsQueries.push(job.get('recommendationSummaries'));
|
|
|
|
}
|
|
|
|
|
2022-01-05 17:43:51 +00:00
|
|
|
// Optimizing future node look ups by preemptively loading everything
|
|
|
|
if (job.get('hasClientStatus') && this.can.can('read client')) {
|
|
|
|
relatedModelsQueries.push(this.store.findAll('node'));
|
|
|
|
}
|
|
|
|
|
2020-11-06 14:21:38 +00:00
|
|
|
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));
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|