member_webapp/src/packages/probe/component/detail/detail.component.ts

81 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-04-06 13:02:46 +00:00
import { Component, OnInit, Inject, AfterContentInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Store, select } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc/protocol';
import * as DetailStore from '../../store/detail';
import { DetailSelector } from '../../store';
import { Probe } from '../../model';
2018-04-11 08:41:38 +00:00
import { ConfirmationService } from 'primeng/primeng';
2018-04-06 13:02:46 +00:00
import * as CIDR from 'ip-cidr';
2018-04-11 06:20:23 +00:00
// import { SettingComponent as DiscoverySettingComponent } from 'packages/discovery/component/setting/setting.component';
2018-04-06 13:02:46 +00:00
@Component({
selector: 'of-probe-detail',
templateUrl: './detail.component.html',
2018-04-11 06:20:23 +00:00
providers: [ConfirmationService]
2018-04-06 13:02:46 +00:00
})
export class DetailComponent implements OnInit, AfterContentInit {
probe$ = this.detailStore.pipe(select(DetailSelector.select('probe')));
probe: Probe = null;
2018-04-16 08:28:39 +00:00
startIP: string;
endIP: string;
2018-04-06 13:02:46 +00:00
constructor(
private route: ActivatedRoute,
private router: Router,
2018-04-11 06:20:23 +00:00
private detailStore: Store<DetailStore.State>,
private confirmationService: ConfirmationService
2018-04-06 13:02:46 +00:00
) { }
ngOnInit() {
this.probe$.subscribe(
(probe: Probe) => {
2018-04-16 08:28:39 +00:00
if (probe) {
2018-04-06 13:02:46 +00:00
this.probe = probe;
this.arrangeInfo();
}
},
(error: RPCClientError) => {
console.log(error.response.message);
}
);
}
ngAfterContentInit() {
const probeId = this.route.snapshot.paramMap.get('id');
this.detailStore.dispatch(
new DetailStore.Read(
{ id: probeId }
)
);
}
arrangeInfo() {
const cidr = new CIDR(this.probe.cidr);
if (!cidr.isValid()) {
}
2018-04-16 08:28:39 +00:00
this.startIP = cidr.addressStart.address;
this.endIP = cidr.addressEnd.address;
2018-04-06 13:02:46 +00:00
}
2018-04-11 06:20:23 +00:00
onDiscoveryClick() {
alert('Discovery를 열거라 대훈');
2018-04-06 13:02:46 +00:00
}
2018-04-11 06:20:23 +00:00
onRemoveClick() {
this.confirmationService.confirm({
header: 'Confirmation',
icon: 'fa fa-trash',
message: 'Are you sure to remove this Probe?',
accept: () => {
this.router.navigate(['probes']);
},
reject: () => {
}
});
2018-04-06 13:02:46 +00:00
}
}
2018-04-06 11:02:18 +00:00