commit 22/01/2026

This commit is contained in:
2026-01-22 15:31:13 +07:00
parent ffd41ee225
commit 4aea9cb619
8 changed files with 73 additions and 36 deletions

View File

@@ -9,7 +9,7 @@ $(document).ready(function() {
});
});
$(window).on('beforeunload', function() {
$(window).on('unload', function() {
console.log("User is leaving home.html");
// Your cleanup code here
});

View File

@@ -1,4 +1,4 @@
$(document).ready(function() {
$(document).ready(function () {
// Your code here
console.log("log.js is loaded and ready.");
let $logchooser = $('#logchooser');
@@ -7,19 +7,19 @@ $(document).ready(function() {
$logchooser.val(new Date().toISOString().split('T')[0]);
}
$('#logoutbtn').on('click', function() {
$('#logoutbtn').on('click', function () {
// Clear session storage on logout
fetch('/logout').then(() => {
window.location.href = '/login.html';
window.location.href = '/login.html';
});
});
$logchooser.on('change', function() {
$logchooser.on('change', function () {
const selectedLog = $(this).val();
GetLog(selectedLog);
});
});
$(window).on('beforeunload', function() {
$(window).on('unload', function () {
console.log("User is leaving log.html");
// Your cleanup code here
});
@@ -27,9 +27,42 @@ $(window).on('beforeunload', function() {
// function GetLog with date parameter in string, with default value today's date in format dd/mm/yyyy
function GetLog(date = new Date().toISOString().split('T')[0]) {
console.log("Fetching logs for date: " + date);
Get('getLogs?'+new URLSearchParams({date: date}).toString(), function(data){
Get('getLogs?' + new URLSearchParams({ date: date }).toString(), function (data) {
console.log(data);
}, function(error){
fill_table(data);
}, function (error) {
fill_table(null);
alert(error);
})
}
/**
* @typedef {Object} logdata
* @property {number} index Index number of the log entry
* @property {string} date Date string in format dd/mm/yyyy
* @property {string} time Time string in format HH:MM:SS
* @property {string} function Function name where the log was generated
* @property {string} message Log message
*/
/**
* Fill table with logdata
* @param {logdata[]} data
*/
function fill_table(data) {
let $logtablebody = $('#logtablebody');
$logtablebody.empty();
if (data && Array.isArray(data) && data.length > 0) {
data.forEach(function (logentry) {
let row = `<tr>
<td>${logentry.index}</td>
<td>${logentry.date}</td>
<td>${logentry.time}</td>
<td>${logentry.function}</td>
<td>${logentry.message}</td>
</tr>`;
$logtablebody.append(row);
});
}
}

View File

@@ -7,7 +7,7 @@ $(document).ready(function() {
}
});
$(window).on('beforeunload', function() {
$(window).on('unload', function() {
console.log("User is leaving login.html");
// Your cleanup code here
});

View File

@@ -20,7 +20,7 @@ $(document).ready(function () {
});
});
$(window).on('beforeunload', function () {
$(window).on('unload', function () {
console.log("User is leaving setting.html");
// Your cleanup code here
});