This commit is contained in:
Garrett K 2021-01-24 07:13:59 +00:00
parent bc21dae866
commit 72325a1aac
2 changed files with 283 additions and 304 deletions

View File

@ -1,30 +1,48 @@
// ### Cabinet Functions ###
function crawlCabinetConnections(selectedPort){
var portArray = [];
function drawCabinet(){
console.log('drawCabinet');
resizeCanvas();
clearCabinetConnections();
crawlCabinet();
drawCabinetConnections();
drawCabinetTrunks();
}
function crawlCabinet(){
console.log('crawlCabinet');
var pathSourceArray = {
'selected': $(document).data('selectedPort'),
'hovered': $(document).data('hoveredPort')
};
var sourceTypeMap = {
'selected': ['cabinetSelectedConnections', 'cabinetSelectedTrunks'],
'hovered': ['cabinetHoveredConnections', 'cabinetHoveredTrunks']
}
$.each(pathSourceArray, function(pathSourceType, pathSource){
var connectionArray = [];
var trunkArray = [];
var partitionArray = [];
var selectedPeerID = $(selectedPort).data('peerGlobalId');
var selectedPortOrig = selectedPort;
if(pathSource !== undefined && pathSource !== false) {
var selectedPort = $(pathSource);
for(x=0; x<2; x++) {
if(x == 1) {
// Crawl trunk peer
var selectedPartition = $(selectedPortOrig).closest('.partition');
var selectedPartition = $(pathSource).closest('.partition');
var selectedPartitionPeerID = $(selectedPartition).data('peerGlobalId');
if($('#'+selectedPartitionPeerID).length) {
var selectedPartitionPeer = $('#'+selectedPartitionPeerID);
trunkArray.push([selectedPartition, selectedPartitionPeer]);
partitionArray.push(selectedPartition, selectedPartitionPeer);
//partitionArray.push(selectedPartition, selectedPartitionPeer);
var selectedPartitionPeerIDArray = selectedPartitionPeerID.split('-');
var peerID = selectedPartitionPeerIDArray[2];
var peerFace = selectedPartitionPeerIDArray[3];
var peerDepth = selectedPartitionPeerIDArray[4];
var peerPort = $(selectedPortOrig).data('portIndex');
var peerPort = $(pathSource).data('portIndex');
var selectedPort = $('#port-4-'+peerID+'-'+peerFace+'-'+peerDepth+'-'+peerPort);
} else {
@ -36,7 +54,6 @@ function crawlCabinetConnections(selectedPort){
}
while($(selectedPort).length) {
portArray.push(selectedPort);
// Crawl connection peer
var connectedPortIDString = $(selectedPort).data('connectedGlobalId');
@ -48,7 +65,6 @@ function crawlCabinetConnections(selectedPort){
var connectedPort = $('#'+connectedPortID);
if($(connectedPort).length) {
portArray.push(connectedPort)
connectionArray.push([selectedPort, connectedPort]);
var connectedPartition = $(connectedPort).closest('.partition');
@ -58,7 +74,7 @@ function crawlCabinetConnections(selectedPort){
var connectedPartitionPeer = $('#'+connectedPartitionPeerID);
trunkArray.push([connectedPartition, connectedPartitionPeer]);
partitionArray.push(connectedPartition, connectedPartitionPeer);
//partitionArray.push(connectedPartition, connectedPartitionPeer);
var connectedPartitionPeerIDArray = connectedPartitionPeerID.split('-');
var peerID = connectedPartitionPeerIDArray[2];
@ -87,22 +103,29 @@ function crawlCabinetConnections(selectedPort){
}
}
}
return {
'partitionArray': partitionArray,
'trunkArray': trunkArray,
'portArray': portArray,
'connectionArray': connectionArray
};
}
function drawCabinetConnections(elementArray){
$(document).data(sourceTypeMap[pathSourceType][0], connectionArray);
$(document).data(sourceTypeMap[pathSourceType][1], trunkArray);
});
}
function drawCabinetConnections(){
console.log('drawCabinetConnections');
pathDataTypeArray = [
'cabinetSelectedConnections',
'cabinetHoveredConnections'
];
cabinetCtx.strokeStyle = 'LightSkyBlue';
cabinetCtx.lineWidth = 3;
cabinetCtx.beginPath();
//console.log('Debug (elementArray): '+JSON.stringify(elementArray));
$.each(elementArray, function(index, element){
$.each(pathDataTypeArray, function(pathDataTypeIndex, pathDataType){
var pathData = $(document).data(pathDataType);
$.each(pathData, function(index, element){
var elemA = element[0];
var elemB = element[1];
@ -176,15 +199,26 @@ function drawCabinetConnections(elementArray){
}
});
});
cabinetCtx.stroke();
}
function drawCabinetTrunks(elementArray){
function drawCabinetTrunks(){
console.log('drawCabinetTrunks');
pathDataTypeArray = [
'cabinetSelectedTrunks',
'cabinetHoveredTrunks'
];
cabinetCtx.strokeStyle = 'MidnightBlue';
cabinetCtx.lineWidth = 3;
cabinetCtx.beginPath();
$.each(elementArray, function(index, element){
$.each(pathDataTypeArray, function(pathDataTypeIndex, pathDataType){
var pathData = $(document).data(pathDataType);
$.each(pathData, function(index, element){
var vertical = canvasInset + (5*index);
@ -231,21 +265,22 @@ function drawCabinetTrunks(elementArray){
}
});
});
cabinetCtx.stroke();
}
function clearCabinetConnections(){
console.log('clearCabinetConnections');
var canvasHeight = $('#canvasCabinet').height();
var canvasWidth = $('#canvasCabinet').width();
cabinetCtx.clearRect(0, 0, canvasWidth, canvasHeight);
$('a.addCabButton').remove();
drawPathConnections();
drawPathTrunks();
}
// ### Path Functions ###
function drawPath(){
console.log('drawPath');
resizeCanvas();
clearPathConnections();
crawlPathConnections();
@ -255,13 +290,13 @@ function drawPath(){
}
function crawlPathConnections(){
console.log('crawlPathConnections');
var pathConnections = {};
var connectorElementArray = $('#containerFullPath').find('.port');
$.each(connectorElementArray, function(index, element){
if($(element).data('connectionPairId') !== undefined) {
var connectionPairID = $(element).data('connectionPairId');
if(pathConnections[connectionPairID] === undefined) {
console.log('here3');
pathConnections[connectionPairID] = [];
}
pathConnections[connectionPairID].push($(element));
@ -271,6 +306,7 @@ function crawlPathConnections(){
}
function crawlPathTrunks(){
console.log('crawlPathTrunks');
var pathTrunks = {};
var connectorElementArray = $('#containerFullPath').find('.objectBox');
@ -290,6 +326,7 @@ function crawlPathTrunks(){
}
function drawPathConnections(){
console.log('drawPathConnections');
var pathConnections = $(document).data('pathConnections');
pathCtx.strokeStyle = 'LightSkyBlue';
pathCtx.lineWidth = 3;
@ -311,6 +348,7 @@ function drawPathConnections(){
}
function drawPathTrunks(){
console.log('drawPathTrunks');
var pathTrunks = $(document).data('pathTrunks');
pathCtx.strokeStyle = 'MidnightBlue';
pathCtx.lineWidth = 3;
@ -354,6 +392,7 @@ function drawPathTrunks(){
}
function clearPathConnections(){
console.log('clearPathConnections');
var canvasHeight = $('#canvasPath').height();
var canvasWidth = $('#canvasPath').width();
pathCtx.clearRect(0, 0, canvasWidth, canvasHeight);
@ -422,101 +461,48 @@ function highlightElement(elemArray, color){
}
function makePortsHoverable(){
console.log('makePortsHoverable');
resizeCanvas();
redraw();
//resizeCanvas();
//redraw();
$('#buildSpaceContent').find('.port').each(function(){
$(this).unbind('mouseenter mouseleave click.drawConnections');
});
$('#buildSpaceContent').find('.port').each(function(){
$(this).hover(function(){
var pathElementArray = crawlCabinetConnections(this);
highlightElement(pathElementArray['partitionArray'], 'black');
drawCabinetTrunks(pathElementArray['trunkArray']);
highlightElement(pathElementArray['portArray'], 'LightSkyBlue');
drawCabinetConnections(pathElementArray['connectionArray']);
$(document).data('hoveredPort', this);
drawCabinet();
}, function(){
redraw();
$(document).data('hoveredPort', false);
drawCabinet();
});
$(this).on('click.drawConnections', function(){
if(typeof $(this).data('pathID') == 'undefined') {
var pathElementArray = crawlCabinetConnections(this);
// Get pathID
// This allows persistant paths to accumulate
//pathID++;
// This allows only 1 persistant path at a time
pathID = 0;
if(typeof $(document).data('cabinetConnections')[pathID] != 'undefined') {
$.each($(document).data('cabinetConnections')[pathID]['portArray'], function(){
$(this).removeData('pathID');
});
}
// Associate ports to pathIDs
$.each(pathElementArray['portArray'], function(){
$(this).data('pathID', pathID);
});
// Store connection path
var workingPathData = {
'portArray': pathElementArray['portArray'],
'connectionArray': pathElementArray['connectionArray'],
'trunkArray': pathElementArray['trunkArray'],
'partitionArray': pathElementArray['partitionArray']
};
$(document).data('cabinetConnections')[pathID] = workingPathData;
if($(document).data('selectedPort') !== undefined && $(document).data('selectedPort') !== false) {
// Gather previously and currently selected port IDs for comparison
var selectedPort = $(document).data('selectedPort');
var selectedPortID = $(selectedPort).attr('id');
var thisPortID = $(this).attr('id');
// Compare previously and currently selected port IDs
if(selectedPortID === thisPortID) {
// Unselect port
$(document).data('selectedPort', false);
} else {
// Clear pathIDs from ports
var thisPathID = $(this).data('pathID');
$.each($(document).data('cabinetConnections')[thisPathID]['portArray'], function(){
$(this).removeData('pathID');
});
// Clear connection path
delete $(document).data('cabinetConnections')[thisPathID];
// Select port
$(document).data('selectedPort', this);
}
});
});
} else {
$(document).data('selectedPort', this);
}
function refreshPathData(){
var cabinetConnections = $(document).data('cabinetConnections');
pathDataOrig = pathData;
$.each(pathDataOrig, function(pathID, path){
$.each(path['portArray'], function(portIndex, port){
var portID = $(port).attr('id');
if($('#'+portID).length) {
var pathElementArray = crawlCabinetConnections($('#'+portID));
// Associate ports to pathIDs
$.each(pathElementArray['portArray'], function(){
$(this).data('pathID', pathID);
});
// Store connection path
var workingCabinetConnections = {
'portArray': pathElementArray['portArray'],
'connectionArray': pathElementArray['connectionArray'],
'trunkArray': pathElementArray['trunkArray'],
'partitionArray': pathElementArray['partitionArray']
};
$(document).data('cabinetConnections', workingCabinetConnections);
return false;
}
drawCabinet();
});
});
}
function makeCabArrowsClickable(){
@ -530,7 +516,8 @@ function makeCabArrowsClickable(){
} else {
$(cabinet).insertAfter($(cabinet).next());
}
redraw();
drawCabinet();
//redraw();
});
}
@ -551,10 +538,11 @@ function makeCabCloseClickable(){
}
});
// Refresh all paths
refreshPathData();
drawCabinet();
redraw();
// Refresh all paths
//refreshPathData();
//redraw();
});
}
@ -566,19 +554,6 @@ function resizeCanvas() {
$('#canvasPath').attr('height', $('#canvasPath').parent().height());
}
function redraw() {
clearCabinetConnections();
var cabinetConnections = $(document).data('cabinetConnections');
if(typeof cabinetConnections != 'undefined') {
$.each(cabinetConnections, function(pathID, path){
drawCabinetTrunks(path['trunkArray']);
highlightElement(path['partitionArray'], 'MidnightBlue');
drawCabinetConnections(path['connectionArray']);
highlightElement(path['portArray'], 'LightSkyBlue');
});
}
}
function initializeCanvas() {
window.addEventListener('resize', resizeCanvas, false);
@ -589,7 +564,10 @@ function initializeCanvas() {
// Cabinet connections
cabinetCtx = canvasCabinet.getContext('2d');
cabinetCtx.lineWidth = lineWidth;
$(document).data('cabinetConnections', {});
$(document).data('cabinetSelectedConnections', []);
$(document).data('cabinetHoveredConnections', []);
$(document).data('cabinetSelectedTrunks', []);
$(document).data('cabinetHoveredTrunks', []);
canvasInset = 10;
pathID = 0;

View File

@ -689,8 +689,9 @@ function postProcessCable(){
$('#checkboxPopulated').prop("disabled", true);
retrievePortPath(objID, objFace, objDepth, objPort);
retrievePortOptions(objID, objFace, objDepth, objPort);
refreshPathData();
redraw();
drawCabinet();
//refreshPathData();
//redraw();
$('#objTree').jstree('deselect_all');
$('#objectTreeModal').modal('hide');
@ -714,8 +715,7 @@ $( document ).ready(function() {
event.preventDefault();
$('#containerFullPath').parent().printThis({
canvas: true,
importStyle: true,
removeInline: true
importStyle: true
});
});
@ -1015,8 +1015,9 @@ $( document ).ready(function() {
$('#checkboxPopulated').prop("disabled", false);
retrievePortPath(objID, objFace, objDepth, objPort);
retrievePortOptions(objID, objFace, objDepth, objPort);
refreshPathData();
redraw();
drawCabinet();
//refreshPathData();
//redraw();
$('#objTree').jstree('deselect_all');
$('#objectTreeModal').modal('hide');