Fix database lockout caused by duplicate files in library (#1102)

This commit is contained in:
Aditya Chandel
2025-09-06 21:22:59 -06:00
committed by GitHub
parent c8e78d3bc8
commit 074d8d6e69
36 changed files with 1766 additions and 359 deletions
+67 -29
View File
@@ -1,4 +1,4 @@
import {Component, inject, OnInit} from '@angular/core';
import {Component, inject, OnInit, OnDestroy} from '@angular/core';
import {RxStompService} from './shared/websocket/rx-stomp.service';
import {BookService} from './book/service/book.service';
import {NotificationEventService} from './shared/websocket/notification-event.service';
@@ -12,6 +12,9 @@ import {MetadataBatchProgressNotification} from './core/model/metadata-batch-pro
import {MetadataProgressService} from './core/service/metadata-progress-service';
import {BookdropFileNotification, BookdropFileService} from './bookdrop/bookdrop-file.service';
import {TaskEventService} from './shared/websocket/task-event.service';
import {DuplicateFileNotification} from './shared/websocket/model/duplicate-file-notification.model';
import {DuplicateFileService} from './shared/websocket/duplicate-file.service';
import {Subscription} from 'rxjs';
@Component({
selector: 'app-root',
@@ -20,9 +23,11 @@ import {TaskEventService} from './shared/websocket/task-event.service';
standalone: true,
imports: [ConfirmDialog, Toast, RouterOutlet]
})
export class AppComponent implements OnInit {
export class AppComponent implements OnInit, OnDestroy {
loading = true;
private subscriptions: Subscription[] = [];
private subscriptionsInitialized = false; // Prevent multiple subscription setups
private authInit = inject(AuthInitializationService);
private bookService = inject(BookService);
private rxStompService = inject(RxStompService);
@@ -30,37 +35,70 @@ export class AppComponent implements OnInit {
private metadataProgressService = inject(MetadataProgressService);
private bookdropFileService = inject(BookdropFileService);
private taskEventService = inject(TaskEventService);
private appConfigService = inject(AppConfigService);
private duplicateFileService = inject(DuplicateFileService);
private appConfigService = inject(AppConfigService); // Keep it here to ensure the service is initialized
ngOnInit(): void {
this.authInit.initialized$.subscribe(ready => {
this.loading = !ready;
});
this.rxStompService.watch('/user/queue/book-add').subscribe(msg =>
this.bookService.handleNewlyCreatedBook(JSON.parse(msg.body))
);
this.rxStompService.watch('/user/queue/books-remove').subscribe(msg =>
this.bookService.handleRemovedBookIds(JSON.parse(msg.body))
);
this.rxStompService.watch('/user/queue/book-metadata-update').subscribe(msg =>
this.bookService.handleBookUpdate(JSON.parse(msg.body))
);
this.rxStompService.watch('/user/queue/book-metadata-batch-update').subscribe(msg =>
this.bookService.handleMultipleBookUpdates(JSON.parse(msg.body))
);
this.rxStompService.watch('/user/queue/book-metadata-batch-progress').subscribe(msg =>
this.metadataProgressService.handleIncomingProgress(JSON.parse(msg.body) as MetadataBatchProgressNotification)
);
this.rxStompService.watch('/user/queue/log').subscribe(msg => {
const logNotification = parseLogNotification(msg.body);
this.notificationEventService.handleNewNotification(logNotification);
});
this.rxStompService.watch('/user/queue/task').subscribe(msg =>
this.taskEventService.handleTaskMessage(parseTaskMessage(msg.body))
);
this.rxStompService.watch('/user/queue/bookdrop-file').subscribe(msg => {
const notification = JSON.parse(msg.body) as BookdropFileNotification;
this.bookdropFileService.handleIncomingFile(notification);
if (ready && !this.subscriptionsInitialized) {
this.setupWebSocketSubscriptions();
this.subscriptionsInitialized = true;
}
});
}
private setupWebSocketSubscriptions(): void {
this.subscriptions.push(
this.rxStompService.watch('/user/queue/book-add').subscribe(msg =>
this.bookService.handleNewlyCreatedBook(JSON.parse(msg.body))
)
);
this.subscriptions.push(
this.rxStompService.watch('/user/queue/books-remove').subscribe(msg =>
this.bookService.handleRemovedBookIds(JSON.parse(msg.body))
)
);
this.subscriptions.push(
this.rxStompService.watch('/user/queue/book-metadata-update').subscribe(msg =>
this.bookService.handleBookUpdate(JSON.parse(msg.body))
)
);
this.subscriptions.push(
this.rxStompService.watch('/user/queue/book-metadata-batch-update').subscribe(msg =>
this.bookService.handleMultipleBookUpdates(JSON.parse(msg.body))
)
);
this.subscriptions.push(
this.rxStompService.watch('/user/queue/book-metadata-batch-progress').subscribe(msg =>
this.metadataProgressService.handleIncomingProgress(JSON.parse(msg.body) as MetadataBatchProgressNotification)
)
);
this.subscriptions.push(
this.rxStompService.watch('/user/queue/log').subscribe(msg => {
const logNotification = parseLogNotification(msg.body);
this.notificationEventService.handleNewNotification(logNotification);
})
);
this.subscriptions.push(
this.rxStompService.watch('/user/queue/task').subscribe(msg =>
this.taskEventService.handleTaskMessage(parseTaskMessage(msg.body))
)
);
this.subscriptions.push(
this.rxStompService.watch('/user/queue/duplicate-file').subscribe(msg =>
this.duplicateFileService.addDuplicateFile(JSON.parse(msg.body) as DuplicateFileNotification)
)
);
this.subscriptions.push(
this.rxStompService.watch('/user/queue/bookdrop-file').subscribe(msg => {
const notification = JSON.parse(msg.body) as BookdropFileNotification;
this.bookdropFileService.handleIncomingFile(notification);
})
);
}
ngOnDestroy(): void {
this.subscriptions.forEach(sub => sub.unsubscribe());
}
}
@@ -0,0 +1,84 @@
<div class="dialog-container">
<div class="info-message">
<i class="pi pi-exclamation-triangle"></i>
<p>{{ totalRecords }} duplicate file groups have been detected in your library. To maintain data integrity and ensure optimal performance, please review and remove these duplicate entries from your file system.</p>
</div>
<div class="table-container">
<p-table
#dataTable
[value]="(duplicateFiles$ | async) || []"
[scrollable]="true"
scrollHeight="100%"
[paginator]="false"
[rows]="15"
[rowHover]="true">
<ng-template pTemplate="body" let-group>
<tr>
<td>
<div class="hash-group">
<div class="hash-header">
<i class="pi pi-copy"></i>
<span class="hash-label">Hash:</span>
<span class="hash-value">{{ group.hash }}</span>
<span class="file-count">({{ group.files.length }} files)</span>
</div>
<div class="files-list">
@for (file of (group.files || []); track file.fullPath) {
<div class="file-item-compact">
<div class="file-icon">
<i class="pi pi-file"></i>
</div>
<div class="file-details">
<div class="filename">{{ file.fileName }}</div>
<div class="file-path" [title]="file.fullPath">{{ file.fullPath }}</div>
<div class="library-info">
<i class="pi pi-database"></i>
<span>{{ file.libraryName }}</span>
<span class="timestamp">{{ file.timestamp | date:'short' }}</span>
</div>
</div>
</div>
}
</div>
</div>
</td>
</tr>
</ng-template>
<ng-template pTemplate="emptymessage">
<tr>
<td class="empty-message">
<div class="empty-content">
<i class="pi pi-info-circle"></i>
<span>No duplicate files detected</span>
</div>
</td>
</tr>
</ng-template>
</p-table>
</div>
<div class="bottom-fixed-area">
<div class="paginator-container">
<p-paginator
[first]="first"
[rows]="rows"
[totalRecords]="totalRecords"
[showCurrentPageReport]="true"
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} duplicate file groups"
(onPageChange)="onPageChange($event)">
</p-paginator>
</div>
<div class="dialog-actions">
<p-button
label="Acknowledge"
icon="pi pi-check"
(click)="acknowledgeAndClose()">
</p-button>
</div>
</div>
</div>
@@ -0,0 +1,235 @@
.dialog-container {
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
}
.table-container {
flex: 1;
overflow: hidden;
margin-bottom: 100px;
::ng-deep .p-datatable {
height: 100%;
.p-datatable-wrapper {
height: 100%;
}
.p-datatable-tbody > tr > td {
border: none !important;
padding: 0.5rem 0.5rem;
}
.p-datatable-tbody > tr {
border: none !important;
}
}
}
.bottom-fixed-area {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: var(--surface-ground);
z-index: 1000;
display: flex;
flex-direction: column;
}
.paginator-container {
::ng-deep .p-paginator {
border: none;
border-bottom: 1px solid var(--border-color);
}
}
.dialog-actions {
display: flex;
justify-content: flex-end;
padding: 1rem;
}
.duplicate-files-content {
overflow: hidden;
}
.hash-group {
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
padding: 1rem;
margin: 0.5rem 0;
}
.hash-header {
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 0.75rem;
padding-bottom: 0.5rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
i {
color: var(--primary-color);
font-size: 0.9rem;
}
.hash-label {
font-weight: 600;
color: rgba(255, 255, 255, 0.9);
font-size: 0.9rem;
}
.hash-value {
font-family: 'Courier New', monospace;
color: rgba(255, 255, 255, 0.7);
font-size: 1rem;
font-weight: 900;
background: rgba(255, 255, 255, 0.05);
padding: 0.25rem 0.5rem;
border-radius: 4px;
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.file-count {
background: var(--primary-color);
color: white;
padding: 0.25rem 0.5rem;
border-radius: 12px;
font-size: 0.8rem;
font-weight: 500;
}
}
.files-list {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.file-item-compact {
display: flex;
align-items: flex-start;
gap: 0.75rem;
padding: 0.75rem;
border-radius: 6px;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
transition: all 0.2s ease;
margin-left: 1rem;
}
.file-icon {
background: var(--primary-color);
color: white;
width: 32px;
height: 32px;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
i {
font-size: 0.9rem;
}
}
.file-details {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.filename {
font-family: 'Courier New', monospace;
font-weight: 600;
font-size: 0.95rem;
color: rgba(255, 255, 255, 0.9);
word-break: break-word;
line-height: 1.2;
}
.file-path {
font-size: 0.95rem;
color: rgba(255, 255, 255, 0.7);
font-family: 'Courier New', monospace;
word-break: break-all;
line-height: 1.2;
max-height: 2.4em;
overflow: hidden;
}
.library-info {
display: inline-flex;
align-items: center;
gap: 0.4rem;
font-size: 0.9rem;
color: rgba(255, 255, 255, 0.8);
margin-top: 0.1rem;
i {
color: var(--primary-color);
font-size: 0.85rem;
}
.timestamp {
margin-left: auto;
font-size: 0.8rem;
color: rgba(255, 255, 255, 0.6);
}
}
.empty-message {
text-align: center !important;
padding: 3rem 1rem !important;
.empty-content {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5rem;
opacity: 0.6;
i {
font-size: 1.5rem;
}
span {
font-size: 0.875rem;
}
}
}
.info-message {
display: flex;
align-items: flex-start;
gap: 0.75rem;
padding: 1rem;
margin-bottom: 1rem;
background: rgba(234, 88, 12, 0.1);
border: 1px solid rgba(234, 88, 12, 0.3);
border-radius: 0.375rem;
color: #fbbf24;
i {
color: #f59e0b;
font-size: 1.125rem;
margin-top: 0.125rem;
flex-shrink: 0;
}
p {
margin: 0;
line-height: 1.5;
font-size: 1rem;
}
}
@@ -0,0 +1,86 @@
import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/dynamicdialog';
import { TableModule } from 'primeng/table';
import { ButtonModule } from 'primeng/button';
import { TooltipModule } from 'primeng/tooltip';
import { PaginatorModule } from 'primeng/paginator';
import { Observable, map } from 'rxjs';
import {DuplicateFileNotification} from '../../../shared/websocket/model/duplicate-file-notification.model';
import {DuplicateFileService} from '../../../shared/websocket/duplicate-file.service';
@Component({
selector: 'app-duplicate-files-dialog',
standalone: true,
imports: [CommonModule, TableModule, ButtonModule, TooltipModule, PaginatorModule],
templateUrl: './duplicate-files-dialog.component.html',
styleUrls: ['./duplicate-files-dialog.component.scss']
})
export class DuplicateFilesDialogComponent implements OnInit {
duplicateFiles$: Observable<{ hash: string; files: DuplicateFileNotification[] }[]>;
totalRecords = 0;
first = 0;
rows = 15;
constructor(
public ref: DynamicDialogRef,
public config: DynamicDialogConfig,
private duplicateFileService: DuplicateFileService
) {
this.duplicateFiles$ = this.config.data.duplicateFiles$.pipe(
map((files: DuplicateFileNotification[] | null) => {
if (!files) return [];
// Group files by hash
const groupedFiles = files.reduce((acc, file) => {
if (!acc[file.hash]) {
acc[file.hash] = [];
}
acc[file.hash].push(file);
return acc;
}, {} as { [hash: string]: DuplicateFileNotification[] });
const groups = Object.entries(groupedFiles).map(([hash, files]) => ({
hash,
files: files.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime())
}));
this.totalRecords = groups.length;
return groups.slice(this.first, this.first + this.rows);
})
);
}
ngOnInit() {}
onPageChange(event: any) {
this.first = event.first;
this.rows = event.rows;
this.duplicateFiles$ = this.config.data.duplicateFiles$.pipe(
map((files: DuplicateFileNotification[] | null) => {
if (!files) return [];
const groupedFiles = files.reduce((acc, file) => {
if (!acc[file.hash]) {
acc[file.hash] = [];
}
acc[file.hash].push(file);
return acc;
}, {} as { [hash: string]: DuplicateFileNotification[] });
const groups = Object.entries(groupedFiles).map(([hash, files]) => ({
hash,
files: files.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime())
}));
this.totalRecords = groups.length;
return groups.slice(this.first, this.first + this.rows);
})
);
}
acknowledgeAndClose() {
this.duplicateFileService.clearDuplicateFiles();
this.ref.close();
}
}
@@ -0,0 +1,22 @@
@if (duplicateFilesCount$ | async; as count) {
@if (count > 0) {
<div class="flex flex-col p-4 space-y-2 live-border">
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<i class="pi pi-exclamation-triangle text-yellow-500"></i>
<span class="font-normal text-zinc-200">{{ count }} duplicate files detected</span>
</div>
<p-tag [value]="count.toString()" severity="warn" [rounded]="true"></p-tag>
</div>
<p-button
label="View Details"
icon="pi pi-list"
outlined
size="small"
severity="info"
fluid
(click)="openDialog()">
</p-button>
</div>
}
}
@@ -0,0 +1,8 @@
.duplicate-files-content {
max-height: 500px;
overflow: hidden;
}
.live-border {
border: 0.5px solid var(--primary-color);
}
@@ -0,0 +1,80 @@
import {Component, inject, OnDestroy} from '@angular/core';
import {CommonModule} from '@angular/common';
import {DialogModule} from 'primeng/dialog';
import {ButtonModule} from 'primeng/button';
import {TableModule} from 'primeng/table';
import {TagModule} from 'primeng/tag';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {DuplicateFileService} from '../../../shared/websocket/duplicate-file.service';
import {DuplicateFileNotification} from '../../../shared/websocket/model/duplicate-file-notification.model';
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {DuplicateFilesDialogComponent} from './duplicate-files-dialog.component';
@Component({
selector: 'app-duplicate-files-notification',
standalone: true,
imports: [CommonModule, DialogModule, ButtonModule, TableModule, TagModule],
templateUrl: './duplicate-files-notification.component.html',
styleUrls: ['./duplicate-files-notification.component.scss'],
providers: [DialogService]
})
export class DuplicateFilesNotificationComponent implements OnDestroy {
displayDialog = false;
private duplicateFileService = inject(DuplicateFileService);
private ref: DynamicDialogRef | undefined;
duplicateFiles$ = this.duplicateFileService.duplicateFiles$;
duplicateFilesCount$: Observable<number> = this.duplicateFiles$.pipe(
map(files => files?.length || 0)
);
constructor(
private dialogService: DialogService
) {
}
openDialog() {
this.ref = this.dialogService.open(DuplicateFilesDialogComponent, {
header: 'Duplicate Files Detected',
width: '80dvw',
height: '75dvh',
contentStyle: {overflow: 'hidden'},
maximizable: true,
modal: true,
data: {
duplicateFiles$: this.duplicateFiles$
}
});
this.ref.onClose.subscribe((result: any) => {
if (result) {
// Handle any result from dialog if needed
}
});
}
closeDialog() {
this.displayDialog = false;
}
clearAllDuplicates() {
this.duplicateFileService.clearDuplicateFiles();
this.closeDialog();
}
removeDuplicate(file: DuplicateFileNotification) {
this.duplicateFileService.removeDuplicateFile(file.fullPath, file.libraryId);
}
formatTimestamp(timestamp: string): string {
return new Date(timestamp).toLocaleString();
}
ngOnDestroy() {
if (this.ref) {
this.ref.close();
}
}
}
@@ -1,5 +1,3 @@
.live-border {
background: var(--card-background);
border: 1px solid var(--primary-color);
border-radius: 0.5rem;
border: 0.5px solid var(--primary-color);
}
@@ -1,6 +1,4 @@
.live-border {
background: var(--card-background);
border: 1px solid var(--primary-color);
border-radius: 0.5rem;
border: 0.5px solid var(--primary-color);
}
@@ -1,5 +1,8 @@
<div class="metadata-progress-box flex gap-4 flex-col w-[25rem] max-h-[60vh] overflow-y-auto">
<app-live-notification-box/>
@if (hasDuplicateFiles$ | async) {
<app-duplicate-files-notification/>
}
@if (hasActiveTasks$ | async) {
<app-live-task-event-box/>
}
@@ -8,6 +8,8 @@ import {map} from 'rxjs/operators';
import {AsyncPipe} from '@angular/common';
import {BookdropFilesWidgetComponent} from '../../../bookdrop/bookdrop-files-widget-component/bookdrop-files-widget.component';
import {BookdropFileService} from '../../../bookdrop/bookdrop-file.service';
import {DuplicateFilesNotificationComponent} from '../duplicate-files-notification/duplicate-files-notification.component';
import {DuplicateFileService} from '../../../shared/websocket/duplicate-file.service';
@Component({
selector: 'app-unified-notification-popover-component',
@@ -16,7 +18,8 @@ import {BookdropFileService} from '../../../bookdrop/bookdrop-file.service';
LiveTaskEventBoxComponent,
MetadataProgressWidgetComponent,
AsyncPipe,
BookdropFilesWidgetComponent
BookdropFilesWidgetComponent,
DuplicateFilesNotificationComponent
],
templateUrl: './unified-notification-popover-component.html',
standalone: true,
@@ -25,6 +28,7 @@ import {BookdropFileService} from '../../../bookdrop/bookdrop-file.service';
export class UnifiedNotificationBoxComponent {
metadataProgressService = inject(MetadataProgressService);
bookdropFileService = inject(BookdropFileService);
duplicateFileService = inject(DuplicateFileService);
taskEventService = inject(TaskEventService);
hasMetadataTasks$ = this.metadataProgressService.activeTasks$.pipe(
@@ -33,6 +37,10 @@ export class UnifiedNotificationBoxComponent {
hasPendingBookdropFiles$ = this.bookdropFileService.hasPendingFiles$;
hasDuplicateFiles$ = this.duplicateFileService.duplicateFiles$.pipe(
map(files => files && files.length > 0)
);
hasActiveTasks$ = this.taskEventService.tasks$.pipe(
map(tasks => tasks.length > 0)
);
@@ -24,6 +24,7 @@ import {UnifiedNotificationBoxComponent} from '../../../core/component/unified-n
import {BookdropFileService} from '../../../bookdrop/bookdrop-file.service';
import {DialogLauncherService} from '../../../dialog-launcher.service';
import {TaskEventService} from '../../../shared/websocket/task-event.service';
import {DuplicateFileService} from '../../../shared/websocket/duplicate-file.service';
@Component({
selector: 'app-topbar',
@@ -62,12 +63,14 @@ export class AppTopBarComponent implements OnDestroy {
showPulse = false;
hasAnyTasks = false;
hasPendingBookdropFiles = false;
hasDuplicateFiles = false;
private eventTimer: any;
private destroy$ = new Subject<void>();
private latestTasks: { [taskId: string]: MetadataBatchProgressNotification } = {};
private latestHasPendingFiles = false;
private latestHasDuplicateFiles = false;
constructor(
public layoutService: LayoutService,
@@ -79,11 +82,13 @@ export class AppTopBarComponent implements OnDestroy {
private metadataProgressService: MetadataProgressService,
private bookdropFileService: BookdropFileService,
private dialogLauncher: DialogLauncherService,
private taskEventService: TaskEventService
private taskEventService: TaskEventService,
private duplicateFileService: DuplicateFileService
) {
this.subscribeToMetadataProgress();
this.subscribeToNotifications();
this.subscribeToTaskEvents();
this.subscribeToDuplicateFiles();
this.metadataProgressService.activeTasks$
.pipe(takeUntil(this.destroy$))
@@ -102,6 +107,15 @@ export class AppTopBarComponent implements OnDestroy {
this.updateCompletedTaskCount();
this.updateTaskVisibilityWithBookdrop();
});
this.duplicateFileService.duplicateFiles$
.pipe(takeUntil(this.destroy$))
.subscribe((duplicateFiles) => {
this.latestHasDuplicateFiles = duplicateFiles && duplicateFiles.length > 0;
this.hasDuplicateFiles = this.latestHasDuplicateFiles;
this.updateCompletedTaskCount();
this.updateTaskVisibilityWithDuplicates();
});
}
ngOnDestroy(): void {
@@ -174,6 +188,16 @@ export class AppTopBarComponent implements OnDestroy {
});
}
private subscribeToDuplicateFiles() {
this.duplicateFileService.duplicateFiles$
.pipe(takeUntil(this.destroy$))
.subscribe((duplicateFiles) => {
if (duplicateFiles && duplicateFiles.length > 0) {
this.triggerPulseEffect();
}
});
}
private triggerPulseEffect() {
this.showPulse = true;
clearTimeout(this.eventTimer);
@@ -185,7 +209,8 @@ export class AppTopBarComponent implements OnDestroy {
private updateCompletedTaskCount() {
const completedMetadataTasks = Object.values(this.latestTasks).filter(task => task.status === 'COMPLETED').length;
const bookdropFileTaskCount = this.latestHasPendingFiles ? 1 : 0;
this.completedTaskCount = completedMetadataTasks + bookdropFileTaskCount;
const duplicateFileTaskCount = this.latestHasDuplicateFiles ? 1 : 0;
this.completedTaskCount = completedMetadataTasks + bookdropFileTaskCount + duplicateFileTaskCount;
}
private updateTaskVisibility(tasks: { [taskId: string]: MetadataBatchProgressNotification }) {
@@ -196,6 +221,11 @@ export class AppTopBarComponent implements OnDestroy {
private updateTaskVisibilityWithBookdrop() {
this.hasActiveOrCompletedTasks = this.hasActiveOrCompletedTasks || this.hasPendingBookdropFiles;
this.updateTaskVisibilityWithDuplicates();
}
private updateTaskVisibilityWithDuplicates() {
this.hasActiveOrCompletedTasks = this.hasActiveOrCompletedTasks || this.hasDuplicateFiles;
}
get iconClass(): string {
@@ -208,7 +238,7 @@ export class AppTopBarComponent implements OnDestroy {
get iconColor(): string {
if (this.progressHighlight) return 'yellow';
if (this.showPulse) return 'red';
if (this.completedTaskCount > 0 || this.hasPendingBookdropFiles) return 'orange';
if (this.completedTaskCount > 0 || this.hasPendingBookdropFiles || this.hasDuplicateFiles) return 'orange';
return 'inherit';
}
@@ -218,7 +248,7 @@ export class AppTopBarComponent implements OnDestroy {
get shouldShowNotificationBadge(): boolean {
return (
(this.completedTaskCount > 0 || this.hasPendingBookdropFiles) &&
(this.completedTaskCount > 0 || this.hasPendingBookdropFiles || this.hasDuplicateFiles) &&
!this.progressHighlight &&
!this.showPulse
);
@@ -0,0 +1,36 @@
import {Injectable} from '@angular/core';
import {BehaviorSubject} from 'rxjs';
import {DuplicateFileNotification} from './model/duplicate-file-notification.model';
@Injectable({
providedIn: 'root'
})
export class DuplicateFileService {
private duplicateFiles: DuplicateFileNotification[] = [];
private duplicateFilesSubject = new BehaviorSubject<DuplicateFileNotification[]>([]);
duplicateFiles$ = this.duplicateFilesSubject.asObservable();
addDuplicateFile(notification: DuplicateFileNotification) {
const exists = this.duplicateFiles.some(file =>
file.fullPath === notification.fullPath && file.libraryId === notification.libraryId
);
if (!exists) {
this.duplicateFiles.unshift(notification);
this.duplicateFilesSubject.next([...this.duplicateFiles]);
}
}
clearDuplicateFiles() {
this.duplicateFiles = [];
this.duplicateFilesSubject.next([]);
}
removeDuplicateFile(fullPath: string, libraryId: number) {
this.duplicateFiles = this.duplicateFiles.filter(file =>
!(file.fullPath === fullPath && file.libraryId === libraryId)
);
this.duplicateFilesSubject.next([...this.duplicateFiles]);
}
}
@@ -0,0 +1,10 @@
export interface DuplicateFileNotification {
libraryId: number;
libraryName: string;
fileId: number;
fileName: string;
fullPath: string;
timestamp: string;
hash: string;
}