github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/routes/variables.js (about) 1 import Route from '@ember/routing/route'; 2 import { inject as service } from '@ember/service'; 3 import WithForbiddenState from 'nomad-ui/mixins/with-forbidden-state'; 4 import notifyForbidden from 'nomad-ui/utils/notify-forbidden'; 5 import PathTree from 'nomad-ui/utils/path-tree'; 6 7 export default class VariablesRoute extends Route.extend(WithForbiddenState) { 8 @service can; 9 @service router; 10 @service store; 11 12 queryParams = { 13 qpNamespace: { 14 refreshModel: true, 15 }, 16 }; 17 18 beforeModel() { 19 if (this.can.cannot('list variables')) { 20 this.router.transitionTo('/jobs'); 21 } 22 } 23 24 async model({ qpNamespace }) { 25 const namespace = qpNamespace ?? '*'; 26 try { 27 await this.store.findAll('namespace'); 28 const variables = await this.store.query( 29 'variable', 30 { namespace }, 31 { reload: true } 32 ); 33 return { 34 variables, 35 pathTree: new PathTree(variables), 36 }; 37 } catch (e) { 38 notifyForbidden(this)(e); 39 return e; 40 } 41 } 42 }