diff --git a/src/app/model/content.model.ts b/src/app/model/content.model.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/app/model/item-wrapper.model.ts b/src/app/model/item-wrapper.model.ts new file mode 100644 index 0000000..f6e365b --- /dev/null +++ b/src/app/model/item-wrapper.model.ts @@ -0,0 +1,9 @@ +import { Item } from "./item.model"; + +export class ItemWrapper { + + constructor( + public item: Item + ){} + +} \ No newline at end of file diff --git a/src/app/model/item.model.ts b/src/app/model/item.model.ts new file mode 100644 index 0000000..e1506d2 --- /dev/null +++ b/src/app/model/item.model.ts @@ -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) {} + +} diff --git a/src/app/model/itemlist.model.ts b/src/app/model/itemlist.model.ts new file mode 100644 index 0000000..664d712 --- /dev/null +++ b/src/app/model/itemlist.model.ts @@ -0,0 +1,10 @@ +import { ItemWrapper } from "./item-wrapper.model"; +import { Item } from "./item.model"; + + +export class ItemList { + + constructor( + public itemlist :Item[] + ) {} +} \ No newline at end of file diff --git a/src/app/model/model.ts b/src/app/model/model.ts new file mode 100644 index 0000000..3396a85 --- /dev/null +++ b/src/app/model/model.ts @@ -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", +} + diff --git a/src/app/show-folder/show-folder.component.ts b/src/app/show-folder/show-folder.component.ts index 07c96c7..b66983a 100644 --- a/src/app/show-folder/show-folder.component.ts +++ b/src/app/show-folder/show-folder.component.ts @@ -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 = []; - }); - }); + } } diff --git a/src/app/storagehub.service.ts b/src/app/storagehub.service.ts index 6255297..8d9c2a4 100644 --- a/src/app/storagehub.service.ts +++ b/src/app/storagehub.service.ts @@ -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 { const getWsURL = `${shURL}?gcube-token=${token}&exclude=hl:accounting`; return this.http.get(getWsURL, {observe: 'body', responseType: 'text'}); } - getTrashRoot(): Observable { + getTrashRoot(): Observable { const getTrashURL = `${shURL}trash/?gcube-token=${token}&exclude=hl:accounting`; - return this.http.get(getTrashURL, {observe: 'body', responseType: 'text'}); + return this.http.get(getTrashURL, {observe: "body", responseType: "json"}).pipe( + map(value => value.item), + catchError(this.error) + ); } getVres(): Observable { @@ -28,11 +37,15 @@ export class StoragehubService { return this.http.get(getVresURL, {observe: 'body', responseType: 'text'}); } - getChildren(id:string, onlyFolder:boolean): Observable{ + getChildren(id:string, onlyFolder:boolean): Observable{ 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(getWsURL).pipe( + map(values => values.itemlist), + catchError(this.error) + ); } getAnchestor(id:string): Observable{ @@ -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; + }); + } + } diff --git a/src/app/trash/trash.page.ts b/src/app/trash/trash.page.ts index 0667942..bfd33f2 100644 --- a/src/app/trash/trash.page.ts +++ b/src/app/trash/trash.page.ts @@ -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 + ) + } }