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,38 +157,86 @@ export class SettingComponent implements OnInit, AfterContentInit {
console.log(this.checkedSet); console.log(this.checkedSet);
} }
findHost(host) { convertTreeView(zone: Zone) {
const jHost: any = { const treeNodes = this.convertViewHost(zone.hosts);
title: 'Host - ' + host.ip,
className : 'cn' + host.ip console.log(treeNodes);
}; }
jHost.obj = host;
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 = { if (ports === undefined && ports.size <= 0) {
title: 'Port - ' + port.portNumber, return null;
className : 'cn' + port.portNumber, }
};
jPort.obj = port;
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) { convertViewService(services): any[] {
const jService: any = {
title: 'Service - ' + service.serviceName, if (services === undefined && services.size <= 0) {
className : 'cn' + service.serviceName, return null;
}; }
jService.obj = service;
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 = [ 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;