I am working on displaying the Json output of a generated flowchart. I have stored the dropped elements' details in an array called finalArray
and am simply adding it to the Json display. All the details seem to be properly displayed except for the attribute names and their attribute types that are retrieved from another array.
I've commented the part that doesn't work in the following code segment
Code in Context
function saveFlowchart(){
var nodes = [];
var matches = [];
var searchEles = document.getElementById("container").children;
for(var i = 0; i < searchEles.length; i++)
{
matches.push(searchEles[i]);
var idOfEl = searchEles[i].id;
if(searchEles[i].id !=null || searchEles[i].id !="")
{
var $element = $("#" + searchEles[i].id);
var dropElem = $("#" + searchEles[i].id).attr('class');
var position = $element.position();
position.bottom = position.top + $element.height();
position.right = position.left + $element.width();
//alert("class:"+dropElem+"\nTop position: " + position.top + "\nLeft position: " + position.left + "\nBottom position: " + position.bottom + "\nRight position: " + position.right);
finalArray[i] = [];
finalArray[idOfEl-1][0]= idOfEl;
finalArray[idOfEl-1][1]= dropElem;
finalArray[idOfEl-1][2]= [];
finalArray[idOfEl-1][2][0] = position.top;
finalArray[idOfEl-1][2][1] = position.left;
finalArray[idOfEl-1][2][2] = position.bottom;
finalArray[idOfEl-1][2][3] = position.right;
var elId = parseInt(idOfEl);
if (dropElem=="streamdrop ui-draggable")
{
for(var count=0;count<100;count++)
{
if(createdImportStreamArray[count][0]==idOfEl)
{
finalArray[elId-1][3]= createdImportStreamArray[count][1]; //Selected Stream from Predefined Streams
finalArray[elId-1][4]= createdImportStreamArray[count][2]; //asName
//alert("createdImportStreamArray[count][0]==elId\n"+count);
}
else if(createdExportStreamArray[count][0]==idOfEl)
{
finalArray[elId-1][3]= createdExportStreamArray[count][1]; //Selected Stream from Predefined Streams
finalArray[elId-1][4]= createdExportStreamArray[count][2]; //asName
}
else if(createdDefinedStreamArray[count][0]==idOfEl)
{
finalArray[elId-1][3]= createdDefinedStreamArray[count][1]; //Stream Name
finalArray[elId-1][4]= createdDefinedStreamArray[count][4]; //Number of Attributes
finalArray[elId-1][5]=[];
for(var f=0;f<createdDefinedStreamArray[count][4].length;f++)
{
finalArray[elId-1][5][f]=[];
The following two are not displayed individually. Instead only "[]" is shown
finalArray[elId-1][5][f][0]=createdDefinedStreamArray[count][2][f][0]; //Attribute Name
finalArray[elId-1][5][f][1]=createdDefinedStreamArray[count][2][f][1]; // Attribute Type
}
}
}
}
else if (dropElem=="wstream ui-draggable")
{
finalArray[elId-1][3]= createdWindowStreamArray[elId-1][1]; // Window Name
finalArray[elId-1][4]= createdImportStreamArray[elId-1][2]; //Selected Stream Index
finalArray[elId-1][4]= createdImportStreamArray[elId-1][3]; //Selected Stream
finalArray[elId-1][5]= [];
var AttributeNumber = createdWindowStreamArray[elId-1][4].length;
for(var attrFill=0;attrFill<AttributeNumber;attrFill++)
{
finalArray[elId-1][5][attrFill]=[];
finalArray[elId-1][5][attrFill][0]=createdWindowStreamArray[elId-1][4][attrFill][0];
finalArray[elId-1][5][attrFill][1]=createdWindowStreamArray[elId-1][4][attrFill][1];
}
//alert("createdImportStreamArray[count][0]==elId\n"+count);
}
else if (dropElem=="squery ui-draggable")
{
ElementType="squery";
}
else if (dropElem=="wquery ui-draggable")
{
ElementType="wquery";
}
else if (dropElem=="joquery ui-draggable")
{
ElementType="joquery";
}
else if(dropElem=="stquery ui-draggable")
{
ElementType="stquery";
}
else if(dropElem=="partitiondrop ui-draggable")
{
ElementType="partitiondrop";
}
}
}
alert(finalArray);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$(".node").each(function (idx, elem) {
var $elem = $(elem);
var endpoints = jsPlumb.getEndpoints($elem.attr('id'));
console.log('endpoints of '+$elem.attr('id'));
console.log(endpoints);
nodes.push({
blockId: $elem.attr('id'),
nodetype: $elem.attr('data-nodetype'),
positionX: parseInt($elem.css("left"), 10),
positionY: parseInt($elem.css("top"), 10)
});
});
var connections = [];
$.each(jsPlumb.getConnections(), function (idx, connection) {
connections.push({
connectionId: connection.id,
pageSourceId: connection.sourceId,
pageTargetId: connection.targetId
});
});
var flowChart = {};
flowChart.nodes = nodes;
flowChart.connections = connections;
flowChart.elements =finalArray;
flowChart.numberOfElements = finalArray.length;
var flowChartJson = JSON.stringify(flowChart);
//console.log(flowChartJson);
$('#jsonOutput').val(flowChartJson);
}
createdDefinedStream Array
//Array that stores all Defined stream data
var createdDefinedStreamArray = [];
for(var x = 0; x < 100; x++){
createdDefinedStreamArray[x] = [];
for(var y = 0; y < 5; y++){
createdDefinedStreamArray[x][y] = null
}
}
function storeDefinedStreamInfo(newAgent,i,e,kind)
{
var StrName= document.getElementById("StreamNameInput").value;
var StreamElementID = i;
var table = document.getElementById('attrtable');
var tblerows = (table.rows.length);
createdDefinedStreamArray[i][2]=new Array(tblerows);
for (r = 1; r < tblerows; r++) {
for(var c=0; c<1;c++) {
var attrNm = table.rows[r].cells[c].innerHTML;
var attrTp = table.rows[r].cells[1].innerHTML;
createdDefinedStreamArray[i][2][r-1]= new Array(2);
createdDefinedStreamArray[i][2][r-1][0]=attrNm;
createdDefinedStreamArray[i][2][r-1][1]=attrTp;
}
}
createdDefinedStreamArray[i][0]=StreamElementID;
createdDefinedStreamArray[i][1]=StrName;
createdDefinedStreamArray[i][3]="Defined Stream";
createdDefinedStreamArray[i][4]= tblerows;
var prop = $('<a onclick="doclickDefine(this)"><b><img src="../Images/settings.png" class="settingsIconLoc"></b></a> ').attr('id', (i+'-prop'));
var conIcon = $('<img src="../Images/connection.png" onclick="connectionShowHideToggle(this)" class="showIconDefined"></b></a> ').attr('id', (i+'vis'));
newAgent.text(StrName).append('<a class="boxclose" id="boxclose"><b><img src="../Images/Cancel.png"></b></a> ').append(conIcon).append(prop);
dropCompleteElement(newAgent,i,e,kind);
}