blob: 9a4d1f162a4b367e6dc115b28cef2063b85dbdd2 [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import {Component, OnInit} from "@angular/core";
import {Router} from "@angular/router";
import {select, Store} from "@ngrx/store";
import {take} from "rxjs/operators";
import {IAPIPositionSearchOptions, IAPIPositionSearchStatementModel} from "../../../../core";
import {ILeafletBounds} from "../../../../shared/leaflet";
import {
getStatementPositionSearchSelector,
openGisAction,
queryParamsCoordSelector,
startStatementPositionSearchAction,
statementLoadingSelector,
statementTypesSelector,
userNameSelector
} from "../../../../store";
import {IFilterToDisplay} from "../search-filter";
@Component({
selector: "app-position-search",
templateUrl: "./position-search.component.html",
styleUrls: ["./position-search.component.scss"]
})
export class PositionSearchComponent implements OnInit {
public coord$ = this.store.pipe(select(queryParamsCoordSelector), take(1));
public searchContent$ = this.store.pipe(select(getStatementPositionSearchSelector));
public statementLoading$ = this.store.pipe(select(statementLoadingSelector));
public statementTypeOptions$ = this.store.pipe(select(statementTypesSelector));
public userName$ = this.store.pipe(select(userNameSelector));
public filtersToShow: IFilterToDisplay = {
filterForType: false,
dueDateFrom: false,
dueDateTo: false
};
public selected: IAPIPositionSearchStatementModel;
public trackById = trackById;
public constructor(public store: Store, public router: Router) {
}
public ngOnInit() {
this.search({});
}
public search(options: IAPIPositionSearchOptions) {
this.store.dispatch(startStatementPositionSearchAction({options}));
}
public changeCenter(latLngZoom: string) {
this.router.navigate([], {queryParams: {coord: latLngZoom}, replaceUrl: true});
}
public openGis(bounds: ILeafletBounds) {
this.userName$.pipe(take(1)).subscribe((user) => {
this.store.dispatch(openGisAction({bounds, user}));
});
}
}
function trackById(index, entry: IAPIPositionSearchStatementModel) {
return entry?.id;
}