github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/components/job-page/parts/recent-allocations.js (about)

     1  import Component from '@ember/component';
     2  import { action, computed } from '@ember/object';
     3  import { inject as service } from '@ember/service';
     4  import PromiseArray from 'nomad-ui/utils/classes/promise-array';
     5  import { classNames } from '@ember-decorators/component';
     6  import classic from 'ember-classic-decorator';
     7  import localStorageProperty from 'nomad-ui/utils/properties/local-storage';
     8  
     9  @classic
    10  @classNames('boxed-section')
    11  export default class RecentAllocations extends Component {
    12    @service router;
    13  
    14    sortProperty = 'modifyIndex';
    15    sortDescending = true;
    16  
    17    @localStorageProperty('nomadShowSubTasks', true) showSubTasks;
    18  
    19    @action
    20    toggleShowSubTasks(e) {
    21      e.preventDefault();
    22      this.set('showSubTasks', !this.get('showSubTasks'));
    23    }
    24  
    25    @computed('job.allocations.@each.modifyIndex')
    26    get sortedAllocations() {
    27      return PromiseArray.create({
    28        promise: this.get('job.allocations').then((allocations) =>
    29          allocations.sortBy('modifyIndex').reverse().slice(0, 5)
    30        ),
    31      });
    32    }
    33  
    34    @action
    35    gotoAllocation(allocation) {
    36      this.router.transitionTo('allocations.allocation', allocation.id);
    37    }
    38  }