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

     1  import { inject as service } from '@ember/service';
     2  import { action, computed } from '@ember/object';
     3  import { alias, readOnly } from '@ember/object/computed';
     4  import { scheduleOnce } from '@ember/runloop';
     5  import Controller, { inject as controller } from '@ember/controller';
     6  import SortableFactory from 'nomad-ui/mixins/sortable-factory';
     7  import Searchable from 'nomad-ui/mixins/searchable';
     8  import { lazyClick } from 'nomad-ui/helpers/lazy-click';
     9  import { serialize } from 'nomad-ui/utils/qp-serialize';
    10  import classic from 'ember-classic-decorator';
    11  
    12  @classic
    13  export default class IndexController extends Controller.extend(
    14    SortableFactory([
    15      'id',
    16      'schedulable',
    17      'controllersHealthyProportion',
    18      'nodesHealthyProportion',
    19      'provider',
    20    ]),
    21    Searchable
    22  ) {
    23    @service system;
    24    @service userSettings;
    25    @service keyboard;
    26    @controller('csi/volumes') volumesController;
    27  
    28    @alias('volumesController.isForbidden')
    29    isForbidden;
    30  
    31    queryParams = [
    32      {
    33        currentPage: 'page',
    34      },
    35      {
    36        searchTerm: 'search',
    37      },
    38      {
    39        sortProperty: 'sort',
    40      },
    41      {
    42        sortDescending: 'desc',
    43      },
    44      {
    45        qpNamespace: 'namespace',
    46      },
    47    ];
    48  
    49    currentPage = 1;
    50    @readOnly('userSettings.pageSize') pageSize;
    51  
    52    sortProperty = 'id';
    53    sortDescending = false;
    54  
    55    @computed
    56    get searchProps() {
    57      return ['name'];
    58    }
    59  
    60    @computed
    61    get fuzzySearchProps() {
    62      return ['name'];
    63    }
    64  
    65    fuzzySearchEnabled = true;
    66  
    67    @computed('qpNamespace', 'model.namespaces.[]')
    68    get optionsNamespaces() {
    69      const availableNamespaces = this.model.namespaces.map((namespace) => ({
    70        key: namespace.name,
    71        label: namespace.name,
    72      }));
    73  
    74      availableNamespaces.unshift({
    75        key: '*',
    76        label: 'All (*)',
    77      });
    78  
    79      // Unset the namespace selection if it was server-side deleted
    80      if (!availableNamespaces.mapBy('key').includes(this.qpNamespace)) {
    81        // eslint-disable-next-line ember/no-incorrect-calls-with-inline-anonymous-functions
    82        scheduleOnce('actions', () => {
    83          // eslint-disable-next-line ember/no-side-effects
    84          this.set('qpNamespace', '*');
    85        });
    86      }
    87  
    88      return availableNamespaces;
    89    }
    90  
    91    /**
    92      Visible volumes are those that match the selected namespace
    93    */
    94    @computed('model.volumes.@each.parent', 'system.{namespaces.length}')
    95    get visibleVolumes() {
    96      if (!this.model.volumes) return [];
    97      return this.model.volumes.compact();
    98    }
    99  
   100    @alias('visibleVolumes') listToSort;
   101    @alias('listSorted') listToSearch;
   102    @alias('listSearched') sortedVolumes;
   103  
   104    setFacetQueryParam(queryParam, selection) {
   105      this.set(queryParam, serialize(selection));
   106    }
   107  
   108    @action
   109    gotoVolume(volume, event) {
   110      lazyClick([
   111        () =>
   112          this.transitionToRoute(
   113            'csi.volumes.volume',
   114            volume.get('idWithNamespace')
   115          ),
   116        event,
   117      ]);
   118    }
   119  }