open-nomad/ui/app/routes/allocations/allocation.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

import Route from '@ember/routing/route';
import { collect } from '@ember/object/computed';
import { watchRecord } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';
import notifyError from 'nomad-ui/utils/notify-error';
import { qpBuilder } from 'nomad-ui/utils/classes/query-params';
import { jobCrumbs } from 'nomad-ui/utils/breadcrumb-utils';
2017-09-28 17:59:59 +00:00
export default class AllocationRoute extends Route.extend(WithWatchers) {
startWatchers(controller, model) {
2018-11-06 00:33:33 +00:00
if (model) {
2019-03-26 07:46:44 +00:00
controller.set('watcher', this.watch.perform(model));
2018-11-06 00:33:33 +00:00
}
}
// Allocation breadcrumbs extend from job / task group breadcrumbs
// even though the route structure does not.
breadcrumbs(model) {
2018-10-17 19:55:00 +00:00
const jobQueryParams = qpBuilder({
jobNamespace: model.get('job.namespace.name') || 'default',
});
return [
2018-10-17 19:55:00 +00:00
{ label: 'Jobs', args: ['jobs.index', jobQueryParams] },
...jobCrumbs(model.get('job')),
{
label: model.get('taskGroupName'),
args: [
'jobs.job.task-group',
2018-10-17 19:55:00 +00:00
model.get('job.plainId'),
model.get('taskGroupName'),
2018-10-17 19:55:00 +00:00
jobQueryParams,
],
},
{
label: model.get('shortId'),
args: ['allocations.allocation', model],
},
];
}
model() {
// Preload the job for the allocation since it's required for the breadcrumb trail
return super
.model(...arguments)
.then(allocation => allocation.get('job').then(() => allocation))
.catch(notifyError(this));
}
@watchRecord('allocation') watch;
@collect('watch') watchers;
}