Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/app/workspace/forms/move-item-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@

<ng-template #pobjectItem let-dest let-depth="depth">
<li class="pobject" *ngIf="dest.type === 'directory' && canMove(pobject, dest)">
<div class="move-item" (click)="target = dest" [ngClass]="{'active': target === dest}">
<div class="move-item" (click)="target = dest; dest.openMove = !dest.openMove" [ngClass]="{'active': target === dest}">
<div class="row">
<div class="col-xs-12">
<span class="title" [ngStyle]="{'margin-left.px': Math.max(0, (depth-1) * 30).toString() }"><span class="glyphicon glyphicon-folder-open"></span> {{dest.title}}</span>
<span class="title" [ngStyle]="{'margin-left.px': Math.max(0, (depth-1) * 30).toString() }">
<span class="glyphicon" [ngClass]="dest.openMove ? 'glyphicon-folder-open' : 'glyphicon-folder-close'"></span> {{dest.title}}</span>
<span *ngIf="dest.openMove && dest.pobjects.length === 0">(empty)</span>
</div>
</div>
</div>
<ul class="pobject-list subgroup">
<ul class="pobject-list subgroup" *ngIf="dest.openMove">
<ng-container *ngFor="let item of dest.pobjects">
<ng-container *ngTemplateOutlet="pobjectItem; context:{$implicit: item, depth: depth + 1}"></ng-container>
</ng-container>
Expand Down
59 changes: 57 additions & 2 deletions src/app/workspace/forms/move-item-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -141,4 +144,56 @@ export class MoveItemFormComponent {
return true;
}

static getOpenDirsSet(fromRoot): Set<number> {
let open: Set<number> = new Set();

// BFS throught the dirs tree

let visited: Set<number> = new Set()
let qFrom = new Array<any>();

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<number>) {
// BFS throught the dirs tree

let visited: Set<number> = new Set()
let qTo = new Array<any>();

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);
}
}
}
}
}
}
31 changes: 29 additions & 2 deletions src/app/workspace/pages/files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class FilesComponent implements OnInit {

/** BACK-END RELATED FUNCTIONS */

getRootDirectory() {
getRootDirectory(oldOpenDirsSet:null|Set<number>=null) {
this.ownFilesLoading = true;

this.http.get(config.backend.host + '/rest/directories/root', AuthService.loadRequestOptions())
Expand All @@ -232,10 +232,32 @@ export class FilesComponent implements OnInit {
this.rootDir = success;
this.createPublicUrls(this.rootDir);
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;
}
});
}

getSharedDirectory() {
getSharedDirectory(oldOpenDirsSet:null|Set<number>=null) {
this.sharedFilesLoading = true;

this.http.get(config.backend.host + '/rest/directories/shared', AuthService.loadRequestOptions())
Expand All @@ -246,6 +268,11 @@ export class FilesComponent implements OnInit {
.subscribe(success => {
this.sharedDir = success;
this.createPublicUrls(this.sharedDir);

// apply open/close from the previous state
if(oldOpenDirsSet != null) {
MoveItemFormComponent.copyStateToTree(this.sharedDir, oldOpenDirsSet)
}
});
}

Expand Down