github.com/hernad/nomad@v1.6.112/ui/app/routes/optimize.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import Route from '@ember/routing/route'; 7 import classic from 'ember-classic-decorator'; 8 import { inject as service } from '@ember/service'; 9 import { action } from '@ember/object'; 10 import { next } from '@ember/runloop'; 11 import RSVP from 'rsvp'; 12 13 @classic 14 export default class OptimizeRoute extends Route { 15 @service can; 16 @service store; 17 18 beforeModel() { 19 if (this.can.cannot('accept recommendation')) { 20 this.transitionTo('jobs'); 21 } 22 } 23 24 async model() { 25 const summaries = await this.store.findAll('recommendation-summary'); 26 const jobs = await RSVP.all(summaries.mapBy('job')); 27 const [namespaces] = await RSVP.all([ 28 this.store.findAll('namespace'), 29 ...jobs 30 .filter((job) => job) 31 .filterBy('isPartial') 32 .map((j) => j.reload()), 33 ]); 34 35 return { 36 summaries: summaries.sortBy('submitTime').reverse(), 37 namespaces, 38 }; 39 } 40 41 @action 42 reachedEnd() { 43 this.store.unloadAll('recommendation-summary'); 44 45 next(() => { 46 this.transitionTo('optimize'); 47 this.refresh(); 48 }); 49 } 50 }