mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 05:23:09 +02:00
show stats for node at /nodes/UUID
This commit is contained in:
parent
8f403609e7
commit
55bc9c059d
3 changed files with 33 additions and 7 deletions
|
@ -42,7 +42,7 @@ $(document).ready(function(){
|
||||||
$(document.body).on('click', '.glyphicon-remove', function(){
|
$(document.body).on('click', '.glyphicon-remove', function(){
|
||||||
// fire off a delete for this node
|
// fire off a delete for this node
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/node/" + $(this).data('uuid'),
|
url: "/nodes/" + $(this).data('uuid'),
|
||||||
type: 'DELETE',
|
type: 'DELETE',
|
||||||
success: function(result) {
|
success: function(result) {
|
||||||
console.log("Succesful request to delete node.");
|
console.log("Succesful request to delete node.");
|
||||||
|
|
|
@ -655,7 +655,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QString&
|
||||||
const QString JSON_MIME_TYPE = "application/json";
|
const QString JSON_MIME_TYPE = "application/json";
|
||||||
|
|
||||||
const QString URI_ASSIGNMENT = "/assignment";
|
const QString URI_ASSIGNMENT = "/assignment";
|
||||||
const QString URI_NODE = "/node";
|
const QString URI_NODES = "/nodes";
|
||||||
|
|
||||||
if (connection->requestOperation() == QNetworkAccessManager::GetOperation) {
|
if (connection->requestOperation() == QNetworkAccessManager::GetOperation) {
|
||||||
if (path == "/assignments.json") {
|
if (path == "/assignments.json") {
|
||||||
|
@ -702,7 +702,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QString&
|
||||||
|
|
||||||
// we've processed this request
|
// we've processed this request
|
||||||
return true;
|
return true;
|
||||||
} else if (path == "/nodes.json") {
|
} else if (path == QString("%1.json").arg(URI_NODES)) {
|
||||||
// setup the JSON
|
// setup the JSON
|
||||||
QJsonObject rootJSON;
|
QJsonObject rootJSON;
|
||||||
QJsonObject nodesJSON;
|
QJsonObject nodesJSON;
|
||||||
|
@ -723,14 +723,36 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QString&
|
||||||
|
|
||||||
// send the response
|
// send the response
|
||||||
connection->respond(HTTPConnection::StatusCode200, nodesDocument.toJson(), qPrintable(JSON_MIME_TYPE));
|
connection->respond(HTTPConnection::StatusCode200, nodesDocument.toJson(), qPrintable(JSON_MIME_TYPE));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
const QString NODE_REGEX_STRING =
|
||||||
|
QString("\\%1\\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\\/?$").arg(URI_NODES);
|
||||||
|
QRegExp nodeShowRegex(NODE_REGEX_STRING);
|
||||||
|
|
||||||
|
if (nodeShowRegex.indexIn(path) != -1) {
|
||||||
|
QUuid matchingUUID = QUuid(nodeShowRegex.cap(1));
|
||||||
|
|
||||||
|
// see if we have a node that matches this ID
|
||||||
|
SharedNodePointer matchingNode = NodeList::getInstance()->nodeWithUUID(matchingUUID);
|
||||||
|
if (matchingNode) {
|
||||||
|
// create a QJsonDocument with the stats QJsonObject
|
||||||
|
QJsonDocument statsDocument(reinterpret_cast<DomainServerNodeData*>(matchingNode->getLinkedData())
|
||||||
|
->getStatsJSONObject());
|
||||||
|
|
||||||
|
// send the resposne
|
||||||
|
connection->respond(HTTPConnection::StatusCode200, statsDocument.toJson(), qPrintable(JSON_MIME_TYPE));
|
||||||
|
|
||||||
|
// tell the caller we processed the request
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (connection->requestOperation() == QNetworkAccessManager::PostOperation) {
|
} else if (connection->requestOperation() == QNetworkAccessManager::PostOperation) {
|
||||||
if (path == URI_ASSIGNMENT) {
|
if (path == URI_ASSIGNMENT) {
|
||||||
// this is a script upload - ask the HTTPConnection to parse the form data
|
// this is a script upload - ask the HTTPConnection to parse the form data
|
||||||
QList<FormData> formData = connection->parseFormData();
|
QList<FormData> formData = connection->parseFormData();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// check how many instances of this assignment the user wants by checking the ASSIGNMENT-INSTANCES header
|
// check how many instances of this assignment the user wants by checking the ASSIGNMENT-INSTANCES header
|
||||||
const QString ASSIGNMENT_INSTANCES_HEADER = "ASSIGNMENT-INSTANCES";
|
const QString ASSIGNMENT_INSTANCES_HEADER = "ASSIGNMENT-INSTANCES";
|
||||||
|
|
||||||
|
@ -770,13 +792,15 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QString&
|
||||||
|
|
||||||
// respond with a 200 code for successful upload
|
// respond with a 200 code for successful upload
|
||||||
connection->respond(HTTPConnection::StatusCode200);
|
connection->respond(HTTPConnection::StatusCode200);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
} else if (connection->requestOperation() == QNetworkAccessManager::DeleteOperation) {
|
} else if (connection->requestOperation() == QNetworkAccessManager::DeleteOperation) {
|
||||||
if (path.startsWith(URI_NODE)) {
|
if (path.startsWith(URI_NODES)) {
|
||||||
// this is a request to DELETE a node by UUID
|
// this is a request to DELETE a node by UUID
|
||||||
|
|
||||||
// pull the UUID from the url
|
// pull the UUID from the url
|
||||||
QUuid deleteUUID = QUuid(path.mid(URI_NODE.size() + sizeof('/')));
|
QUuid deleteUUID = QUuid(path.mid(URI_NODES.size() + sizeof('/')));
|
||||||
|
|
||||||
if (!deleteUUID.isNull()) {
|
if (!deleteUUID.isNull()) {
|
||||||
SharedNodePointer nodeToKill = NodeList::getInstance()->nodeWithUUID(deleteUUID);
|
SharedNodePointer nodeToKill = NodeList::getInstance()->nodeWithUUID(deleteUUID);
|
||||||
|
|
|
@ -19,6 +19,8 @@ public:
|
||||||
DomainServerNodeData();
|
DomainServerNodeData();
|
||||||
int parseData(const QByteArray& packet) { return 0; }
|
int parseData(const QByteArray& packet) { return 0; }
|
||||||
|
|
||||||
|
const QJsonObject& getStatsJSONObject() const { return _statsJSONObject; }
|
||||||
|
|
||||||
void parseJSONStatsPacket(const QByteArray& statsPacket);
|
void parseJSONStatsPacket(const QByteArray& statsPacket);
|
||||||
|
|
||||||
void setStaticAssignmentUUID(const QUuid& staticAssignmentUUID) { _staticAssignmentUUID = staticAssignmentUUID; }
|
void setStaticAssignmentUUID(const QUuid& staticAssignmentUUID) { _staticAssignmentUUID = staticAssignmentUUID; }
|
||||||
|
|
Loading…
Reference in a new issue