2020-06-25 07:47:53 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Observable , Observer } from 'rxjs';
|
|
|
|
import {map} from 'rxjs/operators';
|
|
|
|
import { IListItem } from '../models/list.item';
|
|
|
|
import { IItem } from '../models/item';
|
|
|
|
import { HttpClient } from "@angular/common/http";
|
|
|
|
import { AppConfig } from "../shared/app.config";
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root',
|
|
|
|
})
|
|
|
|
export class FolderService {
|
|
|
|
|
|
|
|
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ApiEndpoint() {
|
|
|
|
return this.appConfig.getConfig("apiEndPoint");
|
|
|
|
}
|
|
|
|
|
|
|
|
parseDates(item: any): IListItem {
|
|
|
|
item.created = new Date(Date.parse(item.created));
|
|
|
|
item.updated = new Date(Date.parse(item.updated));
|
|
|
|
item.dataDate = new Date(Date.parse(item.dataDate));
|
|
|
|
item.dataEndDate = new Date(Date.parse(item.dataEndDate));
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
getFolder(code: string): Observable<IListItem> {
|
|
|
|
return this.httpClient.get<IListItem>(`${this.ApiEndpoint()}/api/v1/folders/${code}`).pipe(map(i => this.parseDates(i)));
|
|
|
|
}
|
|
|
|
|
|
|
|
getMyRoots(): Observable<IListItem[]> {
|
|
|
|
return this.httpClient.get<IListItem[]>(`${this.ApiEndpoint()}/api/v1/folders/my_roots`).pipe(map(ia => ia.map(i => this.parseDates(i))));
|
|
|
|
}
|
|
|
|
|
|
|
|
getFolderParents(code: string): Observable<IListItem[]> {
|
|
|
|
return this.httpClient.get<IListItem[]>(`${this.ApiEndpoint()}/api/v1/folders/${code}/parents`).pipe(map(ia => ia.map(i => this.parseDates(i))));
|
|
|
|
}
|
|
|
|
|
|
|
|
getChildFolders(code: string): Observable<IListItem[]> {
|
|
|
|
return this.httpClient.get<IListItem[]>(`${this.ApiEndpoint()}/api/v1/folders/${code}/listfolders`).pipe(map(ia => ia.map(i => this.parseDates(i))));
|
|
|
|
}
|
|
|
|
|
|
|
|
getItems(code: string,skip:number, take:number): Observable<IListItem[]> {
|
|
|
|
return this.httpClient.get<IListItem[]>(`${this.ApiEndpoint()}/api/v1/folders/${code}/list?skip=${skip}&take=${take}`).pipe(map(ia => ia.map(i => this.parseDates(i))));
|
|
|
|
}
|
|
|
|
|
|
|
|
moveItem(itemCode: string, newParentCode: string): Observable<IListItem> {
|
|
|
|
const body = { itemCode: itemCode,newParentCode: newParentCode };
|
|
|
|
return this.httpClient.post<IListItem>(`${this.ApiEndpoint()}/api/v1/items/move`, body).pipe(map(i => this.parseDates(i)));
|
|
|
|
}
|
|
|
|
|
|
|
|
createFolder(folder: IItem): Observable<IListItem> {
|
|
|
|
return this.httpClient.post<IListItem>(`${this.ApiEndpoint()}/api/v1/folders/`, folder).pipe(map(i => this.parseDates(i)));
|
|
|
|
}
|
|
|
|
}
|