github.com/hernad/nomad@v1.6.112/ui/app/routes/variables.js (about)

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