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 25, 2022
1 parent 0f935ce commit 1bd86f5
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 5 deletions.
1 change: 1 addition & 0 deletions webapp/backend/pkg/database/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type DeviceRepo interface {
UpdateDevice(ctx context.Context, wwn string, collectorSmartData collector.SmartInfo) (models.Device, error)
UpdateDeviceStatus(ctx context.Context, wwn string, status pkg.DeviceStatus) (models.Device, error)
GetDeviceDetails(ctx context.Context, wwn string) (models.Device, error)
DeleteDevice(ctx context.Context, wwn string) error

SaveSmartAttributes(ctx context.Context, wwn string, collectorSmartData collector.SmartInfo) (measurements.Smart, error)
GetSmartAttributeHistory(ctx context.Context, wwn string, durationKey string, attributes []string) ([]measurements.Smart, error)
Expand Down
4 changes: 4 additions & 0 deletions webapp/backend/pkg/database/scrutiny_repository_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ func (sr *scrutinyRepository) GetDeviceDetails(ctx context.Context, wwn string)

return device, nil
}

func (sr *scrutinyRepository) DeleteDevice(ctx context.Context, wwn string) error {
return nil
}
22 changes: 22 additions & 0 deletions webapp/backend/pkg/web/handler/delete_device.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package handler

import (
"github.com/analogj/scrutiny/webapp/backend/pkg/database"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"net/http"
)

