Refactor template selection logic add forpackage decorator
Some checks failed
FarmMaps.Develop/FarmMapsLib/pipeline/head There was a failure building this commit
Some checks failed
FarmMaps.Develop/FarmMapsLib/pipeline/head There was a failure building this commit
This commit is contained in:
parent
cd156ab1bc
commit
cbe27c2add
@ -64,6 +64,7 @@ import { WidgetStatusComponent } from './components/widget-status/widget-status.
|
||||
import { ForChild} from './components/for-item/for-child.decorator';
|
||||
import {ForItemType } from './components/for-item/for-itemtype.decorator';
|
||||
import { ForSourceTask} from './components/for-item/for-sourcetask.decorator';
|
||||
import { ForPackage } from './components/for-item/for-package.decorator';
|
||||
import { PanToLocation} from './components/aol/pan-to-location/pan-to-location.component';
|
||||
import {LayerSwitcher} from './components/layer-switcher/layer-switcher.component';
|
||||
|
||||
@ -143,7 +144,8 @@ export {
|
||||
IPeriodState,
|
||||
ForChild,
|
||||
ForItemType,
|
||||
ForSourceTask
|
||||
ForSourceTask,
|
||||
ForPackage
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
|
@ -2,7 +2,7 @@ import { Component, Input, OnInit, ComponentFactoryResolver, ViewChild, SimpleCh
|
||||
import { Feature } from 'ol';
|
||||
import { FeatureListComponent,AbstractFeatureListComponent } from '../feature-list/feature-list.component';
|
||||
import { WidgetHostDirective } from '../widget-host/widget-host.directive';
|
||||
import {IQueryState } from '@farmmaps/common';
|
||||
import {IQueryState,PackageService } from '@farmmaps/common';
|
||||
import * as mapReducers from '../../reducers/map.reducer';
|
||||
import * as mapActions from '../../actions/map.actions';
|
||||
import { Store } from '@ngrx/store';
|
||||
@ -16,7 +16,7 @@ import { Observable } from 'rxjs';
|
||||
})
|
||||
export class FeatureListContainerComponent {
|
||||
|
||||
constructor(private store: Store<mapReducers.State>,private componentFactoryResolver: ComponentFactoryResolver, @Inject(AbstractFeatureListComponent) public featureLists: AbstractFeatureListComponent[] ) {
|
||||
constructor(private store: Store<mapReducers.State>,private componentFactoryResolver: ComponentFactoryResolver, @Inject(AbstractFeatureListComponent) public featureLists: AbstractFeatureListComponent[],private packageService:PackageService ) {
|
||||
}
|
||||
|
||||
@Input() features: Array<Feature>
|
||||
@ -28,31 +28,38 @@ export class FeatureListContainerComponent {
|
||||
componentRef:any;
|
||||
|
||||
loadComponent(queryState:IQueryState) {
|
||||
var componentFactory: ComponentFactory<AbstractFeatureListComponent> = this.componentFactoryResolver.resolveComponentFactory(FeatureListComponent); // default
|
||||
var selected = -1;
|
||||
for (var i = 0; i < this.featureLists.length; i++) {
|
||||
if (this.featureLists[i]['forItemType'] == queryState.itemType && this.featureLists[i]['forChild'] && queryState.parentCode && queryState.parentCode != "") {
|
||||
selected = i;
|
||||
break;
|
||||
} else if (this.featureLists[i]['forItemType'] == queryState.itemType) {
|
||||
selected = i;
|
||||
break;
|
||||
let componentFactory: ComponentFactory<AbstractFeatureListComponent> = this.componentFactoryResolver.resolveComponentFactory(FeatureListComponent); // default
|
||||
let selected = -1;
|
||||
let maxMatches =0;
|
||||
let showItem = true;
|
||||
for (let i = 0; i < this.featureLists.length; i++) {
|
||||
let matches=0;
|
||||
if (this.featureLists[i]['forItemType'] && this.featureLists[i]['forItemType'].indexOf(queryState.itemType) >= 0) {
|
||||
matches++;
|
||||
}
|
||||
if(this.featureLists[i]['forChild'] && queryState.parentCode && queryState.parentCode != "") {
|
||||
matches++;
|
||||
}
|
||||
if(matches > maxMatches) {
|
||||
selected=i;
|
||||
maxMatches = matches;
|
||||
}
|
||||
}
|
||||
if (selected >= 0) {
|
||||
componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.featureLists[i]['constructor'] as any);
|
||||
componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.featureLists[selected]['constructor'] as any);
|
||||
if (this.featureLists[selected]['collapseSearch'] === true) {
|
||||
this.store.dispatch(new mapActions.CollapseSearch());
|
||||
}
|
||||
}
|
||||
const viewContainerRef = this.widgetHost.viewContainerRef;
|
||||
viewContainerRef.clear();
|
||||
|
||||
if(showItem) {
|
||||
this.componentRef = viewContainerRef.createComponent(componentFactory);
|
||||
(<AbstractFeatureListComponent>this.componentRef.instance).features = null;
|
||||
(<AbstractFeatureListComponent>this.componentRef.instance).queryState = queryState;
|
||||
(<AbstractFeatureListComponent>this.componentRef.instance).selectedFeature = null;
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.clickedFeature.subscribe((feature => {
|
||||
|
@ -23,11 +23,23 @@ export class FeatureListFeatureContainerComponent {
|
||||
|
||||
loadComponent() {
|
||||
var componentFactory: ComponentFactory<AbstractFeatureListFeatureComponent> = this.componentFactoryResolver.resolveComponentFactory(FeatureListFeatureComponent); // default
|
||||
for (var i = 0; i < this.featureLists.length; i++) {
|
||||
|
||||
let selected = -1;
|
||||
let maxMatches =0;
|
||||
for (let i = 0; i < this.featureLists.length; i++) {
|
||||
let matches=0;
|
||||
if (this.featureLists[i]['forItemType'] == this.feature.get("itemType")) {
|
||||
componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.featureLists[i]['constructor'] as any);
|
||||
matches++;
|
||||
}
|
||||
if(matches > maxMatches) {
|
||||
selected=i;
|
||||
maxMatches = matches;
|
||||
}
|
||||
}
|
||||
if (selected >= 0) {
|
||||
componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.featureLists[selected]['constructor'] as any);
|
||||
}
|
||||
|
||||
const viewContainerRef = this.widgetHost.viewContainerRef;
|
||||
viewContainerRef.clear();
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
export function ForPackage(packageCode: string) {
|
||||
return function (constructor:Function) {
|
||||
constructor.prototype.forPackage = packageCode;
|
||||
};
|
||||
}
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
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 (firstComponentWithType) {
|
||||
componentFactory = this.componentFactoryResolver.resolveComponentFactory(firstComponentWithType['constructor'] as any);
|
||||
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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user