Commit 8475bb93 authored by Alexander Philipp Nowosad's avatar Alexander Philipp Nowosad
Browse files

Add generics and inherit types

parent e1873efe
......@@ -39,26 +39,31 @@
<div class="alert alert-info">
Types that are defined for this activity. Angle brackets ("<<", ">>") indicate lists.
</div>
<h5>Needed</h5>
<ul class="list-group" *ngIf="modalElement.businessObject.get('neededType').length > 0">
<li class="list-group-item" *ngFor="let element of modalElement.businessObject.get('neededType')">
<span *ngIf="element.element">{{element.element.name}} (<<{{element.list}}>>)</span>
<span *ngIf="!element.element"><<{{element.list}}>></span>
</li>
</ul>
<div class="alert alert-info" *ngIf="modalElement.businessObject.get('neededType').length === 0">
No needed types defined for this activity.
</div>
<h5 class="mt-3">Forbidden</h5>
<ul class="list-group" *ngIf="modalElement.businessObject.get('forbiddenType').length > 0">
<li class="list-group-item" *ngFor="let element of modalElement.businessObject.get('forbiddenType')">
<span *ngIf="element.element"><<{{element.list}}>> {{element.element.name}}</span>
<span *ngIf="!element.element"><<{{element.list}}>></span>
</li>
</ul>
<div class="alert alert-info" *ngIf="modalElement.businessObject.get('forbiddenType').length === 0">
No forbidden types defined for this activity.
<div class="alert alert-info" *ngIf="modalElement.businessObject.inherit">
Types are inherited from parent element.
</div>
<ng-container *ngIf="!modalElement.businessObject.inherit">
<h5>Needed</h5>
<ul class="list-group" *ngIf="modalElement.businessObject.get('neededType').length > 0">
<li class="list-group-item" *ngFor="let element of modalElement.businessObject.get('neededType')">
<span *ngIf="element.element">{{element.element.name}} (<<{{element.list}}>>)</span>
<span *ngIf="!element.element"><<{{element.list}}>></span>
</li>
</ul>
<div class="alert alert-info" *ngIf="modalElement.businessObject.get('neededType').length === 0">
No needed types defined for this activity.
</div>
<h5 class="mt-3">Forbidden</h5>
<ul class="list-group" *ngIf="modalElement.businessObject.get('forbiddenType').length > 0">
<li class="list-group-item" *ngFor="let element of modalElement.businessObject.get('forbiddenType')">
<span *ngIf="element.element"><<{{element.list}}>> {{element.element.name}}</span>
<span *ngIf="!element.element"><<{{element.list}}>></span>
</li>
</ul>
<div class="alert alert-info" *ngIf="modalElement.businessObject.get('forbiddenType').length === 0">
No forbidden types defined for this activity.
</div>
</ng-container>
</div>
</ng-template>
......
......@@ -168,9 +168,9 @@ export class BmProcessDiagramComponent implements DiagramComponentInterface, OnI
openSelectDevelopmentMethodModal(taskElement) {
this.selectDevelopmentMethodForm.get('developmentMethodId').disable();
this.modalElement = taskElement;
const businessObject = taskElement.businessObject;
const types = this.bpmnService.getTypesOfActivity(this.modeler, taskElement.id);
this.developmentMethodService.getValidDevelopmentMethods(
businessObject.get('neededType'), businessObject.get('forbiddenType'),
types.neededType, types.forbiddenType,
).then((developmentMethods) => {
this.validDevelopmentMethods = developmentMethods.docs;
if (developmentMethods.docs.length > 0) {
......@@ -211,9 +211,9 @@ export class BmProcessDiagramComponent implements DiagramComponentInterface, OnI
}
openSelectProcessPatternModal(callActivityElement) {
const businessObject = callActivityElement.businessObject;
const types = this.bpmnService.getTypesOfActivity(this.modeler, callActivityElement.id);
this.processPatternService.getValidProcessPatterns(
businessObject.get('neededType'), businessObject.get('forbiddenType'),
[...types.neededType, {list: 'generic', element: null}], types.forbiddenType,
).then(list => {
this.modalProcessPatterns = list.docs;
this.modalElement = callActivityElement;
......
......@@ -17,7 +17,9 @@ export default class BmProcessPatternsContextPad {
'bmdl.types': {
group: 'edit',
className: 'bpmn-icon-service ' + (
element.businessObject.get('neededType').length > 0 ? 'highlight-font-symbol-green' : 'highlight-font-symbol-red'
(element.businessObject.get('neededType').length > 0 || element.businessObject.inherit)
? 'highlight-font-symbol-green'
: 'highlight-font-symbol-red'
),
title: 'Manage types',
action: {
......
......@@ -36,6 +36,7 @@ export class ProcessPatternDiagramComponent implements DiagramComponentInterface
modalTask: {
id: string,
name: string,
inherit: boolean,
neededType: { list: string, element: Type }[],
forbiddenType: { list: string, element: Type }[],
};
......@@ -83,6 +84,7 @@ export class ProcessPatternDiagramComponent implements DiagramComponentInterface
this.modalTask = {
id: businessTask.id,
name: businessTask.name,
inherit: businessTask.get('inherit'),
neededType: businessTask.get('neededType'),
forbiddenType: businessTask.get('forbiddenType'),
};
......@@ -91,7 +93,7 @@ export class ProcessPatternDiagramComponent implements DiagramComponentInterface
updateTypes(typesForm: FormGroup) {
this.bpmnService.setTypesOfActivity(
this.modeler, this.modalTask.id, typesForm.value.neededType, typesForm.value.forbiddenType,
this.modeler, this.modalTask.id, typesForm.value.inherit, typesForm.value.neededType, typesForm.value.forbiddenType,
);
this.modalReference.close();
this.saveDiagram();
......
<form [formGroup]="typesForm" (ngSubmit)="submitForm()">
<div class="form-group">
<div class="btn-group btn-group-toggle" ngbRadioGroup name="inherit" formControlName="inherit">
<label ngbButtonLabel class="btn-primary">
<input ngbButton type="radio" [value]="true"> Inherit types
</label>
<label ngbButtonLabel class="btn-primary">
<input ngbButton type="radio" [value]="false"> Do not inherit types
</label>
</div>
</div>
<app-method-elements-selection-form
*ngIf="!typesForm.value.inherit"
class="form-group"
formArrayName="neededType"
[createFormGroupFactory]="createFormGroupFactory"
......@@ -9,6 +21,7 @@
methodElementName="Needed Type"></app-method-elements-selection-form>
<app-method-elements-selection-form
*ngIf="!typesForm.value.inherit"
class="form-group"
formArrayName="forbiddenType"
[createFormGroupFactory]="createFormGroupFactory"
......
......@@ -11,6 +11,7 @@ import { TypeService } from '../../development-process-registry/type.service';
export class ProcessPatternTypesFormComponent implements OnInit, OnChanges {
@Input() types: {
inherit: boolean,
neededType: { list: string, element: Type }[],
forbiddenType: { list: string, element: Type }[],
};
......@@ -18,6 +19,7 @@ export class ProcessPatternTypesFormComponent implements OnInit, OnChanges {
@Output() submitTypesForm = new EventEmitter<FormGroup>();
typesForm: FormGroup = this.fb.group({
inherit: this.fb.control(false, Validators.required),
neededType: this.fb.array([]),
forbiddenType: this.fb.array([]),
});
......@@ -45,7 +47,9 @@ export class ProcessPatternTypesFormComponent implements OnInit, OnChanges {
this.submitTypesForm.emit(this.typesForm);
}
private loadForm(types: { neededType: { list: string, element: Type }[], forbiddenType: { list: string, element: Type }[] }) {
private loadForm(
types: { inherit: boolean, neededType: { list: string, element: Type }[], forbiddenType: { list: string, element: Type }[] }
) {
const mapTypeToFormGroup = (type: { list: string, element: Type }) => this.fb.group({
list: [type.list, Validators.required],
element: type.element,
......@@ -53,6 +57,9 @@ export class ProcessPatternTypesFormComponent implements OnInit, OnChanges {
const neededTypesFormGroups = types.neededType.map(mapTypeToFormGroup);
const forbiddenTypesFormGroups = types.forbiddenType.map(mapTypeToFormGroup);
if (types.inherit) {
this.typesForm.get('inherit').setValue(types.inherit);
}
this.typesForm.setControl('neededType', this.fb.array(neededTypesFormGroups));
this.typesForm.setControl('forbiddenType', this.fb.array(forbiddenTypesFormGroups));
}
......
......@@ -80,22 +80,46 @@ export class BpmnService {
*
* @param modeler the modeler
* @param activityId the id of the activity
* @param inherit whether the types should be inherited
* @param neededTypes the needed types of the method
* @param forbiddenTypes the forbidden types of the method
*/
setTypesOfActivity(
modeler: BpmnModeler, activityId: string,
modeler: BpmnModeler, activityId: string, inherit: boolean,
neededTypes: { list: string, element: Type }[], forbiddenTypes: { list: string, element: Type }[],
) {
const moddle = modeler.get('moddle');
const modeling = modeler.get('modeling');
const elementRegistry = modeler.get('elementRegistry');
modeling.updateProperties(elementRegistry.get(activityId), {
inherit,
neededType: neededTypes.map((element) => mapTypes(moddle, element)),
forbiddenType: forbiddenTypes.map((element) => mapTypes(moddle, element)),
});
}
/**
* Get types of an activity that specify which methods can be used. Also queries parents if types are inherited.
*
* @param modeler the modeler
* @param activityId the id of the activity
*/
getTypesOfActivity(modeler: BpmnModeler, activityId: string): {
neededType: { list: string, element: { _id: string, name: string } }[],
forbiddenType: { list: string, element: { _id: string, name: string } }[],
} {
const elementRegistry = modeler.get('elementRegistry');
const activity = elementRegistry.get(activityId);
let businessObject = activity.businessObject;
while (businessObject && (businessObject.inherit || !businessObject.neededType)) {
businessObject = businessObject.$parent;
}
return {
neededType: businessObject ? businessObject.get('neededType') : [],
forbiddenType: businessObject ? businessObject.get('forbiddenType') : [],
};
}
/**
* Selects a development method for a process pattern task and adds the development method to the task
*
......
......@@ -12,6 +12,10 @@
"bpmn:Activity"
],
"properties": [
{
"name": "inherit",
"type": "Boolean"
},
{
"name": "neededType",
"isMany": true,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment