github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/routes/optimize.js (about)

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