add discovery notification

This commit is contained in:
snoop 2018-03-21 19:48:47 +09:00
parent 7668875fb2
commit 9100dddacd
3 changed files with 100 additions and 20 deletions

View File

@ -4,13 +4,14 @@ import { Store, select } from '@ngrx/store';
import { RPCError } from 'packages/core/rpc/error'; import { RPCError } from 'packages/core/rpc/error';
import { import {
DiscoveryStartInfo, DiscoveryStartInfo,
DiscoveryZone DiscoveryZone,
Zone
} from '../../model'; } from '../../model';
import * as CIDR from 'ip-cidr'; import * as CIDR from 'ip-cidr';
import * as DiscoveredStore from '../../store/setting'; import * as DiscoveredStore from '../../store/setting';
import * as DiscoverStore from '../../store/notification'; import * as DiscoverStore from '../../store/notification';
import { SettingSelector } from '../../store'; import { SettingSelector, NotificationSelector } from '../../store';
@Component({ @Component({
selector: 'of-setting', selector: 'of-setting',
@ -20,6 +21,8 @@ import { SettingSelector } from '../../store';
export class SettingComponent implements OnInit, AfterContentInit { export class SettingComponent implements OnInit, AfterContentInit {
settingSucceed$ = this.discoverdstore.pipe(select(SettingSelector.select('isStart'))); settingSucceed$ = this.discoverdstore.pipe(select(SettingSelector.select('isStart')));
discoveryResult$ = this.discoverstore.pipe(select(NotificationSelector.select('getDiscoveryResult')));
started = false; started = false;
cidr; cidr;
@ -60,6 +63,17 @@ export class SettingComponent implements OnInit, AfterContentInit {
console.log(error.response.message); console.log(error.response.message);
} }
); );
this.discoveryResult$.subscribe(
(zone: Zone) => {
this.convertTreeView(zone);
},
(error: RPCError) => {
console.log(error.response.message);
}
);
} }
ngAfterContentInit() { ngAfterContentInit() {
@ -143,7 +157,18 @@ export class SettingComponent implements OnInit, AfterContentInit {
console.log(this.checkedSet); console.log(this.checkedSet);
} }
findHost(host) { convertTreeView(zone: Zone) {
const treeNodes = this.convertViewHost(zone.hosts);
console.log(treeNodes);
}
convertViewHost(hosts): any[] {
const treeNodes: any[] = [];
hosts.forEach((host, hostKey) => {
const jHost: any = { const jHost: any = {
title: 'Host - ' + host.ip, title: 'Host - ' + host.ip,
@ -151,9 +176,25 @@ export class SettingComponent implements OnInit, AfterContentInit {
}; };
jHost.obj = host; jHost.obj = host;
jHost.children = this.convertViewPort(host.ports);
treeNodes.push(jHost);
});
return treeNodes;
} }
findPort(port) { convertViewPort(ports): any[] {
if (ports === undefined && ports.size <= 0) {
return null;
}
const portChildren: any[] = [];
ports.forEach((port, portKey) => {
const jPort: any = { const jPort: any = {
title: 'Port - ' + port.portNumber, title: 'Port - ' + port.portNumber,
@ -161,20 +202,41 @@ export class SettingComponent implements OnInit, AfterContentInit {
}; };
jPort.obj = port; jPort.obj = port;
jPort.children = this.convertViewService(port.services);
portChildren.push(jPort);
} );
return portChildren;
} }
findService(service) { convertViewService(services): any[] {
if (services === undefined && services.size <= 0) {
return null;
}
const serviceChildren: any[] = [];
services.forEach((service, serviceKey) => {
const jService: any = { const jService: any = {
title: 'Service - ' + service.serviceName, title: 'Service - ' + service.serviceName,
className : 'cn' + service.serviceName, className : 'cn' + service.serviceName,
}; };
jService.obj = service; jService.obj = service;
serviceChildren.push(jService);
});
return serviceChildren;
} }
} }
const nodes = [ const nodes = [
{ {
title: 'host - 3232235781', title: 'host - 3232235781',

View File

@ -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();
}));
});

View File

@ -13,3 +13,6 @@ export const initialState: State = {
processing: false, processing: false,
zones: null, zones: null,
}; };
export const getDiscoveryResult = (state: State) => state.zones;