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

36 lines
925 B
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import EmberError from '@ember/error';
export default class TaskRoute extends Route {
@service store;
breadcrumbs(model) {
if (!model) return [];
return [
{
label: model.get('name'),
args: ['allocations.allocation.task', model.get('allocation'), model],
},
];
}
model({ name }) {
const allocation = this.modelFor('allocations.allocation');
2018-11-06 00:33:33 +00:00
// If there is no allocation, then there is no task.
// Let the allocation route handle the 404 error.
if (!allocation) return;
2018-11-06 00:33:33 +00:00
const task = allocation.get('states').findBy('name', name);
if (!task) {
const err = new EmberError(`Task ${name} not found for allocation ${allocation.get('id')}`);
err.code = '404';
this.controllerFor('application').set('error', err);
}
2018-11-06 00:33:33 +00:00
return task;
}
}