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;
|
2022-05-13 21:01:27 +00:00
|
|
|
@service router;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-10-23 17:27:22 +00:00
|
|
|
serialize(model) {
|
2022-02-16 16:42:26 +00:00
|
|
|
return { job_name: model.get('idWithNamespace') };
|
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-05-13 21:01:27 +00:00
|
|
|
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;
|
|
|
|
}
|
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'),
|
2022-11-02 20:58:24 +00:00
|
|
|
this.store.query('job', { namespace, meta: true }),
|
2021-04-29 20:00:59 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|