Skip to content

Commit

Permalink
fix: location name was not preselected when clicking on a location (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardolauryel authored Jan 31, 2023
1 parent 27f8f01 commit 6107ea6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 42 deletions.
10 changes: 6 additions & 4 deletions modules/circuits/assets/connection/public/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,16 @@ function addDestin(port) {
}

function addMarker(port, color) {
let isLocation = false;

marker = meicanMap.getNodeByPort(port.urn);

if (marker) return;

if(port.lat != undefined)
flagPortLocation = true;
else
flagPortLocation = false;
isLocation = true;

meicanMap.addNode(port, color, 'status');
meicanMap.addNode(port, isLocation, color, 'status');
}

function areMarkersReady(path) {
Expand Down
12 changes: 7 additions & 5 deletions modules/circuits/assets/reservation/public/create/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ function showPointModal(pointElement, pointOrder, nodeId) {
}

if(nodeId) {
var node = meicanMap.getNode(nodeId);
var hasLocation = (node.options.ports[0].lat != null && node.options.ports[0].lng != null);
let node = meicanMap.getNode(nodeId);
let isExpanded = node.options.isExpanded;
let hasLocation = (node.options.ports[0].lat != null && node.options.ports[0].lng != null);

if (node.options.ports.length > 1) {
$("#pointform-domain").val(node.options.ports[0].network.domain.id);
fillNetworkSelect(node.options.ports[0].network.domain.id);
if(hasLocation && flagPortLocation){
if (hasLocation && isExpanded) {
fillPortSelect(null, null, node.options.ports[0].location_name);
}
} else {
Expand All @@ -181,7 +183,7 @@ function showPointModal(pointElement, pointOrder, nodeId) {
}
}

if(hasLocation && flagPortLocation){
if (hasLocation && isExpanded) {
$("#pointform-location").val(node.options.ports[0].location_name);
}

Expand All @@ -190,7 +192,7 @@ function showPointModal(pointElement, pointOrder, nodeId) {
urn = $(pointElement).find('.urn-input').val();
let urn_splitted = $($(pointElement).find('.urn-input').val().split(':'))

for (var i = meicanTopo['ports'].length - 1; i >= 0; i--) {
for (let i = meicanTopo['ports'].length - 1; i >= 0; i--) {
if (meicanTopo['ports'][i]['urn'] == urn) {
port = meicanTopo['ports'][i];
$("#pointform-domain").val(port.network.domain.id);
Expand Down
71 changes: 38 additions & 33 deletions modules/topology/assets/viewer/map/meican-lmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @author Mauricio Quatrin Guerreiro
*/

var flagPortLocation = false;
var flagNetworkWasClicked = false;

function LMap(canvasDivId) {
Expand All @@ -33,9 +32,6 @@ function LMap(canvasDivId) {
LMap.prototype.show = function(instantRefresh) {
let mapId = "map-n";

if(flagPortLocation)
mapId = "map-l";

if($('#'+mapId).length == 1) {
$('#'+mapId).show();
} else {
Expand Down Expand Up @@ -327,16 +323,19 @@ LMap.prototype.removeLinks = function() {
}
}

LMap.prototype.getNodeByPosition = function(position, domain, location_name) {
for (var i = this._nodes.length - 1; i >= 0; i--) {
LMap.prototype.getNodeByPosition = function(position, domain, locationName) {
for (let i = this._nodes.length - 1; i >= 0; i--) {
if ((this._nodes[i].getLatLng().lat === position.lat) &&
(this._nodes[i].getLatLng().lng === position.lng)) {
if (this._nodes[i].options.ports[0].network.domain == domain && (this._nodes[i].options.ports[0].location_name == undefined || !flagPortLocation))
let nodeLocationName = this._nodes[i].options.ports[0].location_name;
let nodeIsExpanded = this._nodes[i].options.isExpanded;

if (this._nodes[i].options.ports[0].network.domain == domain && (nodeLocationName == undefined || !nodeIsExpanded))
return this._nodes[i];
else if(this._nodes[i].options.ports[0].location_name == location_name)
else if(nodeLocationName == locationName)
return this._nodes[i];
else
return this.getNodeByPosition(L.latLng(position.lat + 0.001, position.lng), domain, location_name);
return this.getNodeByPosition(L.latLng(position.lat + 0.001, position.lng), domain, locationName);
}
}

Expand All @@ -357,15 +356,23 @@ LMap.prototype.getParentPosition = function(port) {
return L.latLng([0,0]);
}

LMap.prototype.addNode = function(port, color, mode) {
LMap.prototype.addNode = function(port, parentNodeId, color, mode) {
let nodeType = "domain";
let isExpanded = false;

if (parentNodeId) {
nodeType = "location";
isExpanded = true;
}

if(!port.network)
return;
if (!color)
color = port.network.domain.color;

if(flagPortLocation && port.lat != null && port.lng != null) {
if (isExpanded && port.lat != null && port.lng != null) {
var pos = L.latLng([port.lat,port.lng]);
} else if (!flagPortLocation && typeof port.network !== 'undefined') {
} else if (!isExpanded && typeof port.network !== 'undefined') {
var pos = this.getParentPosition(port);
} else {
var pos = L.latLng([0, 0]);
Expand All @@ -392,32 +399,29 @@ LMap.prototype.addNode = function(port, color, mode) {
className: 'marker-icon-svg',
});


let nodeType = "domain";
if(flagPortLocation)
nodeType = "location"

node = L.marker(
this.buildNodePosition(pos),
{
id: this._nodeAutoInc++,
icon: icon,
name: port.urn,
type: nodeType,
isExpanded: isExpanded,
parentNodeId: parentNodeId,
ports: [port]
}
).bindPopup("#");

if(mode != 'status'){
if(flagPortLocation)
if (isExpanded)
node.bindTooltip(port.location_name, {permanent:true, direction: 'top'}).openTooltip();
else
node.bindTooltip(port.network.domain.name, {permanent:true, direction: 'left'}).openTooltip();
}

this._nodes.push(node);
this._cluster.addLayer(node);
if (!flagPortLocation) {
if (!isExpanded) {
if (port.network.domain.grouped_nodes == 0) {
this._stackDomainsToBeExpanded.push(node.options.id);
}
Expand Down Expand Up @@ -456,20 +460,22 @@ LMap.prototype.prepareLabels = function() {

this.removeLabels();

for (var i = this._nodes.length - 1; i >= 0; i--) {
var label = 'error';
for (let i = this._nodes.length - 1; i >= 0; i--) {
let label = 'error';
labels = [];
for (var k = this._nodes[i].options.ports.length - 1; k >= 0; k--) {
for (let k = this._nodes[i].options.ports.length - 1; k >= 0; k--) {
let nodeIsExpanded = this._nodes[i].options.isExpanded;

if(expandedDomainsNodes.length == 0){
if(flagPortLocation){
if (nodeIsExpanded) {
if(this._nodes[i].options.ports[k].lat != null && this._nodes[i].options.ports[k].lng != null)
labels.push(this._nodes[i].options.ports[k].location_name);
}else{
labels.push(this._nodes[i].options.ports[k].network.domain.name);
}
}else{
for(var j = expandedDomainsNodes.length - 1; j >=0; j--) {
if(flagPortLocation && this._nodes[i].options.ports[k].network.domain.name == expandedDomainsNodes[j].options.ports[0].network.domain.name){
for(let j = expandedDomainsNodes.length - 1; j >=0; j--) {
if(nodeIsExpanded && this._nodes[i].options.ports[k].network.domain.name == expandedDomainsNodes[j].options.ports[0].network.domain.name){
if(this._nodes[i].options.ports[k].lat != null && this._nodes[i].options.ports[k].lng != null)
labels.push(this._nodes[i].options.ports[k].location_name);
}else{
Expand Down Expand Up @@ -1089,34 +1095,33 @@ LMap.prototype.hasLocation = function(networkId) {
}

LMap.prototype.expandLocations = function(nodeId) {
flagPortLocation = true;
let node = this.getNode(nodeId);
let nodes = this.getNodes();
let ports = this.getTopology()['ports'];
let domainId = node.options.ports[0].network.domain_id;

if( this.getQtdPortsWithLocationByDomain(domainId) > 0 ){
node.options.isExpanded = true;

if (this.getQtdPortsWithLocationByDomain(domainId) > 0) {
this.addExpandedDomainNode(node);

for (var i = ports.length - 1; i >= 0; i--) {
if(ports[i].network.domain_id == domainId){
this.addNode(
ports[i]
ports[i],
nodeId
);
}
}
this.hideNode(node);
}

flagPortLocation = false;
}

LMap.prototype.groupLocations = function(nodeId) {
flagPortLocation = false;
let node = this.getNode(nodeId);
let nodes = this.getNodes();
let parentNode = this.getNode(node.options.parentNodeId);
let domainId = node.options.ports[0].network.domain_id;

parentNode.options.isExpanded = false;
this.removeNode(domainId, "location");
this.showNode(meicanMap.getNode(meicanMap.getNodeIdByDomainId(domainId)));
this.removeExpandedDomainNode(domainId);
Expand Down

0 comments on commit 6107ea6

Please sign in to comment.