From 7e869cb96571e4a821db484d46a0e2cbe8a3f552 Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 31 Oct 2017 19:39:17 +0900 Subject: [PATCH] discovery ing --- src/ts/@overflow/discovery/api/model/Zone.ts | 11 ++++ .../discovery/api/service/DiscoveryService.ts | 8 +++ .../discovery/react/components/Discovery.tsx | 2 - .../@overflow/discovery/redux/action/ing.ts | 2 + .../@overflow/discovery/redux/reducer/ing.ts | 60 ++++++++++++++----- 5 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 src/ts/@overflow/discovery/api/model/Zone.ts diff --git a/src/ts/@overflow/discovery/api/model/Zone.ts b/src/ts/@overflow/discovery/api/model/Zone.ts new file mode 100644 index 0000000..27460be --- /dev/null +++ b/src/ts/@overflow/discovery/api/model/Zone.ts @@ -0,0 +1,11 @@ +export interface Zone { + id: number; + network: string; + ip: string; + iface: string; + mac: string; + firstScanRange: number; + lastScanRange: number; +} + +export default Zone; diff --git a/src/ts/@overflow/discovery/api/service/DiscoveryService.ts b/src/ts/@overflow/discovery/api/service/DiscoveryService.ts index 6fd30ed..7c65578 100644 --- a/src/ts/@overflow/discovery/api/service/DiscoveryService.ts +++ b/src/ts/@overflow/discovery/api/service/DiscoveryService.ts @@ -5,6 +5,7 @@ import * as DiscoveryIngActions from '../../redux/action/ing'; import Host from '../model/Host'; import Port from '../model/Port'; import DisService from '../model/Service'; +import Zone from '../model/Zone'; export class DiscoveryService extends Service { // tslint:disable-next-line:no-empty @@ -21,6 +22,13 @@ export class DiscoveryService extends Service { console.log(params); } + public discoveryIngZone(params: any): void { + let zone: Zone = params; + + console.log('discoveryIngZone'); + this.dispatch(DiscoveryIngActions.RECEIVE_ZONE, zone); + } + public discoveryIngHost(params: any): void { let host: Host = params; diff --git a/src/ts/@overflow/discovery/react/components/Discovery.tsx b/src/ts/@overflow/discovery/react/components/Discovery.tsx index d22bf78..3554bfe 100644 --- a/src/ts/@overflow/discovery/react/components/Discovery.tsx +++ b/src/ts/@overflow/discovery/react/components/Discovery.tsx @@ -93,8 +93,6 @@ export class Discovery extends React.Component { let idx: number = Math.floor(Math.random() * (max - min + 1) + min); - - switch(idx) { case 1: this.testHost(); diff --git a/src/ts/@overflow/discovery/redux/action/ing.ts b/src/ts/@overflow/discovery/redux/action/ing.ts index be37557..1bfc668 100644 --- a/src/ts/@overflow/discovery/redux/action/ing.ts +++ b/src/ts/@overflow/discovery/redux/action/ing.ts @@ -4,6 +4,7 @@ export type REQUEST = '@overflow/discovery/ing/REQUEST'; export type REQUEST_SUCCESS = '@overflow/discovery/ing/REQUEST/SUCCESS'; export type REQUEST_FAILURE = '@overflow/discovery/ing/REQUEST/FAILURE'; +export type RECEIVE_ZONE = '@overflow/discovery/zone/RECEIVE'; export type RECEIVE_HOST = '@overflow/discovery/host/RECEIVE'; export type RECEIVE_PORT = '@overflow/discovery/port/RECEIVE'; export type RECEIVE_SERVICE = '@overflow/discovery/service/RECEIVE'; @@ -12,6 +13,7 @@ export const REQUEST: REQUEST = '@overflow/discovery/ing/REQUEST'; export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/discovery/ing/REQUEST/SUCCESS'; export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/discovery/ing/REQUEST/FAILURE'; +export const RECEIVE_ZONE: RECEIVE_ZONE = '@overflow/discovery/zone/RECEIVE'; export const RECEIVE_HOST: RECEIVE_HOST = '@overflow/discovery/host/RECEIVE'; export const RECEIVE_PORT: RECEIVE_PORT = '@overflow/discovery/port/RECEIVE'; export const RECEIVE_SERVICE: RECEIVE_SERVICE = '@overflow/discovery/service/RECEIVE'; diff --git a/src/ts/@overflow/discovery/redux/reducer/ing.ts b/src/ts/@overflow/discovery/redux/reducer/ing.ts index b3a9b9e..a07e449 100644 --- a/src/ts/@overflow/discovery/redux/reducer/ing.ts +++ b/src/ts/@overflow/discovery/redux/reducer/ing.ts @@ -5,6 +5,7 @@ import * as _ from 'lodash'; import Host from '../../api/model/Host'; import Port from '../../api/model/Port'; import Service from '../../api/model/Service'; +import Zone from '../../api/model/Zone'; import * as IngActionTypes from '../action/ing'; import { @@ -15,6 +16,13 @@ import { } from '../state/Ing'; const reducer: ReducersMapObject = { + [IngActionTypes.RECEIVE_ZONE]: (state: DiscoveryIngState = DiscoveryIngDefaultState, + action: Action): DiscoveryIngState => { + + return { + ...state, + }; + }, [IngActionTypes.RECEIVE_HOST]: (state: DiscoveryIngState = DiscoveryIngDefaultState, action: Action): DiscoveryIngState => { @@ -94,10 +102,11 @@ const reducer: ReducersMapObject = { let nPort: Port = _.clone(port); nPort.host = nHost; - let dIdx: number = hostList.indexOf(h, 0); - if(dIdx > -1) { - hostList.slice(dIdx, 1); - } + // let dIdx: number = hostList.indexOf(h, 0); + // if(dIdx > -1) { + // hostList.slice(dIdx, 1); + // } + hostList = removeArray(hostList, h); nHost.ports.push(nPort); hostList.push(nHost); } @@ -176,14 +185,20 @@ const reducer: ReducersMapObject = { nPort.host = nHost; service.port = nPort; - let dIdx: number = hostList.indexOf(h, 0); - if(dIdx > -1) { - hostList.slice(dIdx, 1); - } - dIdx = nHost.ports.indexOf(p, 0); - if(dIdx > -1) { - nHost.ports.slice(dIdx, 1); - } + // let dIdx: number = hostList.indexOf(h, 0); + // if(dIdx > -1) { + // hostList.slice(dIdx, 1); + // } + + hostList = removeArray(hostList, h); + + // dIdx = nHost.ports.indexOf(p, 0); + // if(dIdx > -1) { + // nHost.ports.slice(dIdx, 1); + // } + + nHost.ports = removeArray(nHost.ports, p); + nPort.services.push(service); nHost.ports.push(nPort); hostList.push(nHost); @@ -222,10 +237,13 @@ const reducer: ReducersMapObject = { nPort.host = nHost; service.port = nPort; - let dIdx: number = hostList.indexOf(h, 0); - if(dIdx > -1) { - hostList.slice(dIdx, 1); - } + // let dIdx: number = hostList.indexOf(h, 0); + // if(dIdx > -1) { + // hostList.slice(dIdx, 1); + // } + + hostList = removeArray(hostList, h); + nPort.services.push(service); nHost.ports.push(nPort); hostList.push(nHost); @@ -262,4 +280,14 @@ const reducer: ReducersMapObject = { }, }; +function removeArray(array: any[], obj: any): any[] { + + let dIdx: number = array.indexOf(obj, 0); + if(dIdx > -1) { + array.slice(dIdx, 1); + } + + return array; +} + export default reducer;