From 0c841ce60b6b132f91404e382f6164340c0ef5ea Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Mon, 30 Nov 2015 13:04:38 -0500 Subject: [PATCH] Committing in a bad state...search is half-working --- admin/view_message_log.php | 17 +++++++- internal-api/js/view-message-log.js | 61 ++++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/admin/view_message_log.php b/admin/view_message_log.php index 3c1ad83b..961eaf77 100644 --- a/admin/view_message_log.php +++ b/admin/view_message_log.php @@ -58,7 +58,7 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); - + @@ -67,6 +67,21 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
Logs
+
+ + + + + + + + + + + + +
DateUserLocationMessage
+
diff --git a/internal-api/js/view-message-log.js b/internal-api/js/view-message-log.js index 8c106be6..a90ad7f7 100644 --- a/internal-api/js/view-message-log.js +++ b/internal-api/js/view-message-log.js @@ -1,21 +1,64 @@ $(document).ready(function() { // We should show the latest 50 logs when the user first views the page. + searchLogs(null, null, null, null); + + $('#search-button').click(function() { + var location = getNullableField($('input[name="location"]').val()); + }); +}); + +function getNullableField(value) { + return value !== "" ? value : null; +} + +function searchLogs(location, fromDate, toDate, severity) { var endpoint = getHelpdeskUrl(); endpoint += '/internal-api/admin/message-log/'; + $.ajax({ url: endpoint, data: { - location: null, - fromDate: null, - toDate: null, - severityId: null + location: location, + fromDate: fromDate, + toDate: toDate, + severityId: severity }, method: 'POST', - success: function(data) { - console.log(data); - }, + success: displayResults, error: function(data) { console.error(data); } - }) -}) \ No newline at end of file + }); +} + +function displayResults(data) { + data = $.parseJSON(data); + var table = $('#results-table > tbody'); + table.empty(); + + if (data.length === 0) { + table.append('No results found'); + } else { + for (var index in data) { + var result = data[index]; + table.append('' + + '' + result.timestamp + '' + + '' + result.username + '' + + '' + result.location + '' + + '' + result.message + ''); + } + } +} + +function getRowColor(result) { + switch (result.severity) { + case "1": + return 'class="info"'; + case "2": + return 'class="warning"'; + case "3": + return 'class="danger"'; + } + + return ''; +} \ No newline at end of file