commit 01/10/2025

This commit is contained in:
2025-10-01 13:57:20 +07:00
parent 54775641bb
commit c55db5e4f7
23 changed files with 895 additions and 517 deletions

View File

@@ -2,23 +2,23 @@
* List of voice types available
* @type {string[]}
*/
let voiceTypes = [];
window.voiceTypes = [];
/**
* List of categories available
* @type {string[]}
*/
let categories = [];
window.categories = [];
/**
* List of languages available
* @type {string[]}
*/
let languages = [];
window.languages = [];
/**
* List of scheduled days available
* @type {string[]}
*/
let scheduledays = []
window.scheduledays = []
/**
* Create a list item element
@@ -34,7 +34,7 @@ function ListItem(text, className = "") {
* WebSocket connection
* @type {WebSocket}
*/
let ws = null;
window.ws = null;
/**
* Send a command to the WebSocket server.
@@ -42,8 +42,8 @@ let ws = null;
* @param {String} data data to send
*/
function sendCommand(command, data) {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ command, data }));
if (window.ws.readyState === WebSocket.OPEN) {
window.ws.send(JSON.stringify({ command, data }));
}
}
@@ -118,11 +118,11 @@ function fetchImg(url, cbOK, cbError) {
* Reload voice types from server
*/
function getVoiceTypes() {
voiceTypes = [];
window.voiceTypes = [];
fetchAPI("VoiceType", "GET", {}, null, (okdata) => {
// okdata is a string contains elements separated by semicolon ;
if (Array.isArray(okdata)) {
voiceTypes = okdata.filter(item => item.trim().length > 0);
window.voiceTypes = okdata.filter(item => item.trim().length > 0);
//console.log("Loaded " + voiceTypes.length + " voice types : " + voiceTypes.join(", "));
} else console.log("getVoiceTypes: okdata is not array");
}, (errdata) => {
@@ -134,11 +134,11 @@ function getVoiceTypes() {
* Reload categories from server
*/
function getCategories() {
categories = [];
window.categories = [];
fetchAPI("Category", "GET", {}, null, (okdata) => {
// okdata is a string contains elements separated by semicolon ;
if (Array.isArray(okdata)) {
categories = okdata.filter(item => item.trim().length > 0);
window.categories = okdata.filter(item => item.trim().length > 0);
//console.log("Loaded " + categories.length + " categories : " + categories.join(", "));
} else console.log("getCategories: okdata is not array");
}, (errdata) => {
@@ -150,11 +150,11 @@ function getCategories() {
* Reload languages from server
*/
function getLanguages() {
languages = [];
window.languages = [];
fetchAPI("Language", "GET", {}, null, (okdata) => {
// okdata is a string contains elements separated by semicolon ;
if (Array.isArray(okdata)) {
languages = okdata.filter(item => item.trim().length > 0);
window.languages = okdata.filter(item => item.trim().length > 0);
//console.log("Loaded " + languages.length + " languages : " + languages.join(", ") );
} else console.log("getLanguages: okdata is not array");
}, (errdata) => {
@@ -166,11 +166,11 @@ function getLanguages() {
* Reload scheduled days from server
*/
function getScheduledDays() {
scheduledays = [];
window.scheduledays = [];
fetchAPI("ScheduleDay", "GET", {}, null, (okdata) => {
// okdata is a string contains elements separated by semicolon ;
if (Array.isArray(okdata)) {
scheduledays = okdata.filter(item => item.trim().length > 0);
window.scheduledays = okdata.filter(item => item.trim().length > 0);
//console.log("Loaded " + scheduledays.length + " scheduled days : " + scheduledays.join(", ") );
} else console.log("getScheduledDays: okdata is not array");
}, (errdata) => {
@@ -273,43 +273,36 @@ function DoImport(APIURL, cbOK, cbError) {
fileInput.remove();
}
let $onlineindicator = null;
let $cpustatus = null;
let $ramstatus = null;
let $diskstatus = null;
let $networkstatus = null;
let $datetimetext = null;
let greencircle = null;
let redcircle = null;
window.greencircle = null;
window.redcircle = null;
/**
* App entry point
*/
$(document).ready(function () {
document.title = "Automatic Announcement System"
fetchImg('green_circle.png', (url) => { greencircle = url; }, (err) => { console.error("Error loading green_circle.png : ", err); });
fetchImg('red_circle.png', (url) => { redcircle = url; }, (err) => { console.error("Error loading red_circle.png : ", err); });
if (window.greencircle === null){
fetchImg('green_circle.png', (url) => { window.greencircle = url; }, (err) => { console.error("Error loading green_circle.png : ", err); });
}
if (window.redcircle === null){
fetchImg('red_circle.png', (url) => { window.redcircle = url; }, (err) => { console.error("Error loading red_circle.png : ", err); });
}
const wsURL = window.location.pathname + '/ws'
if (chrome && chrome.runtime && chrome.runtime.lastError) {
alert("Runtime error: " + chrome.runtime.lastError.message);
return;
}
$onlineindicator = $('#onlineindicator');
$cpustatus = $('#cpustatus');
$ramstatus = $('#ramstatus');
$diskstatus = $('#diskstatus');
$networkstatus = $('#networkstatus');
$datetimetext = $('#datetimetext');
// reset status indicators
function resetStatusIndicators() {
$onlineindicator.attr('src', redcircle);
$cpustatus.text("CPU : N/A");
$ramstatus.text("RAM : N/A");
$diskstatus.text("Disk : N/A");
$networkstatus.text("Network : N/A");
$datetimetext.text("Date/Time : N/A");
$('#onlineindicator').attr('src', window.redcircle);
$('#cpustatus').text("CPU : N/A");
$('#ramstatus').text("RAM : N/A");
$('#diskstatus').text("Disk : N/A");
$('#networkstatus').text("Network : N/A");
$('#datetimetext').text("Date/Time : N/A");
}
@@ -321,44 +314,47 @@ $(document).ready(function () {
// Initialize WebSocket connection
ws = new WebSocket(wsURL);
window.ws = new WebSocket(wsURL);
ws.onopen = () => {
window.ws.onopen = () => {
console.log('WebSocket connection established');
$onlineindicator.attr('src', greencircle);
$('#onlineindicator').attr('src', window.greencircle);
};
ws.onmessage = (event) => {
window.ws.onmessage = (event) => {
if ($('#onlineindicator').attr('src') !== window.greencircle) {
$('#onlineindicator').attr('src', window.greencircle);
}
let rep = JSON.parse(event.data);
let cmd = rep.reply
let data = rep.data;
if (cmd && cmd.length > 0) {
switch (cmd) {
case "getCPUStatus":
$cpustatus.text("CPU : " + data)
$('#cpustatus').text("CPU : " + data)
break;
case "getMemoryStatus":
$ramstatus.text("RAM : " + data)
$('#ramstatus').text("RAM : " + data)
break;
case "getDiskStatus":
$diskstatus.text("Disk : " + data)
$('#diskstatus').text("Disk : " + data)
break;
case "getNetworkStatus":
$networkstatus.text("Network : " + data)
$('#networkstatus').text("Network : " + data)
break;
case "getSystemTime":
$datetimetext.text(data)
$('#datetimetext').text(data)
break;
}
}
};
ws.onclose = () => {
window.ws.onclose = () => {
console.log('WebSocket connection closed');
resetStatusIndicators();
};
// ws.onerror = (error) => {
// window.ws.onerror = (error) => {
// console.error('WebSocket error:', error);
// };
@@ -457,6 +453,18 @@ $(document).ready(function () {
}
});
})
$('#usermanagement').click(() => {
sidemenu.hide();
$('#content').load('usermanagement.html', function (response, status, xhr) {
if (status === "success") {
console.log("User Management content loaded successfully");
// pindah ke usermanagement.js
} else {
console.error("Error loading user management content:", xhr.status, xhr.statusText);
}
});
});
$('#settinglink').click(() => {
sidemenu.hide();
$('#content').load('setting.html', function (response, status, xhr) {