github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/ui/app/services/system.js (about) 1 import Service, { inject as service } from '@ember/service'; 2 import { computed } from '@ember/object'; 3 import PromiseObject from '../utils/classes/promise-object'; 4 import { namespace } from '../adapters/application'; 5 6 export default Service.extend({ 7 token: service(), 8 store: service(), 9 10 leader: computed(function() { 11 const token = this.get('token'); 12 13 return PromiseObject.create({ 14 promise: token 15 .authorizedRequest(`/${namespace}/status/leader`) 16 .then(res => res.json()) 17 .then(rpcAddr => ({ rpcAddr })) 18 .then(leader => { 19 // Dirty self so leader can be used as a dependent key 20 this.notifyPropertyChange('leader.rpcAddr'); 21 return leader; 22 }), 23 }); 24 }), 25 26 namespaces: computed(function() { 27 return this.get('store').findAll('namespace'); 28 }), 29 30 shouldShowNamespaces: computed('namespaces.[]', function() { 31 const namespaces = this.get('namespaces').toArray(); 32 return namespaces.length && namespaces.some(namespace => namespace.get('id') !== 'default'); 33 }), 34 35 activeNamespace: computed('namespaces.[]', { 36 get() { 37 const namespaceId = window.localStorage.nomadActiveNamespace || 'default'; 38 return this.get('namespaces').findBy('id', namespaceId); 39 }, 40 set(key, value) { 41 if (value == null) { 42 window.localStorage.removeItem('nomadActiveNamespace'); 43 } else if (typeof value === 'string') { 44 window.localStorage.nomadActiveNamespace = value; 45 return this.get('namespaces').findBy('id', value); 46 } 47 window.localStorage.nomadActiveNamespace = value.get('name'); 48 return value; 49 }, 50 }), 51 });