From 90832d9640136b510442969251ef53449a9c73d0 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Tue, 27 Jun 2023 13:27:56 -0400 Subject: [PATCH 1/4] Move buttons over as expected --- ui/app/styles/components/codemirror.scss | 5 +++ ui/app/templates/components/job-editor.hbs | 22 ++++++++++ .../templates/components/job-editor/edit.hbs | 40 +++++-------------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/ui/app/styles/components/codemirror.scss b/ui/app/styles/components/codemirror.scss index ac752e16bc0..e2605bb6821 100644 --- a/ui/app/styles/components/codemirror.scss +++ b/ui/app/styles/components/codemirror.scss @@ -140,6 +140,7 @@ header.run-job-header { grid-template-columns: 1fr auto; margin-bottom: 2rem; gap: 0 1rem; + align-items: end; & > h1 { grid-column: -1 / 1; } @@ -166,6 +167,10 @@ header.run-job-header { bottom: 0; background: white; padding: 0.5rem 0; + + &.pull-left { + justify-content: flex-start; + } } } diff --git a/ui/app/templates/components/job-editor.hbs b/ui/app/templates/components/job-editor.hbs index 7b3498a6506..cb22d2f8f69 100644 --- a/ui/app/templates/components/job-editor.hbs +++ b/ui/app/templates/components/job-editor.hbs @@ -15,6 +15,28 @@

Paste or author HCL or JSON to submit to your cluster, or select from a list of templates. A plan will be requested before the job is submitted. You can also attach a job spec by uploading a job file or dragging & dropping a file to the editor.

+ + {{#if (can "write variable" path="*" namespace="*")}} + + + + + {{/if}} + {{/if}} {{did-update this.setDefinitionOnModel this.definition}} diff --git a/ui/app/templates/components/job-editor/edit.hbs b/ui/app/templates/components/job-editor/edit.hbs index 2a42cb1ebcc..31c90343eb6 100644 --- a/ui/app/templates/components/job-editor/edit.hbs +++ b/ui/app/templates/components/job-editor/edit.hbs @@ -83,7 +83,7 @@ {{/if}} -
+ {{#if @data.job.isNew}} - - - {{#if (can "write variable" path="*" namespace="*")}} - - - {{/if}} - + {{/if}} -
\ No newline at end of file + From 5169c9d315df24e5ca2cde402f71c429f6745abc Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Tue, 27 Jun 2023 13:51:11 -0400 Subject: [PATCH 2/4] Let a user download file locally --- ui/app/components/job-editor.js | 38 +++++++++++++++++++ .../templates/components/job-editor/edit.hbs | 6 +++ 2 files changed, 44 insertions(+) diff --git a/ui/app/components/job-editor.js b/ui/app/components/job-editor.js index 980b9e9bba6..c03b4666ee1 100644 --- a/ui/app/components/job-editor.js +++ b/ui/app/components/job-editor.js @@ -21,6 +21,7 @@ import { tracked } from '@glimmer/tracking'; export default class JobEditor extends Component { @service config; @service store; + @service notifications; @tracked error = null; @tracked planOutput = null; @@ -199,6 +200,42 @@ export default class JobEditor extends Component { reader.readAsText(file); } + /** + * Download the job's definition or specification as .nomad.hcl file locally + */ + @action + async handleSaveAsFile() { + try { + const blob = new Blob([this.args.job._newDefinition], { + type: 'text/plain', + }); + const url = window.URL.createObjectURL(blob); + const downloadAnchor = document.createElement('a'); + + downloadAnchor.href = url; + downloadAnchor.target = '_blank'; + downloadAnchor.rel = 'noopener noreferrer'; + downloadAnchor.download = 'jobspec.nomad.hcl'; + + downloadAnchor.click(); + downloadAnchor.remove(); + + window.URL.revokeObjectURL(url); + this.notifications.add({ + title: 'jobspec.nomad.hcl has been downloaded', + color: 'success', + icon: 'download', + }); + } catch (err) { + this.notifications.add({ + title: 'Error downloading file', + message: err.message, + color: 'critical', + sticky: true, + }); + } + } + /** * Get the definition or specification based on the view type. * @@ -253,6 +290,7 @@ export default class JobEditor extends Component { onPlan: this.plan, onReset: this.reset, onSaveAs: this.args.handleSaveAsTemplate, + onSaveFile: this.handleSaveAsFile, onSubmit: this.submit, onSelect: this.args.onSelect, onUpdate: this.updateCode, diff --git a/ui/app/templates/components/job-editor/edit.hbs b/ui/app/templates/components/job-editor/edit.hbs index 31c90343eb6..cdcab2af55b 100644 --- a/ui/app/templates/components/job-editor/edit.hbs +++ b/ui/app/templates/components/job-editor/edit.hbs @@ -99,4 +99,10 @@ data-test-save-as-template /> {{/if}} + From bb3cce8ac0fb12bb4846ebd8b9a6de7ea932a656 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Wed, 28 Jun 2023 11:01:28 -0400 Subject: [PATCH 3/4] test mock fns for jobeditor --- ui/tests/integration/components/job-editor-test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui/tests/integration/components/job-editor-test.js b/ui/tests/integration/components/job-editor-test.js index 18d817f8ad0..0d084e49837 100644 --- a/ui/tests/integration/components/job-editor-test.js +++ b/ui/tests/integration/components/job-editor-test.js @@ -85,6 +85,7 @@ module('Integration | Component | job-editor', function (hooks) { @job={{job}} @context={{context}} @onSubmit={{onSubmit}} + @handleSaveAsTemplate={{handleSaveAsTemplate}} /> `; @@ -92,6 +93,7 @@ module('Integration | Component | job-editor', function (hooks) { component.setProperties({ job, onSubmit: sinon.spy(), + handleSaveAsTemplate: sinon.spy(), context: 'new', }); await component.render(commonTemplate); From 0641f88e074e6ffbd7397566906ab3a7ddf99378 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Wed, 28 Jun 2023 15:52:26 -0400 Subject: [PATCH 4/4] Changelog --- .changelog/17752.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/17752.txt diff --git a/.changelog/17752.txt b/.changelog/17752.txt new file mode 100644 index 00000000000..227f7427984 --- /dev/null +++ b/.changelog/17752.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: Adds a Download as .nomad.hcl button to jobspec editing in the UI +```