From 1bc3983f55d7eb961e646bbf75ae0b96917d9b4e Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Tue, 30 May 2023 21:16:20 +0200 Subject: [PATCH] AW-5071 refactor some parts --- .../common/src/fm/services/folder.service.ts | 27 ++++++++++--------- .../common/src/fm/services/item.service.ts | 10 ++++++- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/projects/common/src/fm/services/folder.service.ts b/projects/common/src/fm/services/folder.service.ts index f491509..3f7c07b 100644 --- a/projects/common/src/fm/services/folder.service.ts +++ b/projects/common/src/fm/services/folder.service.ts @@ -1,17 +1,17 @@ -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"; +import {Injectable} from '@angular/core'; +import {Observable} from 'rxjs'; +import {IListItem} from '../models/list.item'; +import {IItem} from '../models/item'; +import {HttpClient} from '@angular/common/http'; +import {AppConfig} from '../shared/app.config'; +import {ItemService} from './item.service'; @Injectable({ providedIn: 'root', }) export class FolderService { - constructor(public httpClient: HttpClient, public appConfig: AppConfig) { + constructor(public httpClient: HttpClient, public appConfig: AppConfig, public itemService: ItemService) { } ApiEndpoint() { @@ -19,23 +19,24 @@ export class FolderService { } getFolder(code: string): Observable { - return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/folders/${code}`); + return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/folders/${code}`); } getMyRoots(): Observable { return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/folders/my_roots`); - } + } getFolderParents(code: string): Observable { - return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/folders/${code}/parents`); + return this.itemService.getBreadcrumbs(code); } getChildFolders(code: string): Observable { - return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/folders/${code}/listfolders`); + const folderItemTypes = "FOLDER,FTP_FOLDER"; + return this.itemService.getChildItemList(code, folderItemTypes); } getItems(code: string,skip:number, take:number): Observable { - return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/folders/${code}/list?skip=${skip}&take=${take}`); + return this.itemService.getChildItemList(code, null, null, 1, true, null, null, skip, take); } moveItem(itemCode: string, newParentCode: string): Observable { diff --git a/projects/common/src/fm/services/item.service.ts b/projects/common/src/fm/services/item.service.ts index 552b650..e0ef352 100644 --- a/projects/common/src/fm/services/item.service.ts +++ b/projects/common/src/fm/services/item.service.ts @@ -8,6 +8,7 @@ import { IItemTask } from '../models/itemTask'; import { HttpClient, HttpParams,HttpHeaders } from "@angular/common/http"; import { AppConfig } from "../shared/app.config"; import {ItemTypeService} from './itemtype.service'; +import {IListItem} from '../models/list.item'; @Injectable({ providedIn: 'root', @@ -84,7 +85,7 @@ export class ItemService { } getChildItemList(parentcode: string, itemType: string, dataFilter?: any, level = 1, deep = true, - startDate?: Date, endDate?: Date): Observable { + startDate?: Date, endDate?: Date, skip?: number, take?: number): Observable { let params = new HttpParams(); if(itemType != null) { params = params.append("it", itemType); @@ -96,6 +97,9 @@ export class ItemService { params = params.append("deep", deep.toString()); if (startDate) params = params.append("sDate", startDate.toISOString()); if (endDate) params = params.append("eDate", endDate.toISOString()); + + if(skip) params = params.append("skip", skip); + if(take) params = params.append("take", take); return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/items/${parentcode}/children`, { params: params }); } @@ -181,4 +185,8 @@ export class ItemService { return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/items/${itemCode}/value/layer/${layerIndex}?c=${x},${y}&crs=${crs}`); } + getBreadcrumbs(itemCode: string): Observable { + return this.httpClient.get(`${this.ApiEndpoint()}/api/v1/items/${itemCode}/breadcrumbs`); + } + }