Skip to content

Commit

Permalink
[WIP] Delete button for devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed May 26, 2022
1 parent 1bd86f5 commit 28a3c3e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h2 mat-dialog-title>Delete {{data.title}}?</h2>
<mat-dialog-actions>
<button mat-button mat-dialog-close>Cancel</button>
<!-- The mat-dialog-close directive optionally accepts a value as a result for the dialog. -->
<button class="red-600" mat-button [mat-dialog-close]="true">
<button class="red-600" mat-button (click)="onDeleteClick()">
<mat-icon class="icon-size-20 mr-3"
[svgIcon]="'delete_forever'"></mat-icon>
Delete</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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<DashboardDeviceDeleteDialogComponent>,
@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);
});

}
}
Original file line number Diff line number Diff line change
@@ -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<any>
{
return this._httpClient.delete( `${getBasePath()}/api/device/${wwn}`, {});
}
}

0 comments on commit 28a3c3e

Please sign in to comment.