From bb2f564b584c9b9c77a3c45e5d8f902e0680ba55 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 4 Nov 2021 20:09:10 +0100 Subject: [PATCH] Add removing option for repositories Signed-off-by: trivernis --- mediarepo-ui/src/app/app.module.ts | 4 ++ .../confirm-dialog.component.html | 10 +++++ .../confirm-dialog.component.scss | 8 ++++ .../confirm-dialog.component.spec.ts | 25 ++++++++++++ .../confirm-dialog.component.ts | 35 ++++++++++++++++ .../add-repository-dialog.component.html | 2 +- .../repository-card.component.html | 5 +++ .../repository-card.component.ts | 40 +++++++++++++++---- .../services/repository/repository.service.ts | 3 +- 9 files changed, 122 insertions(+), 10 deletions(-) create mode 100644 mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.html create mode 100644 mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.scss create mode 100644 mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.spec.ts create mode 100644 mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.ts diff --git a/mediarepo-ui/src/app/app.module.ts b/mediarepo-ui/src/app/app.module.ts index 86daa1c..d88f976 100644 --- a/mediarepo-ui/src/app/app.module.ts +++ b/mediarepo-ui/src/app/app.module.ts @@ -44,6 +44,8 @@ import { ContentAwareImageComponent } from './components/content-aware-image/con import {MatSliderModule} from "@angular/material/slider"; import { AddRepositoryDialogComponent } from './pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component'; import {MatTooltipModule} from "@angular/material/tooltip"; +import {MatMenuModule} from "@angular/material/menu"; +import { ConfirmDialogComponent } from './components/confirm-dialog/confirm-dialog.component'; @NgModule({ declarations: [ @@ -60,6 +62,7 @@ import {MatTooltipModule} from "@angular/material/tooltip"; FileGalleryEntryComponent, ContentAwareImageComponent, AddRepositoryDialogComponent, + ConfirmDialogComponent, ], imports: [ BrowserModule, @@ -94,6 +97,7 @@ import {MatTooltipModule} from "@angular/material/tooltip"; DragDropModule, MatSliderModule, MatTooltipModule, + MatMenuModule, ], providers: [], bootstrap: [AppComponent] diff --git a/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.html b/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.html new file mode 100644 index 0000000..3168e8b --- /dev/null +++ b/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.html @@ -0,0 +1,10 @@ +

+{{title}} +

