Commit fb5c99ef authored by Alexander Philipp Nowosad's avatar Alexander Philipp Nowosad
Browse files

Add new warnings display

parent 2acdcf9c
Pipeline #133879 failed with stages
in 8 seconds
......@@ -145,7 +145,14 @@
There are no warnings about missing situational factors
</div>
<ul *ngIf="missingWarnings.length > 0">
<li *ngFor="let warning of missingWarnings">{{warning}}</li>
<li *ngFor="let warning of missingWarnings">
{{warning.elementName}} <a [routerLink]="[]"
(click)="selectElement(warning.elementId)">{{warning.name}}</a>
is missing the following factors
<ul>
<li *ngFor="let factor of warning.situationalFactors">{{factor}}</li>
</ul>
</li>
</ul>
</ng-template>
</ngb-panel>
......@@ -155,7 +162,14 @@
There are no warnings about situational factors with a too low value
</div>
<ul *ngIf="lowWarnings.length > 0">
<li *ngFor="let warning of lowWarnings">{{warning}}</li>
<li *ngFor="let warning of lowWarnings">
{{warning.elementName}} <a [routerLink]="[]"
(click)="selectElement(warning.elementId)">{{warning.name}}</a>
has a too low value for the following factors
<ul>
<li *ngFor="let factor of warning.situationalFactors">{{factor}}</li>
</ul>
</li>
</ul>
</ng-template>
</ngb-panel>
......@@ -165,7 +179,14 @@
There are no warnings about situational factors with an incorrect value
</div>
<ul *ngIf="incorrectWarnings.length > 0">
<li *ngFor="let warning of incorrectWarnings">{{warning}}</li>
<li *ngFor="let warning of incorrectWarnings">
{{warning.elementName}} <a [routerLink]="[]"
(click)="selectElement(warning.elementId)">{{warning.name}}</a>
has an incorrect value for the following factors
<ul>
<li *ngFor="let factor of warning.situationalFactors">{{factor}}</li>
</ul>
</li>
</ul>
</ng-template>
</ngb-panel>
......
......@@ -37,9 +37,9 @@ export class BmProcessDiagramComponent implements DiagramComponentInterface, OnI
validDevelopmentMethods: DevelopmentMethod[] = null;
missingWarnings: string[] = [];
lowWarnings: string[] = [];
incorrectWarnings: string[] = [];
missingWarnings: { elementName: string, name: string, elementId: string, situationalFactors: string[] }[] = [];
lowWarnings: { elementName: string, name: string, elementId: string, situationalFactors: string[] }[] = [];
incorrectWarnings: { elementName: string, name: string, elementId: string, situationalFactors: string[] }[] = [];
isGeneratingWarnings = false;
private wantsToGenerateWarnings = false;
......@@ -246,30 +246,63 @@ export class BmProcessDiagramComponent implements DiagramComponentInterface, OnI
return;
}
this.isGeneratingWarnings = true;
const missingWarnings: string[] = [];
const lowWarnings: string[] = [];
const incorrectWarnings: string[] = [];
const generateWarnings =
(element: { name: string, situationalFactors: { element: SituationalFactor }[] }, elementName: 'Method' | 'Pattern') => {
const factorMap = SituationalFactor.createMap(element.situationalFactors.map((factor) => factor.element));
const {missing, low, incorrect} = this.bmProcess.checkMatch(factorMap);
missing.forEach((m) => missingWarnings.push(elementName + ' ' + element.name + ' is missing the factor ' + m + '.'));
low.forEach((m) => lowWarnings.push(elementName + ' ' + element.name + ' has a too low value for the factor ' + m + '.'));
incorrect.forEach((m) => incorrectWarnings.push(
elementName + ' ' + element.name + ' has not the correct value for the factor ' + m + '.')
);
const missingWarnings: { elementName: string, name: string, elementId: string, situationalFactors: string[] }[] = [];
const lowWarnings: { elementName: string, name: string, elementId: string, situationalFactors: string[] }[] = [];
const incorrectWarnings: { elementName: string, name: string, elementId: string, situationalFactors: string[] }[] = [];
const generateWarnings = (id: string, elementName: 'Method' | 'Pattern', name: string, factors: SituationalFactor[]) => {
const factorMap = SituationalFactor.createMap(factors);
const {missing, low, incorrect} = this.bmProcess.checkMatch(factorMap);
if (missing.length > 0) {
missingWarnings.push({
elementName,
name,
elementId: id,
situationalFactors: missing,
});
}
if (low.length > 0) {
lowWarnings.push({
elementName,
name,
elementId: id,
situationalFactors: low,
});
}
if (incorrect.length > 0) {
incorrectWarnings.push({
elementName,
name,
elementId: id,
situationalFactors: incorrect,
});
}
};
const generateMethodWarnings =
(element: any) => {
const method = this.bmProcess.decisions[element.id].method;
generateWarnings(element.id, 'Method', method.name, method.situationalFactors.map((factor) => factor.element));
};
const methodWarnings = this.developmentMethodService.getDevelopmentMethods(this.bpmnService.getUsedMethodIds(this.modeler)).then(
(methods) => methods.forEach(
(method) => generateWarnings(method, 'Method'),
)
);
const patternWarnings = this.processPatternService.getProcessPatterns(this.bpmnService.getUsedPatternIds(this.modeler)).then(
(patterns) => patterns.forEach(
(pattern) => generateWarnings(pattern, 'Pattern'),
)
);
Promise.all([methodWarnings, patternWarnings]).then(() => {
const generatePatternWarnings =
(element: any, pattern: ProcessPattern) => {
generateWarnings(element.id, 'Pattern', pattern.name, pattern.situationalFactors.map((factor) => factor.element));
};
const activities = this.bpmnService.getActivitiesWithMethod(this.modeler);
activities.forEach((activity) => generateMethodWarnings(activity));
const patternElements = this.bpmnService.getPatterns(this.modeler);
this.processPatternService.getProcessPatterns(
patternElements.map((element) => element.businessObject.get('processPatternId'))
).then((dbPatterns) => {
const dbPatternsMap: { [id: string]: ProcessPattern } = {};
dbPatterns.forEach((dbPattern) => dbPatternsMap[dbPattern._id] = dbPattern);
patternElements.forEach(
(patternElement) => generatePatternWarnings(patternElement, dbPatternsMap[patternElement.businessObject.get('processPatternId')])
);
if (!this.wantsToGenerateWarnings) {
this.missingWarnings = missingWarnings;
this.lowWarnings = lowWarnings;
......@@ -284,6 +317,11 @@ export class BmProcessDiagramComponent implements DiagramComponentInterface, OnI
});
}
selectElement(id: string) {
this.bpmnService.focusElement(this.modeler, id);
this.canvas.nativeElement.scrollIntoView({behavior: 'smooth'});
}
updateDecisions(value: any) {
this.bmProcess.decisions[this.modalElement.id].update(value);
this.saveDiagram(this.bmProcess.decisions);
......
......@@ -175,6 +175,50 @@ export class BpmnService {
});
}
/**
* Focus a specific element
*
* @param modeler the modeler that currently displays the process
* @param id the id of the element
*/
focusElement(modeler: BpmnModeler, id: string) {
const element = modeler.get('elementRegistry').get(id);
modeler.get('selection').select(element);
const canvas = modeler.get('canvas');
const viewbox = canvas.viewbox();
let adjustRatio = false;
const ratio = viewbox.width / viewbox.height;
if (viewbox.width < element.width) {
viewbox.width = element.width + 600;
adjustRatio = true;
}
if (viewbox.height < element.height) {
viewbox.height = element.height + 600;
adjustRatio = true;
}
if (adjustRatio) {
if (viewbox.width < viewbox.height * ratio) {
viewbox.width = viewbox.height * ratio;
} else if (viewbox.height < 1 / (ratio / viewbox.width)) {
viewbox.height = 1 / (ratio / viewbox.width);
}
}
viewbox.x = element.x - viewbox.width / 2 + element.width / 2;
viewbox.y = element.y - viewbox.height / 2 + element.height / 2;
canvas.viewbox(viewbox);
}
/**
* Get all activities that have a method defined
*
* @param modeler the modeler of the current model
* @returns elements that have a method defined
*/
getActivitiesWithMethod(modeler: BpmnModeler): any[] {
return modeler.get('elementRegistry')
.filter((element) => element.businessObject.get('method'));
}
/**
* Get all method ids used in the model
*
......@@ -182,11 +226,21 @@ export class BpmnService {
* @returns used method ids
*/
getUsedMethodIds(modeler: BpmnModeler): string[] {
return modeler.get('elementRegistry')
.filter((element) => element.businessObject.get('method'))
return this.getActivitiesWithMethod(modeler)
.map((element) => element.businessObject.get('method').get('id'));
}
/**
* Get all pattern elements of the current model
*
* @param modeler the modeler of the current model
* @returns elements that are used as a pattern
*/
getPatterns(modeler: BpmnModeler) {
return modeler.get('elementRegistry')
.filter((element) => element.businessObject.get('processPatternId'));
}
/**
* Get all pattern ids used in the model
*
......@@ -194,8 +248,7 @@ export class BpmnService {
* @returns used method ids
*/
getUsedPatternIds(modeler: BpmnModeler): string[] {
return modeler.get('elementRegistry')
.filter((element) => element.businessObject.get('processPatternId'))
return this.getPatterns(modeler)
.map((element) => element.businessObject.get('processPatternId'));
}
......
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