From c4989c94df6babfbfb5cca610b376a8cd5fa588e Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 19 Mar 2018 19:22:13 +0900 Subject: [PATCH] accept deny button --- .../component/setting/setting.component.ts | 26 ++++++++--- src/packages/discovery/model/DiscoveryHost.ts | 8 ++-- src/packages/discovery/store/index.ts | 1 + .../discovery/store/notification/index.ts | 1 + .../store/notification/notification.action.ts | 38 +++++++++++++++- .../store/notification/notification.effect.ts | 44 +++++++++++++++++++ .../discovery/store/setting/setting.effect.ts | 1 + 7 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 src/packages/discovery/store/notification/notification.effect.ts diff --git a/src/packages/discovery/component/setting/setting.component.ts b/src/packages/discovery/component/setting/setting.component.ts index a4cd06f..d327329 100644 --- a/src/packages/discovery/component/setting/setting.component.ts +++ b/src/packages/discovery/component/setting/setting.component.ts @@ -2,10 +2,14 @@ import { Component, OnInit, AfterContentInit } from '@angular/core'; import { MatCheckboxChange } from '@angular/material'; import { Store, select } from '@ngrx/store'; import { RPCError } from 'packages/core/rpc/error'; -import * as DiscoverySettingStore from '../../store/setting'; -import { DiscoveryStartInfo } from '../../model'; +import { + DiscoveryStartInfo, + DiscoveryZone +} from '../../model'; import * as CIDR from 'ip-cidr'; -import * as DiscoveryStore from '../../store/setting'; +import * as DiscoveredStore from '../../store/setting'; +import * as DiscoverStore from '../../store/notification'; + import { SettingSelector } from '../../store'; @Component({ @@ -15,7 +19,7 @@ import { SettingSelector } from '../../store'; }) export class SettingComponent implements OnInit, AfterContentInit { - settingSucceed$ = this.store.pipe(select(SettingSelector.select('isStart'))); + settingSucceed$ = this.discoverdstore.pipe(select(SettingSelector.select('isStart'))); started = false; cidr; @@ -35,7 +39,8 @@ export class SettingComponent implements OnInit, AfterContentInit { { name: 'Nginx' }, ]; constructor( - private store: Store, + private discoverdstore: Store, + private discoverstore: Store, ) { } @@ -99,7 +104,16 @@ export class SettingComponent implements OnInit, AfterContentInit { startPort: this.startPort, endPort: this.endPort }; - this.store.dispatch(new DiscoverySettingStore.Setting(startInfo)); + + const discoveryZone: DiscoveryZone = { + discoveryHost: { + firstScanRange: this.startIP, + lastScanRange: this.endIP, + } + }; + + // this.store.dispatch(new DiscoverySettingStore.Setting(startInfo)); + this.discoverstore.dispatch(new DiscoverStore.DiscoverZone({probeID: '52abd6fd57e511e7ac52080027658d13', discoveryZone: discoveryZone})); this.started = true; } diff --git a/src/packages/discovery/model/DiscoveryHost.ts b/src/packages/discovery/model/DiscoveryHost.ts index a6a0489..a1dc3e4 100644 --- a/src/packages/discovery/model/DiscoveryHost.ts +++ b/src/packages/discovery/model/DiscoveryHost.ts @@ -1,10 +1,10 @@ import { DiscoveryPort } from './DiscoveryPort'; export interface DiscoveryHost { - firstScanRange: string; - lastScanRange: string; - excludeHosts: string[]; - includeHosts: string[]; + firstScanRange?: string; + lastScanRange?: string; + excludeHosts?: string[]; + includeHosts?: string[]; discoveryPort?: DiscoveryPort; } diff --git a/src/packages/discovery/store/index.ts b/src/packages/discovery/store/index.ts index d173ee3..cf50576 100644 --- a/src/packages/discovery/store/index.ts +++ b/src/packages/discovery/store/index.ts @@ -26,6 +26,7 @@ export const REDUCERS = { export const EFFECTS = [ SettingStore.Effects, + NotificationStore.Effects, ]; export const selectDiscoveryState = createFeatureSelector(MODULE.name); diff --git a/src/packages/discovery/store/notification/index.ts b/src/packages/discovery/store/notification/index.ts index f9e09d0..76ee543 100644 --- a/src/packages/discovery/store/notification/index.ts +++ b/src/packages/discovery/store/notification/index.ts @@ -1,3 +1,4 @@ export * from './notification.action'; export * from './notification.reducer'; export * from './notification.state'; +export * from './notification.effect'; diff --git a/src/packages/discovery/store/notification/notification.action.ts b/src/packages/discovery/store/notification/notification.action.ts index 179b7f5..3ac3b5c 100644 --- a/src/packages/discovery/store/notification/notification.action.ts +++ b/src/packages/discovery/store/notification/notification.action.ts @@ -8,15 +8,47 @@ import { Host, Port, Service, - } from '../../model'; + DiscoveryZone, + DiscoveryHost, + DiscoveryPort, + DiscoveryService as MDiscoveryService, +} from '../../model'; export enum ActionType { + DiscoverZone = '[@@NOTIFICATION] DiscoveryService.discoverZone', + DiscoverHost = '[@@NOTIFICATION] DiscoveryService.discoverHost', + DiscoverPort = '[@@NOTIFICATION] DiscoveryService.discoverPort', + DiscoverService = '[@@NOTIFICATION] DiscoveryService.discoverService', DiscoveredZone = '[@@NOTIFICATION] DiscoveryService.discoveredZone', DiscoveredHost = '[@@NOTIFICATION] DiscoveryService.discoveredHost', DiscoveredPort = '[@@NOTIFICATION] DiscoveryService.discoveredPort', DiscoveredService = '[@@NOTIFICATION] DiscoveryService.discoveredService', } +export class DiscoverZone implements Action { + readonly type = ActionType.DiscoverZone; + + constructor(public payload: {probeID: string, discoveryZone: DiscoveryZone}) {} +} + +export class DiscoverHost implements Action { + readonly type = ActionType.DiscoverHost; + + constructor(public payload: {probeID: string, zone: Zone, discoveryHost: DiscoveryHost}) {} +} + +export class DiscoverPort implements Action { + readonly type = ActionType.DiscoverPort; + + constructor(public payload: {probeID: string, host: Host, discoveryPort: DiscoveryPort}) {} +} + +export class DiscoverService implements Action { + readonly type = ActionType.DiscoverService; + constructor(public payload: {probeID: string, port: Port, discoveryService: MDiscoveryService}) {} +} + + export class DiscoveredZone implements Action { readonly type = ActionType.DiscoveredZone; @@ -41,6 +73,10 @@ export class DiscoveredService implements Action { } export type Actions = + | DiscoverZone + | DiscoverHost + | DiscoverPort + | DiscoverService | DiscoveredZone | DiscoveredHost | DiscoveredPort diff --git a/src/packages/discovery/store/notification/notification.effect.ts b/src/packages/discovery/store/notification/notification.effect.ts new file mode 100644 index 0000000..ce2def8 --- /dev/null +++ b/src/packages/discovery/store/notification/notification.effect.ts @@ -0,0 +1,44 @@ +import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; + +import { Effect, Actions, ofType } from '@ngrx/effects'; +import { Action } from '@ngrx/store'; + +import { Observable } from 'rxjs/Observable'; +import { of } from 'rxjs/observable/of'; + +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/exhaustMap'; +import 'rxjs/add/operator/switchMap'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/take'; + +import { RPCError } from 'packages/core/rpc/error'; +import { + DiscoverZone, + DiscoverHost, + DiscoverPort, + DiscoverService, + ActionType +} from './notification.action'; +import {DiscoveryService} from '../../service/discovery.service'; + + +@Injectable() +export class Effects { + + constructor(private actions$: Actions, + private discoveryService: DiscoveryService, + private router: Router) { + } + + @Effect({ dispatch: false }) + discoveryZone$ = this.actions$ + .ofType(ActionType.DiscoverZone) + .map((action: DiscoverZone) => action.payload) + .do(payload => { + this.discoveryService.discoverZone(payload.probeID, payload.discoveryZone); + }); + +} diff --git a/src/packages/discovery/store/setting/setting.effect.ts b/src/packages/discovery/store/setting/setting.effect.ts index 163016e..9df6d81 100644 --- a/src/packages/discovery/store/setting/setting.effect.ts +++ b/src/packages/discovery/store/setting/setting.effect.ts @@ -47,4 +47,5 @@ export class Effects { console.log(error.response.message); return of(new SettingFailure(error)); }); + }