Files
nomad/ui/app/controllers/variables/variable/index.js
Phil Renaud bad23ee6b1 Link Variables to Jobs (#13627)
* Related entities scaffolded

* Added hint on edit

* Re-classic'd

* Dont create entities when path goes beyond task level

* only show the related entities hint for new vars, not edited ones

* Unit tests for pathLinkedEntities

* Acceptance tests for linked entities

* Add hint on creation

* Will be vs Is on @new boolean flag

* Link styles and namespaces on links

* Unused component class

* Delog

* Defensive shouldShowLinked

* Properly instantiating the accessibilty check test
2022-07-11 13:34:06 -04:00

76 lines
1.6 KiB
JavaScript

import Controller from '@ember/controller';
import { action } from '@ember/object';
import { task } from 'ember-concurrency';
import messageForError from '../../../utils/message-from-adapter-error';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
export default class VariablesVariableIndexController extends Controller {
queryParams = ['view'];
@service router;
@tracked
error = null;
@tracked isDeleting = false;
@action
onDeletePrompt() {
this.isDeleting = true;
}
@action
onDeleteCancel() {
this.isDeleting = false;
}
@task(function* () {
try {
yield this.model.deleteRecord();
yield this.model.save();
if (this.model.parentFolderPath) {
this.router.transitionTo('variables.path', this.model.parentFolderPath);
} else {
this.router.transitionTo('variables');
}
// TODO: alert the user that the variable was successfully deleted
} catch (err) {
this.error = {
title: 'Could Not Delete Variable',
description: messageForError(err, 'delete secure variables'),
};
}
})
deleteVariableFile;
onDismissError() {
this.error = null;
}
//#region Code View
/**
* @type {"table" | "json"}
*/
@tracked
view = 'table';
toggleView() {
if (this.view === 'table') {
this.view = 'json';
} else {
this.view = 'table';
}
}
//#endregion Code View
get shouldShowLinkedEntities() {
return (
this.model.pathLinkedEntities?.job ||
this.model.pathLinkedEntities?.group ||
this.model.pathLinkedEntities?.task
);
}
}