Refactor some stuff to a service
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
parent
516d63a59e
commit
eb50218a8d
@ -58,6 +58,7 @@ import { LayerVectorImageComponent } from './components/aol/layer-vector-image/l
|
||||
import {FeatureIconService} from './services/feature-icon.service';
|
||||
import { GeolocationService } from './services/geolocation.service';
|
||||
import {DeviceOrientationService} from './services/device-orientation.service';
|
||||
import { TemporalService} from './services/temporal.service';
|
||||
import { WidgetStatusComponent } from './components/widget-status/widget-status.component';
|
||||
import { ForChild} from './components/for-item/for-child.decorator';
|
||||
import {ForItemType } from './components/for-item/for-itemtype.decorator';
|
||||
@ -139,6 +140,7 @@ export {
|
||||
FeatureIconService,
|
||||
GeolocationService,
|
||||
DeviceOrientationService,
|
||||
TemporalService,
|
||||
IMapState,
|
||||
ISelectedFeatures,
|
||||
IItemLayer,
|
||||
@ -265,6 +267,7 @@ export {
|
||||
FeatureIconService,
|
||||
GeolocationService,
|
||||
DeviceOrientationService,
|
||||
TemporalService,
|
||||
{ provide: AbstractFeatureListComponent, useClass: FeatureListCroppingschemeComponent, multi: true },
|
||||
{ provide: AbstractFeatureListComponent, useClass: FeatureListCropfieldComponent, multi: true },
|
||||
{ provide: AbstractFeatureListFeatureComponent, useClass: FeatureListFeatureComponent, multi: true },
|
||||
|
@ -9,16 +9,16 @@
|
||||
</div>
|
||||
<div class="legend-container" *ngIf="item?.data.layers;let layers">
|
||||
<div class="card menu-card">
|
||||
<h5><span i18n>Date</span>: {{selectedDate()}}</h5>
|
||||
<h5><span i18n>Date</span>: {{temporalService.selectedDate(itemLayer)}}</h5>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>
|
||||
<button *ngIf="hasPrevious()" type="button" class="btn btn-link p-0" (click)="handlePreviousTemporal($event)">
|
||||
<i class="fal fa-arrow-circle-left" aria-hidden="true" i18n-title title="Previous"></i> {{ previousDate() }}
|
||||
<button *ngIf="temporalService.hasPrevious(itemLayer)" type="button" class="btn btn-link p-0" (click)="handlePreviousTemporal($event)">
|
||||
<i class="fal fa-arrow-circle-left" aria-hidden="true" i18n-title title="Previous"></i> {{ temporalService.previousDate(itemLayer) }}
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button *ngIf="hasNext()" type="button" class="btn btn-link p-0" (click)="handleNextTemporal($event)">
|
||||
{{ nextDate()}} <i class="fal fa-arrow-circle-right" aria-hidden="true" i18n-title title="Next"></i>
|
||||
<button *ngIf="temporalService.hasNext(itemLayer)" type="button" class="btn btn-link p-0" (click)="handleNextTemporal($event)">
|
||||
{{ temporalService.nextDate(itemLayer)}} <i class="fal fa-arrow-circle-right" aria-hidden="true" i18n-title title="Next"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,14 +1,15 @@
|
||||
import { Component, Injectable } from '@angular/core';
|
||||
import { Location,DatePipe } from '@angular/common';
|
||||
import { Location } from '@angular/common';
|
||||
import { Store } from '@ngrx/store';
|
||||
import * as mapReducers from '../../reducers/map.reducer';
|
||||
import { commonReducers, ItemTypeService, ItemService, FolderService,IItem,TimespanService } from '@farmmaps/common';
|
||||
import { commonReducers, ItemTypeService, IItem } from '@farmmaps/common';
|
||||
import { Router } from '@angular/router';
|
||||
import { ForItemType } from '../for-item/for-itemtype.decorator';
|
||||
import { AbstractSelectedItemComponent } from '../selected-item/selected-item.component';
|
||||
import { ITemporalItemLayer} from '../../models/item.layer';
|
||||
import * as mapActions from '../../actions/map.actions';
|
||||
import { IItemLayer } from '../../models/item.layer';
|
||||
import {TemporalService} from '../../services/temporal.service';
|
||||
|
||||
|
||||
@ForItemType("vnd.farmmaps.itemtype.temporal")
|
||||
@ -20,7 +21,7 @@ import { IItemLayer } from '../../models/item.layer';
|
||||
})
|
||||
export class SelectedItemTemporalComponent extends AbstractSelectedItemComponent {
|
||||
|
||||
constructor(store: Store<mapReducers.State | commonReducers.State>, itemTypeService: ItemTypeService, location: Location, router: Router, private itemService$: ItemService,private folderService$: FolderService, private timespanService$:TimespanService,private datePipe$: DatePipe) {
|
||||
constructor(store: Store<mapReducers.State | commonReducers.State>, itemTypeService: ItemTypeService, location: Location, router: Router,public temporalService:TemporalService) {
|
||||
super(store, itemTypeService,location,router);
|
||||
}
|
||||
|
||||
@ -32,60 +33,7 @@ export class SelectedItemTemporalComponent extends AbstractSelectedItemComponent
|
||||
return (this.itemLayer as ITemporalItemLayer)?.selectedItemLayer
|
||||
}
|
||||
|
||||
hasNext():boolean {
|
||||
let temporalItemLayer = this.itemLayer as ITemporalItemLayer;
|
||||
return temporalItemLayer && temporalItemLayer.nextItemLayer != null;
|
||||
}
|
||||
|
||||
selectedDate():string {
|
||||
let temporalItemLayer = this.itemLayer as ITemporalItemLayer;
|
||||
if(temporalItemLayer.selectedItemLayer) {
|
||||
if(temporalItemLayer.selectedItemLayer.item.dataDate && temporalItemLayer.selectedItemLayer.item.dataEndDate) {
|
||||
let sd = new Date(Date.parse(temporalItemLayer.selectedItemLayer.item.dataDate));
|
||||
let ed = new Date(Date.parse(temporalItemLayer.selectedItemLayer.item.dataEndDate));
|
||||
return this.timespanService$.getCaption(sd,ed);
|
||||
} else {
|
||||
let d = new Date(Date.parse(temporalItemLayer.selectedItemLayer.item.dataDate));
|
||||
return this.datePipe$.transform(d, "shortDate");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
nextDate():string {
|
||||
let temporalItemLayer = this.itemLayer as ITemporalItemLayer;
|
||||
if(temporalItemLayer.nextItemLayer.item) {
|
||||
if(temporalItemLayer.nextItemLayer.item.dataDate && temporalItemLayer.nextItemLayer.item.dataEndDate) {
|
||||
let sd = new Date(Date.parse(temporalItemLayer.nextItemLayer.item.dataDate));
|
||||
let ed = new Date(Date.parse(temporalItemLayer.nextItemLayer.item.dataEndDate));
|
||||
return this.timespanService$.getCaption(sd,ed);
|
||||
} else {
|
||||
let d = new Date(Date.parse(temporalItemLayer.nextItemLayer.item.dataDate));
|
||||
return this.datePipe$.transform(d, "shortDate");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
hasPrevious():boolean {
|
||||
let temporalItemLayer = this.itemLayer as ITemporalItemLayer;
|
||||
return temporalItemLayer && temporalItemLayer.previousItemLayer != null;
|
||||
}
|
||||
|
||||
previousDate():string {
|
||||
let temporalItemLayer = this.itemLayer as ITemporalItemLayer;
|
||||
if(temporalItemLayer.previousItemLayer.item) {
|
||||
if(temporalItemLayer.previousItemLayer.item.dataDate && temporalItemLayer.previousItemLayer.item.dataEndDate) {
|
||||
let sd = new Date(Date.parse(temporalItemLayer.previousItemLayer.item.dataDate));
|
||||
let ed = new Date(Date.parse(temporalItemLayer.previousItemLayer.item.dataEndDate));
|
||||
return this.timespanService$.getCaption(sd,ed);
|
||||
} else {
|
||||
let d = new Date(Date.parse(temporalItemLayer.previousItemLayer.item.dataDate));
|
||||
return this.datePipe$.transform(d, "shortDate");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
handleNextTemporal(event:MouseEvent) {
|
||||
this.store.dispatch(new mapActions.NextTemporal());
|
||||
|
65
projects/common-map/src/fm-map/services/temporal.service.ts
Normal file
65
projects/common-map/src/fm-map/services/temporal.service.ts
Normal file
@ -0,0 +1,65 @@
|
||||
import { Injectable} from '@angular/core';
|
||||
import {DatePipe} from '@angular/common';
|
||||
import {TimespanService} from '@farmmaps/common';
|
||||
import { IItemLayer, ITemporalItemLayer,TemporalItemLayer} from '../models/item.layer';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class TemporalService {
|
||||
constructor(private timespanService$:TimespanService,private datePipe$: DatePipe) {}
|
||||
|
||||
hasNext(itemLayer:IItemLayer):boolean {
|
||||
let temporalItemLayer = itemLayer as ITemporalItemLayer;
|
||||
return temporalItemLayer && temporalItemLayer.nextItemLayer != null;
|
||||
}
|
||||
|
||||
selectedDate(itemLayer:IItemLayer):string {
|
||||
let temporalItemLayer = itemLayer as ITemporalItemLayer;
|
||||
if(temporalItemLayer.selectedItemLayer) {
|
||||
if(temporalItemLayer.selectedItemLayer.item.dataDate && temporalItemLayer.selectedItemLayer.item.dataEndDate) {
|
||||
let sd = new Date(Date.parse(temporalItemLayer.selectedItemLayer.item.dataDate));
|
||||
let ed = new Date(Date.parse(temporalItemLayer.selectedItemLayer.item.dataEndDate));
|
||||
return this.timespanService$.getCaption(sd,ed);
|
||||
} else {
|
||||
let d = new Date(Date.parse(temporalItemLayer.selectedItemLayer.item.dataDate));
|
||||
return this.datePipe$.transform(d, "shortDate");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
nextDate(itemLayer:IItemLayer):string {
|
||||
let temporalItemLayer = itemLayer as ITemporalItemLayer;
|
||||
if(temporalItemLayer.nextItemLayer.item) {
|
||||
if(temporalItemLayer.nextItemLayer.item.dataDate && temporalItemLayer.nextItemLayer.item.dataEndDate) {
|
||||
let sd = new Date(Date.parse(temporalItemLayer.nextItemLayer.item.dataDate));
|
||||
let ed = new Date(Date.parse(temporalItemLayer.nextItemLayer.item.dataEndDate));
|
||||
return this.timespanService$.getCaption(sd,ed);
|
||||
} else {
|
||||
let d = new Date(Date.parse(temporalItemLayer.nextItemLayer.item.dataDate));
|
||||
return this.datePipe$.transform(d, "shortDate");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
hasPrevious(itemLayer:IItemLayer):boolean {
|
||||
let temporalItemLayer = itemLayer as ITemporalItemLayer;
|
||||
return temporalItemLayer && temporalItemLayer.previousItemLayer != null;
|
||||
}
|
||||
|
||||
previousDate(itemLayer:IItemLayer):string {
|
||||
let temporalItemLayer = itemLayer as ITemporalItemLayer;
|
||||
if(temporalItemLayer.previousItemLayer.item) {
|
||||
if(temporalItemLayer.previousItemLayer.item.dataDate && temporalItemLayer.previousItemLayer.item.dataEndDate) {
|
||||
let sd = new Date(Date.parse(temporalItemLayer.previousItemLayer.item.dataDate));
|
||||
let ed = new Date(Date.parse(temporalItemLayer.previousItemLayer.item.dataEndDate));
|
||||
return this.timespanService$.getCaption(sd,ed);
|
||||
} else {
|
||||
let d = new Date(Date.parse(temporalItemLayer.previousItemLayer.item.dataDate));
|
||||
return this.datePipe$.transform(d, "shortDate");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user