Skip to content

Commit

Permalink
#46
Browse files Browse the repository at this point in the history
  • Loading branch information
jc7447 committed Jan 8, 2017
1 parent a6abbfa commit 47b2ded
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 98 deletions.
53 changes: 45 additions & 8 deletions bda.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,6 @@ try {
return xmlStr;
};

$.fn.outerHTML = function(s) {
return (s) ? this.before(s).remove() : $("<p>").append(this.eq(0).clone()).html();
};

this.extendComponentPath = function(path) {
var res = path;
if (!path.startsWith('/dyn/admin/nucleus/')) {
Expand All @@ -362,12 +358,52 @@ try {
if (isLoggingTrace) {
console.time(name)
}
}
};

this.traceTimeEnd = function(name) {
if (isLoggingTrace) {
console.timeEnd(name)
}
}
};

this.colorToCss = function (colors)
{
var cssVal = "rgb(" ;
for (var i = 0; i < colors.length; i++)
{
if (i !== 0)
cssVal += ",";
cssVal += colors[i];
}
cssVal += ")";
return cssVal;
};

this.verifyColor = function (colors)
{
for (var i = 0; i < colors.length; i++)
if (colors[i] > 210)
colors[i] = 210;
return colors;
};

this.stringToColour = function (str)
{
var colors = [];
var hash = 0;
for (var i = 0; i < str.length; i++)
hash = str.charCodeAt(i) + ((hash << 5) - hash);
for (i = 0; i < 3; i++) {
var value = (hash >> (i * 8)) & 0xFF;
var hexVal = ('00' + value.toString(16)).substr(-2);
colors.push(parseInt(hexVal, 16));
}
return this.verifyColor(colors);
};

$.fn.outerHTML = function(s) {
return (s) ? this.before(s).remove() : $("<p>").append(this.eq(0).clone()).html();
};

$.fn.adjustToFit = function($parent, targetTotalSize, minSize) {
var curSize = $parent.fullHeight();
Expand Down Expand Up @@ -459,6 +495,7 @@ function debounce(func, wait, immediate) {
};
};


