From 28a3c3e53f576919f00f1e74692efdd0bfe3c8c0 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Wed, 25 May 2022 17:55:23 -0700 Subject: [PATCH] [WIP] Delete button for devices. --- ...hboard-device-delete-dialog.component.html | 2 +- ...ashboard-device-delete-dialog.component.ts | 20 +++++++++-- .../dashboard-device-delete-dialog.service.ts | 34 +++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.service.ts diff --git a/webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component.html b/webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component.html index ab952ba..6cbe6ba 100644 --- a/webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component.html +++ b/webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component.html @@ -3,7 +3,7 @@ - diff --git a/webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component.ts b/webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component.ts index 1fc9729..4db5d9b 100644 --- a/webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component.ts +++ b/webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component.ts @@ -1,5 +1,7 @@ import { Component, OnInit, Inject } from '@angular/core'; -import {MAT_DIALOG_DATA} from '@angular/material/dialog'; +import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; +import {DashboardDeviceDeleteDialogService} from "./dashboard-device-delete-dialog.service"; +import {Subject} from "rxjs"; @Component({ selector: 'app-dashboard-device-delete-dialog', @@ -8,9 +10,23 @@ import {MAT_DIALOG_DATA} from '@angular/material/dialog'; }) export class DashboardDeviceDeleteDialogComponent implements OnInit { - constructor(@Inject(MAT_DIALOG_DATA) public data: {wwn: string, title: string}) { } + constructor( + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: {wwn: string, title: string}, + private _deleteService: DashboardDeviceDeleteDialogService, + ) { + } ngOnInit(): void { } + onDeleteClick(): void { + this._deleteService.deleteDevice(this.data.wwn) + .subscribe((data) => { + + console.log("Delete status:", data) + this.dialogRef.close(data); + }); + + } } diff --git a/webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.service.ts b/webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.service.ts new file mode 100644 index 0000000..e4c0f10 --- /dev/null +++ b/webapp/frontend/src/app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.service.ts @@ -0,0 +1,34 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { BehaviorSubject, Observable } from 'rxjs'; +import { tap } from 'rxjs/operators'; +import { getBasePath } from 'app/app.routing'; + +@Injectable({ + providedIn: 'root' +}) +export class DashboardDeviceDeleteDialogService +{ + + + /** + * Constructor + * + * @param {HttpClient} _httpClient + */ + constructor( + private _httpClient: HttpClient + ) + { + } + + // ----------------------------------------------------------------------------------------------------- + // @ Public methods + // ----------------------------------------------------------------------------------------------------- + + + deleteDevice(wwn: string): Observable + { + return this._httpClient.delete( `${getBasePath()}/api/device/${wwn}`, {}); + } +}