Willem Dantuma 2920fd82f1
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
Fix viewer
2020-02-18 17:00:19 +01:00

58 lines
1.9 KiB
TypeScript

import {Component, Injectable, Input} from '@angular/core';
import {Location} from '@angular/common';
import {Store} from '@ngrx/store';
import * as mapReducers from '../../reducers/map.reducer';
import {AppConfig, commonReducers, IItem, ItemTypeService} from '@farmmaps/common';
import * as mapActions from '../../actions/map.actions';
import {Router} from '@angular/router';
@Injectable()
export abstract class AbstractSelectedItemComponent {
@Input() item: IItem
constructor(public store: Store<mapReducers.State | commonReducers.State>, public itemTypeService: ItemTypeService, private location: Location, private router: Router) {
}
handleOnView(item: IItem) {
if (this.itemTypeService.hasViewer(item)) {
let viewer = this.itemTypeService.itemTypes[item.itemType].viewer;
let url = `/viewer/${viewer}/item/${item.code}`;
this.router.navigate([url]);
}
return false;
}
handleOnEdit(item: IItem) {
var editor = "property";
if(this.itemTypeService.hasEditor(item)) {
editor = this.itemTypeService.itemTypes[item.itemType].editor;
}
let url = `/editor/${editor}/item/${item.code}`
this.router.navigate([url]);
return false;
}
handleAddAsLayer(item: IItem,layerIndex:number = -1) {
this.store.dispatch(new mapActions.AddLayer(item,layerIndex));
return false;
}
handleBackToList(event: MouseEvent) {
event.preventDefault();
this.location.back();
}
}
@Injectable()
@Component({
selector: 'fm-map-selected-item',
templateUrl: './selected-item.component.html',
styleUrls: ['./selected-item.component.scss']
})
export class SelectedItemComponent extends AbstractSelectedItemComponent {
constructor(store: Store<mapReducers.State | commonReducers.State>, itemTypeService: ItemTypeService, location: Location, router: Router, public config:AppConfig) {
super(store, itemTypeService,location,router);
}
}