|
|
@ -1,5 +1,5 @@
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
Component, ElementRef,
|
|
|
|
EventEmitter,
|
|
|
|
EventEmitter,
|
|
|
|
HostListener,
|
|
|
|
HostListener,
|
|
|
|
Input, OnChanges,
|
|
|
|
Input, OnChanges,
|
|
|
@ -27,6 +27,7 @@ export class FileGridComponent implements OnChanges, OnInit {
|
|
|
|
@Output() fileSelectEvent = new EventEmitter<File | undefined>();
|
|
|
|
@Output() fileSelectEvent = new EventEmitter<File | undefined>();
|
|
|
|
|
|
|
|
|
|
|
|
@ViewChild("virtualScrollGrid") virtualScroll!: CdkVirtualScrollViewport;
|
|
|
|
@ViewChild("virtualScrollGrid") virtualScroll!: CdkVirtualScrollViewport;
|
|
|
|
|
|
|
|
@ViewChild("galleryWrapper") galleryWrapper!: ElementRef<HTMLDivElement>;
|
|
|
|
|
|
|
|
|
|
|
|
selectedEntries: GridEntry[] = [];
|
|
|
|
selectedEntries: GridEntry[] = [];
|
|
|
|
|
|
|
|
|
|
|
@ -50,22 +51,36 @@ export class FileGridComponent implements OnChanges, OnInit {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private handlePreselection() {
|
|
|
|
/**
|
|
|
|
if (this.preselectedFile && this.selectedEntries.length === 0) {
|
|
|
|
* File selector logic
|
|
|
|
const selectedEntry = this.gridEntries.find(e => e.file.hash == this.preselectedFile?.hash);
|
|
|
|
* @param {FileGridEntryComponent} clickedEntry
|
|
|
|
if (selectedEntry) {
|
|
|
|
*/
|
|
|
|
this.setSelectedFile(selectedEntry);
|
|
|
|
setSelectedFile(clickedEntry: GridEntry) {
|
|
|
|
|
|
|
|
const previousSelectionSize = this.selectedEntries.length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!(this.shiftClicked || this.ctrlClicked) && this.selectedEntries.length > 0) {
|
|
|
|
|
|
|
|
this.selectedEntries.forEach(entry => {if (entry !== clickedEntry) entry.selected = false});
|
|
|
|
|
|
|
|
this.selectedEntries = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.shiftClicked && this.selectedEntries.length > 0) {
|
|
|
|
|
|
|
|
this.handleShiftSelect(clickedEntry);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
clickedEntry.selected = !clickedEntry.selected;
|
|
|
|
|
|
|
|
if (!clickedEntry.selected) {
|
|
|
|
|
|
|
|
const index = this.selectedEntries.indexOf(clickedEntry);
|
|
|
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
|
|
|
this.selectedEntries.splice(index, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.selectedEntries.push(clickedEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private handleScrollToPreselection() {
|
|
|
|
|
|
|
|
if (this.preselectedFile && this.selectedEntries.length === 0) {
|
|
|
|
|
|
|
|
const rowIndex = this.partitionedGridEntries.findIndex(
|
|
|
|
|
|
|
|
r => r.findIndex(e => e.file.hash == this.preselectedFile?.hash) >= 0);
|
|
|
|
|
|
|
|
if (rowIndex >= 0) {
|
|
|
|
|
|
|
|
this.virtualScroll?.scrollToIndex(rowIndex);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.selectedEntries.length == 1) {
|
|
|
|
|
|
|
|
this.fileSelectEvent.emit(this.selectedEntries.map(entry => entry.file)[0]);
|
|
|
|
|
|
|
|
} else if (this.selectedEntries.length == 0 && previousSelectionSize == 1){
|
|
|
|
|
|
|
|
this.fileSelectEvent.emit(undefined);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.fileMultiselectEvent.emit(this.selectedEntries.map(entry => entry.file));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -98,39 +113,6 @@ export class FileGridComponent implements OnChanges, OnInit {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* File selector logic
|
|
|
|
|
|
|
|
* @param {FileGridEntryComponent} clickedEntry
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
setSelectedFile(clickedEntry: GridEntry) {
|
|
|
|
|
|
|
|
const previousSelectionSize = this.selectedEntries.length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!(this.shiftClicked || this.ctrlClicked) && this.selectedEntries.length > 0) {
|
|
|
|
|
|
|
|
this.selectedEntries.forEach(entry => {if (entry !== clickedEntry) entry.selected = false});
|
|
|
|
|
|
|
|
this.selectedEntries = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.shiftClicked && this.selectedEntries.length > 0) {
|
|
|
|
|
|
|
|
this.handleShiftSelect(clickedEntry);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
clickedEntry.selected = !clickedEntry.selected;
|
|
|
|
|
|
|
|
if (!clickedEntry.selected) {
|
|
|
|
|
|
|
|
const index = this.selectedEntries.indexOf(clickedEntry);
|
|
|
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
|
|
|
this.selectedEntries.splice(index, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.selectedEntries.push(clickedEntry);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.selectedEntries.length == 1) {
|
|
|
|
|
|
|
|
this.fileSelectEvent.emit(this.selectedEntries.map(entry => entry.file)[0]);
|
|
|
|
|
|
|
|
} else if (this.selectedEntries.length == 0 && previousSelectionSize == 1){
|
|
|
|
|
|
|
|
this.fileSelectEvent.emit(undefined);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.fileMultiselectEvent.emit(this.selectedEntries.map(entry => entry.file));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private handleShiftSelect(clickedEntry: GridEntry): void {
|
|
|
|
private handleShiftSelect(clickedEntry: GridEntry): void {
|
|
|
|
const lastEntry = this.selectedEntries[this.selectedEntries.length - 1];
|
|
|
|
const lastEntry = this.selectedEntries[this.selectedEntries.length - 1];
|
|
|
|
let found = false;
|
|
|
|
let found = false;
|
|
|
|