github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/controllers/csi/plugins/plugin/allocations.js (about)

     1  import Controller from '@ember/controller';
     2  import { inject as service } from '@ember/service';
     3  import { action, computed } from '@ember/object';
     4  import { alias, readOnly } from '@ember/object/computed';
     5  import SortableFactory from 'nomad-ui/mixins/sortable-factory';
     6  import { lazyClick } from 'nomad-ui/helpers/lazy-click';
     7  import {
     8    serialize,
     9    deserializedQueryParam as selection,
    10  } from 'nomad-ui/utils/qp-serialize';
    11  import classic from 'ember-classic-decorator';
    12  
    13  @classic
    14  export default class AllocationsController extends Controller.extend(
    15    SortableFactory(['updateTime', 'healthy'])
    16  ) {
    17    @service userSettings;
    18  
    19    queryParams = [
    20      {
    21        currentPage: 'page',
    22      },
    23      {
    24        sortProperty: 'sort',
    25      },
    26      {
    27        sortDescending: 'desc',
    28      },
    29      {
    30        qpHealth: 'healthy',
    31      },
    32      {
    33        qpType: 'type',
    34      },
    35    ];
    36  
    37    currentPage = 1;
    38    @readOnly('userSettings.pageSize') pageSize;
    39  
    40    sortProperty = 'updateTime';
    41    sortDescending = false;
    42  
    43    qpType = '';
    44    qpHealth = '';
    45  
    46    @selection('qpType') selectionType;
    47    @selection('qpHealth') selectionHealth;
    48  
    49    @computed
    50    get optionsType() {
    51      return [
    52        { key: 'controller', label: 'Controller' },
    53        { key: 'node', label: 'Node' },
    54      ];
    55    }
    56  
    57    @computed
    58    get optionsHealth() {
    59      return [
    60        { key: 'true', label: 'Healthy' },
    61        { key: 'false', label: 'Unhealthy' },
    62      ];
    63    }
    64  
    65    @computed('model.{controllers.[],nodes.[]}')
    66    get combinedAllocations() {
    67      return this.model.controllers.toArray().concat(this.model.nodes.toArray());
    68    }
    69  
    70    @computed(
    71      'combinedAllocations.[]',
    72      'model.{controllers.[],nodes.[]}',
    73      'selectionType',
    74      'selectionHealth'
    75    )
    76    get filteredAllocations() {
    77      const { selectionType: types, selectionHealth: healths } = this;
    78  
    79      // Instead of filtering the combined list, revert back to one of the two
    80      // pre-existing lists.
    81      let listToFilter = this.combinedAllocations;
    82      if (types.length === 1 && types[0] === 'controller') {
    83        listToFilter = this.model.controllers;
    84      } else if (types.length === 1 && types[0] === 'node') {
    85        listToFilter = this.model.nodes;
    86      }
    87  
    88      if (healths.length === 1 && healths[0] === 'true')
    89        return listToFilter.filterBy('healthy');
    90      if (healths.length === 1 && healths[0] === 'false')
    91        return listToFilter.filterBy('healthy', false);
    92      return listToFilter;
    93    }
    94  
    95    @alias('filteredAllocations') listToSort;
    96    @alias('listSorted') sortedAllocations;
    97  
    98    resetPagination() {
    99      if (this.currentPage != null) {
   100        this.set('currentPage', 1);
   101      }
   102    }
   103  
   104    setFacetQueryParam(queryParam, selection) {
   105      this.set(queryParam, serialize(selection));
   106    }
   107  
   108    @action
   109    gotoAllocation(allocation, event) {
   110      lazyClick([
   111        () => this.transitionToRoute('allocations.allocation', allocation),
   112        event,
   113      ]);
   114    }
   115  }