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