From 3e57539e9143a4092d05e702947b6854bc9a5dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Tue, 12 Jun 2018 21:13:09 +0200 Subject: [PATCH] Added resetClientStatusList button to Dashboard #129 --- index.html | 32 ++++++++++++++++++++++++++++++++ src/cc/Service.cpp | 9 +++++++++ src/cc/Service.h | 1 + 3 files changed, 42 insertions(+) diff --git a/index.html b/index.html index 52eb308d32..acca552273 100644 --- a/index.html +++ b/index.html @@ -314,6 +314,23 @@ } }); + new $.fn.dataTable.Buttons(table, { + buttons: [ + { text: ' Reset ClientStatusList', + className: 'btn-danger', + enabled: true, + action: function () { + resetClientStatusList(); + } + } + ] + }); + + table.buttons(1, null ).container().appendTo( + table.table().container() + ); + + table.on('xhr.dt', function ( e, settings, json, xhr ) { // check version if (latestRelease === "" && json !== undefined) { @@ -488,6 +505,21 @@ }); } + function resetClientStatusList() { + $.ajax({ + type: "POST", + url: "/admin/resetClientStatusList", + dataType:"text", + data: '', + success: function(data){ + setSuccess('Successfully send the reset client status list request to the Server. - Now just wait for the next refresh.'); + }, + error: function (data) { + setError('Failed to send the reset client status list request to the Server. \nError: ' + JSON.stringify(data,undefined, 2)); + } + }); + } + function uptime( data, type, row ) { if (type !== 'sort') { var lastStatus = row.client_status.last_status_update * 1000; diff --git a/src/cc/Service.cpp b/src/cc/Service.cpp index b7c35733af..05e1542bea 100644 --- a/src/cc/Service.cpp +++ b/src/cc/Service.cpp @@ -105,6 +105,8 @@ unsigned Service::handlePOST(const Options* options, const std::string& url, con resultCode = setClientConfig(options, clientId, data, resp); } else if (url.rfind("/admin/setClientCommand", 0) == 0) { resultCode = setClientCommand(clientId, data, resp); + } else if (url.rfind("/admin/resetClientStatusList", 0) == 0) { + resultCode = resetClientStatusList(data, resp); } uv_mutex_unlock(&m_mutex); @@ -280,6 +282,13 @@ unsigned Service::setClientCommand(const std::string& clientId, const std::strin } } +unsigned Service::resetClientStatusList(const std::string& data, std::string& resp) +{ + m_clientStatus.clear(); + + return MHD_HTTP_OK; +} + unsigned Service::getAdminPage(const Options* options, std::string& resp) { std::stringstream data; diff --git a/src/cc/Service.h b/src/cc/Service.h index 6a330e41a1..4993e9787e 100644 --- a/src/cc/Service.h +++ b/src/cc/Service.h @@ -54,6 +54,7 @@ class Service static unsigned setClientStatus(const std::string& clientIp, const std::string& clientId, const std::string& data, std::string& resp); static unsigned setClientCommand(const std::string& clientId, const std::string& data, std::string& resp); static unsigned setClientConfig(const Options* options, const std::string &clientId, const std::string &data, std::string &resp); + static unsigned resetClientStatusList(const std::string& data, std::string& resp); static std::string getClientConfigFileName(const Options *options, const std::string &clientId);