github.com/hernad/nomad@v1.6.112/ui/app/controllers/csi/plugins/plugin/allocations.js (about)

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