aboutsummaryrefslogtreecommitdiff
path: root/src/public/js/logviewer.js
blob: d376196f60a6e98632ff16dcd2f2ab8af9e40f78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
let socket = io();

module.exports = () => {
    M.AutoInit();

    socket.emit("GetLog", {filter: "success error event debug python info warning", entryN: 1000});
    socket.on("lastLogEntries", (entries) => {
        M.toast({html: "Loading log-files..."});
        console.log("Log-entries received: " + entries.length);
        let HTMLBasicTable = "";
        let HTMLAdvancedTable = "";
        let HTMLScriptTable = "";
        let HTMLRAWTable = "";

        entries.forEach((entry) => {
            let strHTML = "<tr><td>" + prettifyType(entry.type) + "</td><td>" + entry.time + "</td><td>" + entry.details + "</td></tr>";

            if (entry.type === "SUCCESS") { HTMLBasicTable += strHTML; }
            if (entry.type === "ERROR") { HTMLBasicTable += strHTML; }
            if (entry.type === "EVENT") { HTMLBasicTable += strHTML; }
            if (entry.type === "PYTHON") { HTMLScriptTable += strHTML; }
            if (entry.type !== "PYTHON") { HTMLAdvancedTable += strHTML; }

            //HTMLRAWTable += entry.join(" ");
        });

        document.getElementById("log-table-basic").innerHTML = HTMLBasicTable;
        document.getElementById("log-table-script").innerHTML = HTMLScriptTable;
        document.getElementById("log-table-advanced").innerHTML = HTMLAdvancedTable;
        //document.getElementById("log-table-raw").innerHTML = HTMLRAWTable;

    });

    socket.on("newLogEntry", (entry) => {
        if (entry.type === "SUCCESS") { appendEntryToTable("log-table-basic", entry); }
        if (entry.type === "ERROR") { appendEntryToTable("log-table-basic", entry); }
        if (entry.type === "EVENT") { appendEntryToTable("log-table-basic", entry); }
        if (entry.type === "PYTHON") { appendEntryToTable("log-table-script", entry); }
        if (entry.type !== "PYTHON") { appendEntryToTable("log-table-advanced", entry); }
    });

};

function appendEntryToTable(tableName, entry) {
    let newEntry = document.getElementById(tableName).insertRow(0);
    newEntry.insertCell(0).innerHTML = prettifyType(entry.type);
    newEntry.insertCell(1).innerHTML = entry.time;
    newEntry.insertCell(2).innerHTML = entry.details;
    M.AutoInit();
    newEntry.className = "newLogEntry";
}

function prettifyType(type) {
    let prettyTable = {
        "DEBUG": `<span class="tooltipped" data-position="top" data-tooltip="Debug-log">😸</span>`,
        "INFO": `<span class="tooltipped" data-position="top" data-tooltip="Just some information">ℹ️</span>`,
        "WARNING": `<span class="tooltipped" data-position="top" data-tooltip="A warning">⚠️</span>`,
        "EVENT": `<span class="tooltipped" data-position="top" data-tooltip="Event">⚡️</span>`,
        "SUCCESS": `<span class="tooltipped" data-position="top" data-tooltip="Something exited successfully">✅</span>`,
        "ERROR": `<span class="tooltipped" data-position="top" data-tooltip="Error">🔴</span>`,
        "PYTHON": `<span class="tooltipped" data-position="top" data-tooltip="Output from user-script">🐍</span>`
    };
    return prettyTable[type];
}