fixes for admin interface with multiple nodes of same type

This commit is contained in:
Stephen Birarda 2013-10-24 16:37:41 -07:00
parent d3ac055add
commit 9339538a74
2 changed files with 26 additions and 14 deletions

View file

@ -4,14 +4,14 @@ $(document).ready(function(){
$.getJSON("nodes.json", function(json){
nodesTableBody = "";
$.each(json.nodes, function (type, data) {
$.each(json.nodes, function (uuid, data) {
nodesTableBody += "<tr>";
nodesTableBody += "<td>" + type + "</td>";
nodesTableBody += "<td>" + data.UUID + "</td>";
nodesTableBody += "<td>" + data.type + "</td>";
nodesTableBody += "<td>" + uuid + "</td>";
nodesTableBody += "<td>" + (data.pool ? data.pool : "") + "</td>";
nodesTableBody += "<td>" + data.public.ip + "<span class='port'>:" + data.public.port + "</span></td>";
nodesTableBody += "<td>" + data.local.ip + "<span class='port'>:" + data.local.port + "</span></td>";
nodesTableBody += "<td><span class='glyphicon glyphicon-remove' data-uuid=" + data.UUID + "></span></td>";
nodesTableBody += "<td><span class='glyphicon glyphicon-remove' data-uuid=" + uuid + "></span></td>";
nodesTableBody += "</tr>";
});
@ -21,10 +21,10 @@ $(document).ready(function(){
$.getJSON("assignments.json", function(json){
queuedTableBody = "";
$.each(json.queued, function (type, data) {
$.each(json.queued, function (uuid, data) {
queuedTableBody += "<tr>";
queuedTableBody += "<td>" + type + "</td>";
queuedTableBody += "<td>" + data.UUID + "</td>";
queuedTableBody += "<td>" + uuid + "</td>";
queuedTableBody += "<td>" + data.type + "</td>";
queuedTableBody += "<td>" + (data.pool ? data.pool : "") + "</td>";
queuedTableBody += "</tr>";
});

View file

@ -45,8 +45,9 @@ QJsonObject jsonForSocket(sockaddr* socket) {
const char JSON_KEY_TYPE[] = "type";
const char JSON_KEY_PUBLIC_SOCKET[] = "public";
const char JSON_KEY_LOCAL_SOCKET[] = "local";
const char JSON_KEY_POOL[] = "pool";
void addNodeToJsonObject(Node* node, QJsonObject& jsonObject) {
QJsonObject jsonObjectForNode(Node* node) {
QJsonObject nodeJson;
// re-format the type name so it matches the target name
@ -60,11 +61,13 @@ void addNodeToJsonObject(Node* node, QJsonObject& jsonObject) {
// add the node socket information
nodeJson[JSON_KEY_PUBLIC_SOCKET] = jsonForSocket(node->getPublicSocket());
nodeJson[JSON_KEY_LOCAL_SOCKET] = jsonForSocket(node->getLocalSocket());
// add the node using the UUID as the key
QString uuidString = uuidStringWithoutCurlyBraces(node->getUUID());
jsonObject[uuidString] = nodeJson;
// if the node has pool information, add it
if (node->getLinkedData() && ((Assignment*) node->getLinkedData())->hasPool()) {
nodeJson[JSON_KEY_POOL] = QString(((Assignment*) node->getLinkedData())->getPool());
}
return nodeJson;
}
int DomainServer::civetwebRequestHandler(struct mg_connection *connection) {
@ -92,7 +95,9 @@ int DomainServer::civetwebRequestHandler(struct mg_connection *connection) {
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
if (node->getLinkedData()) {
addNodeToJsonObject(&(*node), assignedNodesJSON);
// add the node using the UUID as the key
QString uuidString = uuidStringWithoutCurlyBraces(node->getUUID());
assignedNodesJSON[uuidString] = jsonObjectForNode(&(*node));
}
}
@ -109,6 +114,11 @@ int DomainServer::civetwebRequestHandler(struct mg_connection *connection) {
QString uuidString = uuidStringWithoutCurlyBraces((*assignment)->getUUID());
queuedAssignmentJSON[JSON_KEY_TYPE] = QString((*assignment)->getTypeName());
// if the assignment has a pool, add it
if ((*assignment)->hasPool()) {
queuedAssignmentJSON[JSON_KEY_POOL] = QString((*assignment)->getPool());
}
// add this queued assignment to the JSON
queuedAssignmentsJSON[uuidString] = queuedAssignmentJSON;
@ -136,7 +146,9 @@ int DomainServer::civetwebRequestHandler(struct mg_connection *connection) {
NodeList* nodeList = NodeList::getInstance();
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
addNodeToJsonObject(&(*node), nodesJSON);
// add the node using the UUID as the key
QString uuidString = uuidStringWithoutCurlyBraces(node->getUUID());
nodesJSON[uuidString] = jsonObjectForNode(&(*node));
}
rootJSON["nodes"] = nodesJSON;