From aeb077e709f702089e06e14bf7e6d3e1783e2718 Mon Sep 17 00:00:00 2001 From: snoop Date: Fri, 13 Oct 2017 14:02:50 +0900 Subject: [PATCH] added discovery ing --- .../@overflow/discovery/redux/reducer/ing.ts | 55 ++++++++++++++++--- src/ts/@overflow/discovery/redux/state/Ing.ts | 11 ++++ 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/ts/@overflow/discovery/redux/reducer/ing.ts b/src/ts/@overflow/discovery/redux/reducer/ing.ts index ae4c6f7..e1af3d1 100644 --- a/src/ts/@overflow/discovery/redux/reducer/ing.ts +++ b/src/ts/@overflow/discovery/redux/reducer/ing.ts @@ -1,5 +1,6 @@ import Action from '@overflow/commons/redux/Action'; import { ReducersMapObject } from 'redux'; +import * as _ from 'lodash'; import Host from '../../api/model/Host'; import Port from '../../api/model/Port'; @@ -10,34 +11,70 @@ import { HostState, hostDefaultState, PortState, portDefaultState, ServiceState, serviceDefaultState, + DiscoveryIngState, DiscoveryIngDefaultState, } from '../state/Ing'; const reducer: ReducersMapObject = { - [IngActionTypes.RECEIVE_HOST]: (state: HostState = hostDefaultState, - action: Action): HostState => { + [IngActionTypes.RECEIVE_HOST]: (state: DiscoveryIngState = DiscoveryIngDefaultState, + action: Action): DiscoveryIngState => { + let hostList: Host[] = null; + if(state.hostList === null || state.hostList === undefined) { + hostList = new Array(); + hostList.push(action.payload); + } else { + hostList = _.clone(state.hostList); + hostList.push(action.payload); + } return { ...state, - // discoveryData: action.payload, + hostList: hostList, }; }, - [IngActionTypes.RECEIVE_PORT]: (state: PortState = portDefaultState, - action: Action): PortState => { + [IngActionTypes.RECEIVE_PORT]: (state: DiscoveryIngState = DiscoveryIngDefaultState, + action: Action): DiscoveryIngState => { + let hostList: Host[] = null; + if(state.hostList === null || state.hostList === undefined) { + hostList = new Array(); + let port: Port = action.payload; + let host: Host = _.clone(port.host); + host.ports = new Array(); + port.host = host; + host.ports.push(port); + hostList.push(port.host); + + } else { + hostList = _.clone(state.hostList); + let port: Port = action.payload; + // let host: Host = _.clone(port.host); + + for(let h of hostList) { + if(h.ip === port.host.ip) { + port.host = h; + if(h.ports === null || h.ports === undefined) { + h.ports = new Array(); + } + h.ports.push(port); + } + } + + } return { ...state, - // discoveryData: action.payload, + hostList: hostList, }; }, - [IngActionTypes.RECEIVE_SERVICE]: (state: ServiceState = serviceDefaultState, - action: Action): ServiceState => { + [IngActionTypes.RECEIVE_SERVICE]: (state: DiscoveryIngState = DiscoveryIngDefaultState, + action: Action): DiscoveryIngState => { + return { ...state, - // discoveryData: action.payload, + // service: action.payload, }; }, }; diff --git a/src/ts/@overflow/discovery/redux/state/Ing.ts b/src/ts/@overflow/discovery/redux/state/Ing.ts index 3a708b3..068a11e 100644 --- a/src/ts/@overflow/discovery/redux/state/Ing.ts +++ b/src/ts/@overflow/discovery/redux/state/Ing.ts @@ -3,6 +3,17 @@ import Host from '../../api/model/Host'; import Port from '../../api/model/Port'; import Service from '../../api/model/Service'; +export interface DiscoveryIngState { + readonly hostList: Host[]; + readonly error?: Error; +} + +export const DiscoveryIngDefaultState: DiscoveryIngState = { + hostList: undefined, + error: undefined, +}; + + export interface HostState { readonly host: Host; readonly error?: Error;