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