open-nomad/ui/app/routes/jobs/job/task-group.js
Buck Doyle 89136cbf6a Add massaged results of class codemod
Manual interventions:
• decorators on the same line for service and controller
  injections and most computed property macros
• preserving import order when possible, both per-line
  and intra-line
• moving new imports to the bottom
• removal of classic decorator for trivial cases
• conversion of init to constructor when appropriate
2020-06-10 16:18:42 -05:00

71 lines
2.2 KiB
JavaScript

import Route from '@ember/routing/route';
import { collect } from '@ember/object/computed';
import EmberError from '@ember/error';
import { resolve } from 'rsvp';
import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';
import { qpBuilder } from 'nomad-ui/utils/classes/query-params';
import notifyError from 'nomad-ui/utils/notify-error';
export default class TaskGroupRoute extends Route.extend(WithWatchers) {
breadcrumbs(model) {
if (!model) return [];
return [
{
label: model.get('name'),
args: [
'jobs.job.task-group',
model.get('job'),
model.get('name'),
qpBuilder({ jobNamespace: model.get('job.namespace.name') || 'default' }),
],
},
];
}
model({ name }) {
const job = this.modelFor('jobs.job');
// If there is no job, then there is no task group.
// Let the job route handle the 404.
if (!job) return;
// If the job is a partial (from the list request) it won't have task
// groups. Reload the job to ensure task groups are present.
const reload = job.get('isPartial') ? job.reload() : resolve();
return reload
.then(() => {
const taskGroup = job.get('taskGroups').findBy('name', name);
if (!taskGroup) {
const err = new EmberError(`Task group ${name} for job ${job.get('name')} not found`);
err.code = '404';
throw err;
}
// Refresh job allocations before-hand (so page sort works on load)
return job
.hasMany('allocations')
.reload()
.then(() => taskGroup);
})
.catch(notifyError(this));
}
startWatchers(controller, model) {
if (model) {
const job = model.get('job');
controller.set('watchers', {
job: this.watchJob.perform(job),
summary: this.watchSummary.perform(job.get('summary')),
allocations: this.watchAllocations.perform(job),
});
}
}
@watchRecord('job') watchJob;
@watchRecord('job-summary') watchSummary;
@watchRelationship('allocations') watchAllocations;
@collect('watchJob', 'watchSummary', 'watchAllocations') watchers;
}