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,15 +23,28 @@ export class ItemListItemContainerComponent {
loadComponent() {
var componentFactory: ComponentFactory<AbstractItemListItemComponent> = this.componentFactoryResolver.resolveComponentFactory(ItemListItemComponent); // default
for (var i = 0; i < this.itemComponentList.length; i++) {
if (this.itemComponentList[i]['forItemType'] &&
this.itemComponentList[i]['forItemType'].indexOf(this.item.itemType) >= 0 &&
this.itemComponentList[i]['forSourceTask'] &&
this.itemComponentList[i]['forSourceTask'].indexOf(this.item.sourceTask) >= 0 )
{
componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.itemComponentList[i]['constructor'] as any);
let selected = -1;
let maxMatches =0;
let showItem = true;
for (let i = 0; i < this.itemComponentList.length; i++) {
let matches=0;
if (this.itemComponentList[i]['forItemType'] && this.itemComponentList[i]['forItemType'].indexOf(this.item.itemType) >= 0) {
matches++;
}
}
if (this.itemComponentList[i]['forSourceTask'] && this.itemComponentList[i]['forSourceTask'].indexOf(this.item.sourceTask) >= 0) {
matches++;
}
if(matches > maxMatches) {
selected=i;
maxMatches = matches;
}
}
if (selected >= 0) {
componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.itemComponentList[selected]['constructor'] as any);
}
const viewContainerRef = this.widgetHost.viewContainerRef;
viewContainerRef.clear();