|
|
@ -1,6 +1,6 @@
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
EventEmitter, Inject,
|
|
|
|
Input,
|
|
|
|
Input,
|
|
|
|
OnChanges,
|
|
|
|
OnChanges,
|
|
|
|
OnInit,
|
|
|
|
OnInit,
|
|
|
@ -9,7 +9,7 @@ import {
|
|
|
|
} 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 {SafeResourceUrl} from "@angular/platform-browser";
|
|
|
|
import {DomSanitizer, SafeResourceUrl} from "@angular/platform-browser";
|
|
|
|
import {ErrorBrokerService} from "../../../services/error-broker/error-broker.service";
|
|
|
|
import {ErrorBrokerService} from "../../../services/error-broker/error-broker.service";
|
|
|
|
import {Selectable} from "../../../models/Selectable";
|
|
|
|
import {Selectable} from "../../../models/Selectable";
|
|
|
|
|
|
|
|
|
|
|
@ -26,32 +26,18 @@ export class FileGalleryEntryComponent implements OnInit, OnChanges {
|
|
|
|
|
|
|
|
|
|
|
|
private cachedFile: File | undefined;
|
|
|
|
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> {
|
|
|
|
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
|
|
|
|
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.cachedFile = this.file.data;
|
|
|
|
this.contentUrl = undefined;
|
|
|
|
this.contentUrl = this.fileService.buildThumbnailUrl(this.file.data, 250, 250);
|
|
|
|
await this.loadImage();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
async ngOnInit() {
|
|
|
|
this.cachedFile = this.file.data;
|
|
|
|
this.cachedFile = this.file.data;
|
|
|
|
await this.loadImage();
|
|
|
|
this.contentUrl = this.fileService.buildThumbnailUrl(this.file.data, 250, 250);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|