Skip to content

Commit

Permalink
Allow removing & editing workflow steps
Browse files Browse the repository at this point in the history
  • Loading branch information
tkleinke committed Mar 3, 2025
1 parent 991ad35 commit 8ccd6cc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MenuContext } from '../../../../services/menu-context';
import { DoceditComponent } from '../../../docedit/docedit.component';
import { Messages } from '../../../messages/messages';
import { M } from '../../../messages/m';
import { AngularUtility } from '../../../../angular/angular-utility';


@Component({
Expand Down Expand Up @@ -60,7 +61,7 @@ export class WorkflowEditorModalComponent {

public async createWorkflowStep(category: CategoryForm) {

const newWorkflowStep: Document = await this.openEditorModal(
const newWorkflowStep: Document = await this.editWorkflowStep(
WorkflowEditorModalComponent.buildWorkflowStepDocument(category)
);
if (!newWorkflowStep) return;
Expand All @@ -70,10 +71,19 @@ export class WorkflowEditorModalComponent {
}


public async removeWorkflowStep(workflowStep: Document) {

// TODO Confirm deletion
await this.removeRelation(workflowStep);
await this.relationsManager.remove(workflowStep);
await this.updateWorkflowSteps();
}


/**
* @returns edited document if changes have been saved, undefined if the modal has been canceled
*/
private async openEditorModal(document: Document): Promise<Document|undefined> {
public async editWorkflowStep(document: Document): Promise<Document|undefined> {

this.menus.setContext(MenuContext.DOCEDIT);

Expand All @@ -87,6 +97,7 @@ export class WorkflowEditorModalComponent {
// Modal has been canceled
return undefined;
} finally {
AngularUtility.blurActiveElement();
this.menus.setContext(MenuContext.WORKFLOW_EDITOR);
}
}
Expand All @@ -101,6 +112,27 @@ export class WorkflowEditorModalComponent {
if (!resource.relations[Relation.HAS_WORKFLOW_STEP]) resource.relations[Relation.HAS_WORKFLOW_STEP] = [];
resource.relations[Relation.HAS_WORKFLOW_STEP].push(workflowStep.resource.id);

await this.applyRelationChanges(oldVersion);
}


private async removeRelation(workflowStep: Document) {

const oldVersion: Document = Document.clone(workflowStep);

const resource: Resource = this.document.resource;
resource.relations[Relation.HAS_WORKFLOW_STEP]
= resource.relations[Relation.HAS_WORKFLOW_STEP].filter(targetId => targetId !== workflowStep.resource.id);
if (!resource.relations[Relation.HAS_WORKFLOW_STEP].length) {
delete resource.relations[Relation.HAS_WORKFLOW_STEP];
}

await this.applyRelationChanges(oldVersion);
}


private async applyRelationChanges(oldVersion: Document) {

try {
await this.relationsManager.update(this.document, oldVersion);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
<div class="workflow-step-execution-date">{{workflowStep.resource.executionDate}}</div>
<div class="workflow-step-category">{{getCategoryLabel(workflowStep)}}</div>
<div class="workflow-step-short-description">{{getShortDescriptionLabel(workflowStep)}}</div>
<div class="workflow-step-buttons input-group">
<button class="btn btn-danger" (click)="removeWorkflowStep(workflowStep)">
<span class="mdi mdi-delete"></span>
</button>
<button class="btn btn-info" (click)="editWorkflowStep(workflowStep)">
<span class="mdi mdi-pencil"></span>
</button>
</div>
</div>
</div>
<div id="workflow-step-plus-button-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@
}

.workflow-step-short-description {
width: calc(100% - 400px);
width: calc(100% - 397px);
}

.workflow-step-buttons {
width: 84px;

button {
border-radius: 0;
}
}
}
}
Expand Down

0 comments on commit 8ccd6cc

Please sign in to comment.