+
+{{message}} +
+
+ + +
diff --git a/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.scss b/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.scss new file mode 100644 index 0000000..50ae3d5 --- /dev/null +++ b/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.scss @@ -0,0 +1,8 @@ +.confirm-dialog-actions { + display: block; + + button { + float: right; + margin-left: 1em; + } +} diff --git a/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.spec.ts b/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.spec.ts new file mode 100644 index 0000000..fe08dc5 --- /dev/null +++ b/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ConfirmDialogComponent } from './confirm-dialog.component'; + +describe('ConfirmDialogComponent', () => { + let component: ConfirmDialogComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ConfirmDialogComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ConfirmDialogComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.ts b/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.ts new file mode 100644 index 0000000..0c2bda6 --- /dev/null +++ b/mediarepo-ui/src/app/components/confirm-dialog/confirm-dialog.component.ts @@ -0,0 +1,35 @@ +import {Component, Inject, OnInit} from '@angular/core'; +import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {ThemePalette} from "@angular/material/core"; + +@Component({ + selector: 'app-confirm-dialog', + templateUrl: './confirm-dialog.component.html', + styleUrls: ['./confirm-dialog.component.scss'] +}) +export class ConfirmDialogComponent { + + title = ""; + message = ""; + confirmAction = ""; + confirmColor: ThemePalette = "primary"; + denyAction = "Cancel"; + denyColor: ThemePalette = "accent"; + + constructor( + public dialogRef: MatDialogRef, + @Inject( + MAT_DIALOG_DATA) data: { title: string, message: string, confirmAction: string, denyAction?: string, confirmColor?: ThemePalette, denyColor?: ThemePalette } + ) { + this.title = data.title; + this.message = data.message; + this.confirmAction = data.confirmAction; + this.denyAction = data.denyAction ?? this.denyAction; + this.confirmColor = data.confirmColor ?? this.confirmColor; + this.denyColor = data.denyColor ?? this.denyColor; + } + + public closeDialog(result: boolean) { + this.dialogRef.close(result); + } +} diff --git a/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.html b/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.html index c31b827..bf5b3e6 100644 --- a/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.html +++ b/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.html @@ -38,6 +38,7 @@
+ - diff --git a/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.html b/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.html index 36e10c5..a42a172 100644 --- a/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.html +++ b/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.html @@ -12,5 +12,10 @@ + + + + + diff --git a/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.ts b/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.ts index 5491464..7623bfb 100644 --- a/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.ts +++ b/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.ts @@ -3,6 +3,8 @@ import {Repository} from "../../../../models/Repository"; import {RepositoryService} from "../../../../services/repository/repository.service"; import {Router} from "@angular/router"; import {ErrorBrokerService} from "../../../../services/error-broker/error-broker.service"; +import {MatDialog} from "@angular/material/dialog"; +import {ConfirmDialogComponent} from "../../../../components/confirm-dialog/confirm-dialog.component"; @Component({ selector: 'app-repository-card', @@ -17,12 +19,18 @@ export class RepositoryCardComponent implements OnInit, OnDestroy { statusRefreshInterval: number | undefined; - constructor(public repoService: RepositoryService, private router: Router, private errorBroker: ErrorBrokerService) {} + constructor( + public repoService: RepositoryService, + private router: Router, + private errorBroker: ErrorBrokerService, + public dialog: MatDialog) { + } public async ngOnInit() { if (!this.repository.local) { await this.checkRemoteRepositoryStatus(); - this.statusRefreshInterval = setInterval(async() => await this.checkRemoteRepositoryStatus(), 10000); + this.statusRefreshInterval = setInterval( + async () => await this.checkRemoteRepositoryStatus(), 10000); } } @@ -36,6 +44,21 @@ export class RepositoryCardComponent implements OnInit, OnDestroy { return this.repoService.selectedRepository.getValue()?.name === this.repository.name } + public async removeRepository() { + await this.dialog.open(ConfirmDialogComponent, { + data: { + title: "Remove repository", + message: `Do you really want to remove the repository "${this.repository.name}"?`, + confirmAction: "Remove", + confirmColor: "warn" + } + }).afterClosed().subscribe(async confirmation => { + if (confirmation === true) { + await this.repoService.removeRepository(this.repository.name); + } + }); + } + public getDaemonStatusText(): string { if (this.repository.local) { return "Local"; @@ -72,14 +95,15 @@ export class RepositoryCardComponent implements OnInit, OnDestroy { } public async selectRepository() { - try { - await this.repoService.setRepository(this.repository); - } catch(err) { - this.errorBroker.showError(err); - } + try { + await this.repoService.setRepository(this.repository); + } catch (err) { + this.errorBroker.showError(err); + } } async checkRemoteRepositoryStatus() { - this.daemonRunning = await this.repoService.checkDaemonRunning(this.repository.address!); + this.daemonRunning = await this.repoService.checkDaemonRunning( + this.repository.address!); } } diff --git a/mediarepo-ui/src/app/services/repository/repository.service.ts b/mediarepo-ui/src/app/services/repository/repository.service.ts index 5e4c52a..9131041 100644 --- a/mediarepo-ui/src/app/services/repository/repository.service.ts +++ b/mediarepo-ui/src/app/services/repository/repository.service.ts @@ -108,7 +108,8 @@ export class RepositoryService { * @returns {Promise} */ public async removeRepository(name: string): Promise { - await invoke("plugin:mediarepo|remove_repository", {name}) + await invoke("plugin:mediarepo|remove_repository", {name}); + await this.loadRepositories(); } /**