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"))}} -
Paste or author HCL or JSON to submit - to your cluster. A plan will be requested before the job is - submitted.
-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.
+ +