60 lines
No EOL
1.6 KiB
TypeScript
60 lines
No EOL
1.6 KiB
TypeScript
import { ResponseData, Interfaces, MainData, IEdge, NetworkData } from '../../const/types/types'
|
|
import { ipsInitor } from './nodeCreator/inits/initIpArray';
|
|
|
|
export const initNetworkIntData = (mainGroups: ResponseData[]): { interfaces: Interfaces[], edgeData: IEdge[] } => {
|
|
const edgeData: IEdge[] = [];
|
|
const interfaces: Interfaces[] = [];
|
|
|
|
if (mainGroups) {
|
|
mainGroups.map((el, indx) => {
|
|
let nodeData: MainData[] = [];
|
|
el.interfaces.map((net, index) => {
|
|
let nodeID = `g${indx}_nw${index}`;
|
|
let portID = `p-nw${index}`;
|
|
let targetId = `${portID}_target-right`;
|
|
let sourceId = `${nodeID}-source-left`;
|
|
|
|
if (indx === 0) {
|
|
const edge: IEdge = {
|
|
id: `${nodeID}-${portID}`,
|
|
source: nodeID,
|
|
target: portID,
|
|
sourceHandle: sourceId,
|
|
targetHandle: targetId,
|
|
type: "default",
|
|
};
|
|
edgeData.push(edge);
|
|
}
|
|
|
|
const network: NetworkData = {
|
|
device: net.name,
|
|
type: net.type,
|
|
mac: net.mac_address,
|
|
connection: net.active_connection,
|
|
mtu: net.device_mtu,
|
|
state: net.device_state,
|
|
strength: net.strength
|
|
};
|
|
|
|
const ipArray = ipsInitor(net);
|
|
|
|
let interfaceData: MainData = {
|
|
networkData: network,
|
|
ipArrays: ipArray
|
|
};
|
|
|
|
nodeData.push(interfaceData);
|
|
});
|
|
|
|
let j: Interfaces = {
|
|
container_x: el.container_x,
|
|
container_y: el.container_y,
|
|
mainData: nodeData
|
|
};
|
|
|
|
interfaces.push(j);
|
|
});
|
|
}
|
|
|
|
return { interfaces, edgeData };
|
|
}; |