From 71d4287246045209bbdf16e4c4d5a050c039a938 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 20 Feb 2022 14:02:33 +0100 Subject: [PATCH] Fix file status not updating visually TG-107 #closed Signed-off-by: trivernis --- mediarepo-ui/src/api/models/File.ts | 20 ++++++++++++++----- .../file-action-base.component.ts | 4 ++-- .../file/file-card/file-card.component.html | 1 - .../file/file-card/file-card.component.ts | 20 ------------------- .../file-context-menu.component.ts | 10 +++++----- .../file-gallery/file-gallery.component.html | 5 ++--- .../file-gallery/file-gallery.component.ts | 6 ------ .../file-grid/file-grid.component.html | 5 ++--- .../file-grid/file-grid.component.ts | 6 ------ .../file-multiview.component.ts | 2 +- .../file-thumbnail.component.html | 6 +++--- .../file-thumbnail.component.ts | 16 +-------------- 12 files changed, 31 insertions(+), 70 deletions(-) diff --git a/mediarepo-ui/src/api/models/File.ts b/mediarepo-ui/src/api/models/File.ts index 67f3bd8..d73cfed 100644 --- a/mediarepo-ui/src/api/models/File.ts +++ b/mediarepo-ui/src/api/models/File.ts @@ -1,9 +1,14 @@ import {FileBasicData, FileStatus} from "../api-types/files"; +import {BehaviorSubject, Observable} from "rxjs"; export class File { + + private statusSubject: BehaviorSubject; + constructor( private basicData: FileBasicData, ) { + this.statusSubject = new BehaviorSubject(basicData.status); } public get rawData(): FileBasicData { @@ -18,15 +23,20 @@ export class File { return this.basicData.cd; } - public get status(): FileStatus { - return this.basicData.status; + public get status(): Observable { + return this.statusSubject.asObservable(); + } + + public get mimeType(): string { + return this.basicData.mime_type; } - public set status(value: FileStatus) { + public setStatus(value: FileStatus) { this.basicData.status = value; + this.statusSubject.next(value); } - public get mimeType(): string { - return this.basicData.mime_type; + public getStatus(): FileStatus { + return this.basicData.status; } } diff --git a/mediarepo-ui/src/app/components/shared/app-base/file-action-base/file-action-base.component.ts b/mediarepo-ui/src/app/components/shared/app-base/file-action-base/file-action-base.component.ts index e912a41..a43053a 100644 --- a/mediarepo-ui/src/app/components/shared/app-base/file-action-base/file-action-base.component.ts +++ b/mediarepo-ui/src/app/components/shared/app-base/file-action-base/file-action-base.component.ts @@ -56,7 +56,7 @@ export class FileActionBaseComponent { if (changeConfirmed) { await this.errorBroker.try(async () => { const newFile = await this.fileService.updateFileStatus(files[0].id, status); - files[0].status = newFile.status; + files[0].setStatus(newFile.getStatus()); }); } } else { @@ -72,7 +72,7 @@ export class FileActionBaseComponent { files, (file) => this.errorBroker.try(async () => { const newFile = await this.fileService.updateFileStatus(file.id, status); - file.status = newFile.status; + file.setStatus(newFile.getStatus()); }) ); } diff --git a/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.html b/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.html index 1856588..fc6cf37 100644 --- a/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.html +++ b/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.html @@ -5,7 +5,6 @@ diff --git a/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.ts b/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.ts index 1936c67..7819289 100644 --- a/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.ts +++ b/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.ts @@ -13,7 +13,6 @@ import { import {File} from "../../../../../api/models/File"; import {Selectable} from "../../../../models/Selectable"; import {SchedulingService} from "../../../../services/scheduling/scheduling.service"; -import {BehaviorSubject} from "rxjs"; const LOADING_WORK_KEY = "FILE_THUMBNAIL_LOADING"; @@ -26,7 +25,6 @@ const LOADING_WORK_KEY = "FILE_THUMBNAIL_LOADING"; export class FileCardComponent implements OnInit, OnChanges, OnDestroy { @Input() public entry!: Selectable; - @Input() public fileChanged: BehaviorSubject = new BehaviorSubject(undefined); @Output() clickEvent = new EventEmitter(); @Output() dblClickEvent = new EventEmitter(); @@ -47,9 +45,6 @@ export class FileCardComponent implements OnInit, OnChanges, OnDestroy { this.cachedId = this.entry.data.id; this.loading = true; } - if (changes["fileChanged"]) { - this.fileChanged.subscribe(() => this.changeDetector.markForCheck()); - } } public ngOnDestroy(): void { @@ -62,19 +57,4 @@ export class FileCardComponent implements OnInit, OnChanges, OnDestroy { console.debug(this.entry.data.id); this.clickEvent.emit(this); } - - private setImageDelayed() { - if (this.workId) { - this.schedulingService.cancelWork(LOADING_WORK_KEY, this.workId); - } - this.loading = true; - this.workId = this.schedulingService.addWork( - LOADING_WORK_KEY, - async () => { - await this.schedulingService.delay(0); - this.loading = false; - this.changeDetector.markForCheck(); - } - ); - } } diff --git a/mediarepo-ui/src/app/components/shared/file/file-context-menu/file-context-menu.component.ts b/mediarepo-ui/src/app/components/shared/file/file-context-menu/file-context-menu.component.ts index 90a2151..1b4a3e7 100644 --- a/mediarepo-ui/src/app/components/shared/file/file-context-menu/file-context-menu.component.ts +++ b/mediarepo-ui/src/app/components/shared/file/file-context-menu/file-context-menu.component.ts @@ -60,11 +60,11 @@ export class FileContextMenuComponent extends FileActionBaseComponent implements this.actionDelete = this.actionArchive = this.actionImported = this.actionRestore = false; for (const file of this.files) { - this.actionDeletePermantently &&= file.status === "Deleted"; - this.actionDelete ||= file.status !== "Deleted"; - this.actionArchive ||= file.status !== "Archived" && file.status !== "Deleted"; - this.actionImported ||= file.status !== "Imported" && file.status !== "Deleted"; - this.actionRestore ||= file.status === "Deleted"; + this.actionDeletePermantently &&= file.getStatus() === "Deleted"; + this.actionDelete ||= file.getStatus() !== "Deleted"; + this.actionArchive ||= file.getStatus() !== "Archived" && file.getStatus() !== "Deleted"; + this.actionImported ||= file.getStatus() !== "Imported" && file.getStatus() !== "Deleted"; + this.actionRestore ||= file.getStatus() === "Deleted"; } } } diff --git a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.html b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.html index 281b9bc..ed3abbc 100644 --- a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.html +++ b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.html @@ -24,11 +24,10 @@
+ [entry]="entry">
+ (fileDeleted)="this.fileDeleted.emit($event)"> diff --git a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.ts b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.ts index 963006d..4e93fe8 100644 --- a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.ts +++ b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.ts @@ -19,7 +19,6 @@ import {SafeResourceUrl} from "@angular/platform-browser"; import {Selectable} from "../../../../../models/Selectable"; import {TabService} from "../../../../../services/tab/tab.service"; import {Key} from "w3c-keys"; -import {BehaviorSubject} from "rxjs"; @Component({ selector: "app-file-gallery", @@ -43,7 +42,6 @@ export class FileGalleryComponent implements OnChanges, OnInit, AfterViewInit, A public entries: Selectable[] = []; public selectedFile: Selectable | undefined; public fileContentUrl: SafeResourceUrl | undefined; - public fileChanged = new BehaviorSubject(undefined); public selectedIndex = 0; public imageViewHeightPercent = 80; @@ -182,10 +180,6 @@ export class FileGalleryComponent implements OnChanges, OnInit, AfterViewInit, A return item?.data.id; } - public onFileStatusChange(): void { - this.fileChanged.next(); - } - public togglePreviewStrip(): void { if (this.previewStripVisible) { this.imageViewHeightPercent = 100; diff --git a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.html b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.html index 19a4afd..94afd4d 100644 --- a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.html +++ b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.html @@ -14,7 +14,7 @@ (contextmenu)="this.selectEntryWhenNotSelected(gridEntry); fileContextMenu.onContextMenu($event, this.getSelectedFiles())" (dblClickEvent)="fileOpen.emit($event.entry.data)" *ngIf="gridEntry" - [entry]="gridEntry" [fileChanged]="this.fileChanged"> + [entry]="gridEntry">
@@ -23,8 +23,7 @@ + (fileDeleted)="this.fileDeleted.emit($event)">