Fix file grid being wider than 100%

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 0d8c971056
commit 942650407e

@ -1,6 +1,6 @@
<div #imageContainer class="image-container">
<img #image [src]="this.imageSrc" alt="" (load)="this.adjustSize(image, imageContainer)"
(window:resize)="this.adjustSize(image, imageContainer)"
[class.scale-width]="scaleWidth" [class.scale-height]="!scaleWidth"
[class.scale-width]="scaleWidth && maximizeWidth" [class.scale-height]="(!scaleWidth) && maximizeHeight"
decoding="async">
</div>

@ -4,16 +4,18 @@
display: flex;
}
.image-container > img {
img {
margin: auto;
max-height: 100%;
max-width: 100%;
height: auto;
width: auto;
}
img.scale-height {
height: 100%;
width: auto;
}
img.scale-width {
width: 100%;
height: auto;
}

@ -9,6 +9,8 @@ import {SafeResourceUrl} from "@angular/platform-browser";
export class ContentAwareImageComponent {
@Input() imageSrc!: string | SafeResourceUrl;
@Input() maximizeHeight: boolean = true;
@Input() maximizeWidth: boolean = true;
scaleWidth = false;

@ -1,7 +1,7 @@
<mat-card #card (click)="clickEvent.emit(this)" (dblclick)="dblClickEvent.emit(this)" [ngClass]="{'selected': gridEntry.selected}">
<mat-card-title *ngIf="!!gridEntry.file?.name">{{gridEntry.file?.name}}</mat-card-title>
<mat-card-content *ngIf="contentUrl !== undefined">
<app-content-aware-image class="entry-image" *ngIf="contentUrl" [imageSrc]="contentUrl"></app-content-aware-image>
<app-content-aware-image [maximizeHeight]="false" class="entry-image" *ngIf="contentUrl" [imageSrc]="contentUrl"></app-content-aware-image>
</mat-card-content>
<mat-card-footer>
<mat-progress-bar *ngIf="contentUrl === undefined" mode="indeterminate"></mat-progress-bar>

@ -1,8 +1,11 @@
<cdk-virtual-scroll-viewport #virtualScrollGrid class="file-scroll" maxBufferPx="500" minBufferPx="500" itemSize="250">
<div *cdkVirtualFor="let rowEntry of partitionedGridEntries">
<div class="file-row">
<app-file-grid-entry (clickEvent)="setSelectedFile($event.gridEntry)" (dblClickEvent)="fileDblClickEvent.emit($event.gridEntry.file)"
*ngFor="let gridEntry of rowEntry" [gridEntry]="gridEntry"></app-file-grid-entry>
<div class="file-gallery-inner">
<cdk-virtual-scroll-viewport #virtualScrollGrid class="file-scroll" maxBufferPx="500" minBufferPx="500" itemSize="250">
<div *cdkVirtualFor="let rowEntry of partitionedGridEntries">
<div class="file-row">
<app-file-grid-entry (clickEvent)="setSelectedFile($event.gridEntry)" (dblClickEvent)="fileDblClickEvent.emit($event.gridEntry.file)"
*ngFor="let gridEntry of rowEntry" [gridEntry]="gridEntry"></app-file-grid-entry>
</div>
</div>
</div>
</cdk-virtual-scroll-viewport>
</cdk-virtual-scroll-viewport>
</div>

@ -6,9 +6,18 @@ app-file-grid-entry {
.file-scroll {
height: 100%;
width: 100%;
}
.file-gallery-inner {
width: 100%;
height: 100%;
display: block;
overflow: hidden;
}
.file-row {
display: flex;
flex-direction: row;
width: 100%;
}

@ -1,5 +1,5 @@
import {
Component,
Component, ElementRef,
EventEmitter,
HostListener,
Input, OnChanges,
@ -27,6 +27,7 @@ export class FileGridComponent implements OnChanges, OnInit {
@Output() fileSelectEvent = new EventEmitter<File | undefined>();
@ViewChild("virtualScrollGrid") virtualScroll!: CdkVirtualScrollViewport;
@ViewChild("galleryWrapper") galleryWrapper!: ElementRef<HTMLDivElement>;
selectedEntries: GridEntry[] = [];
@ -50,23 +51,37 @@ export class FileGridComponent implements OnChanges, OnInit {
}
}
private handlePreselection() {
if (this.preselectedFile && this.selectedEntries.length === 0) {
const selectedEntry = this.gridEntries.find(e => e.file.hash == this.preselectedFile?.hash);
if (selectedEntry) {
this.setSelectedFile(selectedEntry);
}
}
}
/**
* File selector logic
* @param {FileGridEntryComponent} clickedEntry
*/
setSelectedFile(clickedEntry: GridEntry) {
const previousSelectionSize = this.selectedEntries.length;
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.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 setPartitionedGridEntries() {
@ -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 {
const lastEntry = this.selectedEntries[this.selectedEntries.length - 1];
let found = false;

Loading…
Cancel
Save