func DeleteDevice(c *gin.Context) {
logger := c.MustGet("LOGGER").(logrus.FieldLogger)
deviceRepo := c.MustGet("DEVICE_REPOSITORY").(database.DeviceRepo)

err := deviceRepo.DeleteDevice(c, c.Param("wwn"))
if err != nil {
logger.Errorln("An error occurred while deleting device", err)
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
return
}

c.JSON(http.StatusOK, gin.H{"success": true})
}
2 changes: 2 additions & 0 deletions webapp/backend/pkg/web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (ae *AppEngine) Setup(logger logrus.FieldLogger) *gin.Engine {
api.POST("/device/:wwn/smart", handler.UploadDeviceMetrics) //used by Collector to upload data
api.POST("/device/:wwn/selftest", handler.UploadDeviceSelfTests)
api.GET("/device/:wwn/details", handler.GetDeviceDetails) //used by Details
api.DELETE("/device/:wwn", handler.DeleteDevice) //used by UI to delete device

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h2 mat-dialog-title>Delete {{data.title}}?</h2>
<mat-dialog-content>This will delete all data associated with this device (including all historical data).</mat-dialog-content>
<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">
<mat-icon class="icon-size-20 mr-3"
[svgIcon]="'delete_forever'"></mat-icon>
Delete</button>
</mat-dialog-actions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { DashboardDeviceDeleteDialogComponent } from './dashboard-device-delete-dialog.component';

describe('DashboardDeviceDeleteDialogComponent', () => {
let component: DashboardDeviceDeleteDialogComponent;
let fixture: ComponentFixture<DashboardDeviceDeleteDialogComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DashboardDeviceDeleteDialogComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DashboardDeviceDeleteDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, OnInit, Inject } from '@angular/core';
import {MAT_DIALOG_DATA} from '@angular/material/dialog';

@Component({
selector: 'app-dashboard-device-delete-dialog',
templateUrl: './dashboard-device-delete-dialog.component.html',
styleUrls: ['./dashboard-device-delete-dialog.component.scss']
})
export class DashboardDeviceDeleteDialogComponent implements OnInit {

constructor(@Inject(MAT_DIALOG_DATA) public data: {wwn: string, title: string}) { }

ngOnInit(): void {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Overlay } from '@angular/cdk/overlay';
import { MAT_AUTOCOMPLETE_SCROLL_STRATEGY, MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatButtonModule } from '@angular/material/button';
import { MatSelectModule } from '@angular/material/select';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { SharedModule } from 'app/shared/shared.module';
import {DashboardDeviceDeleteDialogComponent} from 'app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component'
import { MatButtonToggleModule} from "@angular/material/button-toggle";
import {MatTabsModule} from "@angular/material/tabs";
import {MatSliderModule} from "@angular/material/slider";
import {MatSlideToggleModule} from "@angular/material/slide-toggle";
import {MatTooltipModule} from "@angular/material/tooltip";
import {dashboardRoutes} from "../../../modules/dashboard/dashboard.routing";
import {MatDividerModule} from "@angular/material/divider";
import {MatMenuModule} from "@angular/material/menu";
import {MatProgressBarModule} from "@angular/material/progress-bar";
import {MatSortModule} from "@angular/material/sort";
import {MatTableModule} from "@angular/material/table";
import {NgApexchartsModule} from "ng-apexcharts";
import { MatDialogModule } from '@angular/material/dialog';

@NgModule({
declarations: [
DashboardDeviceDeleteDialogComponent
],
imports : [
RouterModule.forChild([]),
RouterModule.forChild(dashboardRoutes),
MatButtonModule,
MatDividerModule,
MatTooltipModule,
MatIconModule,
MatMenuModule,
MatProgressBarModule,
MatSortModule,
MatTableModule,
NgApexchartsModule,
SharedModule,
MatDialogModule
],
exports : [
DashboardDeviceDeleteDialogComponent,
],
providers : []
})
export class DashboardDeviceDeleteDialogModule
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@
<a mat-menu-item [routerLink]="'/device/'+ deviceSummary.device.wwn">
<span class="flex items-center">
<mat-icon class="icon-size-20 mr-3"
[svgIcon]="'payment'"></mat-icon>
[svgIcon]="'assessment'"></mat-icon>
<span>View Details</span>
</span>
</a>
<a mat-menu-item (click)="openDeleteDialog()">
<span class="flex items-center">
<mat-icon class="icon-size-20 mr-3"
[svgIcon]="'delete_forever'"></mat-icon>
<span>Delete Device</span>
</span>
</a>
</mat-menu>
</div>
</div>
Expand All @@ -58,4 +65,3 @@
</div>
</div>
</div>

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {AppConfig} from "app/core/config/app.config";
import {TreoConfigService} from "@treo/services/config";
import {Subject} from "rxjs";
import humanizeDuration from 'humanize-duration'
import {MatDialog} from '@angular/material/dialog';
import {DashboardDeviceDeleteDialogComponent} from "app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component";

@Component({
selector: 'app-dashboard-device',
Expand All @@ -21,6 +23,7 @@ export class DashboardDeviceComponent implements OnInit {

constructor(
private _configService: TreoConfigService,
public dialog: MatDialog
) {
// Set the private defaults
this._unsubscribeAll = new Subject();
Expand Down Expand Up @@ -82,6 +85,18 @@ export class DashboardDeviceComponent implements OnInit {

readonly humanizeDuration = humanizeDuration;



openDeleteDialog(): void {
const dialogRef = this.dialog.open(DashboardDeviceDeleteDialogComponent, {
// width: '250px',
data: {wwn: this.deviceWWN, title: this.deviceTitle(this.deviceSummary.device)}
});

dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
});
}
}

export function deviceDisplayTitle(disk, titleType: string){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {MatProgressBarModule} from "@angular/material/progress-bar";
import {MatSortModule} from "@angular/material/sort";
import {MatTableModule} from "@angular/material/table";
import {NgApexchartsModule} from "ng-apexcharts";
import {DashboardSettingsModule} from "../dashboard-settings/dashboard-settings.module";
import {DashboardDeviceDeleteDialogModule} from "../dashboard-device-delete-dialog/dashboard-device-delete-dialog.module";

@NgModule({
declarations: [
Expand All @@ -41,6 +41,7 @@ import {DashboardSettingsModule} from "../dashboard-settings/dashboard-settings.
MatTableModule,
NgApexchartsModule,
SharedModule,
DashboardDeviceDeleteDialogModule
],
exports : [
DashboardDeviceComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,4 @@ <h1>No Devices Detected!</h1>
<code>scrutiny-collector-metrics run</code>

</div>


</ng-template>

0 comments on commit 1bd86f5

Please sign in to comment.