From 9100dddacd6cf3229ad07b127b889864aea6a3ba Mon Sep 17 00:00:00 2001 From: snoop Date: Wed, 21 Mar 2018 19:48:47 +0900 Subject: [PATCH] add discovery notification --- .../component/setting/setting.component.ts | 102 ++++++++++++++---- .../notification/notification.effect.spec.ts | 15 +++ .../store/notification/notification.state.ts | 3 + 3 files changed, 100 insertions(+), 20 deletions(-) create mode 100644 src/packages/discovery/store/notification/notification.effect.spec.ts diff --git a/src/packages/discovery/component/setting/setting.component.ts b/src/packages/discovery/component/setting/setting.component.ts index c315cb4..441c7f4 100644 --- a/src/packages/discovery/component/setting/setting.component.ts +++ b/src/packages/discovery/component/setting/setting.component.ts @@ -4,13 +4,14 @@ import { Store, select } from '@ngrx/store'; import { RPCError } from 'packages/core/rpc/error'; import { DiscoveryStartInfo, - DiscoveryZone + DiscoveryZone, + Zone } from '../../model'; import * as CIDR from 'ip-cidr'; import * as DiscoveredStore from '../../store/setting'; import * as DiscoverStore from '../../store/notification'; -import { SettingSelector } from '../../store'; +import { SettingSelector, NotificationSelector } from '../../store'; @Component({ selector: 'of-setting', @@ -20,6 +21,8 @@ import { SettingSelector } from '../../store'; export class SettingComponent implements OnInit, AfterContentInit { settingSucceed$ = this.discoverdstore.pipe(select(SettingSelector.select('isStart'))); + discoveryResult$ = this.discoverstore.pipe(select(NotificationSelector.select('getDiscoveryResult'))); + started = false; cidr; @@ -60,6 +63,17 @@ export class SettingComponent implements OnInit, AfterContentInit { console.log(error.response.message); } ); + + this.discoveryResult$.subscribe( + (zone: Zone) => { + this.convertTreeView(zone); + }, + (error: RPCError) => { + console.log(error.response.message); + } + ); + + } ngAfterContentInit() { @@ -143,38 +157,86 @@ export class SettingComponent implements OnInit, AfterContentInit { console.log(this.checkedSet); } - findHost(host) { + convertTreeView(zone: Zone) { - const jHost: any = { - title: 'Host - ' + host.ip, - className : 'cn' + host.ip - }; - jHost.obj = host; + const treeNodes = this.convertViewHost(zone.hosts); + + console.log(treeNodes); + } + + convertViewHost(hosts): any[] { + + const treeNodes: any[] = []; + + hosts.forEach((host, hostKey) => { + + const jHost: any = { + title: 'Host - ' + host.ip, + className : 'cn' + host.ip + }; + jHost.obj = host; + + jHost.children = this.convertViewPort(host.ports); + + treeNodes.push(jHost); + + }); + + return treeNodes; } - findPort(port) { + convertViewPort(ports): any[] { - const jPort: any = { - title: 'Port - ' + port.portNumber, - className : 'cn' + port.portNumber, - }; - jPort.obj = port; + if (ports === undefined && ports.size <= 0) { + return null; + } + const portChildren: any[] = []; + + ports.forEach((port, portKey) => { + + const jPort: any = { + title: 'Port - ' + port.portNumber, + className : 'cn' + port.portNumber, + }; + jPort.obj = port; + + jPort.children = this.convertViewService(port.services); + + portChildren.push(jPort); + } ); + + + return portChildren; } - findService(service) { - const jService: any = { - title: 'Service - ' + service.serviceName, - className : 'cn' + service.serviceName, - }; - jService.obj = service; + convertViewService(services): any[] { + + if (services === undefined && services.size <= 0) { + return null; + } + + const serviceChildren: any[] = []; + + services.forEach((service, serviceKey) => { + const jService: any = { + title: 'Service - ' + service.serviceName, + className : 'cn' + service.serviceName, + }; + jService.obj = service; + + serviceChildren.push(jService); + }); + + return serviceChildren; } } + const nodes = [ { title: 'host - 3232235781', diff --git a/src/packages/discovery/store/notification/notification.effect.spec.ts b/src/packages/discovery/store/notification/notification.effect.spec.ts new file mode 100644 index 0000000..4bbc6cf --- /dev/null +++ b/src/packages/discovery/store/notification/notification.effect.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { Effects } from './notification.effect'; + +describe('Notification.Effects', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [Effects] + }); + }); + + it('should be created', inject([Effects], (effects: Effects) => { + expect(effects).toBeTruthy(); + })); +}); diff --git a/src/packages/discovery/store/notification/notification.state.ts b/src/packages/discovery/store/notification/notification.state.ts index 1299095..5ad59cc 100644 --- a/src/packages/discovery/store/notification/notification.state.ts +++ b/src/packages/discovery/store/notification/notification.state.ts @@ -13,3 +13,6 @@ export const initialState: State = { processing: false, zones: null, }; + + +export const getDiscoveryResult = (state: State) => state.zones;