|
|
@ -1,25 +1,38 @@
|
|
|
|
import {AfterViewInit, Component, Input, OnChanges, SimpleChanges} from "@angular/core";
|
|
|
|
import {
|
|
|
|
|
|
|
|
AfterViewChecked,
|
|
|
|
|
|
|
|
AfterViewInit,
|
|
|
|
|
|
|
|
ChangeDetectionStrategy,
|
|
|
|
|
|
|
|
ChangeDetectorRef,
|
|
|
|
|
|
|
|
Component,
|
|
|
|
|
|
|
|
Input,
|
|
|
|
|
|
|
|
OnChanges,
|
|
|
|
|
|
|
|
SimpleChanges
|
|
|
|
|
|
|
|
} from "@angular/core";
|
|
|
|
import {File} from "../../../../../api/models/File";
|
|
|
|
import {File} from "../../../../../api/models/File";
|
|
|
|
import {FileService} from "../../../../services/file/file.service";
|
|
|
|
import {FileService} from "../../../../services/file/file.service";
|
|
|
|
import {FileHelper} from "../../../../services/file/file.helper";
|
|
|
|
import {FileHelper} from "../../../../services/file/file.helper";
|
|
|
|
import {SafeResourceUrl} from "@angular/platform-browser";
|
|
|
|
import {SafeResourceUrl} from "@angular/platform-browser";
|
|
|
|
|
|
|
|
import {BehaviorSubject} from "rxjs";
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
selector: "app-file-thumbnail",
|
|
|
|
selector: "app-file-thumbnail",
|
|
|
|
templateUrl: "./file-thumbnail.component.html",
|
|
|
|
templateUrl: "./file-thumbnail.component.html",
|
|
|
|
styleUrls: ["./file-thumbnail.component.scss"]
|
|
|
|
styleUrls: ["./file-thumbnail.component.scss"],
|
|
|
|
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
})
|
|
|
|
})
|
|
|
|
export class FileThumbnailComponent implements OnChanges, AfterViewInit {
|
|
|
|
export class FileThumbnailComponent implements OnChanges, AfterViewInit, AfterViewChecked {
|
|
|
|
|
|
|
|
|
|
|
|
@Input() file!: File;
|
|
|
|
@Input() file!: File;
|
|
|
|
|
|
|
|
@Input() public fileChanged: BehaviorSubject<void> = new BehaviorSubject<void>(undefined);
|
|
|
|
|
|
|
|
|
|
|
|
public thumbUrl: SafeResourceUrl | undefined;
|
|
|
|
public thumbUrl: SafeResourceUrl | undefined;
|
|
|
|
public fileType!: string;
|
|
|
|
public fileType!: string;
|
|
|
|
public thumbnailSupported: boolean = false;
|
|
|
|
public thumbnailSupported: boolean = false;
|
|
|
|
|
|
|
|
|
|
|
|
private supportedThumbnailTypes = ["image", "video"];
|
|
|
|
private supportedThumbnailTypes = ["image", "video"];
|
|
|
|
|
|
|
|
private previousStatus = "imported";
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private fileService: FileService) {
|
|
|
|
constructor(private changeDetector: ChangeDetectorRef, private fileService: FileService) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async ngAfterViewInit() {
|
|
|
|
public async ngAfterViewInit() {
|
|
|
@ -28,6 +41,13 @@ export class FileThumbnailComponent implements OnChanges, AfterViewInit {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ngAfterViewChecked(): void {
|
|
|
|
|
|
|
|
if (this.file && this.file.status != this.previousStatus) {
|
|
|
|
|
|
|
|
this.previousStatus = this.file.status;
|
|
|
|
|
|
|
|
this.changeDetector.markForCheck();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async ngOnChanges(changes: SimpleChanges) {
|
|
|
|
public async ngOnChanges(changes: SimpleChanges) {
|
|
|
|
if (changes["file"]) {
|
|
|
|
if (changes["file"]) {
|
|
|
|
this.thumbUrl = this.fileService.buildThumbnailUrl(this.file,
|
|
|
|
this.thumbUrl = this.fileService.buildThumbnailUrl(this.file,
|
|
|
@ -36,16 +56,19 @@ export class FileThumbnailComponent implements OnChanges, AfterViewInit {
|
|
|
|
this.fileType = this.getFileType();
|
|
|
|
this.fileType = this.getFileType();
|
|
|
|
this.thumbnailSupported = this.getThumbnailSupported();
|
|
|
|
this.thumbnailSupported = this.getThumbnailSupported();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changes["fileChanged"]) {
|
|
|
|
|
|
|
|
this.fileChanged.subscribe(() => this.changeDetector.markForCheck());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getThumbnailSupported(): boolean {
|
|
|
|
private getThumbnailSupported(): boolean {
|
|
|
|
const mimeParts = FileHelper.parseMime(this.file.mimeType);
|
|
|
|
const mimeParts = FileHelper.parseMime(this.file.mimeType);
|
|
|
|
|
|
|
|
|
|
|
|
return !!mimeParts && this.supportedThumbnailTypes.includes(
|
|
|
|
return !!mimeParts && this.supportedThumbnailTypes.includes(
|
|
|
|
mimeParts[0]);
|
|
|
|
mimeParts[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getFileType(): string {
|
|
|
|
private getFileType(): string {
|
|
|
|
const mimeParts = FileHelper.parseMime(this.file.mimeType);
|
|
|
|
const mimeParts = FileHelper.parseMime(this.file.mimeType);
|
|
|
|
return (mimeParts && mimeParts[0]) ?? "other";
|
|
|
|
return (mimeParts && mimeParts[0]) ?? "other";
|
|
|
|
}
|
|
|
|
}
|
|
|
|