fix event log ordering, paging, add timestamp

This commit is contained in:
Hay1tsme 2024-06-16 14:42:23 -04:00
parent 00224585bb
commit 784ac544f0
2 changed files with 29 additions and 13 deletions

View File

@ -109,7 +109,7 @@ class BaseData:
return result.lastrowid return result.lastrowid
async def get_event_log(self, entries: int = 100) -> Optional[List[Row]]: async def get_event_log(self, entries: int = 100) -> Optional[List[Row]]:
sql = event_log.select().limit(entries) sql = event_log.select().order_by(event_log.c.id.desc()).limit(entries)
result = await self.execute(sql) result = await self.execute(sql)
if result is None: if result is None:

View File

@ -6,6 +6,7 @@
<thead> <thead>
<tr> <tr>
<th>Severity</th> <th>Severity</th>
<th>Timestamp</th>
<th>System</th> <th>System</th>
<th>Name</th> <th>Name</th>
<th>User</th> <th>User</th>
@ -19,7 +20,7 @@
</thead> </thead>
{% if events is not defined or events|length == 0 %} {% if events is not defined or events|length == 0 %}
<tr> <tr>
<td colspan="10" style="text-align:center"><i>No Events</i></td> <td colspan="11" style="text-align:center"><i>No Events</i></td>
</tr> </tr>
{% endif %} {% endif %}
</table> </table>
@ -66,7 +67,11 @@ function update_tbl() {
for (var i = 0; i < per_page; i++) { for (var i = 0; i < per_page; i++) {
let off = (page * per_page) + i; let off = (page * per_page) + i;
if (off >= TBL_DATA.length ) { if (off >= TBL_DATA.length) {
if (page != 0) {
document.getElementById("btn_next").disabled = true;
document.getElementById("btn_prev").disabled = false;
}
break; break;
} }
@ -99,56 +104,59 @@ function update_tbl() {
row.classList.add("table-primary"); row.classList.add("table-primary");
break; break;
} }
var cell_ts = row.insertCell(1);
cell_ts.innerHTML = data.when_logged;
var cell_mod = row.insertCell(1); var cell_mod = row.insertCell(2);
cell_mod.innerHTML = data.system; cell_mod.innerHTML = data.system;
var cell_name = row.insertCell(2); var cell_name = row.insertCell(3);
cell_name.innerHTML = data.type; cell_name.innerHTML = data.type;
var cell_usr = row.insertCell(3); var cell_usr = row.insertCell(4);
if (data.user == 'NONE') { if (data.user == 'NONE') {
cell_usr.innerHTML = "---"; cell_usr.innerHTML = "---";
} else { } else {
cell_usr.innerHTML = "<a href=\"/user/" + data.user + "\">" + data.user + "</a>"; cell_usr.innerHTML = "<a href=\"/user/" + data.user + "\">" + data.user + "</a>";
} }
var cell_arcade = row.insertCell(4); var cell_arcade = row.insertCell(5);
if (data.arcade == 'NONE') { if (data.arcade == 'NONE') {
cell_arcade.innerHTML = "---"; cell_arcade.innerHTML = "---";
} else { } else {
cell_arcade.innerHTML = "<a href=\"/shop/" + data.arcade + "\">" + data.arcade + "</a>"; cell_arcade.innerHTML = "<a href=\"/shop/" + data.arcade + "\">" + data.arcade + "</a>";
} }
var cell_machine = row.insertCell(5); var cell_machine = row.insertCell(6);
if (data.arcade == 'NONE') { if (data.arcade == 'NONE') {
cell_machine.innerHTML = "---"; cell_machine.innerHTML = "---";
} else { } else {
cell_machine.innerHTML = "<a href=\"/cab/" + data.machine + "\">" + data.machine + "</a>"; cell_machine.innerHTML = "<a href=\"/cab/" + data.machine + "\">" + data.machine + "</a>";
} }
var cell_game = row.insertCell(6); var cell_game = row.insertCell(7);
if (data.game == 'NONE') { if (data.game == 'NONE') {
cell_game.innerHTML = "---"; cell_game.innerHTML = "---";
} else { } else {
cell_game.innerHTML = data.game; cell_game.innerHTML = data.game;
} }
var cell_version = row.insertCell(7); var cell_version = row.insertCell(8);
if (data.version == 'NONE') { if (data.version == 'NONE') {
cell_version.innerHTML = "---"; cell_version.innerHTML = "---";
} else { } else {
cell_version.innerHTML = data.version; cell_version.innerHTML = data.version;
} }
var cell_msg = row.insertCell(8); var cell_msg = row.insertCell(9);
if (data.message == '') { if (data.message == '') {
cell_msg.innerHTML = "---"; cell_msg.innerHTML = "---";
} else { } else {
cell_msg.innerHTML = data.message; cell_msg.innerHTML = data.message;
} }
var cell_deets = row.insertCell(9); var cell_deets = row.insertCell(10);
if (data.details == '{}') { if (data.details == '{}') {
cell_deets.innerHTML = "---"; cell_deets.innerHTML = "---";
} else { } else {
@ -160,9 +168,11 @@ function update_tbl() {
function chg_page(num) { function chg_page(num) {
var max_page = TBL_DATA.length / per_page; var max_page = TBL_DATA.length / per_page;
console.log(max_page);
page = page + num; page = page + num;
if (page > max_page) {
if (page > max_page && max_page >= 1) {
page = max_page; page = max_page;
document.getElementById("btn_next").disabled = true; document.getElementById("btn_next").disabled = true;
document.getElementById("btn_prev").disabled = false; document.getElementById("btn_prev").disabled = false;
@ -172,6 +182,12 @@ function chg_page(num) {
document.getElementById("btn_next").disabled = false; document.getElementById("btn_next").disabled = false;
document.getElementById("btn_prev").disabled = true; document.getElementById("btn_prev").disabled = true;
return; return;
} else if (page == 0) {
document.getElementById("btn_next").disabled = false;
document.getElementById("btn_prev").disabled = true;
} else {
document.getElementById("btn_next").disabled = false;
document.getElementById("btn_prev").disabled = false;
} }
update_tbl(); update_tbl();