2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-17 18:52:14 +00:00
|
|
|
import Route from '@ember/routing/route';
|
|
|
|
import { inject as service } from '@ember/service';
|
2022-05-30 17:10:44 +00:00
|
|
|
import WithForbiddenState from 'nomad-ui/mixins/with-forbidden-state';
|
2022-08-15 15:56:09 +00:00
|
|
|
import notifyForbidden from 'nomad-ui/utils/notify-forbidden';
|
2022-06-07 01:42:23 +00:00
|
|
|
import PathTree from 'nomad-ui/utils/path-tree';
|
2022-05-17 18:52:14 +00:00
|
|
|
|
2022-05-30 17:10:44 +00:00
|
|
|
export default class VariablesRoute extends Route.extend(WithForbiddenState) {
|
2022-05-17 18:52:14 +00:00
|
|
|
@service can;
|
|
|
|
@service router;
|
2022-06-07 01:42:23 +00:00
|
|
|
@service store;
|
2022-05-17 18:52:14 +00:00
|
|
|
|
2022-07-22 20:05:35 +00:00
|
|
|
queryParams = {
|
|
|
|
qpNamespace: {
|
|
|
|
refreshModel: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-05-17 18:52:14 +00:00
|
|
|
beforeModel() {
|
|
|
|
if (this.can.cannot('list variables')) {
|
|
|
|
this.router.transitionTo('/jobs');
|
|
|
|
}
|
|
|
|
}
|
2022-07-22 20:05:35 +00:00
|
|
|
|
|
|
|
async model({ qpNamespace }) {
|
|
|
|
const namespace = qpNamespace ?? '*';
|
2022-06-07 01:42:23 +00:00
|
|
|
try {
|
2022-07-22 20:05:35 +00:00
|
|
|
await this.store.findAll('namespace');
|
|
|
|
const variables = await this.store.query(
|
|
|
|
'variable',
|
|
|
|
{ namespace },
|
|
|
|
{ reload: true }
|
|
|
|
);
|
2022-06-07 01:42:23 +00:00
|
|
|
return {
|
|
|
|
variables,
|
|
|
|
pathTree: new PathTree(variables),
|
|
|
|
};
|
|
|
|
} catch (e) {
|
2022-08-15 15:56:09 +00:00
|
|
|
notifyForbidden(this)(e);
|
|
|
|
return e;
|
2022-06-07 01:42:23 +00:00
|
|
|
}
|
2022-05-17 18:52:14 +00:00
|
|
|
}
|
|
|
|
}
|