diff --git a/mediarepo-ui/src/app/components/shared/file/content-viewer/content-viewer.component.html b/mediarepo-ui/src/app/components/shared/file/content-viewer/content-viewer.component.html index 8077d88..c74112c 100644 --- a/mediarepo-ui/src/app/components/shared/file/content-viewer/content-viewer.component.html +++ b/mediarepo-ui/src/app/components/shared/file/content-viewer/content-viewer.component.html @@ -1,8 +1,8 @@ - - - + + + -
+
Unsupported content type {{this.file.mimeType}}
diff --git a/mediarepo-ui/src/app/components/shared/file/content-viewer/content-viewer.component.ts b/mediarepo-ui/src/app/components/shared/file/content-viewer/content-viewer.component.ts index e6400cb..2f52ce5 100644 --- a/mediarepo-ui/src/app/components/shared/file/content-viewer/content-viewer.component.ts +++ b/mediarepo-ui/src/app/components/shared/file/content-viewer/content-viewer.component.ts @@ -1,5 +1,6 @@ import { AfterViewInit, + ChangeDetectionStrategy, Component, Input, OnChanges, @@ -11,25 +12,23 @@ import {SafeResourceUrl} from "@angular/platform-browser"; import {File} from "../../../../../api/models/File"; import {FileService} from "../../../../services/file/file.service"; import {FileHelper} from "../../../../services/file/file.helper"; -import { - ErrorBrokerService -} from "../../../../services/error-broker/error-broker.service"; -import { - BusyIndicatorComponent -} from "../../app-common/busy-indicator/busy-indicator.component"; +import {ErrorBrokerService} from "../../../../services/error-broker/error-broker.service"; +import {BusyIndicatorComponent} from "../../app-common/busy-indicator/busy-indicator.component"; type ContentType = "image" | "video" | "audio" | "other"; @Component({ selector: "app-content-viewer", templateUrl: "./content-viewer.component.html", - styleUrls: ["./content-viewer.component.scss"] + styleUrls: ["./content-viewer.component.scss"], + changeDetection: ChangeDetectionStrategy.OnPush }) export class ContentViewerComponent implements AfterViewInit, OnChanges, OnDestroy { @Input() file!: File; public contentUrl: SafeResourceUrl | undefined; public blobUrl: SafeResourceUrl | undefined; + public contentType: ContentType = "other"; @ViewChild(BusyIndicatorComponent) busyIndicator!: BusyIndicatorComponent; @@ -40,7 +39,8 @@ export class ContentViewerComponent implements AfterViewInit, OnChanges, OnDestr } public async ngAfterViewInit() { - if (["audio", "video"].includes(this.getContentType())) { + this.contentType = this.getContentType(); + if (["audio", "video"].includes(this.contentType)) { await this.loadBlobUrl(); } else { this.contentUrl = this.fileService.buildContentUrl(this.file); @@ -49,8 +49,9 @@ export class ContentViewerComponent implements AfterViewInit, OnChanges, OnDestr public async ngOnChanges(changes: SimpleChanges) { if (changes["file"]) { - if (["audio", "video"].includes( - this.getContentType()) && this.busyIndicator) { + this.contentType = this.getContentType(); + + if (["audio", "video"].includes(this.contentType) && this.busyIndicator) { await this.loadBlobUrl(); } else { this.contentUrl = this.fileService.buildContentUrl(this.file); @@ -63,23 +64,6 @@ export class ContentViewerComponent implements AfterViewInit, OnChanges, OnDestr this.unloadBlobUrl(); } - public getContentType(): ContentType { - let mimeParts = this.file.mimeType.split("/"); - const type = mimeParts.shift() ?? "other"; - const subtype = mimeParts.shift() ?? "*"; - - switch (type) { - case "image": - return "image"; - case "video": - return "video"; - case "audio": - return "audio"; - default: - return "other"; - } - } - public async downloadContent() { const path = await FileHelper.getFileDownloadLocation(this.file); @@ -103,6 +87,22 @@ export class ContentViewerComponent implements AfterViewInit, OnChanges, OnDestr }); } + private getContentType(): ContentType { + let mimeParts = this.file.mimeType.split("/"); + const type = mimeParts.shift() ?? "other"; + + switch (type) { + case "image": + return "image"; + case "video": + return "video"; + case "audio": + return "audio"; + default: + return "other"; + } + } + private unloadBlobUrl() { if (this.blobUrl) { URL?.revokeObjectURL(this.blobUrl as string); diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-metadata/file-metadata.component.html b/mediarepo-ui/src/app/components/shared/sidebar/file-metadata/file-metadata.component.html index 0644be9..ed8b0b1 100644 --- a/mediarepo-ui/src/app/components/shared/sidebar/file-metadata/file-metadata.component.html +++ b/mediarepo-ui/src/app/components/shared/sidebar/file-metadata/file-metadata.component.html @@ -3,15 +3,21 @@

File Metadata

- + diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-metadata/file-metadata.component.ts b/mediarepo-ui/src/app/components/shared/sidebar/file-metadata/file-metadata.component.ts index 733385d..f897032 100644 --- a/mediarepo-ui/src/app/components/shared/sidebar/file-metadata/file-metadata.component.ts +++ b/mediarepo-ui/src/app/components/shared/sidebar/file-metadata/file-metadata.component.ts @@ -1,48 +1,45 @@ -import { - Component, - Input, - OnChanges, - OnInit, - SimpleChanges -} from "@angular/core"; +import {ChangeDetectionStrategy, Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from "@angular/core"; import {File} from "../../../../../api/models/File"; import {FileService} from "../../../../services/file/file.service"; import {FileMetadata} from "../../../../../api/api-types/files"; +import {BusyIndicatorComponent} from "../../app-common/busy-indicator/busy-indicator.component"; @Component({ selector: "app-file-metadata", templateUrl: "./file-metadata.component.html", - styleUrls: ["./file-metadata.component.scss"] + styleUrls: ["./file-metadata.component.scss"], + changeDetection: ChangeDetectionStrategy.OnPush }) export class FileMetadataComponent implements OnInit, OnChanges { @Input() file!: File; public fileMetadata: FileMetadata | undefined; - public loading = false; + + @ViewChild(BusyIndicatorComponent) busyIndicator!: BusyIndicatorComponent; constructor(private fileService: FileService) { } public async ngOnInit() { - this.loading = true; - this.fileMetadata = await this.fileService.getFileMetadata(this.file.id); - this.loading = false; + await this.busyIndicator.wrapAsyncOperation(async () => { + this.fileMetadata = await this.fileService.getFileMetadata(this.file.id); + }); } - public async ngOnChanges(changes:SimpleChanges) { + public async ngOnChanges(changes: SimpleChanges) { if (changes["file"] && (!this.fileMetadata || this.fileMetadata.file_id != this.file.id)) { - this.loading = true; - this.fileMetadata = await this.fileService.getFileMetadata(this.file.id); - this.loading = false; + await this.busyIndicator.wrapAsyncOperation(async () => { + this.fileMetadata = await this.fileService.getFileMetadata(this.file.id); + }); } } public async saveFileName(name: string) { - this.loading = true; - const newFile = await this.fileService.updateFileName(this.file.id, name); - if (this.fileMetadata) { - this.fileMetadata.name = newFile.name; - } - this.loading = false; + await this.busyIndicator.wrapAsyncOperation(async () => { + const newFile = await this.fileService.updateFileName(this.file.id, name); + if (this.fileMetadata) { + this.fileMetadata.name = newFile.name; + } + }); } }