2019-07-15 14:54:19 +00:00
|
|
|
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 {
|
|
|
|
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
|
2019-07-18 16:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ApiEndpoint() {
|
|
|
|
return this.appConfig.getConfig("apiEndPoint");
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 }> {
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<{ [id: string]: IItemType }>(`${this.ApiEndpoint()}/api/v1/itemtypes/`);
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:32:42 +00:00
|
|
|
getFeatures(extent: number[], crs: string, searchText?: string, searchTags?:string,startDate?:Date,endDate?:Date,itemType?:string,parentCode?:string,dataFilter?:string,level?:number): Observable<any> {
|
2019-07-15 14:54:19 +00:00
|
|
|
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());
|
2019-08-05 11:35:52 +00:00
|
|
|
if (itemType) params = params.append("it", itemType);
|
2019-08-09 19:32:42 +00:00
|
|
|
if (parentCode) params = params.append("pc", parentCode);
|
|
|
|
if (dataFilter) params = params.append("df", dataFilter);
|
|
|
|
if (level) params = params.append("lvl", dataFilter);
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/features/`, {params:params});
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getFeature(code:string, crs: string): Observable<any> {
|
|
|
|
var params = new HttpParams();
|
|
|
|
params = params.append("crs", crs);
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/feature/`, { params: params });
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getItem(code: string): Observable<IItem> {
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<IItem>(`${this.ApiEndpoint()}/api/v1/items/${code}`).pipe(map(i => this.parseDates(i)));
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getItemByCodeAndType(code: string, itemType: string): Observable<IItem> {
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<IItem>(`${this.ApiEndpoint()}/api/v1/items/${code}/${itemType}`);
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<IItem[]>(`${this.ApiEndpoint()}/api/v1/items/`, { params: params }).pipe(map(ia => ia.map(i => this.parseDates(i))));
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<IItem[]>(`${this.ApiEndpoint()}/api/v1/items/${parentcode}/children`, { params: params });
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<IItem[]>(`${this.ApiEndpoint()}/api/v1/items/${parentcode}/children`, { params: params });
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/features/layer/${layerIndex}`, { params: params });
|
2019-07-15 14:54:19 +00:00
|
|
|
else
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/features`, { params: params });
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
putItem(item:IItem): Observable<IItem> {
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.put<IItem>(`${this.ApiEndpoint()}/api/v1/items/${item.code}`,item);
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteItems(itemCodes:string[]): Observable<any> {
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.post<any>(`${this.ApiEndpoint()}/api/v1/items/delete`, itemCodes);
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getTemporalLast(code: string): Observable<any> {
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/temporal/last`);
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/items/${code}/temporal/`, { params: params });
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
postItemTask(item: IItem, task: IItemTask): Observable<IItemTask> {
|
2019-07-18 16:59:42 +00:00
|
|
|
return this.httpClient.post<IItemTask>(`${this.ApiEndpoint()}/api/v1/items/${item.code}/tasks`, task);
|
2019-07-15 14:54:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|