Skip to content

Commit

Permalink
Fix: nn-reassigned install selected when clicking node dot on map (#797)
Browse files Browse the repository at this point in the history
* Fix: nn-reassigned install selected when clicking node dot on map

* Closed installs also excluded

* Parallel API calls

* Fix missing brackets

* Fix: old nodes selected when opened in edit pane

---------

Co-authored-by: Willard Nilges <[email protected]>
  • Loading branch information
Andrew-Dickinson and WillNilges authored Jan 4, 2025
1 parent 310e682 commit c285614
Showing 1 changed file with 75 additions and 17 deletions.
92 changes: 75 additions & 17 deletions src/meshweb/static/admin/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ async function getNewSelectedNodes(){
const installResponse = await fetch(`/api/v1/installs/${id}/`);
if (!installResponse.ok) return null;
const install = await installResponse.json();
nodeId = install.install_number;
if (install.status !== "Closed" && install.status !== "NN Reassigned") {
nodeId = install.install_number;
}
} else if (type === "node") {
if (!id) return null;
const nodeResponse = await fetch(`/api/v1/nodes/${id}/`);
Expand All @@ -40,7 +42,12 @@ async function getNewSelectedNodes(){
if (node.network_number) {
nodeId = node.network_number;
} else {
nodeId = node.installs[0].install_number;
for (const install of node.installs) {
if (install.status !== "Closed" && install.status !== "NN Reassigned") {
nodeId = install.install_number;
break;
}
}
}
} else if (type === "building") {
if (!id) return null;
Expand All @@ -50,7 +57,18 @@ async function getNewSelectedNodes(){
if (building.primary_node && building.primary_node.network_number) {
nodeId = building.primary_node.network_number;
} else if (building.installs) {
nodeId = building.installs[0].install_number;
const installResponses = await Promise.all(
building.installs.map(install => fetch(`/api/v1/installs/${install.id}/`))
);
for (const installResponse of installResponses) {
if (installResponse.ok){
const install = await installResponse.json();
if (install.status !== "Closed" && install.status !== "NN Reassigned") {
nodeId = install.install_number;
break;
}
}
}
}
} else if (["device", "sector", "accesspoint"].indexOf(type) !== -1) {
if (!id) return null;
Expand All @@ -63,7 +81,16 @@ async function getNewSelectedNodes(){
const memberResponse = await fetch(`/api/v1/members/${id}/`);
if (!memberResponse.ok) return null;
const member = await memberResponse.json();
nodeId = member.installs.map(install => install.install_number).join("-");

const installResponses = await Promise.all(
member.installs.map(install => fetch(`/api/v1/installs/${install.id}/`))
);

nodeId = (await Promise.all(installResponses
.filter(installResponse => installResponse.ok)
.map(installResponse => installResponse.json())))
.filter(install => install.status !== "Closed" && install.status !== "NN Reassigned")
.map(install => install.install_number).join("-");
} else if (type === "link") {
if (!id) return null;
const linkResponse = await fetch(`/api/v1/links/${id}/`);
Expand Down Expand Up @@ -94,7 +121,18 @@ async function getNewSelectedNodes(){
if (building1.primary_node && building1.primary_node.network_number) {
b1NodeId = building1.primary_node.network_number;
} else if (building1.installs) {
b1NodeId = building1.installs[0].install_number;
const installResponses = await Promise.all(
building1.installs.map(install => fetch(`/api/v1/installs/${install.id}/`))
);
for (const installResponse of installResponses) {
if (installResponse.ok){
const install = await installResponse.json();
if (install.status !== "Closed" && install.status !== "NN Reassigned") {
b1NodeId = install.install_number;
break;
}
}
}
}

let b2NodeId = null;
Expand All @@ -104,7 +142,18 @@ async function getNewSelectedNodes(){
if (building2.primary_node && building2.primary_node.network_number) {
b2NodeId = building2.primary_node.network_number;
} else if (building2.installs) {
b2NodeId = building2.installs[0].install_number;
const installResponses = await Promise.all(
building2.installs.map(install => fetch(`/api/v1/installs/${install.id}/`))
);
for (const installResponse of installResponses) {
if (installResponse.ok){
const install = await installResponse.json();
if (install.status !== "Closed" && install.status !== "NN Reassigned") {
b2NodeId = install.install_number;
break;
}
}
}
}

if (b1NodeId && b2NodeId) nodeId = `${b1NodeId}-${b2NodeId}`;
Expand Down Expand Up @@ -307,21 +356,30 @@ async function nodeSelectedOnMap(selectedNodes) {
return;
}

const installResponse = await fetch(`/api/v1/installs/${selectedNodes}/`);
const nodeResponse = await fetch(`/api/v1/nodes/${selectedNodes}/`);
const [installResponse, nodeResponse] = await Promise.all(
[
fetch(`/api/v1/installs/${selectedNodes}/`),
fetch(`/api/v1/nodes/${selectedNodes}/`)
]
);
if (installResponse.ok){
const installJson = await installResponse.json();
if (installJson.node && installJson.node.network_number) {
await updateAdminContent(new URL(`/admin/meshapi/node/${installJson.node.id}/change`, document.location).href);
updateMapForLocation(installJson.node.network_number.toString());
} else {
if (installJson.status !== "NN Reassigned" && installJson.status !== "Closed") {
if (installJson.node && installJson.node.network_number) {
await updateAdminContent(new URL(`/admin/meshapi/node/${installJson.node.id}/change`, document.location).href);
updateMapForLocation(installJson.node.network_number.toString());
return;
}

updateAdminContent(new URL(`/admin/meshapi/install/${installJson.id}/change`, document.location).href);
return;
}
} else {
if (nodeResponse.ok) {
const nodeJson = await nodeResponse.json();
updateAdminContent(new URL(`/admin/meshapi/node/${nodeJson.id}/change`, document.location).href);
}
}

if (nodeResponse.ok) {
const nodeJson = await nodeResponse.json();
updateAdminContent(new URL(`/admin/meshapi/node/${nodeJson.id}/change`, document.location).href);
return;
}

}
Expand Down

0 comments on commit c285614

Please sign in to comment.