|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import {
|
|
|
|
|
Component,
|
|
|
|
|
EventEmitter,
|
|
|
|
|
EventEmitter, Inject,
|
|
|
|
|
Input,
|
|
|
|
|
OnChanges,
|
|
|
|
|
OnInit,
|
|
|
|
@ -9,7 +9,7 @@ import {
|
|
|
|
|
} from '@angular/core';
|
|
|
|
|
import {File} from "../../../models/File";
|
|
|
|
|
import {FileService} from "../../../services/file/file.service";
|
|
|
|
|
import {SafeResourceUrl} from "@angular/platform-browser";
|
|
|
|
|
import {DomSanitizer, SafeResourceUrl} from "@angular/platform-browser";
|
|
|
|
|
import {ErrorBrokerService} from "../../../services/error-broker/error-broker.service";
|
|
|
|
|
import {Selectable} from "../../../models/Selectable";
|
|
|
|
|
|
|
|
|
@ -26,32 +26,18 @@ export class FileGalleryEntryComponent implements OnInit, OnChanges {
|
|
|
|
|
|
|
|
|
|
private cachedFile: File | undefined;
|
|
|
|
|
|
|
|
|
|
constructor(private fileService: FileService, private errorBroker: ErrorBrokerService) {
|
|
|
|
|
constructor(@Inject(DomSanitizer) private sanitizer: DomSanitizer, private fileService: FileService, private errorBroker: ErrorBrokerService) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async ngOnChanges(changes: SimpleChanges): Promise<void> {
|
|
|
|
|
if (changes["file"] && (!this.cachedFile || this.file.data.hash !== this.cachedFile!.hash)) { // handle changes to the file when the component is not destroyed
|
|
|
|
|
this.cachedFile = this.file.data;
|
|
|
|
|
this.contentUrl = undefined;
|
|
|
|
|
await this.loadImage();
|
|
|
|
|
this.contentUrl = this.fileService.buildThumbnailUrl(this.file.data, 250, 250);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
|
this.cachedFile = this.file.data;
|
|
|
|
|
await this.loadImage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async loadImage() {
|
|
|
|
|
try {
|
|
|
|
|
const hash = this.file.data.hash;
|
|
|
|
|
const contentUrl = await this.fileService.getFileThumbnail(this.file.data, 250, 250);
|
|
|
|
|
|
|
|
|
|
if (this.file.data.hash === hash) { // avoid issues with changed files
|
|
|
|
|
this.contentUrl = contentUrl;
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
this.errorBroker.showError(err);
|
|
|
|
|
}
|
|
|
|
|
this.contentUrl = this.fileService.buildThumbnailUrl(this.file.data, 250, 250);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|