github.com/hernad/nomad@v1.6.112/ui/app/components/job-page/parts/recent-allocations.js (about)

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