github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/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  
    11    @computed('system.namespaces.@each.name')
    12    get sortedNamespaces() {
    13      const namespaces = this.get('system.namespaces').toArray() || [];
    14  
    15      return namespaces.sort((a, b) => {
    16        const aName = a.get('name');
    17        const bName = b.get('name');
    18  
    19        // Make sure the default namespace is always first in the list
    20        if (aName === 'default') {
    21          return -1;
    22        }
    23        if (bName === 'default') {
    24          return 1;
    25        }
    26  
    27        if (aName < bName) {
    28          return -1;
    29        }
    30        if (aName > bName) {
    31          return 1;
    32        }
    33  
    34        return 0;
    35      });
    36    }
    37  
    38    onHamburgerClick() {}
    39  
    40    gotoJobsForNamespace(namespace) {
    41      if (!namespace || !namespace.get('id')) return;
    42  
    43      // Jobs and CSI Volumes are both namespace-sensitive. Changing namespaces is
    44      // an intent to reset context, but where to reset to depends on where the namespace
    45      // is being switched from. Jobs take precedence, but if the namespace is switched from
    46      // a storage-related page, context should be reset to volumes.
    47      const destination = this.router.currentRouteName.startsWith('csi.') ? 'csi.volumes' : 'jobs';
    48  
    49      this.router.transitionTo(destination, {
    50        queryParams: { namespace: namespace.get('id') },
    51      });
    52    }
    53  }