github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/components/gutter-menu.js (about)

     1  import { inject as service } from '@ember/service';
     2  import Component from '@ember/component';
     3  import { computed } from '@ember/object';
     4  import classic from 'ember-classic-decorator';
     5  
     6  @classic
     7  export default class GutterMenu extends Component {
     8    @service system;
     9    @service router;
    10    @service keyboard;
    11  
    12    @computed('system.namespaces.@each.name')
    13    get sortedNamespaces() {
    14      const namespaces = this.get('system.namespaces').toArray() || [];
    15  
    16      return namespaces.sort((a, b) => {
    17        const aName = a.get('name');
    18        const bName = b.get('name');
    19  
    20        // Make sure the default namespace is always first in the list
    21        if (aName === 'default') {
    22          return -1;
    23        }
    24        if (bName === 'default') {
    25          return 1;
    26        }
    27  
    28        if (aName < bName) {
    29          return -1;
    30        }
    31        if (aName > bName) {
    32          return 1;
    33        }
    34  
    35        return 0;
    36      });
    37    }
    38  
    39    onHamburgerClick() {}
    40  
    41    // Seemingly redundant, but serves to ensure the action is passed to the keyboard service correctly
    42    transitionTo(destination) {
    43      return this.router.transitionTo(destination);
    44    }
    45  
    46    gotoJobsForNamespace(namespace) {
    47      if (!namespace || !namespace.get('id')) return;
    48  
    49      // Jobs and CSI Volumes are both namespace-sensitive. Changing namespaces is
    50      // an intent to reset context, but where to reset to depends on where the namespace
    51      // is being switched from. Jobs take precedence, but if the namespace is switched from
    52      // a storage-related page, context should be reset to volumes.
    53      const destination = this.router.currentRouteName.startsWith('csi.')
    54        ? 'csi.volumes'
    55        : 'jobs';
    56  
    57      this.router.transitionTo(destination, {
    58        queryParams: { namespace: namespace.get('id') },
    59      });
    60    }
    61  }