|
|
@ -1,26 +1,29 @@
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
AfterContentChecked,
|
|
|
|
|
|
|
|
Component,
|
|
|
|
Component,
|
|
|
|
Input,
|
|
|
|
Input,
|
|
|
|
OnInit,
|
|
|
|
OnInit,
|
|
|
|
ViewChild,
|
|
|
|
ViewChild,
|
|
|
|
ElementRef, AfterViewInit
|
|
|
|
ElementRef, Output, EventEmitter, OnDestroy
|
|
|
|
} from '@angular/core';
|
|
|
|
} from '@angular/core';
|
|
|
|
import {File} from "../../../models/File";
|
|
|
|
import {File} from "../../../models/File";
|
|
|
|
import {FileService} from "../../../services/file/file.service";
|
|
|
|
import {FileService} from "../../../services/file/file.service";
|
|
|
|
import {ErrorBrokerService} from "../../../services/error-broker/error-broker.service";
|
|
|
|
import {ErrorBrokerService} from "../../../services/error-broker/error-broker.service";
|
|
|
|
import {SafeResourceUrl} from "@angular/platform-browser";
|
|
|
|
import {SafeResourceUrl} from "@angular/platform-browser";
|
|
|
|
import {MatCard} from "@angular/material/card";
|
|
|
|
import {MatCard} from "@angular/material/card";
|
|
|
|
|
|
|
|
import {Thumbnail} from "../../../models/Thumbnail";
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
selector: 'app-file-grid-entry',
|
|
|
|
selector: 'app-file-grid-entry',
|
|
|
|
templateUrl: './file-grid-entry.component.html',
|
|
|
|
templateUrl: './file-grid-entry.component.html',
|
|
|
|
styleUrls: ['./file-grid-entry.component.scss']
|
|
|
|
styleUrls: ['./file-grid-entry.component.scss']
|
|
|
|
})
|
|
|
|
})
|
|
|
|
export class FileGridEntryComponent implements OnInit {
|
|
|
|
export class FileGridEntryComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
|
|
|
|
@ViewChild("card") card!: ElementRef;
|
|
|
|
@ViewChild("card") card!: ElementRef;
|
|
|
|
@Input() file!: File;
|
|
|
|
@Input() file!: File;
|
|
|
|
|
|
|
|
@Output() clickEvent = new EventEmitter<File>();
|
|
|
|
|
|
|
|
@Output() dblClickEvent = new EventEmitter<File>();
|
|
|
|
|
|
|
|
selectedThumbnail: Thumbnail | undefined;
|
|
|
|
|
|
|
|
|
|
|
|
contentUrl: SafeResourceUrl | undefined;
|
|
|
|
contentUrl: SafeResourceUrl | undefined;
|
|
|
|
constructor(private fileService: FileService, private errorBroker: ErrorBrokerService) { }
|
|
|
|
constructor(private fileService: FileService, private errorBroker: ErrorBrokerService) { }
|
|
|
@ -29,11 +32,24 @@ export class FileGridEntryComponent implements OnInit {
|
|
|
|
await this.loadImage();
|
|
|
|
await this.loadImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy(): void {
|
|
|
|
|
|
|
|
if (this.contentUrl) {
|
|
|
|
|
|
|
|
const url = this.contentUrl;
|
|
|
|
|
|
|
|
this.contentUrl = undefined;
|
|
|
|
|
|
|
|
URL?.revokeObjectURL(url as string);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async loadImage() {
|
|
|
|
async loadImage() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const thumbnails = await this.fileService.getThumbnails(this.file.hash);
|
|
|
|
const thumbnails = await this.fileService.getThumbnails(this.file.hash);
|
|
|
|
let thumbnail = thumbnails.find(t => (t.height > 250 || t.width > 250) && (t.height < 500 && t.width < 500));
|
|
|
|
let thumbnail = thumbnails.find(t => (t.height > 250 || t.width > 250) && (t.height < 500 && t.width < 500));
|
|
|
|
this.contentUrl = await this.fileService.readThumbnail(thumbnail!!);
|
|
|
|
this.selectedThumbnail = thumbnail;
|
|
|
|
|
|
|
|
if (!thumbnail) {
|
|
|
|
|
|
|
|
console.log("Thumbnail is empty?!", thumbnails);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.contentUrl = await this.fileService.readThumbnail(thumbnail!!);
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
this.errorBroker.showError(err);
|
|
|
|
this.errorBroker.showError(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|