model added

This commit is contained in:
Lucio Lelii 2023-02-17 13:42:01 +01:00
parent 731ee97b76
commit a6781699e8
8 changed files with 170 additions and 18 deletions

View File

View File

@ -0,0 +1,9 @@
import { Item } from "./item.model";
export class ItemWrapper {
constructor(
public item: Item
){}
}

View File

@ -0,0 +1,31 @@
import {Content, LastAction } from "./model";
export class Item {
constructor(
public name: string,
public path: string,
public parentId: string,
public parentPath: String,
public primaryType: String,
public trashed: boolean,
public externalManaged: boolean,
public shared: boolean,
public locked: boolean,
public publicItem: boolean,
public title: string,
public description: string,
public lastModifiedBy: string,
public lastModificationTime: number,
public creationTime: number,
public lastAction: LastAction,
public hidden: boolean,
public accounting: null,
public id: string,
public content?: Content | undefined,
public externalRoot?: boolean | undefined,
public privilege?: null | undefined,
public vreFolder?: boolean | undefined,
public displayName?: string | undefined) {}
}

View File

@ -0,0 +1,10 @@
import { ItemWrapper } from "./item-wrapper.model";
import { Item } from "./item.model";
export class ItemList {
constructor(
public itemlist :Item[]
) {}
}

59
src/app/model/model.ts Normal file
View File

@ -0,0 +1,59 @@
/*export interface Items {
itemlist: Item[];
}*/
export interface AbstractItem {
content?: Content;
id: string;
name: string;
path: string;
parentId: string;
parentPath: String;
primaryType: String;
trashed: boolean;
externalManaged: boolean;
shared: boolean;
locked: boolean;
publicItem: boolean;
title: string;
description: string;
lastModifiedBy: string;
lastModificationTime: number;
creationTime: number;
lastAction: LastAction;
hidden: boolean;
accounting: null;
externalRoot?: boolean;
privilege?: null;
vreFolder?: boolean;
displayName?: string;
}
export interface Content {
size: number;
data: string;
remotePath: string;
mimeType: string;
storageId: string;
managedBy: String;
numberOfPages?: number;
version?: string;
author?: string;
title?: string;
producer?: string;
width?: number;
height?: number;
thumbnailWidth?: number;
thumbnailHeight?: number;
thumbnailData?: Blob;
}
export enum LastAction {
Cloned = "CLONED",
Created = "CREATED",
Moved = "MOVED",
Renamed = "RENAMED",
Updated = "UPDATED",
}

View File

@ -43,13 +43,7 @@ export class ShowFolderComponent implements OnInit {
}
loadDocuments() {
this.plt.ready().then(() => {
this.storagehub.getTrashRoot().toPromise().then(res => {
this.items = JSON.parse(res).itemlist;
if (!this.items)
this.items = [];
});
});
}
}

View File

@ -2,7 +2,12 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { catchError, map, retry, switchMap } from 'rxjs/operators';
import { HttpErrorResponse } from 'node-angular-http-client';
import { Item } from './model/item.model';
import { ItemList } from './model/itemlist.model';
import { ItemWrapper } from './model/item-wrapper.model';
const token = "b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548";
const shURL = "https://workspace-repository.dev.d4science.org/storagehub/workspace/";
@ -10,17 +15,21 @@ const shURL = "https://workspace-repository.dev.d4science.org/storagehub/workspa
@Injectable()
export class StoragehubService {
constructor(private http: HttpClient) { }
constructor(private http: HttpClient) {
}
getWsRoot(): Observable<any> {
const getWsURL = `${shURL}?gcube-token=${token}&exclude=hl:accounting`;
return this.http.get(getWsURL, {observe: 'body', responseType: 'text'});
}
getTrashRoot(): Observable<any> {
getTrashRoot(): Observable<Item> {
const getTrashURL = `${shURL}trash/?gcube-token=${token}&exclude=hl:accounting`;
return this.http.get(getTrashURL, {observe: 'body', responseType: 'text'});
return this.http.get<ItemWrapper>(getTrashURL, {observe: "body", responseType: "json"}).pipe(
map(value => value.item),
catchError(this.error)
);
}
getVres(): Observable<any> {
@ -28,11 +37,15 @@ export class StoragehubService {
return this.http.get(getVresURL, {observe: 'body', responseType: 'text'});
}
getChildren(id:string, onlyFolder:boolean): Observable<any>{
getChildren(id:string, onlyFolder:boolean): Observable<Item[]>{
let getWsURL = `${shURL}items/${id}/children?gcube-token=${token}&exclude=hl:accounting`;
if (onlyFolder)
getWsURL += '&onlyType=nthl:workspaceItem';
return this.http.get(getWsURL, {observe: 'body', responseType: 'text'});
console.log("requested resource is "+id);
return this.http.get<ItemList>(getWsURL).pipe(
map(values => values.itemlist),
catchError(this.error)
);
}
getAnchestor(id:string): Observable<any>{
@ -41,4 +54,17 @@ export class StoragehubService {
return this.http.get(getWsURL, {observe: 'body', responseType: 'text'});
}
error(error: HttpErrorResponse) {
let errorMessage = '';
if (error.error instanceof ErrorEvent) {
errorMessage = error.error.message;
} else {
errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
}
console.log(errorMessage);
return throwError(() => {
return errorMessage;
});
}
}

View File

@ -1,12 +1,35 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { lastValueFrom } from 'rxjs';
import { Item } from '../model/item.model';
import { StoragehubService } from '../storagehub.service';
@Component({
selector: 'app-trash',
templateUrl: 'trash.page.html',
styleUrls: ['trash.page.scss']
styleUrls: ['trash.page.scss'],
providers: [StoragehubService],
})
export class TrashPage {
constructor() {}
export class TrashPage implements OnInit{
values : Item[] = [];
constructor(private storagehub: StoragehubService) {}
ngOnInit() {
this.storagehub.getTrashRoot().subscribe(
(res) => this.onSuccess(res)
);
console.log("values "+this.values);
}
private onSuccess(res: Item){
this.storagehub.getChildren(res.id, false).subscribe(
(res) => this.values = res
)
}
}