Peter Bastiani
6c828f6c6d
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
143 lines
6.3 KiB
TypeScript
143 lines
6.3 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({
|
|
providedIn: 'root',
|
|
})
|
|
export class ItemService {
|
|
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
|
|
}
|
|
|
|
ApiEndpoint() {
|
|
return this.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,itemType?:string,parentCode?:string,dataFilter?:string,level?:number): 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());
|
|
if (itemType) params = params.append("it", itemType);
|
|
if (parentCode) params = params.append("pc", parentCode);
|
|
if (dataFilter) params = params.append("df", dataFilter);
|
|
if (level) params = params.append("lvl", dataFilter);
|
|
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 }).pipe(map(ia => ia.map(i => this.parseDates(i))));
|
|
}
|
|
|
|
getChildItemListCount(parentcode: string, itemType: string): Observable<Number> {
|
|
var params = new HttpParams();
|
|
params = params.append("it", itemType);
|
|
return this.httpClient.get<Number>(`${this.ApiEndpoint()}/api/v1/items/${parentcode}/children/count`, { 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 }).pipe(map(ia => ia.map(i => this.parseDates(i))));
|
|
}
|
|
|
|
getItemFeatures(code: string, extent: number[], crs: string, layerIndex?:number): Observable<any> {
|
|
var params = new HttpParams();
|
|
params = params.append("crs", crs);
|
|
if(extent != null) {
|
|
params = params.append("bbox", extent.join(","));
|
|
}
|
|
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 });
|
|
}
|
|
|
|
postItem(item:IItem): Observable<IItem> {
|
|
return this.httpClient.post<IItem>(`${this.ApiEndpoint()}/api/v1/items`,item);
|
|
}
|
|
|
|
putItem(item:IItem): Observable<IItem> {
|
|
return this.httpClient.put<IItem>(`${this.ApiEndpoint()}/api/v1/items/${item.code}`,item);
|
|
}
|
|
|
|
deleteItem(code: string): Observable<any> {
|
|
return this.httpClient.delete<any>(`${this.ApiEndpoint()}/api/v1/items/${code}`);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|