github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/ui/app/controllers/allocations/allocation/index.js (about)

     1  import Controller from '@ember/controller';
     2  import { inject as service } from '@ember/service';
     3  import { computed, observer } from '@ember/object';
     4  import { alias } from '@ember/object/computed';
     5  import { task } from 'ember-concurrency';
     6  import Sortable from 'nomad-ui/mixins/sortable';
     7  import { lazyClick } from 'nomad-ui/helpers/lazy-click';
     8  import { watchRecord } from 'nomad-ui/utils/properties/watch';
     9  
    10  export default Controller.extend(Sortable, {
    11    token: service(),
    12  
    13    queryParams: {
    14      sortProperty: 'sort',
    15      sortDescending: 'desc',
    16    },
    17  
    18    sortProperty: 'name',
    19    sortDescending: false,
    20  
    21    listToSort: alias('model.states'),
    22    sortedStates: alias('listSorted'),
    23  
    24    // Set in the route
    25    preempter: null,
    26  
    27    error: computed(() => {
    28      // { title, description }
    29      return null;
    30    }),
    31  
    32    onDismiss() {
    33      this.set('error', null);
    34    },
    35  
    36    watchNext: watchRecord('allocation'),
    37  
    38    observeWatchNext: observer('model.nextAllocation.clientStatus', function() {
    39      const nextAllocation = this.model.nextAllocation;
    40      if (nextAllocation && nextAllocation.content) {
    41        this.watchNext.perform(nextAllocation);
    42      } else {
    43        this.watchNext.cancelAll();
    44      }
    45    }),
    46  
    47    stopAllocation: task(function*() {
    48      try {
    49        yield this.model.stop();
    50        // Eagerly update the allocation clientStatus to avoid flickering
    51        this.model.set('clientStatus', 'complete');
    52      } catch (err) {
    53        this.set('error', {
    54          title: 'Could Not Stop Allocation',
    55          description: 'Your ACL token does not grant allocation lifecycle permissions.',
    56        });
    57      }
    58    }),
    59  
    60    restartAllocation: task(function*() {
    61      try {
    62        yield this.model.restart();
    63      } catch (err) {
    64        this.set('error', {
    65          title: 'Could Not Restart Allocation',
    66          description: 'Your ACL token does not grant allocation lifecycle permissions.',
    67        });
    68      }
    69    }),
    70  
    71    actions: {
    72      gotoTask(allocation, task) {
    73        this.transitionToRoute('allocations.allocation.task', task);
    74      },
    75  
    76      taskClick(allocation, task, event) {
    77        lazyClick([() => this.send('gotoTask', allocation, task), event]);
    78      },
    79    },
    80  });