open-nomad/ui/app/templates/components/job-editor.hbs
Phil Renaud c8455d34d4 Edit Secure Variables as JSON (#13461)
* Toying with insert and update helpers before translation func

* Working prototype that lets you switch between json and tabular

* No longer add the bonus items row in json mode

* Trimmed the ivy from the codemirror (#13503)

* Trimmed the ivy from the codemirror

* editedJSONItems removal

* De-debugger

* Replaced other instances of IvyCodeMirror throughout the app (#13528)

* Replaced other instances of IvyCodeMirror throughout the app

* PR requests for codemirror modifier

* Screen reader setting as param

* Trying a simpler codemirror test helper

* Lint removal

* Screen Reader Label added for a11y

* JSONViewer cleanup

* JSON editor added to /new and all variables stringified before save or translate

* Give users a foothold when editing an empty item in JSON mode

* Copy the empty KV

* No duplicate keys in KV

* Better handling of cursor snapping in json edit field

* Catch formatting errors on the fly

* Basic tests for JSON to Table and Table to JSON in form
2022-07-11 13:34:06 -04:00

175 lines
5.3 KiB
Handlebars

{{#if this.parseError}}
<div data-test-parse-error class="notification is-danger">
<h3 class="title is-4" data-test-parse-error-title>Parse Error</h3>
<p data-test-parse-error-message>{{this.parseError}}</p>
</div>
{{/if}}
{{#if this.planError}}
<div data-test-plan-error class="notification is-danger">
<h3 class="title is-4" data-test-plan-error-title>Plan Error</h3>
<p data-test-plan-error-message>{{this.planError}}</p>
</div>
{{/if}}
{{#if this.runError}}
<div data-test-run-error class="notification is-danger">
<h3 class="title is-4" data-test-run-error-title>Run Error</h3>
<p data-test-run-error-message>{{this.runError}}</p>
</div>
{{/if}}
{{#if (eq this.stage "editor")}}
{{#if (and this.showEditorMessage (eq this.context "new"))}}
<div class="notification is-info">
<div class="columns">
<div class="column">
<h3 class="title is-4" data-test-editor-help-title>Run a Job</h3>
<p data-test-editor-help-message>Paste or author HCL or JSON to submit
to your cluster. A plan will be requested before the job is
submitted.</p>
</div>
<div class="column is-centered is-minimum">
<button
class="button is-info"
onclick={{toggle-action "showEditorMessage" this}}
data-test-editor-help-dismiss
type="button"
>Okay</button>
</div>
</div>
</div>
{{/if}}
<div class="boxed-section">
<div class="boxed-section-head">
Job Definition
{{#if this.cancelable}}
<button
class="button is-light is-compact pull-right"
onclick={{action this.onCancel}}
data-test-cancel-editing
type="button"
>Cancel</button>
{{/if}}
</div>
<div class="boxed-section-body is-full-bleed">
<div
data-test-editor
{{code-mirror
screenReaderLabel="Job definition"
content=this.job._newDefinition
theme="hashi"
onUpdate=this.updateCode
mode="javascript"
}}
/>
</div>
</div>
<div class="content is-associative">
<button
class="button is-primary {{if this.plan.isRunning 'is-loading'}}"
type="button"
onclick={{perform this.plan}}
disabled={{or this.plan.isRunning (not this.job._newDefinition)}}
data-test-plan
>Plan</button>
</div>
{{/if}}
{{#if (eq this.stage "plan")}}
{{#if this.showPlanMessage}}
<div class="notification is-info">
<div class="columns">
<div class="column">
<h3 class="title is-4" data-test-plan-help-title>Job Plan</h3>
<p data-test-plan-help-message>This is the impact running this job
will have on your cluster.</p>
</div>
<div class="column is-centered is-minimum">
<button
class="button is-info"
onclick={{toggle-action "showPlanMessage" this}}
data-test-plan-help-dismiss
type="button"
>Okay</button>
</div>
</div>
</div>
{{/if}}
<div class="boxed-section">
<div class="boxed-section-head">Job Plan</div>
<div class="boxed-section-body is-dark">
<JobDiff
data-test-plan-output
@diff={{this.planOutput.diff}}
@verbose={{false}}
/>
</div>
</div>
<div
class="boxed-section
{{if this.planOutput.failedTGAllocs 'is-warning' 'is-primary'}}"
data-test-dry-run-message
>
<div class="boxed-section-head" data-test-dry-run-title>Scheduler dry-run</div>
<div class="boxed-section-body" data-test-dry-run-body>
{{#if this.planOutput.failedTGAllocs}}
{{#each this.planOutput.failedTGAllocs as |placementFailure|}}
<PlacementFailure @failedTGAlloc={{placementFailure}} />
{{/each}}
{{else}}
All tasks successfully allocated.
{{/if}}
</div>
</div>
{{#if
(and
this.planOutput.preemptions.isFulfilled this.planOutput.preemptions.length
)
}}
<div class="boxed-section is-warning" data-test-preemptions>
<div class="boxed-section-head" data-test-preemptions-title>
Preemptions (if you choose to run this job, these allocations will be
stopped)
</div>
<div class="boxed-section-body" data-test-preemptions-body>
<ListTable
@source={{this.planOutput.preemptions}}
@class="allocations is-isolated"
as |t|
>
<t.head>
<th class="is-narrow"></th>
<th>ID</th>
<th>Task Group</th>
<th>Created</th>
<th>Modified</th>
<th>Status</th>
<th>Version</th>
<th>Node</th>
<th>Volume</th>
<th>CPU</th>
<th>Memory</th>
</t.head>
<t.body as |row|>
<AllocationRow @allocation={{row.model}} @context="job" />
</t.body>
</ListTable>
</div>
</div>
{{/if}}
<div class="content is-associative">
<button
class="button is-primary {{if this.submit.isRunning 'is-loading'}}"
type="button"
onclick={{perform this.submit}}
disabled={{this.submit.isRunning}}
data-test-run
>Run</button>
<button
class="button is-light"
type="button"
onclick={{action this.reset}}
data-test-cancel
>Cancel</button>
</div>
{{/if}}