From 755475bff7b31134cb61246f122fe8dfa30fd0e2 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Wed, 19 Feb 2020 11:37:21 +0100 Subject: [PATCH] Remove stateserializerservice from common-map --- .../src/fm-map/actions/map.actions.ts | 2 +- .../src/fm-map/common-map.module.ts | 5 - .../feature-list-container.component.ts | 2 +- .../feature-list/feature-list.component.ts | 104 +++++++++--------- .../map-search/map-search.component.ts | 2 +- .../fm-map/components/map/map.component.ts | 4 +- .../src/fm-map/models/query.state.ts | 12 -- .../src/fm-map/reducers/map.reducer.ts | 2 +- .../services/state-serializer.service.ts | 52 --------- 9 files changed, 58 insertions(+), 127 deletions(-) delete mode 100644 projects/common-map/src/fm-map/models/query.state.ts delete mode 100644 projects/common-map/src/fm-map/services/state-serializer.service.ts diff --git a/projects/common-map/src/fm-map/actions/map.actions.ts b/projects/common-map/src/fm-map/actions/map.actions.ts index afd8cab..cb87f3c 100644 --- a/projects/common-map/src/fm-map/actions/map.actions.ts +++ b/projects/common-map/src/fm-map/actions/map.actions.ts @@ -2,7 +2,7 @@ import { Action } from '@ngrx/store'; import { IMapState } from '../models/map.state'; import { IItemLayer } from '../models/item.layer'; -import { IQueryState } from '../models/query.state'; +import { IQueryState } from '@farmmaps/common'; import { IItem } from '@farmmaps/common'; import { Feature,Style } from 'ol'; diff --git a/projects/common-map/src/fm-map/common-map.module.ts b/projects/common-map/src/fm-map/common-map.module.ts index 0178b67..aa84e50 100644 --- a/projects/common-map/src/fm-map/common-map.module.ts +++ b/projects/common-map/src/fm-map/common-map.module.ts @@ -20,7 +20,6 @@ import { IMapState} from './models/map.state'; import { ISelectedFeatures } from './models/selected.features'; import { IItemLayer } from './models/item.layer'; import { ItemLayer} from './models/item.layer'; -import { IQueryState } from './models/query.state'; import { IPeriodState } from './models/period.state'; // components @@ -57,7 +56,6 @@ import { MapSearchComponent } from './components/map-search/map-search.component import { MapRoutingModule } from './common-map-routing.module'; import { LegendComponent } from './components/legend/legend.component'; import { LayerVectorImageComponent } from './components/aol/layer-vector-image/layer-vector-image.component'; -import { StateSerializerService } from './services/state-serializer.service'; import {FeatureIconService} from './services/feature-icon.service'; import { GeolocationService } from './services/geolocation.service'; import {DeviceOrientationService} from './services/device-orientation.service'; @@ -133,7 +131,6 @@ export { AbstractItemWidgetComponent, AbstractItemListItemComponent, AbstractItemListComponent, - StateSerializerService, FeatureIconService, GeolocationService, DeviceOrientationService, @@ -141,7 +138,6 @@ export { ISelectedFeatures, IItemLayer, ItemLayer, - IQueryState, IPeriodState, ForChild, ForItemType, @@ -254,7 +250,6 @@ export class AppCommonMapModule { return { ngModule: AppCommonMapModule, providers: [ - StateSerializerService, FeatureIconService, GeolocationService, DeviceOrientationService, diff --git a/projects/common-map/src/fm-map/components/feature-list-container/feature-list-container.component.ts b/projects/common-map/src/fm-map/components/feature-list-container/feature-list-container.component.ts index de80465..80482a2 100644 --- a/projects/common-map/src/fm-map/components/feature-list-container/feature-list-container.component.ts +++ b/projects/common-map/src/fm-map/components/feature-list-container/feature-list-container.component.ts @@ -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 '../../models/query.state'; +import {IQueryState } from '@farmmaps/common'; import * as mapReducers from '../../reducers/map.reducer'; import * as mapActions from '../../actions/map.actions'; import { Store } from '@ngrx/store'; diff --git a/projects/common-map/src/fm-map/components/feature-list/feature-list.component.ts b/projects/common-map/src/fm-map/components/feature-list/feature-list.component.ts index 4b89734..119866c 100644 --- a/projects/common-map/src/fm-map/components/feature-list/feature-list.component.ts +++ b/projects/common-map/src/fm-map/components/feature-list/feature-list.component.ts @@ -1,52 +1,52 @@ -import { Component, Input, Injectable } from '@angular/core'; -import { Location } from '@angular/common'; -import { Feature } from 'ol'; -import { Store } from '@ngrx/store'; -import * as mapReducers from '../../reducers/map.reducer'; -import { commonReducers,ItemTypeService, IItem, Item } from '@farmmaps/common'; -import * as mapActions from '../../actions/map.actions'; -import { Observable, from } from 'rxjs'; -import { withLatestFrom } from 'rxjs/operators'; -import { tassign } from 'tassign'; -import { IQueryState } from '../../models/query.state'; - - -@Injectable() -export abstract class AbstractFeatureListComponent { - @Input() features: Array; - @Input() queryState: IQueryState; - constructor(public store: Store, public itemTypeService: ItemTypeService, private location: Location) { - } - - handleFeatureClick(feature:Feature) { - var newQuery: any = tassign(mapReducers.initialState.query); - newQuery.itemCode = feature.get('code'); - this.store.dispatch(new mapActions.DoQuery(newQuery)); - } - - handleFeatureMouseEnter(feature) { - this.store.dispatch(new mapActions.SelectFeature(feature)); - } - - handleFeatureMouseLeave(feature) { - this.store.dispatch(new mapActions.SelectFeature(null)); - } - - handleBackClick(event: MouseEvent) { - event.preventDefault(); - this.location.back(); - } -} - -@Injectable() -@Component({ - selector: 'fm-map-feature-list', - templateUrl: './feature-list.component.html', - styleUrls: ['./feature-list.component.scss'] -}) -export class FeatureListComponent extends AbstractFeatureListComponent { - - constructor(store: Store, itemTypeService: ItemTypeService,location:Location) { - super(store, itemTypeService,location); - } -} +import { Component, Input, Injectable } from '@angular/core'; +import { Location } from '@angular/common'; +import { Feature } from 'ol'; +import { Store } from '@ngrx/store'; +import * as mapReducers from '../../reducers/map.reducer'; +import { commonReducers,ItemTypeService, IItem, Item } from '@farmmaps/common'; +import * as mapActions from '../../actions/map.actions'; +import { Observable, from } from 'rxjs'; +import { withLatestFrom } from 'rxjs/operators'; +import { tassign } from 'tassign'; +import { IQueryState } from '@farmmaps/common'; + + +@Injectable() +export abstract class AbstractFeatureListComponent { + @Input() features: Array; + @Input() queryState: IQueryState; + constructor(public store: Store, public itemTypeService: ItemTypeService, private location: Location) { + } + + handleFeatureClick(feature:Feature) { + var newQuery: any = tassign(mapReducers.initialState.query); + newQuery.itemCode = feature.get('code'); + this.store.dispatch(new mapActions.DoQuery(newQuery)); + } + + handleFeatureMouseEnter(feature) { + this.store.dispatch(new mapActions.SelectFeature(feature)); + } + + handleFeatureMouseLeave(feature) { + this.store.dispatch(new mapActions.SelectFeature(null)); + } + + handleBackClick(event: MouseEvent) { + event.preventDefault(); + this.location.back(); + } +} + +@Injectable() +@Component({ + selector: 'fm-map-feature-list', + templateUrl: './feature-list.component.html', + styleUrls: ['./feature-list.component.scss'] +}) +export class FeatureListComponent extends AbstractFeatureListComponent { + + constructor(store: Store, itemTypeService: ItemTypeService,location:Location) { + super(store, itemTypeService,location); + } +} diff --git a/projects/common-map/src/fm-map/components/map-search/map-search.component.ts b/projects/common-map/src/fm-map/components/map-search/map-search.component.ts index a099c26..fe8c2e5 100644 --- a/projects/common-map/src/fm-map/components/map-search/map-search.component.ts +++ b/projects/common-map/src/fm-map/components/map-search/map-search.component.ts @@ -2,7 +2,7 @@ import { Component, Input, Output, OnInit, EventEmitter, SimpleChanges, OnChange import { Observable , of } from 'rxjs'; import { debounceTime,distinctUntilChanged,tap,switchMap,merge,catchError} from 'rxjs/operators'; import { TypeaheadService, TimespanService } from '@farmmaps/common'; -import { IQueryState } from '../../models/query.state'; +import { IQueryState } from '@farmmaps/common'; import { IPeriodState } from '../../models/period.state'; import { tassign } from 'tassign'; diff --git a/projects/common-map/src/fm-map/components/map/map.component.ts b/projects/common-map/src/fm-map/components/map/map.component.ts index 6928321..8f7ddb5 100644 --- a/projects/common-map/src/fm-map/components/map/map.component.ts +++ b/projects/common-map/src/fm-map/components/map/map.component.ts @@ -12,12 +12,12 @@ import * as mapActions from '../../actions/map.actions'; import { IMapState} from '../../models/map.state'; import { ISelectedFeatures } from '../../models/selected.features'; import { IItemLayer } from '../../models/item.layer'; -import { IQueryState } from '../../models/query.state'; +import { IQueryState } from '@farmmaps/common'; import { IPeriodState } from '../../models/period.state'; import {IStyles} from '../../models/style.cache'; import { IDroppedFile } from '../aol/file-drop-target/file-drop-target.component'; import { IMetaData } from '../meta-data-modal/meta-data-modal.component'; -import { StateSerializerService } from '../../services/state-serializer.service'; +import { StateSerializerService } from '@farmmaps/common'; import { GeolocationService} from '../../services/geolocation.service'; import {DeviceOrientationService} from '../../services/device-orientation.service'; diff --git a/projects/common-map/src/fm-map/models/query.state.ts b/projects/common-map/src/fm-map/models/query.state.ts deleted file mode 100644 index cc011cd..0000000 --- a/projects/common-map/src/fm-map/models/query.state.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface IQueryState { - itemCode: string; - parentCode: string; - level: number; - itemType: string; - query: string; - tags: string; - bboxFilter: boolean; - startDate: Date; - endDate: Date; - bbox: number[]; -} diff --git a/projects/common-map/src/fm-map/reducers/map.reducer.ts b/projects/common-map/src/fm-map/reducers/map.reducer.ts index 0a7d7e7..b2e7fda 100644 --- a/projects/common-map/src/fm-map/reducers/map.reducer.ts +++ b/projects/common-map/src/fm-map/reducers/map.reducer.ts @@ -2,7 +2,7 @@ import { tassign } from 'tassign'; import { IItem,Item } from '@farmmaps/common'; import { IItemLayer,ItemLayer} from '../models/item.layer'; import { IMapState} from '../models/map.state'; -import { IQueryState} from '../models/query.state'; +import { IQueryState} from '@farmmaps/common'; import { IPeriodState} from '../models/period.state'; import { IStyles} from '../models/style.cache'; import * as mapActions from '../actions/map.actions'; diff --git a/projects/common-map/src/fm-map/services/state-serializer.service.ts b/projects/common-map/src/fm-map/services/state-serializer.service.ts deleted file mode 100644 index 3fb9b31..0000000 --- a/projects/common-map/src/fm-map/services/state-serializer.service.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { Injectable, Query } from '@angular/core'; -import { IQueryState } from '../models/query.state'; -import { query } from '@angular/animations'; - -@Injectable() -export class StateSerializerService { - - serialize(queryState: IQueryState): string { - - var state = ""; - state += (queryState.itemCode) ? queryState.itemCode : ""; - state += ";"; - state += (queryState.parentCode) ? queryState.parentCode + ";" + queryState.level.toString() : ";"; - state += ";"; - state += (queryState.itemType) ? queryState.itemType : ""; - state += ";"; - state += (queryState.query) ? encodeURIComponent( queryState.query ) : ""; - state += ";"; - state += (queryState.tags) ? encodeURIComponent( queryState.tags ) : ""; - state += ";"; - state += (queryState.bboxFilter) ? "1" : "0"; - state += ";"; - state += (queryState.startDate) ? JSON.stringify(queryState.startDate) : ""; - state += ";"; - state += (queryState.endDate) ? JSON.stringify(queryState.endDate) : ""; - state += ";"; - state += (queryState.bboxFilter && queryState.bbox && queryState.bbox.length>0) ? JSON.stringify(queryState.bbox) : ""; - - return btoa(state); - } - - deserialize(queryState: string): IQueryState { - var state: IQueryState = { itemCode: null, parentCode: null, level: 1, itemType: null, query: null, tags: null, bboxFilter: false, startDate: null, endDate: null,bbox:[] }; - var stateParts = atob(queryState).split(";"); - if (stateParts.length == 10) { - if (stateParts[0] != "") state.itemCode = stateParts[0]; - if (stateParts[1] != "") { - state.parentCode = stateParts[1]; - state.level = parseInt(stateParts[2]); - } - if (stateParts[3] != "") state.itemType = stateParts[3]; - if (stateParts[4] != "") state.query = decodeURIComponent(stateParts[4]); - if (stateParts[5] != "") state.tags = decodeURIComponent( stateParts[5]); - if (stateParts[6] != "") state.bboxFilter = parseInt(stateParts[6]) == 1; - if (stateParts[7] != "") state.startDate = new Date(Date.parse(JSON.parse(stateParts[7]))); - if (stateParts[8] != "") state.endDate = new Date(Date.parse(JSON.parse(stateParts[8]))); - if (stateParts[9] != "") state.bbox = JSON.parse(stateParts[9]); - } - - return state; - } -}