From 6d5fe56fa1a01b30326676a3bcaf23348e647e64 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Wed, 2 Nov 2022 10:34:10 -0400 Subject: [PATCH] Job spec upload (#14747) * Job spec upload by click or drag * pseudo-restrict formats * Changelog * Tweak to job spec upload to be above editor layer * Within the job-editor again tho * Beginning testcase cleanup * Test progression * refact: update codemirror fillin logic Co-authored-by: Jai Bhagat --- .changelog/14747.txt | 3 ++ ui/app/components/job-editor.js | 11 +++++- ui/app/styles/components/codemirror.scss | 22 +++++++++++ ui/app/templates/components/job-editor.hbs | 31 ++++++--------- .../integration/components/job-editor-test.js | 38 ++----------------- ui/tests/pages/components/job-editor.js | 7 ---- 6 files changed, 50 insertions(+), 62 deletions(-) create mode 100644 .changelog/14747.txt diff --git a/.changelog/14747.txt b/.changelog/14747.txt new file mode 100644 index 000000000..bcc0207d3 --- /dev/null +++ b/.changelog/14747.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: allow users to upload files by click or drag in the web ui +``` diff --git a/ui/app/components/job-editor.js b/ui/app/components/job-editor.js index c2944e4a2..1690c7830 100644 --- a/ui/app/components/job-editor.js +++ b/ui/app/components/job-editor.js @@ -49,7 +49,6 @@ export default class JobEditor extends Component { planOutput = null; @localStorageProperty('nomadMessageJobPlan', true) showPlanMessage; - @localStorageProperty('nomadMessageJobEditor', true) showEditorMessage; @computed('planOutput') get stage() { @@ -117,4 +116,14 @@ export default class JobEditor extends Component { window.scrollTo(0, 0); } } + + @action uploadJobSpec(event) { + const reader = new FileReader(); + reader.onload = () => { + this.updateCode(reader.result); + }; + + const [file] = event.target.files; + reader.readAsText(file); + } } diff --git a/ui/app/styles/components/codemirror.scss b/ui/app/styles/components/codemirror.scss index 81c08356e..3c158074b 100644 --- a/ui/app/styles/components/codemirror.scss +++ b/ui/app/styles/components/codemirror.scss @@ -129,3 +129,25 @@ $dark-bright: lighten($dark, 15%); background-color: $dark-2; } } + +header.run-job-header { + display: grid; + grid-template-columns: 1fr auto; + margin-bottom: 2rem; + gap: 0 1rem; + & > h1 { + grid-column: -1 / 1; + } + + .job-spec-upload { + .button { + cursor: pointer; + } + input { + width: 100%; + height: 100%; + position: absolute; + display: none; + } + } +} diff --git a/ui/app/templates/components/job-editor.hbs b/ui/app/templates/components/job-editor.hbs index 50d3ea47b..7404deb67 100644 --- a/ui/app/templates/components/job-editor.hbs +++ b/ui/app/templates/components/job-editor.hbs @@ -18,26 +18,16 @@ {{/if}} {{#if (eq this.stage "editor")}} - {{#if (and this.showEditorMessage (eq this.context "new"))}} -
-
-
-

Run a Job

-

Paste or author HCL or JSON to submit - to your cluster. A plan will be requested before the job is - submitted.

-
-
- -
-
-
- {{/if}} + +
+

Run a job

+

Paste or author HCL or JSON to submit to your cluster. 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.

+ +
+
Job Definition @@ -63,6 +53,7 @@ />
+