commons - confirm dialog

This commit is contained in:
insanity 2018-03-09 16:25:33 +09:00
parent 916063c9bf
commit 0fcda0b58d
10 changed files with 78 additions and 72 deletions

View File

@ -0,0 +1,6 @@
<h2 mat-dialog-title>{{data.title}}</h2>
<mat-dialog-content>{{data.message}}</mat-dialog-content>
<mat-dialog-actions>
<button mat-button mat-dialog-close>No</button>
<button mat-button [mat-dialog-close]="true">Yes</button>
</mat-dialog-actions>

View File

@ -1,20 +1,20 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RemoveWarningComponent } from './remove-warning-dialog.component'; import { ConfirmDialogComponent } from './confirm-dialog.component';
describe('RemoveWarningComponent', () => { describe('ConfirmDialogComponent', () => {
let component: RemoveWarningComponent; let component: ConfirmDialogComponent;
let fixture: ComponentFixture<RemoveWarningComponent>; let fixture: ComponentFixture<ConfirmDialogComponent>;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ RemoveWarningComponent ] declarations: [ ConfirmDialogComponent ]
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(RemoveWarningComponent); fixture = TestBed.createComponent(ConfirmDialogComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
fixture.detectChanges(); fixture.detectChanges();
}); });

View File

@ -0,0 +1,15 @@
import { Component, OnInit, Inject } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material';
@Component({
selector: 'of-confirm-dialog',
templateUrl: './confirm-dialog.component.html',
styleUrls: ['./confirm-dialog.component.scss']
})
export class ConfirmDialogComponent implements OnInit {
constructor(@Inject(MAT_DIALOG_DATA) public data: any) { }
ngOnInit() {
}
}

View File

@ -1,7 +1,7 @@
import { Component, OnInit, Inject } from '@angular/core'; import { Component, OnInit, Inject } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { RemoveWarningComponent } from './remove-warning-dialog/remove-warning-dialog.component'; import { ConfirmDialogComponent } from 'app/commons/component/confirm-dialog/confirm-dialog.component';
@Component({ @Component({
selector: 'of-probe-detail', selector: 'of-probe-detail',
@ -36,7 +36,8 @@ export class DetailComponent implements OnInit {
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
public dialog: MatDialog) { } public dialog: MatDialog,
) { }
ngOnInit() { ngOnInit() {
this.probeId = this.route.snapshot.paramMap.get('id'); this.probeId = this.route.snapshot.paramMap.get('id');
@ -48,13 +49,23 @@ export class DetailComponent implements OnInit {
} }
handleRemove() { handleRemove() {
const dialogRef = this.dialog.open(RemoveWarningComponent, { const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px', width: '250px',
data: { } data: {
title: 'Remove',
message: 'Are you sure?'
}
}); });
dialogRef.afterClosed().subscribe(result => { // const dialogRef = this.dialog.open(RemoveWarningComponent, {
console.log(result); // width: '250px',
// data: { }
// });
dialogRef.afterClosed().subscribe(confirmed => {
if (confirmed) {
console.log('confirmed');
}
// 삭제 후 list로 back // 삭제 후 list로 back
}); });
} }

View File

@ -1,5 +0,0 @@
<div>레알루다가? 다 지워질건데?</div>
<div style="margin-top: 50px">
<button mat-raised-button color="primary" (click)="onClick(false)">Cancel</button>
<button mat-raised-button color="accent" (click)="onClick(true)">Remove</button>
</div>

View File

@ -1,21 +0,0 @@
import { Component, OnInit, Input } from '@angular/core';
import { MatDialogRef } from '@angular/material';
@Component({
selector: 'of-remove-warning-dialog',
templateUrl: './remove-warning-dialog.component.html',
styleUrls: ['./remove-warning-dialog.component.scss']
})
export class RemoveWarningComponent implements OnInit {
constructor(
public dialogRef: MatDialogRef<RemoveWarningComponent>
) { }
ngOnInit() {
}
onClick(res: boolean) {
this.dialogRef.close(res);
}
}

View File

@ -1,11 +1,11 @@
import { DetailComponent } from './detail/detail.component'; import { DetailComponent } from './detail/detail.component';
import { ListComponent } from './list/list.component'; import { ListComponent } from './list/list.component';
import { DownloadComponent } from './download/download.component'; import { DownloadComponent } from './download/download.component';
import { RemoveWarningComponent } from './detail/remove-warning-dialog/remove-warning-dialog.component'; import { ConfirmDialogComponent } from 'app/commons/component/confirm-dialog/confirm-dialog.component';
export const COMPONENTS = [ export const COMPONENTS = [
ListComponent, ListComponent,
DetailComponent, DetailComponent,
DownloadComponent, DownloadComponent,
RemoveWarningComponent ConfirmDialogComponent
]; ];

View File

@ -37,7 +37,7 @@ export class ListComponent implements OnInit, AfterContentInit {
this.dataSource.sort = this.sort; this.dataSource.sort = this.sort;
}, },
(error: ErrorResponse) => { (error: ErrorResponse) => {
console.log(error);
} }
); );
@ -46,38 +46,38 @@ export class ListComponent implements OnInit, AfterContentInit {
this.store.dispatch(new ListStore.ReadAllByDomain(domain)); this.store.dispatch(new ListStore.ReadAllByDomain(domain));
}, },
(error) => { (error) => {
console.log(error);
} }
); );
// // temporary data // temporary data
// const data: Probe[] = new Array(); const data: Probe[] = new Array();
// for (let i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) {
// const p: Probe = { const p: Probe = {
// id: i, id: i,
// displayName: String('displayName' + i), displayName: String('displayName' + i),
// host: { host: {
// ip: i, ip: i,
// os: { os: {
// meta: 'blahblahblah' meta: 'blahblahblah'
// }, },
// }, },
// cidr: String('cidr' + i), cidr: String('cidr' + i),
// targets: [ targets: [
// { {
// id: i, id: i,
// }, },
// ], ],
// authorizeDate: new Date(), authorizeDate: new Date(),
// authorizeMember: { authorizeMember: {
// 'name': String('insanity') 'name': String('insanity')
// }, },
// }; };
// data.push(p); data.push(p);
// } }
// this.dataSource = new MatTableDataSource(data); this.dataSource = new MatTableDataSource(data);
// this.dataSource.sort = this.sort; this.dataSource.sort = this.sort;
} }
ngOnInit() { ngOnInit() {

View File

@ -6,14 +6,14 @@ import { InfoTableModule } from 'app/commons/component/info-table/info-table.mod
import { COMPONENTS } from './component'; import { COMPONENTS } from './component';
import { ProbeStoreModule } from './probe-store.module'; import { ProbeStoreModule } from './probe-store.module';
import { SERVICES } from './service'; import { SERVICES } from './service';
import { RemoveWarningComponent } from './component/detail/remove-warning-dialog/remove-warning-dialog.component'; import { ConfirmDialogComponent } from 'app/commons/component/confirm-dialog/confirm-dialog.component';
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, CommonModule,
MaterialModule, MaterialModule,
InfoTableModule, InfoTableModule,
ProbeStoreModule ProbeStoreModule,
], ],
declarations: [ declarations: [
COMPONENTS, COMPONENTS,
@ -25,7 +25,7 @@ import { RemoveWarningComponent } from './component/detail/remove-warning-dialog
SERVICES, SERVICES,
], ],
entryComponents: [ entryComponents: [
RemoveWarningComponent, ConfirmDialogComponent,
] ]
}) })
export class ProbeModule { } export class ProbeModule { }