120 lines
5.2 KiB
TypeScript
120 lines
5.2 KiB
TypeScript
|
import { Injectable } from '@angular/core';
|
||
|
import { Observable } from 'rxjs';
|
||
|
import { map } from 'rxjs/operators';
|
||
|
import { IItemType } from '../models/item.type';
|
||
|
import { IItem } from '../models/item';
|
||
|
import { IItemTask } from '../models/itemTask';
|
||
|
import { HttpClient, HttpParams } from "@angular/common/http";
|
||
|
import { AppConfig } from "../shared/app.config";
|
||
|
|
||
|
@Injectable()
|
||
|
export class ItemService {
|
||
|
private _apiEndPoint: string;
|
||
|
|
||
|
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
|
||
|
this._apiEndPoint = ""; //appConfig.getConfig("apiEndPoint");
|
||
|
}
|
||
|
|
||
|
parseDates(item: any): IItem {
|
||
|
item.created = new Date(Date.parse(item.created));
|
||
|
item.updated = new Date(Date.parse(item.updated));
|
||
|
item.dataDate = new Date(Date.parse(item.dataDate));
|
||
|
return item;
|
||
|
}
|
||
|
|
||
|
getItemTypes(): Observable<{ [id: string]: IItemType }> {
|
||
|
return this.httpClient.get<{ [id: string]: IItemType }>(`${this._apiEndPoint}/api/v1/itemtypes/`);
|
||
|
}
|
||
|
|
||
|
getFeatures(extent: number[], crs: string, searchText?: string, searchTags?:string,startDate?:Date,endDate?:Date): Observable<any> {
|
||
|
var params = new HttpParams();
|
||
|
params = params.append("bbox", extent.join(","));
|
||
|
params = params.append("crs", crs);
|
||
|
if (searchText) params = params.append("q", searchText);
|
||
|
if (searchTags) params = params.append("t", searchTags);
|
||
|
if (startDate) params = params.append("sd", startDate.toISOString());
|
||
|
if (endDate) params = params.append("ed", endDate.toISOString());
|
||
|
return this.httpClient.get<any>(`${this._apiEndPoint}/api/v1/items/features/`, {params:params});
|
||
|
}
|
||
|
|
||
|
getFeature(code:string, crs: string): Observable<any> {
|
||
|
var params = new HttpParams();
|
||
|
params = params.append("crs", crs);
|
||
|
return this.httpClient.get<any>(`${this._apiEndPoint}/api/v1/items/${code}/feature/`, { params: params });
|
||
|
}
|
||
|
|
||
|
getItem(code: string): Observable<IItem> {
|
||
|
return this.httpClient.get<IItem>(`${this._apiEndPoint}/api/v1/items/${code}`).pipe(map(i => this.parseDates(i)));
|
||
|
}
|
||
|
|
||
|
getItemByCodeAndType(code: string, itemType: string): Observable<IItem> {
|
||
|
return this.httpClient.get<IItem>(`${this._apiEndPoint}/api/v1/items/${code}/${itemType}`);
|
||
|
}
|
||
|
|
||
|
getItemList(itemType: string, dataFilter?: any, level: number = 1): Observable<IItem[]> {
|
||
|
var params = new HttpParams();
|
||
|
params = params.append("it", itemType);
|
||
|
if(dataFilter != null){
|
||
|
params = params.append("df", JSON.stringify(dataFilter));
|
||
|
}
|
||
|
params = params.append("lvl", itemType);
|
||
|
return this.httpClient.get<IItem[]>(`${this._apiEndPoint}/api/v1/items/`, { params: params }).pipe(map(ia => ia.map(i => this.parseDates(i))));
|
||
|
}
|
||
|
|
||
|
getChildItemList(parentcode: string, itemType: string, dataFilter?: any, level: number = 1): Observable<IItem[]> {
|
||
|
var params = new HttpParams();
|
||
|
params = params.append("it", itemType);
|
||
|
if (dataFilter != null) {
|
||
|
params = params.append("df", JSON.stringify(dataFilter));
|
||
|
}
|
||
|
params = params.append("lvl", level.toString());
|
||
|
return this.httpClient.get<IItem[]>(`${this._apiEndPoint}/api/v1/items/${parentcode}/children`, { params: params });
|
||
|
}
|
||
|
|
||
|
getChildItemListByExtent(parentcode: string, itemType: string, extent: number[], crs: string, dataFilter?: any, level: number = 1): Observable<IItem[]> {
|
||
|
var params = new HttpParams();
|
||
|
params = params.append("it", itemType);
|
||
|
params = params.append("bbox", extent.join(","));
|
||
|
params = params.append("crs", crs);
|
||
|
if (dataFilter != null) {
|
||
|
params = params.append("df", JSON.stringify(dataFilter));
|
||
|
}
|
||
|
params = params.append("lvl", level.toString());
|
||
|
return this.httpClient.get<IItem[]>(`${this._apiEndPoint}/api/v1/items/${parentcode}/children`, { params: params });
|
||
|
}
|
||
|
|
||
|
getItemFeatures(code: string, extent: number[], crs: string, layerIndex?:number): Observable<any> {
|
||
|
var params = new HttpParams();
|
||
|
params = params.append("bbox", extent.join(","));
|
||
|
params = params.append("crs", crs);
|
||
|
if(layerIndex!=null)
|
||
|
return this.httpClient.get<any>(`${this._apiEndPoint}/api/v1/items/${code}/features/layer/${layerIndex}`, { params: params });
|
||
|
else
|
||
|
return this.httpClient.get<any>(`${this._apiEndPoint}/api/v1/items/${code}/features`, { params: params });
|
||
|
}
|
||
|
|
||
|
putItem(item:IItem): Observable<IItem> {
|
||
|
return this.httpClient.put<IItem>(`${this._apiEndPoint}/api/v1/items/${item.code}`,item);
|
||
|
}
|
||
|
|
||
|
deleteItems(itemCodes:string[]): Observable<any> {
|
||
|
return this.httpClient.post<any>(`${this._apiEndPoint}/api/v1/items/delete`, itemCodes);
|
||
|
}
|
||
|
|
||
|
getTemporalLast(code: string): Observable<any> {
|
||
|
return this.httpClient.get<any>(`${this._apiEndPoint}/api/v1/items/${code}/temporal/last`);
|
||
|
}
|
||
|
|
||
|
getTemporal(code: string, startDate?: Date, endDate?: Date): Observable<any> {
|
||
|
var params = new HttpParams();
|
||
|
if (startDate) params = params.append("sd", startDate.toISOString());
|
||
|
if (endDate) params = params.append("ed", endDate.toISOString());
|
||
|
return this.httpClient.get<any>(`${this._apiEndPoint}/api/v1/items/${code}/temporal/`, { params: params });
|
||
|
}
|
||
|
|
||
|
postItemTask(item: IItem, task: IItemTask): Observable<IItemTask> {
|
||
|
return this.httpClient.post<IItemTask>(`${this._apiEndPoint}/api/v1/items/${item.code}/tasks`, task);
|
||
|
}
|
||
|
}
|
||
|
|