open-nomad/ui/app/routes/optimize.js
Buck Doyle 20ec481090
Add DAS subroute and copy button (#9201)
This continues iteration on the DAS UI by adding the ability to directly
navigate to a recommendation summary by (namespaced) slug and a copy
button for the direct navigation link.

It includes a change to CopyButton allowing it to take a block that’s
rendered within the button.

It also changes some instances of multi-relationship traversal to use
in-summary attributes, such as summary.jobNamespace instead of
summary.job.namespace.name.
2020-11-04 12:22:24 -06:00

48 lines
1 KiB
JavaScript

import Route from '@ember/routing/route';
import classic from 'ember-classic-decorator';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { next } from '@ember/runloop';
import RSVP from 'rsvp';
@classic
export default class OptimizeRoute extends Route {
@service can;
breadcrumbs = [
{
label: 'Recommendations',
args: ['optimize'],
},
];
beforeModel() {
if (this.can.cannot('accept recommendation')) {
this.transitionTo('jobs');
}
}
async model() {
const summaries = await this.store.findAll('recommendation-summary');
const jobs = await RSVP.all(summaries.mapBy('job'));
await RSVP.all(
jobs
.filter(job => job)
.filterBy('isPartial')
.map(j => j.reload())
);
return summaries.sortBy('submitTime').reverse();
}
@action
reachedEnd() {
this.store.unloadAll('recommendation-summary');
next(() => {
this.transitionTo('optimize');
this.refresh();
});
}
}