github.com/hernad/nomad@v1.6.112/ui/app/controllers/jobs/job/definition.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  // @ts-check
     7  import Controller from '@ember/controller';
     8  import { action } from '@ember/object';
     9  import { alias } from '@ember/object/computed';
    10  import { inject as service } from '@ember/service';
    11  import { tracked } from '@glimmer/tracking';
    12  import classic from 'ember-classic-decorator';
    13  import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';
    14  
    15  /**
    16   * Controller for handling job definition and specification, along with editing state and view.
    17   * @augments Controller
    18   */
    19  @classic
    20  export default class DefinitionController extends Controller.extend(
    21    WithNamespaceResetting
    22  ) {
    23    @alias('model.definition') definition;
    24    @alias('model.format') format;
    25    @alias('model.job') job;
    26    @alias('model.specification') specification;
    27    @alias('model.variableFlags') variableFlags;
    28    @alias('model.variableLiteral') variableLiteral;
    29  
    30    @tracked view;
    31    @tracked isEditing = false;
    32    queryParams = ['isEditing', 'view'];
    33  
    34    @service router;
    35  
    36    /**
    37     * Get the context of the controller based on the editing state.
    38     * @returns {"edit"|"read"} The context, either 'edit' or 'read'.
    39     */
    40    get context() {
    41      return this.isEditing ? 'edit' : 'read';
    42    }
    43  
    44    /**
    45     * Toggle the editing state.
    46     * @param {boolean} [bool] - Optional boolean value to set the editing state.
    47     */
    48    @action
    49    toggleEdit(bool) {
    50      this.isEditing = bool || !this.isEditing;
    51    }
    52  
    53    /**
    54     * Update the view based on the selected view.
    55     * @param {"job-spec" | "full-definition"} selectedView - The selected view, either 'job-spec' or 'full-definition'.
    56     */
    57    @action
    58    selectView(selectedView) {
    59      this.view = selectedView;
    60    }
    61  
    62    onSubmit() {
    63      this.router.transitionTo('jobs.job', this.job.idWithNamespace);
    64    }
    65  }