diff --git a/httpd/web.go b/httpd/web.go index 2bc0be9b..a6b0ee9c 100644 --- a/httpd/web.go +++ b/httpd/web.go @@ -39,6 +39,7 @@ type basePage struct { UserURL string APIUserURL string APIConnectionsURL string + APIQuotaScanURL string ConnectionsURL string UsersTitle string ConnectionsTitle string @@ -104,6 +105,7 @@ func getBasePageData(title, currentURL string) basePage { UserURL: webUserPath, APIUserURL: userPath, APIConnectionsURL: activeConnectionsPath, + APIQuotaScanURL: quotaScanPath, ConnectionsURL: webConnectionsPath, UsersTitle: pageUsersTitle, ConnectionsTitle: pageConnectionsTitle, diff --git a/templates/users.html b/templates/users.html index 46382e35..9c93bc00 100644 --- a/templates/users.html +++ b/templates/users.html @@ -14,6 +14,10 @@
+ +
View and manage users
@@ -152,6 +156,47 @@ enabled: false }; + $.fn.dataTable.ext.buttons.quota_scan = { + text: 'Quota scan', + action: function (e, dt, node, config) { + table.button(3).enable(false); + var username = dt.row({ selected: true }).data()[1]; + var path = '{{.APIQuotaScanURL}}' + $.ajax({ + url: path, + type: 'POST', + dataType: 'json', + data: JSON.stringify({ "username": username }), + timeout: 15000, + success: function (result) { + table.button(3).enable(true); + $('#successTxt').text("Quota scan started for the selected user. Please reload the user's page to check when the scan ends"); + $('#successMsg').show(); + setTimeout(function () { + $('#successMsg').hide(); + }, 5000); + }, + error: function ($xhr, textStatus, errorThrown) { + console.log("quota scan error") + table.button(3).enable(true); + var txt = "Unable to update quota for the selected user"; + if ($xhr) { + var json = $xhr.responseJSON; + if (json) { + txt += ": " + json.error; + } + } + $('#errorTxt').text(txt); + $('#errorMsg').show(); + setTimeout(function () { + $('#errorMsg').hide(); + }, 5000); + } + }); + }, + enabled: false + }; + var table = $('#dataTable').DataTable({ dom: "<'row'<'col-sm-12'B>>" + "<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>>" + @@ -159,7 +204,7 @@ "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", select: true, buttons: [ - 'add', 'edit', 'delete' + 'add', 'edit', 'delete', 'quota_scan' ], "columnDefs": [ { @@ -176,6 +221,7 @@ var selectedRows = table.rows({ selected: true }).count(); table.button(1).enable(selectedRows == 1); table.button(2).enable(selectedRows == 1); + table.button(3).enable(selectedRows == 1); }); });