This commit is contained in:
Garrett 2020-12-27 07:01:47 +00:00
parent 49dec8d17b
commit 5bb2d9d0ea
4 changed files with 182 additions and 177 deletions

View File

@ -679,14 +679,42 @@ function postProcessCable(){
var objPort = data.objPort;
var value = data.value;
var optionText = $('#selectPort').find(':selected').text();
$('#port-4-'+objID+'-'+objFace+'-'+objDepth+'-'+objPort).addClass('populated').data('connectedGlobalId', 'port-'+responseJSON.success.peerPortID);
if($('#port-'+responseJSON.success.peerPortID).length) {
$('#port-'+responseJSON.success.peerPortID).addClass('populated').data('connectedGlobalId', 'port-4-'+objID+'-'+objFace+'-'+objDepth+'-'+objPort);
// Compile localPortGlobalID
var localPortGlobalID = 'port-4-'+objID+'-'+objFace+'-'+objDepth+'-'+objPort;
var localPortGlobalIDBase64 = btoa(JSON.stringify([localPortGlobalID]));
// Append each remotePortGlobalID with "port-"
var remotePortGlobalIDArray = [];
$.each(value, function(index, remotePortGlobalID){
var remotePortGlobalID = 'port-'+remotePortGlobalID;
remotePortGlobalIDArray.push(remotePortGlobalID);
});
var remotePortGlobalIDArrayBase64 = btoa(JSON.stringify(remotePortGlobalIDArray));
// Compile emptyGlobalIDArrayBase64
var emptyGlobalIDArrayBase64 = btoa(JSON.stringify([]));
// Clear previous remote port(s)
var prevRemotePortGlobalIDArray = JSON.parse(atob($('#'+localPortGlobalID).data('connectedGlobalId')));
$.each(prevRemotePortGlobalIDArray, function(index, prevRemotePortGlobalID){
if($('#'+prevRemotePortGlobalID).length) {
$('#'+prevRemotePortGlobalID).removeClass('populated').data('connectedGlobalId', emptyGlobalIDArrayBase64);
}
if($('#port-'+responseJSON.success.oldPeerPortID).length) {
$('#port-'+responseJSON.success.oldPeerPortID).removeClass('populated').data('connectedGlobalId', 'none');
});
// Update local port
$('#'+localPortGlobalID).addClass('populated').data('connectedGlobalId', remotePortGlobalIDArrayBase64);
// Update remote port(s)
$.each(remotePortGlobalIDArray, function(index, remotePortGlobalID){
console.log('Debug (remotePortGlobalID): '+remotePortGlobalID);
if($('#'+remotePortGlobalID).length) {
console.log('Debug (localPortGlobalIDBase64): '+localPortGlobalIDBase64);
$('#'+remotePortGlobalID).addClass('populated').data('connectedGlobalId', localPortGlobalIDBase64);
}
});
var interfaceSelectionElem = $('#selectPort').find(':selected');
portDesignation(interfaceSelectionElem, 'add', 'C');
$('#checkboxPopulated').prop("checked", true);
@ -1001,15 +1029,20 @@ $( document ).ready(function() {
} else if ($(responseJSON.error).size() > 0){
displayError(responseJSON.error);
} else {
$('#port-4-'+objID+'-'+objFace+'-'+objDepth+'-'+objPort).removeClass('populated').data('connectedGlobalId', 'none');
if(responseJSON.success.oldPeerPortID) {
if($('#port-'+responseJSON.success.oldPeerPortID).length) {
$('#port-'+responseJSON.success.oldPeerPortID).removeClass('populated').data('connectedGlobalId', 'none');
}
// Compile localPortGlobalID
var localPortGlobalID = 'port-4-'+objID+'-'+objFace+'-'+objDepth+'-'+objPort;
// Update remote port(s)
var remotePortGlobalIDArray = JSON.parse(atob($('#'+localPortGlobalID).data('connectedGlobalId')));
$.each(remotePortGlobalIDArray, function(index, remotePortGlobalID){
if($('#'+remotePortGlobalID).length) {
$('#'+remotePortGlobalID).removeClass('populated').data('connectedGlobalId', btoa(JSON.stringify([])));
}
});
$('#'+localPortGlobalID).removeClass('populated').data('connectedGlobalId', btoa(JSON.stringify([])));
var interfaceSelectionElem = $('#selectPort').find(':selected');
//portDesignation(interfaceSelectionElem, 'remove', 'C');
$('#checkboxPopulated').prop("checked", false);
$('#checkboxPopulated').prop("disabled", false);
retrievePortPath(objID, objFace, objDepth, objPort);

View File

@ -401,11 +401,13 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
// Validate trunk peers are not connected to each other
if(isset($qls->App->inventoryArray[$objectID][$objectFace][$objectDepth])) {
$peersConnected = false;
foreach($qls->App->inventoryArray[$objectID][$objectFace][$objectDepth] as $objConnection) {
foreach($qls->App->inventoryArray[$objectID][$objectFace][$objectDepth] as $objPort) {
foreach($objPort as $objConnection) {
if($objConnection['id'] == $elementID and $objConnection['face'] == $elementFace and $objConnection['depth'] == $elementDepth) {
$peersConnected = true;
}
}
}
if($peersConnected) {
$errMsg = 'Cannot trunk partitions that are connected to each other.';
array_push($validate->returnData['error'], $errMsg);
@ -509,7 +511,8 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
// Delete peer entries
foreach($deleteArray as $entry) {
// Delete from inventory table
if($inventoryEntry = $qls->App->inventoryArray[$entry['id']][$entry['face']][$entry['depth']][$entry['port']]) {
if($inventoryPort = $qls->App->inventoryArray[$entry['id']][$entry['face']][$entry['depth']][$entry['port']]) {
foreach($inventoryPort as $inventoryEntry) {
$rowID = $inventoryEntry['rowID'];
if($inventoryEntry['localEndID'] === 0 and $inventoryEntry['remoteEndID'] === 0) {
// If this is an unmanaged connection, delete the entry
@ -531,6 +534,7 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
$qls->App->inventoryArray[$inventoryEntry['id']][$inventoryEntry['face']][$inventoryEntry['depth']][$inventoryEntry['port']]['port'] = 0;
}
}
}
unset($qls->App->inventoryArray[$entry['id']][$entry['face']][$entry['depth']][$entry['port']]);
}
@ -552,14 +556,16 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
foreach($qls->App->inventoryArray[$objectID] as $faceID => $face) {
foreach($face as $depthID => $depth) {
foreach($depth as $portID => $port) {
$rowID = $port['rowID'];
if($port['localEndID'] == 0 and $port['remoteEndID'] == 0) {
$deleteEntry = false;
foreach($port as $connection) {
$rowID = $connection['rowID'];
if($connection['localEndID'] == 0 and $connection['remoteEndID'] == 0) {
// Delete entry if not managed cable
$qls->SQL->delete('app_inventory', array('id' => array('=', $rowID)));
unset($qls->App->inventoryArray[$objectID][$faceID][$depthID][$portID]);
$deleteEntry = true;
} else {
// Clear entry if managed cable
$localAttrPrefix = $port['localAttrPrefix'];
$localAttrPrefix = $connection['localAttrPrefix'];
$set = array(
$localAttrPrefix.'_object_id' => 0,
$localAttrPrefix.'_object_face' => 0,
@ -569,6 +575,10 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
$qls->SQL->update('app_inventory', $set, array('id' => array('=', $rowID)));
}
}
if($deleteEntry) {
unset($qls->App->inventoryArray[$objectID][$faceID][$depthID][$portID]);
}
}
}
}
}

View File

@ -109,19 +109,14 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
// Clear any inventory entries
if (isset($qls->App->inventoryArray[$elementID][$elementFace][$elementDepth][$elementPort])) {
$inventoryEntry = $qls->App->inventoryArray[$elementID][$elementFace][$elementDepth][$elementPort];
foreach($qls->App->inventoryArray[$elementID][$elementFace][$elementDepth][$elementPort] as $inventoryEntry) {
$rowID = $inventoryEntry['rowID'];
$localAttrPrefix = $inventoryEntry['localAttrPrefix'];
if ($inventoryEntry['localEndID'] == 0) {
// Found entry is not a managed cable... delete
$qls->SQL->delete(
'app_inventory',
array(
'id' => array('=', $rowID)
)
);
$qls->SQL->delete('app_inventory', array('id' => array('=', $rowID)));
} else {
// Found entry is a managed cable... zeroize
@ -139,6 +134,7 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
);
}
}
}
// Update connection in database
$qls->SQL->update(
@ -175,21 +171,17 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
$objFace = $data['objFace'];
$objDepth = $data['objDepth'];
$objPort = $data['objPort'];
$obj = (isset($qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort])) ? $qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort] : false;
// Retrieve old peer port ID so it can have the "populated" class cleared
if($obj) {
$oldPeerPortID = '4-'.$obj['id'].'-'.$obj['face'].'-'.$obj['depth'].'-'.$obj['port'];
} else {
$oldPeerPortID = false;
}
if(isset($qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort])) {
$port = $qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort];
foreach($port as $connection) {
// Clear inventory table entry
$objRowID = $obj['rowID'];
if($obj['localEndID'] or $obj['remoteEndID']) {
clearTableInventory($qls, $obj['localAttrPrefix'], $objRowID);
$rowID = $connection['rowID'];
if($connection['localEndID'] or $connection['remoteEndID']) {
clearTableInventory($qls, $connection['localAttrPrefix'], $rowID);
} else {
$qls->SQL->delete('app_inventory', array('id' => array('=', $objRowID)));
$qls->SQL->delete('app_inventory', array('id' => array('=', $rowID)));
}
}
}
// Clear populated port entry
@ -197,17 +189,20 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
// Log history
$localPort = $qls->App->generateObjectPortName($objID, $objFace, $objDepth, $objPort);
$remotePortData = $qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort];
$remoteObjID = $remotePortData['id'];
$remoteObjFace = $remotePortData['face'];
$remoteObjDepth = $remotePortData['depth'];
$remoteObjPort = $remotePortData['port'];
$remotePort = $qls->App->generateObjectPortName($remoteObjID, $remoteObjFace, $remoteObjDepth, $remoteObjPort);
$actionString = 'Deleted connection: <strong>'.$localPort.'</strong> to <strong>'.$remotePort.'</strong>';
$port = $qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort];
$remotePortArray = array();
foreach($port as $connection) {
$remoteObjID = $connection['id'];
$remoteObjFace = $connection['face'];
$remoteObjDepth = $connection['depth'];
$remoteObjPort = $connection['port'];
$remotePortName = $qls->App->generateObjectPortName($remoteObjID, $remoteObjFace, $remoteObjDepth, $remoteObjPort);
array_push($remotePortArray, $remotePortName);
}
$remotePortString = implode('<br>', $remotePortArray);
$actionString = 'Deleted connection: <strong>'.$localPort.'</strong> to <strong>'.$remotePortString.'</strong>';
$qls->App->logAction(3, 3, $actionString);
$validate->returnData['success']['oldPeerPortID'] = $oldPeerPortID;
break;
case 'connectionExplore':
@ -215,7 +210,6 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
$validate->returnData['success'] = array();
$value = $data['value'];
$clear = $value == 'clear' ? true : false;
$peerPortID = '';
foreach($value as $peerPortString) {
@ -233,8 +227,6 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
$objPort = $data['objPort'];
$obj = (isset($qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort])) ? $qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort] : false;
$peerPortID = '4-'.$elementID.'-'.$elementFace.'-'.$elementDepth.'-'.$elementPort;
// Clear trunk if this is a trunked floorplan object
$objIDArray = array($elementID, $objID);
foreach($objIDArray as $objID) {
@ -253,60 +245,61 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
}
}
// Retrieve old peer port ID so it can have the "populated" class cleared
if($obj) {
$oldPeerPortID = '4-'.$obj['id'].'-'.$obj['face'].'-'.$obj['depth'].'-'.$obj['port'];
} else {
$oldPeerPortID = false;
}
// Clear existing connections
if($obj and $element) {
$objRowID = $obj['rowID'];
$elementRowID = $element['rowID'];
foreach($obj as $objConnection) {
$objRowID = $objConnection['rowID'];
foreach($element as $elementConnection) {
$elementRowID = $elementConnection['rowID'];
// Are the ports connected to each other?
if($obj['rowID'] == $element['rowID']) {
if($obj['localEndID'] or $obj['remoteEndID']) {
if($objConnection['rowID'] == $elementConnection['rowID']) {
if($objConnection['localEndID'] or $objConnection['remoteEndID']) {
clearTableInventory($qls, 'a', $objRowID);
clearTableInventory($qls, 'b', $objRowID);
} else {
$qls->SQL->delete('app_inventory', array('id' => array('=', $objRowID)));
}
} else {
if($obj['localEndID'] or $obj['remoteEndID']) {
clearTableInventory($qls, $obj['localAttrPrefix'], $objRowID);
if($objConnection['localEndID'] or $objConnection['remoteEndID']) {
clearTableInventory($qls, $objConnection['localAttrPrefix'], $objRowID);
} else {
$qls->SQL->delete('app_inventory', array('id' => array('=', $objRowID)));
}
if($element['localEndID'] or $element['remoteEndID']) {
clearTableInventory($qls, $element['localAttrPrefix'], $elementRowID);
if($elementConnection['localEndID'] or $elementConnection['remoteEndID']) {
clearTableInventory($qls, $elementConnection['localAttrPrefix'], $elementRowID);
} else {
$qls->SQL->delete('app_inventory', array('id' => array('=', $elementRowID)));
}
}
}
}
} else if($obj) {
$objRowID = $obj['rowID'];
foreach($obj as $objConnection) {
$objRowID = $objConnection['rowID'];
if($obj['localEndID'] or $obj['remoteEndID']) {
clearTableInventory($qls, $obj['localAttrPrefix'], $objRowID);
if($objConnection['localEndID'] or $objConnection['remoteEndID']) {
clearTableInventory($qls, $objConnection['localAttrPrefix'], $objRowID);
} else {
$qls->SQL->delete('app_inventory', array('id' => array('=', $objRowID)));
}
}
} else if($element) {
$elementRowID = $element['rowID'];
foreach($element as $elementConnection) {
$elementRowID = $elementConnection['rowID'];
if($element['localEndID'] or $element['remoteEndID']) {
clearTableInventory($qls, $element['localAttrPrefix'], $elementRowID);
if($elementConnection['localEndID'] or $elementConnection['remoteEndID']) {
clearTableInventory($qls, $elementConnection['localAttrPrefix'], $elementRowID);
} else {
$qls->SQL->delete('app_inventory', array('id' => array('=', $elementRowID)));
}
}
}
// Clear populated port entry
clearTablePopulated($qls, $objID, $objFace, $objDepth, $objPort);
@ -323,9 +316,6 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){
}
$validate->returnData['success']['peerPortID'] = $peerPortID;
$validate->returnData['success']['oldPeerPortID'] = $oldPeerPortID;
break;
}
}

View File

@ -91,13 +91,6 @@ for($x=0; $x<2; $x++){
'connectorType' => $connection[$localAttrPrefix.'_connector']
)
);
/*
if($x == 0) {
array_push($path, $workingArray);
} else {
array_unshift($path, $workingArray);
}
*/
// Cable
$mediaTypeID = $connection['mediaType'];
@ -111,13 +104,6 @@ for($x=0; $x<2; $x++){
'length' => $length
)
);
/*
if($x == 0) {
array_push($path, $workingArray);
} else {
array_unshift($path, $workingArray);
}
*/
// Remote Connection
$connector2WorkingArray = array(
@ -127,13 +113,6 @@ for($x=0; $x<2; $x++){
'connectorType' => $connection[$remoteAttrPrefix.'_connector']
)
);
/*
if($x == 0) {
array_push($path, $workingArray);
} else {
array_unshift($path, $workingArray);
}
*/
// Object
if($connection[$remoteAttrPrefix.'_object_id'] != 0) {
@ -172,13 +151,6 @@ for($x=0; $x<2; $x++){
'type' => 'trunk',
'data' => array()
);
/*
if($x == 0) {
array_push($path, $workingArray);
} else {
array_unshift($path, $workingArray);
}
*/
} else {
// No trunk peer found