2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2017-10-10 02:00:14 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
export default class GutterMenu extends Component {
|
|
|
|
@service system;
|
|
|
|
@service router;
|
2022-08-17 16:59:33 +00:00
|
|
|
@service keyboard;
|
2017-10-10 02:00:14 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('system.namespaces.@each.name')
|
|
|
|
get sortedNamespaces() {
|
2017-10-11 17:10:27 +00:00
|
|
|
const namespaces = this.get('system.namespaces').toArray() || [];
|
|
|
|
|
|
|
|
return namespaces.sort((a, b) => {
|
|
|
|
const aName = a.get('name');
|
|
|
|
const bName = b.get('name');
|
|
|
|
|
|
|
|
// Make sure the default namespace is always first in the list
|
|
|
|
if (aName === 'default') {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (bName === 'default') {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aName < bName) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (aName > bName) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-10-11 17:10:27 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
onHamburgerClick() {}
|
2018-07-25 17:35:03 +00:00
|
|
|
|
2022-08-17 16:59:33 +00:00
|
|
|
// Seemingly redundant, but serves to ensure the action is passed to the keyboard service correctly
|
|
|
|
transitionTo(destination) {
|
|
|
|
return this.router.transitionTo(destination);
|
|
|
|
}
|
|
|
|
|
2018-07-25 21:10:51 +00:00
|
|
|
gotoJobsForNamespace(namespace) {
|
|
|
|
if (!namespace || !namespace.get('id')) return;
|
|
|
|
|
2020-05-08 04:18:55 +00:00
|
|
|
// Jobs and CSI Volumes are both namespace-sensitive. Changing namespaces is
|
|
|
|
// an intent to reset context, but where to reset to depends on where the namespace
|
|
|
|
// is being switched from. Jobs take precedence, but if the namespace is switched from
|
|
|
|
// a storage-related page, context should be reset to volumes.
|
2021-12-28 16:08:12 +00:00
|
|
|
const destination = this.router.currentRouteName.startsWith('csi.')
|
|
|
|
? 'csi.volumes'
|
|
|
|
: 'jobs';
|
2020-05-08 04:18:55 +00:00
|
|
|
|
|
|
|
this.router.transitionTo(destination, {
|
2018-07-25 21:10:51 +00:00
|
|
|
queryParams: { namespace: namespace.get('id') },
|
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|