Discovery ing all
This commit is contained in:
parent
517c765868
commit
58e33421ad
|
@ -89,11 +89,11 @@ export class Discovery extends React.Component<Props, State> {
|
|||
public handleTest = () => {
|
||||
|
||||
let min: number = 1;
|
||||
let max: number = 2;
|
||||
let max: number = 3;
|
||||
|
||||
let idx: number = Math.floor(Math.random() * (max - min + 1) + min);
|
||||
|
||||
idx = 3;
|
||||
|
||||
|
||||
switch(idx) {
|
||||
case 1:
|
||||
|
|
|
@ -19,13 +19,26 @@ const reducer: ReducersMapObject = {
|
|||
action: Action<Host>): DiscoveryIngState => {
|
||||
|
||||
let obj: any = action.payload;
|
||||
let host: Host = JSON.parse(obj);
|
||||
let hostList: Host[] = null;
|
||||
if(state.hostList === null || state.hostList === undefined) {
|
||||
hostList = new Array();
|
||||
hostList.push(JSON.parse(obj));
|
||||
} else {
|
||||
|
||||
hostList = _.clone(state.hostList);
|
||||
hostList.push(JSON.parse(obj));
|
||||
|
||||
let tHost: Host = null;
|
||||
for(let h of hostList) {
|
||||
if(h.ip === host.ip) {
|
||||
tHost = h;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(tHost === null) {
|
||||
hostList.push(host);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -49,36 +62,59 @@ const reducer: ReducersMapObject = {
|
|||
|
||||
} else {
|
||||
hostList = _.clone(state.hostList);
|
||||
let port: Port = JSON.parse(obj);
|
||||
// let host: Host = _.clone(port.host);
|
||||
|
||||
let tHost: Host = null;
|
||||
let tPort: Port = null;
|
||||
let port: Port = JSON.parse(obj);
|
||||
|
||||
for(let h of hostList) {
|
||||
if(h.ip === port.host.ip) {
|
||||
tHost = h;
|
||||
port.host = h;
|
||||
if(h.ports === null || h.ports === undefined) {
|
||||
h.ports = new Array();
|
||||
|
||||
let chkObj: Object = h;
|
||||
if(chkObj.hasOwnProperty('ports') === false
|
||||
|| h.ports === null) {
|
||||
let nPort: Port = _.clone(port);
|
||||
let nHost: Host = _.clone(h);
|
||||
nPort.host = nHost;
|
||||
nHost.ports = new Array();
|
||||
nHost.ports.push(nPort);
|
||||
hostList.push(nHost);
|
||||
break;
|
||||
}
|
||||
|
||||
tPort = null;
|
||||
for(let p of h.ports) {
|
||||
if(p.portNumber === port.portNumber) {
|
||||
tPort = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(tPort === null) {
|
||||
let nHost: Host = _.clone(h);
|
||||
let nPort: Port = _.clone(port);
|
||||
nPort.host = nHost;
|
||||
|
||||
let dIdx: number = hostList.indexOf(h, 0);
|
||||
if(dIdx > -1) {
|
||||
hostList.slice(dIdx, 1);
|
||||
}
|
||||
nHost.ports.push(nPort);
|
||||
hostList.push(nHost);
|
||||
}
|
||||
h.ports.push(port);
|
||||
break;
|
||||
}
|
||||
}
|
||||
let dIdx: number = hostList.indexOf(tHost, 0);
|
||||
if(dIdx > -1) {
|
||||
hostList.slice(dIdx, 1);
|
||||
hostList.push(tHost);
|
||||
} else {
|
||||
let host: Host = _.clone(port.host);
|
||||
host.ports = new Array();
|
||||
port.host = host;
|
||||
host.ports.push(port);
|
||||
hostList.push(host);
|
||||
if(tHost === null) {
|
||||
let nHost: Host = _.clone(port.host);
|
||||
let nPort: Port = _.clone(port);
|
||||
|
||||
nPort.host = nHost;
|
||||
nHost.ports = new Array();
|
||||
nHost.ports.push(nPort);
|
||||
hostList.push(nHost);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
...state,
|
||||
hostList: hostList,
|
||||
|
|
Loading…
Reference in New Issue
Block a user