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

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import Controller from '@ember/controller';
     7  import { set, action } from '@ember/object';
     8  import { task } from 'ember-concurrency';
     9  import { inject as service } from '@ember/service';
    10  import { tracked } from '@glimmer/tracking';
    11  
    12  export default class VariablesVariableIndexController extends Controller {
    13    queryParams = ['view'];
    14  
    15    @service router;
    16    queryParams = ['sortProperty', 'sortDescending'];
    17  
    18    @tracked sortProperty = 'key';
    19    @tracked sortDescending = true;
    20  
    21    @service notifications;
    22  
    23    get sortedKeyValues() {
    24      const sorted = this.model.keyValues.sortBy(this.sortProperty);
    25      return this.sortDescending ? sorted : sorted.reverse();
    26    }
    27  
    28    @tracked isDeleting = false;
    29  
    30    @action
    31    onDeletePrompt() {
    32      this.isDeleting = true;
    33    }
    34  
    35    @action
    36    onDeleteCancel() {
    37      this.isDeleting = false;
    38    }
    39  
    40    @task(function* () {
    41      try {
    42        yield this.model.deleteRecord();
    43        yield this.model.save();
    44        if (this.model.parentFolderPath) {
    45          this.router.transitionTo('variables.path', this.model.parentFolderPath);
    46        } else {
    47          this.router.transitionTo('variables');
    48        }
    49        this.notifications.add({
    50          title: 'Variable deleted',
    51          message: `${this.model.path} successfully deleted`,
    52          color: 'success',
    53        });
    54      } catch (err) {
    55        this.notifications.add({
    56          title: `Error deleting ${this.model.path}`,
    57          message: err,
    58          color: 'critical',
    59          sticky: true,
    60        });
    61      }
    62    })
    63    deleteVariableFile;
    64  
    65    //#region Code View
    66    /**
    67     * @type {"table" | "json"}
    68     */
    69    @tracked
    70    view = 'table';
    71  
    72    toggleView() {
    73      if (this.view === 'table') {
    74        this.view = 'json';
    75      } else {
    76        this.view = 'table';
    77      }
    78    }
    79    //#endregion Code View
    80  
    81    get shouldShowLinkedEntities() {
    82      return (
    83        this.model.pathLinkedEntities?.job ||
    84        this.model.pathLinkedEntities?.group ||
    85        this.model.pathLinkedEntities?.task ||
    86        this.model.path === 'nomad/jobs'
    87      );
    88    }
    89  
    90    toggleRowVisibility(kv) {
    91      set(kv, 'isVisible', !kv.isVisible);
    92    }
    93  }