From a5d6f63d466672be65a1d08e742618ae7ed013b8 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Thu, 10 Oct 2024 16:13:39 -0400 Subject: [PATCH] Reworked as Clone and Revert --- ui/app/components/job-version.js | 27 ++++++++- ui/app/routes/jobs/job/definition.js | 1 + ui/app/routes/jobs/run/index.js | 11 +++- ui/app/templates/components/job-version.hbs | 63 ++++++++++++--------- 4 files changed, 71 insertions(+), 31 deletions(-) diff --git a/ui/app/components/job-version.js b/ui/app/components/job-version.js index bcb7228b0b8..d777cea1cbe 100644 --- a/ui/app/components/job-version.js +++ b/ui/app/components/job-version.js @@ -85,7 +85,7 @@ export default class JobVersion extends Component { /** * @type {'idle' | 'confirming'} */ - @tracked revertButtonStatus = 'idle'; + @tracked cloneButtonStatus = 'idle'; @task(function* () { try { @@ -95,6 +95,7 @@ export default class JobVersion extends Component { const versionAfterReversion = this.version.get('job.version'); if (versionBeforeReversion === versionAfterReversion) { + // TODO: I don't think this is ever hit, we have template checks against it. this.args.handleError({ level: 'warn', title: 'Reversion Had No Effect', @@ -115,7 +116,7 @@ export default class JobVersion extends Component { }) revertTo; - @action async editFromVersion() { + @action async cloneAsNewVersion() { try { this.router.transitionTo( 'jobs.job.definition', @@ -135,6 +136,28 @@ export default class JobVersion extends Component { } } + @action async cloneAsNewJob() { + console.log('cloneAsNewJob'); + try { + // TODO: copy the job definition over there. + console.log('Do I have submission info???', this.version); + let job = await this.version.get('job'); + let specification = await job.fetchRawSpecification(this.version.number); + console.log('Do I have specification???', specification); + let specificationSourceString = specification.Source; // TODO: should do some Format checking here, at the very least. + this.router.transitionTo('jobs.run', { + queryParams: { + sourceString: specificationSourceString, + }, + }); + } catch (e) { + this.args.handleError({ + level: 'danger', + title: 'Could Not Clone as New Job', + }); + } + } + @action handleKeydown(event) { if (event.key === 'Escape') { diff --git a/ui/app/routes/jobs/job/definition.js b/ui/app/routes/jobs/job/definition.js index bd670a9d676..98277cbda2d 100644 --- a/ui/app/routes/jobs/job/definition.js +++ b/ui/app/routes/jobs/job/definition.js @@ -26,6 +26,7 @@ export default class DefinitionRoute extends Route { */ async model({ version }) { version = +version; // query parameter is a string; convert to number + /** @type {import('../../../models/job').default} */ const job = this.modelFor('jobs.job'); if (!job) return; diff --git a/ui/app/routes/jobs/run/index.js b/ui/app/routes/jobs/run/index.js index 95c0bbffd2d..ff48debc6bd 100644 --- a/ui/app/routes/jobs/run/index.js +++ b/ui/app/routes/jobs/run/index.js @@ -21,6 +21,9 @@ export default class JobsRunIndexRoute extends Route { template: { refreshModel: true, }, + sourceString: { + refreshModel: true, + }, }; beforeModel(transition) { @@ -33,7 +36,7 @@ export default class JobsRunIndexRoute extends Route { } } - async model({ template }) { + async model({ template, sourceString }) { try { // When jobs are created with a namespace attribute, it is verified against // available namespaces to prevent redirecting to a non-existent namespace. @@ -45,6 +48,12 @@ export default class JobsRunIndexRoute extends Route { return this.store.createRecord('job', { _newDefinition: templateRecord.items.template, }); + } else if (sourceString) { + console.log('elsif', sourceString); + // Add an alert to the page to let the user know that they are submitting a job from a template, and that they should change the name! + return this.store.createRecord('job', { + _newDefinition: sourceString, + }); } else { return this.store.createRecord('job'); } diff --git a/ui/app/templates/components/job-version.hbs b/ui/app/templates/components/job-version.hbs index c56503db4a1..789e6649335 100644 --- a/ui/app/templates/components/job-version.hbs +++ b/ui/app/templates/components/job-version.hbs @@ -81,53 +81,60 @@
{{#unless this.isCurrent}} {{#if (can "run job" namespace=this.version.job.namespace)}} - {{#if (eq this.revertButtonStatus 'idle')}} + {{#if (eq this.cloneButtonStatus 'idle')}} - {{else if (eq this.revertButtonStatus 'confirming')}} - + + + + + {{else if (eq this.cloneButtonStatus 'confirming')}} + {{!-- Are you sure you want to revert to this version? - + --}} - {{else if (eq this.revertButtonStatus 'running')}} - {{/if}} {{else}}