mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Custom alpha sort with default always on top
This commit is contained in:
@@ -1,9 +1,35 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
const { Component, inject } = Ember;
|
||||
const { Component, inject, computed } = Ember;
|
||||
|
||||
export default Component.extend({
|
||||
system: inject.service(),
|
||||
|
||||
sortedNamespaces: computed('system.namespaces.@each.name', function() {
|
||||
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;
|
||||
});
|
||||
}),
|
||||
|
||||
onNamespaceChange() {},
|
||||
});
|
||||
|
||||
@@ -9,14 +9,16 @@
|
||||
<li>
|
||||
<div class="menu-item">
|
||||
{{#power-select
|
||||
options=system.namespaces
|
||||
options=sortedNamespaces
|
||||
selected=system.activeNamespace
|
||||
searchField="name"
|
||||
searchEnabled=(gt system.namespaces.length 10)
|
||||
searchEnabled=(gt sortedNamespaces.length 10)
|
||||
onchange=(action (queue
|
||||
(action (mut system.activeNamespace))
|
||||
(action onNamespaceChange)
|
||||
))
|
||||
tagName="div"
|
||||
class="namespace-switcher"
|
||||
as |namespace|}}
|
||||
{{#if (eq namespace.name "default")}}
|
||||
Default Namespace
|
||||
|
||||
Reference in New Issue
Block a user