github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/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 return super.findAll(...arguments).then((data) => { 11 data.forEach((record) => { 12 record.Namespace = 'default'; 13 }); 14 return data; 15 }); 16 } 17 18 query(store, type, { namespace }) { 19 return super.query(...arguments).then((data) => { 20 data.forEach((record) => { 21 if (!record.Namespace) record.Namespace = namespace; 22 }); 23 return data; 24 }); 25 } 26 27 findRecord(store, type, id, snapshot) { 28 const [, namespace] = JSON.parse(id); 29 const namespaceQuery = 30 namespace && namespace !== 'default' ? { namespace } : {}; 31 32 return super.findRecord(store, type, id, snapshot, namespaceQuery); 33 } 34 35 urlForFindAll() { 36 const url = super.urlForFindAll(...arguments); 37 return associateNamespace(url); 38 } 39 40 urlForQuery() { 41 const url = super.urlForQuery(...arguments); 42 return associateNamespace(url); 43 } 44 45 urlForFindRecord(id, type, hash, pathSuffix) { 46 const [name, namespace] = JSON.parse(id); 47 let url = super.urlForFindRecord(name, type, hash); 48 if (pathSuffix) url += `/${pathSuffix}`; 49 return associateNamespace(url, namespace); 50 } 51 52 xhrKey(url, method, options = {}) { 53 const plainKey = super.xhrKey(...arguments); 54 const namespace = options.data && options.data.namespace; 55 return associateNamespace(plainKey, namespace); 56 } 57 } 58 59 function associateNamespace(url, namespace) { 60 if (namespace && namespace !== 'default') { 61 url += `?namespace=${namespace}`; 62 } 63 return url; 64 }