Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | 67x 67x 67x 67x 67x 67x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { CdkDrag } from '@angular/cdk/drag-drop';
import { Component, ElementRef, Input, OnChanges, SimpleChanges } from '@angular/core';
import { Router } from '@angular/router';
import { mapValues } from 'lodash-es';
import { toJS } from 'mobx';
import { catchError, of, Subscription } from 'rxjs';
import { HasChanges } from '../../guard/pending-changes.guard';
import { Ext } from '../../model/ext';
import { Page } from '../../model/page';
import { Ref } from '../../model/ref';
import { Pos } from '../../mods/org/folder';
import { ExtService } from '../../service/api/ext.service';
import { Store } from '../../store/store';
import { escapePath } from '../../util/json-patch';
import { defaultOrigin, level, tagOrigin } from '../../util/tag';
import { FileComponent } from './file/file.component';
import { SubfolderComponent } from './subfolder/subfolder.component';
@Component({
selector: 'app-folder',
templateUrl: './folder.component.html',
styleUrls: ['./folder.component.scss'],
host: { 'class': 'folder ext' },
imports: [
FileComponent,
SubfolderComponent,
CdkDrag,
],
})
export class FolderComponent implements OnChanges, HasChanges {
@Input()
tag?: string;
@Input()
ext?: Ext;
@Input()
pinned?: Ref[] | null;
@Input()
emptyMessage = '';
error: any;
parent?: Ext;
flatten = false;
files: Record<string, string | undefined> = {};
subfolders: Record<string, string | undefined> = {};
folderExts?: Ext[];
cursor = '';
dragging = false;
zIndex = 1;
private _page?: Page<Ref>;
private folderSubscription?: Subscription;
// TODO: handle resize moving relatively positioned moved tiles
constructor(
private store: Store,
private router: Router,
private exts: ExtService,
private el: ElementRef<HTMLElement>,
) { }
saveChanges() {
// TODO
return true;
}
ngOnChanges(changes: SimpleChanges) {
if (changes.tag) {
delete this.folderExts;
delete this.parent;
if (this.tag?.includes('/')) {
this.exts.getCachedExt(this.tag.substring(0, this.tag.lastIndexOf('/')), tagOrigin(this.tag) || '@')
.subscribe(ext => this.parent = ext);
}
this.folderSubscription?.unsubscribe();
if (!this.tag) return;
this.folderSubscription = this.exts.page({
query: defaultOrigin(this.tag, (this.ext?.origin || '@')),
level: level(this.tag) + 1,
size: 100
}).pipe(
catchError(() => of(undefined)),
).subscribe(page => {
this.folderExts = page?.content;
});
}
if (changes.ext) {
this.files = {};
this.subfolders = {};
this.flatten = this.ext?.config.flatten;
if (!this.ext) return;
this.cursor = this.ext.modifiedString!;
this.files = mapValues(toJS(this.ext.config.files) || {}, p => this.transform(p));
for (const e of Object.entries<Pos>(toJS(this.ext.config.subfolders) || {})) {
this.subfolders[this.ext.tag + (e[0] !== '..' ? '/' + e[0] : '')] = this.transform(e[1]);
}
}
}
get local() {
return this.ext?.origin === this.store.account.origin;
}
get page(): Page<Ref> | undefined {
return this._page;
}
@Input()
set page(value: Page<Ref> | undefined) {
this._page = value;
if (this._page) {
if (this._page.page.number > 0 && this._page.page.number >= this._page.page.totalPages) {
this.router.navigate([], {
queryParams: {
pageNumber: this._page.page.totalPages - 1
},
queryParamsHandling: "merge",
});
}
}
}
startMoving(target: HTMLElement) {
target.style.zIndex = ""+(this.zIndex++);
}
moveFile(url: string, target: HTMLElement) {
if (!this.cursor) return; // Wait for last move to complete
if (!this.local) return;
const cursor = this.cursor;
this.cursor = '';
this.dragging = true
const pos = {
x: Math.floor(target.getBoundingClientRect().x + window.scrollX - this.el.nativeElement.offsetLeft),
y: Math.floor(target.getBoundingClientRect().y + window.scrollY - this.el.nativeElement.offsetTop),
};
this.exts.patch(this.ext!.tag + this.store.account.origin, cursor, [{
op: 'add',
path: '/config/files/' + escapePath(url),
value: pos,
}]).subscribe(cursor => this.cursor = cursor);
}
moveFolder(tag: string, target: HTMLElement) {
// TODO: write patches to websocket
if (!this.cursor) return; // Wait for last move to complete
if (!this.local) return;
const cursor = this.cursor;
this.cursor = '';
this.dragging = true
this.exts.patch(this.ext!.tag + this.store.account.origin, cursor, [{
op: 'add',
path: '/config/subfolders/' + (tag === this.tag ? '..' : escapePath(tag.substring(this.ext!.tag.length + 1))),
value: {
x: Math.floor(target.getBoundingClientRect().x + window.scrollX - this.el.nativeElement.offsetLeft),
y: Math.floor(target.getBoundingClientRect().y + window.scrollY - this.el.nativeElement.offsetTop),
},
}]).subscribe(cursor => this.cursor = cursor);
}
inSubfolder(ref: Ref) {
return ref.tags?.find(t => t.startsWith(this.ext!.tag + '/'));
}
transform(p: Pos) {
if (!p) return undefined;
return 'translate3d(' + (p.x || 0) + 'px, ' + (p.y || 0) + 'px, 0)';
}
}
|