-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow creating workflow steps in workflow editor modal
- Loading branch information
Showing
12 changed files
with
287 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...top/src/app/components/resources/actions/edit-workflow/workflow-editor-modal.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { Component } from '@angular/core'; | ||
import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'; | ||
import { CategoryForm, FieldDocument, Document, RelationsManager, Relation, Resource, | ||
Datastore } from 'idai-field-core'; | ||
import { Menus } from '../../../../services/menus'; | ||
import { MenuContext } from '../../../../services/menu-context'; | ||
import { DoceditComponent } from '../../../docedit/docedit.component'; | ||
import { Messages } from '../../../messages/messages'; | ||
import { M } from '../../../messages/m'; | ||
|
||
|
||
@Component({ | ||
templateUrl: './workflow-editor-modal.html', | ||
host: { | ||
'(window:keydown)': 'onKeyDown($event)' | ||
}, | ||
standalone: false | ||
}) | ||
/** | ||
* @author Thomas Kleinke | ||
*/ | ||
export class WorkflowEditorModalComponent { | ||
|
||
public document: FieldDocument; | ||
public workflowSteps: Array<Document>; | ||
|
||
|
||
constructor(private activeModal: NgbActiveModal, | ||
private menus: Menus, | ||
private modalService: NgbModal, | ||
private relationsManager: RelationsManager, | ||
private datastore: Datastore, | ||
private messages: Messages) {} | ||
|
||
|
||
public cancel = () => this.activeModal.close(); | ||
|
||
|
||
public async onKeyDown(event: KeyboardEvent) { | ||
|
||
if (event.key === 'Escape' && this.menus.getContext() === MenuContext.WORKFLOW_EDITOR) { | ||
this.cancel(); | ||
} | ||
} | ||
|
||
|
||
public async initialize() { | ||
|
||
await this.updateWorkflowSteps(); | ||
} | ||
|
||
|
||
public async createWorkflowStep(category: CategoryForm) { | ||
|
||
const newWorkflowStep: Document = await this.openEditorModal( | ||
WorkflowEditorModalComponent.buildWorkflowStepDocument(category) | ||
); | ||
if (!newWorkflowStep) return; | ||
|
||
await this.addRelation(newWorkflowStep); | ||
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> { | ||
|
||
this.menus.setContext(MenuContext.DOCEDIT); | ||
|
||
const doceditRef = this.modalService.open(DoceditComponent, | ||
{ size: 'lg', backdrop: 'static', keyboard: false, animation: false }); | ||
doceditRef.componentInstance.setDocument(document); | ||
|
||
try { | ||
return (await doceditRef.result).document; | ||
} catch(_) { | ||
// Modal has been canceled | ||
return undefined; | ||
} finally { | ||
this.menus.setContext(MenuContext.WORKFLOW_EDITOR); | ||
} | ||
} | ||
|
||
|
||
private async addRelation(workflowStep: Document) { | ||
|
||
const oldVersion: Document = Document.clone(workflowStep); | ||
|
||
const resource: Resource = this.document.resource; | ||
if (!resource.relations) resource.relations = {}; | ||
if (!resource.relations[Relation.HAS_WORKFLOW_STEP]) resource.relations[Relation.HAS_WORKFLOW_STEP] = []; | ||
resource.relations[Relation.HAS_WORKFLOW_STEP].push(workflowStep.resource.id); | ||
|
||
try { | ||
await this.relationsManager.update(this.document, oldVersion); | ||
} catch (err) { | ||
console.error(err); | ||
this.messages.add([M.DOCEDIT_ERROR_SAVE]); | ||
} | ||
} | ||
|
||
|
||
private async updateWorkflowSteps() { | ||
|
||
const targetIds: string[] = this.document.resource.relations?.[Relation.HAS_WORKFLOW_STEP] ?? []; | ||
this.workflowSteps = await this.datastore.getMultiple(targetIds); | ||
} | ||
|
||
|
||
private static buildWorkflowStepDocument(category: CategoryForm): Document { | ||
|
||
return <Document> { | ||
resource: { | ||
relations: {}, | ||
category: category.name | ||
} | ||
}; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
desktop/src/app/components/resources/actions/edit-workflow/workflow-editor-modal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div id="view-modal-header" class="modal-header"> | ||
<div class="text-truncate heading" | ||
i18n="@@resources.workflowEditorModal.header"> | ||
Arbeitssschritte für Ressource <b>{{document.resource.identifier}}</b> dokumentieren | ||
</div> | ||
<button id="workflow-editor-cancel-button" class="btn btn-primary btn-square" (click)="cancel()"> | ||
<span class="mdi mdi-close"></span> | ||
</button> | ||
</div> | ||
<div id="view-modal-body" class="modal-body bg-light workflow-editor-modal-body"> | ||
<div id="workflow-steps-container"> | ||
<div *ngFor="let workflowStep of workflowSteps"> | ||
<document-teaser [document]="workflowStep"></document-teaser> | ||
</div> | ||
</div> | ||
<div id="workflow-step-plus-button-container"> | ||
<workflow-step-plus-button [baseDocument]="document" | ||
(onCategorySelected)="createWorkflowStep($event)"></workflow-step-plus-button> | ||
</div> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
desktop/src/app/components/resources/actions/edit-workflow/workflow-editor-modal.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.workflow-editor-modal-body { | ||
padding: 16px 16px 22px 16px !important; | ||
|
||
#workflow-steps-container { | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
overflow-x: hidden; | ||
overflow-y: auto; | ||
background-color: white; | ||
border: 1px solid #ccc; | ||
border-radius: 10px; | ||
user-select: none; | ||
} | ||
|
||
#workflow-step-plus-button-container { | ||
position: absolute; | ||
bottom: 4px; | ||
width: 100%; | ||
height: 39px; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...src/app/components/resources/actions/edit-workflow/workflow-step-plus-button.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core'; | ||
import { CategoryForm, FieldDocument, ProjectConfiguration, Relation } from 'idai-field-core'; | ||
|
||
|
||
@Component({ | ||
selector: 'workflow-step-plus-button', | ||
templateUrl: './workflow-step-plus-button.html', | ||
standalone: false | ||
}) | ||
/** | ||
* @author Thomas Kleinke | ||
*/ | ||
export class WorkflowStepPlusButtonComponent implements OnChanges { | ||
|
||
@Input() baseDocument: FieldDocument; | ||
|
||
@Output() onCategorySelected: EventEmitter<CategoryForm> = new EventEmitter<CategoryForm>(); | ||
|
||
public topLevelCategoriesArray: Array<CategoryForm>; | ||
|
||
|
||
constructor(private projectConfiguration: ProjectConfiguration) {} | ||
|
||
|
||
public selectCategory = (category: CategoryForm) => this.onCategorySelected.emit(category); | ||
|
||
|
||
ngOnChanges() { | ||
|
||
this.topLevelCategoriesArray = this.initializeTopLevelCategoriesArray(); | ||
} | ||
|
||
|
||
public hasMultipleCategoryOptions(): boolean { | ||
|
||
return this.topLevelCategoriesArray.length > 1 || this.topLevelCategoriesArray[0].children?.length > 0; | ||
} | ||
|
||
|
||
private initializeTopLevelCategoriesArray(): Array<CategoryForm> { | ||
|
||
return this.projectConfiguration.getTopLevelCategories().filter(category => { | ||
return this.projectConfiguration.isAllowedRelationDomainCategory( | ||
this.baseDocument.resource.category, | ||
category.name, | ||
Relation.HAS_WORKFLOW_STEP | ||
); | ||
}); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
desktop/src/app/components/resources/actions/edit-workflow/workflow-step-plus-button.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<div *ngIf="topLevelCategoriesArray"> | ||
<div *ngIf="hasMultipleCategoryOptions()" | ||
class="circular-button green-button" | ||
[ngbPopover]="categoryPickerMenu" | ||
#popover="ngbPopover" | ||
triggers="manual" | ||
autoClose="outside" | ||
(click)="popover.toggle();" | ||
placement="top"> | ||
<span class="mdi mdi-plus"></span> | ||
</div> | ||
|
||
<div *ngIf="!hasMultipleCategoryOptions()" | ||
class="circular-button category-button" | ||
(click)="selectCategory(topLevelCategoriesArray[0])"> | ||
<category-icon [category]="topLevelCategoriesArray[0].name" size="41"></category-icon> | ||
<div class="plus-sign-circle"> | ||
<span class="mdi mdi-plus mdi-18px"></span> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<ng-template #categoryPickerMenu> | ||
<div> | ||
<div id="category-picker-menu"> | ||
<div class="popover-custom-title"> | ||
<span i18n="@@resources.plusButton.selectCategory">Bitte wählen Sie eine Kategorie aus.</span> | ||
</div> | ||
<category-picker [topLevelCategoriesArray]="topLevelCategoriesArray" | ||
(onCategoryPicked)="selectCategory($event)"></category-picker> | ||
</div> | ||
</div> | ||
</ng-template> |
5 changes: 5 additions & 0 deletions
5
desktop/src/app/components/resources/actions/edit-workflow/workflow-step-plus-button.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
workflow-step-plus-button { | ||
.circular-button { | ||
left: calc(50% - 20px); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters