github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/adapters/watchable-namespace-ids.js (about) 1 import { inject as service } from '@ember/service'; 2 import Watchable from './watchable'; 3 import classic from 'ember-classic-decorator'; 4 5 @classic 6 export default class WatchableNamespaceIDs extends Watchable { 7 @service system; 8 9 findAll() { 10 const namespace = this.get('system.activeNamespace'); 11 return super.findAll(...arguments).then(data => { 12 data.forEach(record => { 13 record.Namespace = namespace ? namespace.get('id') : 'default'; 14 }); 15 return data; 16 }); 17 } 18 19 findRecord(store, type, id, snapshot) { 20 const [, namespace] = JSON.parse(id); 21 const namespaceQuery = namespace && namespace !== 'default' ? { namespace } : {}; 22 23 return super.findRecord(store, type, id, snapshot, namespaceQuery); 24 } 25 26 urlForFindAll() { 27 const url = super.urlForFindAll(...arguments); 28 const namespace = this.get('system.activeNamespace.id'); 29 return associateNamespace(url, namespace); 30 } 31 32 urlForQuery() { 33 const url = super.urlForQuery(...arguments); 34 const namespace = this.get('system.activeNamespace.id'); 35 return associateNamespace(url, namespace); 36 } 37 38 urlForFindRecord(id, type, hash, pathSuffix) { 39 const [name, namespace] = JSON.parse(id); 40 let url = super.urlForFindRecord(name, type, hash); 41 if (pathSuffix) url += `/${pathSuffix}`; 42 return associateNamespace(url, namespace); 43 } 44 45 xhrKey(url, method, options = {}) { 46 const plainKey = super.xhrKey(...arguments); 47 const namespace = options.data && options.data.namespace; 48 return associateNamespace(plainKey, namespace); 49 } 50 } 51 52 function associateNamespace(url, namespace) { 53 if (namespace && namespace !== 'default') { 54 url += `?namespace=${namespace}`; 55 } 56 return url; 57 }