import { Component, Injectable } from '@angular/core'; import { Location } from '@angular/common'; import { Store } from '@ngrx/store'; import * as mapReducers from '../../reducers/map.reducer'; import { commonReducers, ItemTypeService, ItemService, FolderService,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'; @ForItemType("vnd.farmmaps.itemtype.temporal") @Injectable() @Component({ selector: 'fm-map-selected-item-temporal', templateUrl: './selected-item-temporal.component.html', styleUrls: ['./selected-item-temporal.component.scss'] }) export class SelectedItemTemporalComponent extends AbstractSelectedItemComponent { constructor(store: Store, itemTypeService: ItemTypeService, location: Location, router: Router, private itemService$: ItemService,private folderService$: FolderService) { super(store, itemTypeService,location,router); } onLayerChanged(layerIndex: number) { this.store.dispatch(new mapActions.SetLayerIndex(layerIndex)); } hasNext():boolean { let temporalItemLayer = this.itemLayer as ITemporalItemLayer; return temporalItemLayer && temporalItemLayer.nextItemLayer != null; } nextDate():Date { let temporalItemLayer = this.itemLayer as ITemporalItemLayer; if(temporalItemLayer.nextItemLayer.item) return new Date(Date.parse(temporalItemLayer.nextItemLayer.item.dataDate)) ; return null; } hasPrevious():boolean { let temporalItemLayer = this.itemLayer as ITemporalItemLayer; return temporalItemLayer && temporalItemLayer.previousItemLayer != null; } previousDate():Date { let temporalItemLayer = this.itemLayer as ITemporalItemLayer; if(temporalItemLayer.previousItemLayer.item) return new Date(Date.parse(temporalItemLayer.previousItemLayer.item.dataDate)); return null; } handleNextTemporal(event:MouseEvent) { this.store.dispatch(new mapActions.NextTemporal()); event.preventDefault(); } handlePreviousTemporal(event:MouseEvent) { this.store.dispatch(new mapActions.PreviousTemporal()); event.preventDefault(); } selectedItem():IItem { let temporalItemLayer = this.itemLayer as ITemporalItemLayer; if(temporalItemLayer && temporalItemLayer.selectedItemLayer) { return temporalItemLayer.selectedItemLayer.item; } return null; } layer(layers:any,layerIndex:number) { return layers.find(l => l.index == layerIndex); } handleGoToChart(item: IItem) { this.router.navigate(['/viewer', 'temporal', 'item', item.parentCode, new Date(Date.parse(item.dataDate)).getUTCFullYear()]); return false; } }