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 = () => {
|
public handleTest = () => {
|
||||||
|
|
||||||
let min: number = 1;
|
let min: number = 1;
|
||||||
let max: number = 2;
|
let max: number = 3;
|
||||||
|
|
||||||
let idx: number = Math.floor(Math.random() * (max - min + 1) + min);
|
let idx: number = Math.floor(Math.random() * (max - min + 1) + min);
|
||||||
|
|
||||||
idx = 3;
|
|
||||||
|
|
||||||
switch(idx) {
|
switch(idx) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|
|
@ -19,13 +19,26 @@ const reducer: ReducersMapObject = {
|
||||||
action: Action<Host>): DiscoveryIngState => {
|
action: Action<Host>): DiscoveryIngState => {
|
||||||
|
|
||||||
let obj: any = action.payload;
|
let obj: any = action.payload;
|
||||||
|
let host: Host = JSON.parse(obj);
|
||||||
let hostList: Host[] = null;
|
let hostList: Host[] = null;
|
||||||
if(state.hostList === null || state.hostList === undefined) {
|
if(state.hostList === null || state.hostList === undefined) {
|
||||||
hostList = new Array();
|
hostList = new Array();
|
||||||
hostList.push(JSON.parse(obj));
|
hostList.push(JSON.parse(obj));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
hostList = _.clone(state.hostList);
|
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 {
|
return {
|
||||||
|
@ -49,36 +62,59 @@ const reducer: ReducersMapObject = {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
hostList = _.clone(state.hostList);
|
hostList = _.clone(state.hostList);
|
||||||
let port: Port = JSON.parse(obj);
|
|
||||||
// let host: Host = _.clone(port.host);
|
|
||||||
|
|
||||||
let tHost: Host = null;
|
let tHost: Host = null;
|
||||||
|
let tPort: Port = null;
|
||||||
|
let port: Port = JSON.parse(obj);
|
||||||
|
|
||||||
for(let h of hostList) {
|
for(let h of hostList) {
|
||||||
if(h.ip === port.host.ip) {
|
if(h.ip === port.host.ip) {
|
||||||
tHost = h;
|
tHost = h;
|
||||||
port.host = h;
|
|
||||||
if(h.ports === null || h.ports === undefined) {
|
let chkObj: Object = h;
|
||||||
h.ports = new Array();
|
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(tHost === null) {
|
||||||
if(dIdx > -1) {
|
let nHost: Host = _.clone(port.host);
|
||||||
hostList.slice(dIdx, 1);
|
let nPort: Port = _.clone(port);
|
||||||
hostList.push(tHost);
|
|
||||||
} else {
|
nPort.host = nHost;
|
||||||
let host: Host = _.clone(port.host);
|
nHost.ports = new Array();
|
||||||
host.ports = new Array();
|
nHost.ports.push(nPort);
|
||||||
port.host = host;
|
hostList.push(nHost);
|
||||||
host.ports.push(port);
|
|
||||||
hostList.push(host);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
hostList: hostList,
|
hostList: hostList,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user