Refactor template selection logic add forpackage decorator
Some checks failed
FarmMaps.Develop/FarmMapsLib/pipeline/head There was a failure building this commit

This commit is contained in:
Willem Dantuma
2020-06-24 08:35:34 +02:00
parent cd156ab1bc
commit cbe27c2add
6 changed files with 88 additions and 43 deletions

View File

@@ -23,22 +23,28 @@ export class SelectedItemContainerComponent {
loadComponent() {
let componentFactory: ComponentFactory<AbstractSelectedItemComponent> = this.componentFactoryResolver.resolveComponentFactory(SelectedItemComponent); // default
let firstComponentWithTypeAndTask = this.selectedItemComponents
.find(value => value['forSourceTask'] == this.item.sourceTask &&
value['forItemType'] == this.item.itemType
);
if (firstComponentWithTypeAndTask) {
componentFactory = this.componentFactoryResolver.resolveComponentFactory(firstComponentWithTypeAndTask['constructor'] as any);
} else {
let firstComponentWithType = this.selectedItemComponents
.find(value => value['forSourceTask'] == null &&
value['forItemType'] == this.item.itemType);
if (firstComponentWithType) {
componentFactory = this.componentFactoryResolver.resolveComponentFactory(firstComponentWithType['constructor'] as any);
let selected = -1;
let maxMatches =0;
let showItem = true;
for (let i = 0; i < this.selectedItemComponents.length; i++) {
let matches=0;
if (this.selectedItemComponents[i]['forItemType'] && this.selectedItemComponents[i]['forItemType'].indexOf(this.item.itemType) >= 0) {
matches++;
}
if (this.selectedItemComponents[i]['forSourceTask'] && this.selectedItemComponents[i]['forSourceTask'].indexOf(this.item.sourceTask) >= 0) {
matches++;
}
if(matches > maxMatches) {
selected=i;
maxMatches = matches;
}
}
if (selected >= 0) {
componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.selectedItemComponents[selected]['constructor'] as any);
}
const viewContainerRef = this.widgetHost.viewContainerRef;
viewContainerRef.clear();