github.com/hernad/nomad@v1.6.112/ui/app/controllers/jobs/run/templates/template.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 { inject as service } from '@ember/service';
     8  import { action } from '@ember/object';
     9  import { tracked } from '@glimmer/tracking';
    10  import { task } from 'ember-concurrency';
    11  
    12  export default class JobsRunTemplatesController extends Controller {
    13    @service notifications;
    14    @service router;
    15    @service system;
    16  
    17    @tracked formModalActive = false;
    18  
    19    @action
    20    updateKeyValue(key, value) {
    21      if (this.model.keyValues.find((kv) => kv.key === key)) {
    22        this.model.keyValues.find((kv) => kv.key === key).value = value;
    23      } else {
    24        this.model.keyValues.pushObject({ key, value });
    25      }
    26    }
    27  
    28    @action
    29    toggleModal() {
    30      this.formModalActive = !this.formModalActive;
    31    }
    32  
    33    @action
    34    async save(e, overwrite = false) {
    35      if (e.type === 'submit') {
    36        e.preventDefault();
    37      }
    38  
    39      try {
    40        await this.model.save({ adapterOptions: { overwrite } });
    41  
    42        this.notifications.add({
    43          title: 'Job template saved',
    44          message: `${this.model.path} successfully editted`,
    45          color: 'success',
    46        });
    47  
    48        this.router.transitionTo('jobs.run.templates');
    49      } catch (e) {
    50        this.notifications.add({
    51          title: 'Job template cannot be editted.',
    52          message: e,
    53          color: 'critical',
    54        });
    55      }
    56    }
    57  
    58    @task(function* () {
    59      try {
    60        yield this.model.destroyRecord();
    61  
    62        this.notifications.add({
    63          title: 'Job template deleted',
    64          message: `${this.model.path} successfully deleted`,
    65          color: 'success',
    66        });
    67        this.router.transitionTo('jobs.run.templates.manage');
    68      } catch (err) {
    69        this.notifications.add({
    70          title: `Job template could not be deleted.`,
    71          message: err,
    72          color: 'critical',
    73          sticky: true,
    74        });
    75      }
    76    })
    77    deleteTemplate;
    78  }