/*
highlight v4
Expand Down Expand Up @@ -592,15 +629,15 @@ Johann Burkard
callback.apply(this.$modal);
}
plugin._hide();

}
}

for (var i = 0; i < opts.options.length; i++) {
var opt = opts.options[i];
logTrace( opt);



$('<input></input>', {
type: 'button',
Expand Down
28 changes: 28 additions & 0 deletions bda.css
Original file line number Diff line number Diff line change
Expand Up @@ -1228,3 +1228,31 @@ ol.itemDescAttributes {
.notifyjs-bootstrap-base {
font-size: 12px;
}

.legend {
display : inline-block;
color : black;
border-radius : 5px;
font-size : 11px;
padding : 3px;
margin : 5px;
}

#treePopup {
height: 90%;
width: 95%;
}

#treeContainer {
flex:1;
}

#treeInfo {
display:none;
float:left;
}

.flexContainer {
display:flex;
height:100%;
}
124 changes: 75 additions & 49 deletions bda.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@
var $itemDesc = $xmlDef.find("item-descriptor[name='" + itemDesc + "']");
// First check in current item desc
isId = BDA_REPOSITORY.isPropertyId(propertyName, $itemDesc);
// In case we found the property but it's not an ID, we don't want to seach in super-type
// In case we found the property but it's not an ID, we don't want to search in super-type
if (isId == "FOUND_NOT_ID")
return null;
// In case we found the property and it's an ID
Expand Down Expand Up @@ -1191,7 +1191,7 @@
$itemTree.append("<h2>Get Item Tree</h2>");
$itemTree.append("<p>This tool will recursively retrieve items and print the result with the chosen output." + "<br> For example, if you give an order ID in the form below, you will get all shipping groups, payment groups, commerceItems, priceInfo... of the given order" + "<br><b> Be careful when using this tool on a live instance ! Set a low max items value.</b></p>");

$itemTree.append("<div id='itemTreeForm'>" + "id : <input type='text' id='itemTreeId' /> &nbsp;" + "descriptor : <span id='itemTreeDescriptorField' ><select id='itemTreeDesc' class='itemDescriptor' >" + BDA_REPOSITORY.getDescriptorOptions() + "</select></span>" + "max items : <input type='text' id='itemTreeMax' value='50' /> &nbsp;<br><br>" + "output format : <select id='itemTreeOutput'>" + "<option value='HTMLtab'>HTML tab</option>" + "<option value='addItem'>add-item XML</option>" + "<option value='removeItem'>remove-item XML</option>" + "<option value='printItem'>print-item XML</option>" + "<option value='tree'>Tree</option>" + "</select>&nbsp;" + "<input type='checkbox' id='printRepositoryAttr' /><label for='printRepositoryAttr'>Print attribute : </label>" + "<pre style='margin:0; display:inline;'>repository='" + getCurrentComponentPath() + "'</pre> <br><br>" + "<button id='itemTreeBtn'>Enter <i class='fa fa-play fa-x'></i></button>" + "</div>");
$itemTree.append("<div id='itemTreeForm'>" + "id : <input type='text' id='itemTreeId' /> &nbsp;" + "descriptor : <span id='itemTreeDescriptorField' ><select id='itemTreeDesc' class='itemDescriptor' >" + BDA_REPOSITORY.getDescriptorOptions() + "</select></span>" + "max items : <input type='text' id='itemTreeMax' value='50' /> &nbsp;<br><br>" + "output format : <select id='itemTreeOutput'>" + "<option value='HTMLtab'>HTML tab</option>" + "<option value='addItem'>add-item XML</option>" + "<option value='removeItem'>remove-item XML</option>" + "<option value='printItem'>print-item XML</option>" + "<option value='tree'>Tree (experimental)</option>" + "</select>&nbsp;" + "<input type='checkbox' id='printRepositoryAttr' /><label for='printRepositoryAttr'>Print attribute : </label>" + "<pre style='margin:0; display:inline;'>repository='" + getCurrentComponentPath() + "'</pre> <br><br>" + "<button id='itemTreeBtn'>Enter <i class='fa fa-play fa-x'></i></button>" + "</div>");
$itemTree.append("<div id='itemTreeInfo' />");
$itemTree.append("<div id='itemTreeResult' />");
$("#itemTreeBtn").click(function() {
Expand Down Expand Up @@ -1358,7 +1358,7 @@
$("#itemTreeInfo").empty();
$("#itemTreeResult").empty();
var res = "";
if (outputType !== "HTMLtab") {
if (outputType !== "HTMLtab" && outputType != "tree") {
logTrace("Render copy button");
$("#itemTreeInfo").append("<input type='button' id='itemTreeCopyButton' value='Copy result to clipboard'></input>");
$('#itemTreeCopyButton').click(function() {
Expand Down Expand Up @@ -1412,53 +1412,79 @@
console.log("render as tree");
var nodes = [];
var edges = [];
var i = 0;
var legends = new Map();
// $("#itemTreeResult").css("display", "none");
BDA_REPOSITORY.itemTree.forEach(function(data, id) {
console.log(data);
$(data).find("add-item").each(function(elm) {
var htmlTab = "<table>";
$(elm).find("set-property").each(function(index) {
$this = $(this);
htmlTab += "<tr>";
htmlTab += "<td>" + $this.attr("name") + "</td>";
htmlTab += "<td>" + $this.val() + "</td>";
htmltab += "</tr>";
});
htmlTab += "</table>";
var svg = '<svg xmlns="http://www.w3.org/2000/svg" width="390" height="400">' +
'<rect x="0" y="0" width="100%" height="100%" fill="#7890A7" stroke-width="20" stroke="#ffffff" ></rect>' +
'<foreignObject x="15" y="10" width="100%" height="100%">' +
'<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:10px">' +
htmlTab +
'</div>' +
'</foreignObject>' +
'</svg>';
console.log(url);
var url = "data:image/svg+xml;charset=utf-8,"+ encodeURIComponent(svg);

nodes.push({id: i, label: '', image: url, shape: 'image'});
// nodes.push({id: 2, label: 'Using SVG', image: url, shape: 'image'});
// edges.push({from: 1, to: 2, length: 300});
i++;
});
//console.log("data : " + data);
var xmlDoc = $.parseXML("<xml>" + data + "</xml>");
var $xml = $(xmlDoc);
var $addItem = $xml.find("add-item").first();
var itemDesc = $addItem.attr("item-descriptor");
var itemId = $addItem.attr("id");

$xml.find("set-property").each(function(index) {
var $this = $(this);
var propertyName = $this.attr("name");
var propertyValue = $this.text();
if (propertyName != "order" && propertyName != "relationships" && propertyName != "orderRef") {
var isId = BDA_REPOSITORY.isTypeId(propertyName, itemDesc, $xmlDef)
if (isId != null && isId != "FOUND_NOT_ID") {
var idAsTab = BDA_REPOSITORY.parseRepositoryId(propertyValue);
for (var i = 0; i != idAsTab.length; i++) {
edges.push({from: itemId, to:idAsTab[i], arrows:'to', title:propertyName});
}
}
}
});

console.log(nodes);
// create a network
$("#itemTreeResult").empty();
var container = document.getElementById('itemTreeResult');
var data = {
nodes: nodes,
edges: edges
};
var options = {
physics: {stabilization: false},
edges: {smooth: false}
};

var network = new vis.Network(container, data, options);

var nodeColor = colorToCss(stringToColour(itemDesc));
nodes.push({id: itemId, label: itemDesc + "\n" + itemId, color: nodeColor, shape: 'box'});
legends.set(itemDesc, nodeColor);
});

// Create popup
$("#itemTreeResult").empty()
.append("<div class='popup_block' id='treePopup'>"
+ "<div><a href='javascript:void(0)' class='close'><i class='fa fa-times' /></a></div>"
+ "<div id='treeLegend'></div>"
+ "<div class='flexContainer'>"
+ "<div id='treeInfo'></div>"
+ "<div id='treeContainer'></div></div></div>");
$("#treePopup .close").click(function() {
$("#treePopup").fadeOut();
});

// Setup legend

legends.forEach(function(value, key) {
$("#treeLegend").append("<div class='legend' style='background-color:" + value + "'>" + key + "</div>");
});

console.log(nodes);
console.log(edges);

// Create the network
var data = {
nodes: nodes,
edges: edges
};

var options = {
physics: {stabilization: true},
edges: {smooth: true}
};

$("#treePopup").show();
var container = document.getElementById('treeContainer');
var network = new vis.Network(container, data, options);
network.on("click", function (params) {
params.event = "[original event]";
if (params.nodes && params.nodes.length == 1) {
//$("#treeContainer").css("width", "70%");
$("#treeInfo").empty();
BDA_REPOSITORY.showXMLAsTab(BDA_REPOSITORY.itemTree.get(params.nodes[0]), null, $("#treeInfo"), false);
$("#treeInfo").show("slide", { direction: "right" });
}
});
},

createSpeedbar: function() {
Expand Down Expand Up @@ -1773,7 +1799,7 @@
var fullColSize = 23;
if(BDA.isOldDynamo){
fullColSize=18;

}


Expand All @@ -1782,7 +1808,7 @@

//expand the cell width
var $td = $tr.find('td').first();

$td.attr('colspan', fullColSize); //extend to full with
//query cache line
var $queryCols = $tr.next().next().children('td');
Expand Down
47 changes: 6 additions & 41 deletions bda.toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
var compObj = {};
compObj.componentPath = component;
compObj.componentName = getComponentNameFromPath(component);
compObj.colors = BDA_TOOLBAR.stringToColour(compObj.componentName);
compObj.colors = stringToColour(compObj.componentName);
var storedComp = BDA_STORAGE.getStoredComponents();
if (storedComp.length > 0)
compObj.id = storedComp[storedComp.length - 1].id + 1;
Expand All @@ -135,42 +135,7 @@
colorValue = 0;
borderColor.push(colorValue);
}
return BDA_TOOLBAR.colorToCss(borderColor);
},

colorToCss : function (colors)
{
var cssVal = "rgb(" ;
for (var i = 0; i < colors.length; i++)
{
if (i !== 0)
cssVal += ",";
cssVal += colors[i];
}
cssVal += ")";
return cssVal;
},

verifyColor : function (colors)
{
for (var i = 0; i < colors.length; i++)
if (colors[i] > 210)
colors[i] = 210;
return colors;
},

stringToColour : function (str)
{
var colors = [];
var hash = 0;
for (var i = 0; i < str.length; i++)
hash = str.charCodeAt(i) + ((hash << 5) - hash);
for (i = 0; i < 3; i++) {
var value = (hash >> (i * 8)) & 0xFF;
var hexVal = ('00' + value.toString(16)).substr(-2);
colors.push(parseInt(hexVal, 16));
}
return BDA_TOOLBAR.verifyColor(colors);
return colorToCss(borderColor);
},

showMoreInfos : function (component)
Expand Down Expand Up @@ -274,7 +239,7 @@
//check filters
if(show)
{
var colors = BDA_TOOLBAR.stringToColour(fav.componentName);
var colors = stringToColour(fav.componentName);
var shortName = getComponentShortName(fav.componentName);
var callableHTML = "<div class='favMethods'>";
if(fav.methods !== undefined)
Expand All @@ -301,7 +266,7 @@
}

$("<div class='toolbar-elem fav'></div>")
.css("background-color", BDA_TOOLBAR.colorToCss(colors))
.css("background-color", colorToCss(colors))
.css("border", "1px solid " + BDA_TOOLBAR.getBorderColor(colors))
.html("<div class='favLink'>"
+ "<a href='" + fav.componentPath + "' title='" + fav.componentName + "' >"
Expand Down Expand Up @@ -525,7 +490,7 @@
for (var i = 0; i < sortedTags.length; i++) {
tagName = sortedTags[i];
var tag = tags[tagName];
var tagColor = BDA_TOOLBAR.stringToColour(tagName);
var tagColor = stringToColour(tagName);

$('<label >#' + tagName + '</label>')
.attr('for','favFilter_'+tagName)
Expand All @@ -550,7 +515,7 @@
})
.appendTo(
$('<li class="bda-button tag-filter" ></li>')
.css("background-color", BDA_TOOLBAR.colorToCss(tagColor))
.css("background-color", colorToCss(tagColor))
.css("border", "1px solid " + BDA_TOOLBAR.getBorderColor(tagColor))
.appendTo($list)
)
Expand Down

0 comments on commit 47b2ded

Please sign in to comment.