Skip to content

Commit

Permalink
Monument revision has a setup function to call the remap endpoint and…
Browse files Browse the repository at this point in the history
… create the resource
  • Loading branch information
taylorn01 committed Feb 21, 2024
1 parent 8f4811f commit f87ef82
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion coral/media/js/views/components/plugins/open-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ define([
'templates/views/components/plugins/open-workflow.htm'
], function ($, ko, koMapping, arches, pageTemplate) {
const openWorkflowViewModel = function (params) {
this.loading = params.loading;

this.WORKFLOW_LABEL = 'workflow-slug';
this.WORKFLOW_OPEN_MODE_LABEL = 'workflow-open-mode';
this.WORKFLOW_COMPONENT_ABSTRACTS_LABEL = 'workflow-component-abstracts';
Expand All @@ -18,7 +20,6 @@ define([
this.workflowSlug = ko.observable();
this.workflow = ko.observable();
this.graphId = ko.observable();
this.loading = ko.observable(false);

this.resourceName = ko.observable();
this.recentlyOpened = ko.observable();
Expand Down Expand Up @@ -67,14 +68,42 @@ define([
await this.loadResourceData(resourceId);
};

this.setupWorkflow = async () => {
let result = null;
if (this.workflow().setupFunction) {
result = await this[this.workflow().setupFunction]();
}
return result;
};

this.setupMonumentRevision = async () => {
const monumentResourceId = this.selectedResource();
const response = await $.ajax({
type: 'POST',
url: '/monument-revision-remap',
dataType: 'json',
data: JSON.stringify({
monumentResourceId: monumentResourceId
}),
context: this,
error: (response, status, error) => {
console.log(response, status, error);
}
});
this.selectedResource(response.revisionResourceId);
};

this.openWorkflow = async () => {
if (!this.selectedResource()) return;
this.loading(true);
localStorage.setItem(this.WORKFLOW_OPEN_MODE_LABEL, JSON.stringify(true));
this.updateRecentlyOpened(this.selectedResource());
await this.setupWorkflow();
this.workflowUrl(
arches.urls.plugin(this.workflowSlug()) + `?resource-id=${this.selectedResource()}`
);
window.window.location = this.workflowUrl();
this.loading(false);
};

this.updateRecentlyOpened = (resourceId) => {
Expand Down

0 comments on commit f87ef82

Please sign in to comment.