From cc96a3d487b27ea26fc2b0c88230bd1ddb1acf16 Mon Sep 17 00:00:00 2001 From: Eduardo Brito Date: Thu, 6 Oct 2022 14:16:07 +0000 Subject: [PATCH 1/3] add click fold & unfold feature to move dirs --- src/app/workspace/forms/move-item-form.component.html | 8 +++++--- src/app/workspace/pages/files.component.ts | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/app/workspace/forms/move-item-form.component.html b/src/app/workspace/forms/move-item-form.component.html index a38d9f7..ba05e6e 100644 --- a/src/app/workspace/forms/move-item-form.component.html +++ b/src/app/workspace/forms/move-item-form.component.html @@ -14,14 +14,16 @@
  • -
    +
    - {{dest.title}} + + {{dest.title}} + (empty)
    -
      +
        diff --git a/src/app/workspace/pages/files.component.ts b/src/app/workspace/pages/files.component.ts index 29938d4..fc2edf3 100644 --- a/src/app/workspace/pages/files.component.ts +++ b/src/app/workspace/pages/files.component.ts @@ -232,6 +232,7 @@ export class FilesComponent implements OnInit { this.rootDir = success; this.createPublicUrls(this.rootDir); this.rootDir.open = true; + this.rootDir.openMove = true; }); } From 656d06eee9e226f904bc7ffb545525a465ca3e78 Mon Sep 17 00:00:00 2001 From: Eduardo Brito Date: Tue, 11 Oct 2022 13:09:19 +0000 Subject: [PATCH 2/3] maintain open/close state after the move --- .../forms/move-item-form.component.ts | 59 ++++++++++++++++++- src/app/workspace/pages/files.component.ts | 12 +++- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/app/workspace/forms/move-item-form.component.ts b/src/app/workspace/forms/move-item-form.component.ts index 5eac417..d67dae7 100644 --- a/src/app/workspace/forms/move-item-form.component.ts +++ b/src/app/workspace/forms/move-item-form.component.ts @@ -105,8 +105,11 @@ export class MoveItemFormComponent { })) .subscribe( () => { - this.filesComponent.getSharedDirectory(); - this.filesComponent.getRootDirectory(); + let oldOpenStateShared = MoveItemFormComponent.getOpenDirsSet(this.filesComponent.getShared()) + let oldOpenStateRoot = MoveItemFormComponent.getOpenDirsSet(this.filesComponent.getRoot()) + + this.filesComponent.getSharedDirectory(oldOpenStateShared); + this.filesComponent.getRootDirectory(oldOpenStateRoot); if (this.pobject.type === 'file') this.toastr.success('File moved'); @@ -141,4 +144,56 @@ export class MoveItemFormComponent { return true; } + static getOpenDirsSet(fromRoot): Set { + let open: Set = new Set(); + + // BFS throught the dirs tree + + let visited: Set = new Set() + let qFrom = new Array(); + + visited.add(fromRoot.id); + qFrom.push(fromRoot); + + while (qFrom.length > 0) { + const vFrom = qFrom.shift(); + if (vFrom.hasOwnProperty("open") && vFrom.open) { + open.add(vFrom.id) + } + if (vFrom.hasOwnProperty("pobjects")) { + for (let child of vFrom.pobjects) { + if (!visited.has(child.id)) { + visited.add(child.id); + qFrom.push(child); + } + } + } + } + return open; + } + + static copyStateToTree(root, openDirs:Set) { + // BFS throught the dirs tree + + let visited: Set = new Set() + let qTo = new Array(); + + visited.add(root.id);; + qTo.push(root); + + while (qTo.length > 0) { + let vTo = qTo.shift(); + if(openDirs.has(vTo.id)) { + vTo.open = true; + } + if (vTo.hasOwnProperty("pobjects")) { + for (let child of vTo.pobjects) { + if (!visited.has(child.id)) { + visited.add(child.id); + qTo.push(child); + } + } + } + } + } } diff --git a/src/app/workspace/pages/files.component.ts b/src/app/workspace/pages/files.component.ts index fc2edf3..bb7a53f 100644 --- a/src/app/workspace/pages/files.component.ts +++ b/src/app/workspace/pages/files.component.ts @@ -220,7 +220,7 @@ export class FilesComponent implements OnInit { /** BACK-END RELATED FUNCTIONS */ - getRootDirectory() { + getRootDirectory(oldOpenDirsSet:null|Set=null) { this.ownFilesLoading = true; this.http.get(config.backend.host + '/rest/directories/root', AuthService.loadRequestOptions()) @@ -233,10 +233,14 @@ export class FilesComponent implements OnInit { this.createPublicUrls(this.rootDir); this.rootDir.open = true; this.rootDir.openMove = true; + + if(oldOpenDirsSet != null) { + MoveItemFormComponent.copyStateToTree(this.rootDir, oldOpenDirsSet) + } }); } - getSharedDirectory() { + getSharedDirectory(oldOpenDirsSet:null|Set=null) { this.sharedFilesLoading = true; this.http.get(config.backend.host + '/rest/directories/shared', AuthService.loadRequestOptions()) @@ -247,6 +251,10 @@ export class FilesComponent implements OnInit { .subscribe(success => { this.sharedDir = success; this.createPublicUrls(this.sharedDir); + + if(oldOpenDirsSet != null) { + MoveItemFormComponent.copyStateToTree(this.sharedDir, oldOpenDirsSet) + } }); } From 708a33df2875dfba7a974c7c5a0c0448cf2836b7 Mon Sep 17 00:00:00 2001 From: Eduardo Brito Date: Tue, 11 Oct 2022 13:44:43 +0000 Subject: [PATCH 3/3] maintain sort order after move --- src/app/workspace/pages/files.component.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/app/workspace/pages/files.component.ts b/src/app/workspace/pages/files.component.ts index bb7a53f..ba331e4 100644 --- a/src/app/workspace/pages/files.component.ts +++ b/src/app/workspace/pages/files.component.ts @@ -234,9 +234,26 @@ export class FilesComponent implements OnInit { this.rootDir.open = true; this.rootDir.openMove = true; + // apply open/close from the previous state if(oldOpenDirsSet != null) { MoveItemFormComponent.copyStateToTree(this.rootDir, oldOpenDirsSet) } + + // sort as in the previous state + switch (this.sort) { + case 2: + this.sortPobjectsByTitleDesc(); + break; + case 3: + this.sortPobjectsByLastModifiedAsc(); + break; + case 4: + this.sortPobjectsByLastModifiedDesc(); + break; + default: // 0 and 1 cases + this.sortPobjectsByTitleAsc(); + break; + } }); } @@ -252,6 +269,7 @@ export class FilesComponent implements OnInit { this.sharedDir = success; this.createPublicUrls(this.sharedDir); + // apply open/close from the previous state if(oldOpenDirsSet != null) { MoveItemFormComponent.copyStateToTree(this.sharedDir, oldOpenDirsSet) }