From c0c9864b071baf563f74ac46ef2ddf750a5d7c19 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Tue, 17 Aug 2021 19:36:30 +0200 Subject: [PATCH] AW-2714 --- .../src/fm-map/actions/map.actions.ts | 11 ++++- .../src/fm-map/common-map.module.ts | 10 ++++- .../map-search/map-search.component.html | 2 +- .../map-search/map-search.component.ts | 43 ++++++++++--------- .../fm-map/components/map/map.component.html | 2 +- .../fm-map/components/map/map.component.ts | 4 ++ .../src/fm-map/reducers/map.reducer.ts | 10 +++-- 7 files changed, 55 insertions(+), 27 deletions(-) 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 1141da6..018b6d9 100644 --- a/projects/common-map/src/fm-map/actions/map.actions.ts +++ b/projects/common-map/src/fm-map/actions/map.actions.ts @@ -6,12 +6,14 @@ import { ILayervalue } from '../models/layer.value'; import { IQueryState } from '@farmmaps/common'; import { IItem } from '@farmmaps/common'; import { Feature,Style } from 'ol'; +import { IPeriodState } from 'common-map/public-api'; export const SETSTATE = '[Map] SetState'; export const SETMAPSTATE = '[Map] MapState'; export const SETVIEWEXTENT = '[Map] SetViewExtent'; export const INIT = '[Map] Init'; export const SETPARENT = '[Map] SetParent'; +export const SETPERIOD = '[Map] SetPeriod'; export const STARTSEARCH = '[Map] StartSearch'; export const STARTSEARCHSUCCESS = '[Map] StartSearchSuccess'; export const SELECTFEATURE = '[Map] SelectFeature'; @@ -86,6 +88,12 @@ export class SetParent implements Action { constructor(public parentCode:string) { } } +export class SetPeriod implements Action { + readonly type = SETPERIOD; + + constructor(public period:IPeriodState) { } +} + export class StartSearch implements Action { readonly type = STARTSEARCH; @@ -348,5 +356,6 @@ export type Actions = SetMapState | SetLayerValuesLocation | ToggleLayerValuesEnabled | GetLayerValueSuccess - | GetLayerValue; + | GetLayerValue + | SetPeriod; 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 d045795..9860d47 100644 --- a/projects/common-map/src/fm-map/common-map.module.ts +++ b/projects/common-map/src/fm-map/common-map.module.ts @@ -82,9 +82,17 @@ export function LocalStorageSync(reducer: ActionReducer): ActionReducer - + 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 a31750d..5cd587b 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 @@ -22,7 +22,10 @@ export class MapSearchComponent { @Input() set searchMinified(minified: boolean) { this.searchMinifiedLocal = minified; } - @Input() period: IPeriodState + @Input() set period(period:IPeriodState) { + this.periodLocal = tassign(this.periodLocal,{startDate: period.startDate,endDate:period.endDate}); + this.startEndCaption = this.timespanService.getCaption(period.startDate, period.endDate, 4) + } @Output() onSearch = new EventEmitter(); @Output() onClear = new EventEmitter(); @Output() onSearchCollapse = new EventEmitter(); @@ -30,6 +33,7 @@ export class MapSearchComponent { @Output() onToggleMenu = new EventEmitter(); @Output() onOpenModal = new EventEmitter(); @Output() onCloseModal = new EventEmitter(); + @Output() onPeriodChange = new EventEmitter(); @Input() openedModalName: string; @Input() set filterOptions(filterOptions: IQueryState) { if (filterOptions && filterOptions.query && filterOptions.query.length > 0) { @@ -42,23 +46,18 @@ export class MapSearchComponent { this.searchTextLocal = { name: filterOptions.tags }; } else { this.searchTextLocal = { name: filterOptions.query }; - } - if (this.dateFilter) { - this.filterOptionsLocal.startDate = this.startDate; - this.filterOptionsLocal.endDate = this.endDate; - } + } } public collapsedLocal: boolean = true; public searchMinifiedLocal: boolean = false; + public periodLocal: IPeriodState = { startDate:new Date(new Date(Date.now()).getFullYear(), new Date(Date.now()).getMonth() - 3, 1), endDate:new Date(Date.now())}; public filterOptionsLocal: IQueryState; private extent: number[]; public searchTextLocal: any; public searchTextLocalOutput: string; - public dateFilter: boolean = true; - public startDate: Date = new Date(new Date(Date.now()).getFullYear(), new Date(Date.now()).getMonth() - 3, 1); - public endDate: Date = new Date(Date.now()); - public startEndCaption: string = this.timespanService.getCaption(this.startDate, this.endDate, 4); + public dateFilter: boolean = true; + public startEndCaption: string = this.timespanService.getCaption(this.periodLocal.startDate, this.periodLocal.endDate, 4); searching = false; searchFailed = false; @@ -94,8 +93,8 @@ export class MapSearchComponent { this.filterOptionsLocal.parentCode = null; this.filterOptionsLocal.query = this.searchTextLocalOutput; if (this.dateFilter) { - this.filterOptionsLocal.startDate = this.startDate; - this.filterOptionsLocal.endDate = this.endDate; + this.filterOptionsLocal.startDate = this.periodLocal.startDate; + this.filterOptionsLocal.endDate = this.periodLocal.endDate; } this.onSearch.emit(this.filterOptionsLocal); } @@ -117,26 +116,30 @@ export class MapSearchComponent { this.filterOptionsLocal.parentCode = null; this.filterOptionsLocal.tags = event.item.name; if (this.dateFilter) { - this.filterOptionsLocal.startDate = this.startDate; - this.filterOptionsLocal.endDate = this.endDate; + this.filterOptionsLocal.startDate = this.periodLocal.startDate; + this.filterOptionsLocal.endDate = this.periodLocal.endDate; } this.onSearch.emit(this.filterOptionsLocal); this.searchTextLocal = { name: this.filterOptionsLocal.tags }; } handleSelectPeriod(event: { startDate: Date, endDate: Date }) { - this.startDate = event.startDate; - this.endDate = event.endDate; - this.handleCloseModal(); + this.periodLocal = { startDate: event.startDate, endDate: event.endDate} + this.onPeriodChange.emit(this.periodLocal); this.startEndCaption = this.timespanService.getCaption(event.startDate, event.endDate, 4); - this.onSearch.emit(this.filterOptionsLocal); + if(this.dateFilter) { + this.filterOptionsLocal.startDate =event.startDate; + this.filterOptionsLocal.endDate = event.endDate; + this.onSearch.emit(this.filterOptionsLocal); + } + this.handleCloseModal(); } handleChangeEnableDateFilter(enabled) { this.dateFilter = enabled; if (enabled) { - this.filterOptionsLocal.startDate = this.startDate; - this.filterOptionsLocal.endDate = this.endDate; + this.filterOptionsLocal.startDate = this.periodLocal.startDate; + this.filterOptionsLocal.endDate = this.periodLocal.endDate; } else { this.filterOptionsLocal.startDate = null; this.filterOptionsLocal.endDate = null; diff --git a/projects/common-map/src/fm-map/components/map/map.component.html b/projects/common-map/src/fm-map/components/map/map.component.html index 4d32049..7c3ac19 100644 --- a/projects/common-map/src/fm-map/components/map/map.component.html +++ b/projects/common-map/src/fm-map/components/map/map.component.html @@ -50,7 +50,7 @@
- +
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 a5cb95e..4745d0e 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 @@ -434,6 +434,10 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { this.store.dispatch(new mapActions.SelectOverlayLayer(itemLayer)); } + handlePeriodChange(period:IPeriodState) { + this.store.dispatch(new mapActions.SetPeriod(period)); + } + ngOnDestroy() { if (this.paramSub) this.paramSub.unsubscribe(); if (this.itemTypeSub) this.itemTypeSub.unsubscribe(); 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 3455ec9..86253e1 100644 --- a/projects/common-map/src/fm-map/reducers/map.reducer.ts +++ b/projects/common-map/src/fm-map/reducers/map.reducer.ts @@ -3,7 +3,7 @@ import { IItem,Item } from '@farmmaps/common'; import { IItemLayer,ItemLayer,ITemporalItemLayer,TemporalItemLayer} from '../models/item.layer'; import { IMapState} from '../models/map.state'; import { IQueryState} from '@farmmaps/common'; -import { IPeriodState} from '../models/period.state'; +import { IPeriodState } from '../models/period.state'; import { IStyles} from '../models/style.cache'; import { ILayervalue } from '../models/layer.value'; import * as mapActions from '../actions/map.actions'; @@ -304,10 +304,14 @@ export function reducer(state = initialState, action: mapActions.Actions | commo return tassign(state, { query: tassign(state.query, { - querystate: tassign(a.query, { bbox: a.query.bboxFilter ? state.viewExtent : [] }), + querystate: tassign(a.query, { bbox: a.query.bboxFilter ? state.viewExtent : [] }), replace:a.replace }) - }) + }) + } + + case mapActions.SETPERIOD: { + return tassign(state,{ period: action.period}); } case mapActions.ADDFEATURESUCCESS: {