Get region names from API instead of hard-coding them
This commit is contained in:
+66
-12
@@ -48,6 +48,7 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
|
||||
data.noTag = false;
|
||||
data.notifications = [];
|
||||
data.plans = [];
|
||||
data.regions = [];
|
||||
|
||||
// Static references to UI elements
|
||||
var ui = {};
|
||||
@@ -60,6 +61,8 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
|
||||
var state = {};
|
||||
state.haveLinodes = false;
|
||||
state.haveNotifications = false;
|
||||
state.haveRegions = false;
|
||||
state.haveTypes = false;
|
||||
|
||||
var createLinodeRow = function(linode, alt)
|
||||
{
|
||||
@@ -92,8 +95,10 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
|
||||
plan.innerHTML = getPlanLabel(linode.type);
|
||||
else
|
||||
plan.innerHTML = "Unknown";
|
||||
if (plan.innerHTML == "")
|
||||
if (plan.innerHTML == "") {
|
||||
plan.innerHTML = linode.type;
|
||||
translatePlan(linode.type, plan);
|
||||
}
|
||||
var ip = document.createElement("td");
|
||||
ip.innerHTML = linode.ipv4[0];
|
||||
var ipCount = 0;
|
||||
@@ -110,8 +115,17 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
|
||||
plus.innerHTML = " (+" + ipCount + ")";
|
||||
ip.appendChild(plus);
|
||||
}
|
||||
var regionData = null;
|
||||
for (var i = 0; i < data.regions.length; i++) {
|
||||
if (data.regions[i].id == linode.region) {
|
||||
regionData = data.regions[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
var region = document.createElement("td");
|
||||
if (regionNames[linode.region])
|
||||
if (regionData && regionData.label && regionData.label.length)
|
||||
region.innerHTML = regionData.label;
|
||||
else if (regionNames[linode.region])
|
||||
region.innerHTML = regionNames[linode.region];
|
||||
else
|
||||
region.innerHTML = linode.region;
|
||||
@@ -312,8 +326,19 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
|
||||
body.innerHTML = data.notifications[i].message;
|
||||
}
|
||||
// Replace "this facility" with actual location for outages
|
||||
if (data.notifications[i].type == "outage" && data.notifications[i].entity && data.notifications[i].entity.type == "region" && regionNames[data.notifications[i].entity.id])
|
||||
header.innerHTML = header.innerHTML.replace("this facility", regionNames[data.notifications[i].entity.id]);
|
||||
if (data.notifications[i].type == "outage" && data.notifications[i].entity && data.notifications[i].entity.type == "region") {
|
||||
var region = null;
|
||||
for (var j = 0; j < data.regions.length; j++) {
|
||||
if (data.regions[j].id == data.notifications[i].entity.id) {
|
||||
region = data.regions[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (region && region.label && region.label.length)
|
||||
header.innerHTML = header.innerHTML.replace("this facility", region.label);
|
||||
else if (regionNames[data.notifications[i].entity.id])
|
||||
header.innerHTML = header.innerHTML.replace("this facility", regionNames[data.notifications[i].entity.id]);
|
||||
}
|
||||
notification.appendChild(header);
|
||||
notification.appendChild(body);
|
||||
ui.notifications.appendChild(notification);
|
||||
@@ -379,13 +404,42 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
|
||||
return;
|
||||
}
|
||||
|
||||
// Get linodes
|
||||
var filters = null;
|
||||
if (data.params.tag)
|
||||
filters = {
|
||||
"tags": data.params.tag
|
||||
};
|
||||
apiGet("/linode/instances", displayLinodes, filters);
|
||||
state.haveTypes = true;
|
||||
if (state.haveRegions) {
|
||||
// Get linodes
|
||||
var filters = null;
|
||||
if (data.params.tag)
|
||||
filters = {
|
||||
"tags": data.params.tag
|
||||
};
|
||||
apiGet("/linode/instances", displayLinodes, filters);
|
||||
}
|
||||
};
|
||||
|
||||
var getRegions = function(response)
|
||||
{
|
||||
// Add regions to array
|
||||
data.regions = data.regions.concat(response.data);
|
||||
|
||||
// Request the next page if there are more pages
|
||||
if (response.page != response.pages) {
|
||||
apiGet("/regions?page=" + (response.page + 1), getRegions, null);
|
||||
return;
|
||||
}
|
||||
|
||||
state.haveRegions = true;
|
||||
if (state.haveTypes) {
|
||||
// Get linodes
|
||||
var filters = null;
|
||||
if (data.params.tag)
|
||||
filters = {
|
||||
"tags": data.params.tag
|
||||
};
|
||||
apiGet("/linode/instances", displayLinodes, filters);
|
||||
}
|
||||
|
||||
// Get notifications
|
||||
apiGet("/account/notifications", displayNotifications, null);
|
||||
};
|
||||
|
||||
var insertLinodes = function()
|
||||
@@ -425,9 +479,9 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
|
||||
setupHeader();
|
||||
|
||||
// Get linode and transfer info
|
||||
apiGet("/regions", getRegions, null);
|
||||
apiGet("/linode/types", getPlans, null);
|
||||
apiGet("/account/transfer", displayTransfer, null);
|
||||
apiGet("/account/notifications", displayNotifications, null);
|
||||
};
|
||||
|
||||
var translatePlan = function(name, cell)
|
||||
|
||||
Reference in New Issue
Block a user