]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - js/unrealircd-admin.js
More towards notes (still not finished)
[irc/unrealircd/unrealircd-webpanel.git] / js / unrealircd-admin.js
index 8c7ee0c867cfd89f893602a1f24777bf88e2b4c2..688fc3b5a3a596753f800ff92a39b55019350097 100644 (file)
@@ -63,6 +63,8 @@ function toggle_checkbox(source) {
     }
 }
 
+/* Popup notifications */
+
 function generate_notif(title, body)
 {
     /* generate a random number between 1000 and 90000 to use as an id */
@@ -71,18 +73,12 @@ function generate_notif(title, body)
     const id = Math.floor(Math.random() * (max - min + 1)) + min;
 
     const toast = document.createElement('div');
-    toast.classList.add('position-fixed', 'bottom-0', 'right-0', 'p-4');
-    toast.style.right = 0;
-    toast.style.zIndex = 5;
-    toast.style.bottom = "50px";
-
-    const inner = document.createElement('div');
-    inner.classList.add('toast', 'hide');
-    inner.id = 'toast' + id;
-    inner.role = 'alert';
-    inner.ariaLive = 'assertive';
-    inner.ariaAtomic = 'true';
-    inner.setAttribute('data-delay', '5000');
+    toast.classList.add('toast', 'hide');
+    toast.id = 'toast' + id;
+    toast.role = 'alert';
+    toast.ariaLive = 'assertive';
+    toast.ariaAtomic = 'true';
+    toast.setAttribute('data-delay', '10000');
 
     const header = document.createElement('div');
     header.classList.add('toast-header');
@@ -91,8 +87,9 @@ function generate_notif(title, body)
     theTitle.classList.add('mr-auto');
     theTitle.textContent = title;
     
-    const notiftime = document.createElement('small');
-    notiftime.textContent = "Just now"; // always just now I think right :D
+    const notiftime = document.createElement('div');
+    notiftime.classList.add('badge', 'rounded-pill', 'badge-primary', 'ml-1');
+    notiftime.textContent = 'Just now'; // always just now I think right :D
 
     const closebutton = document.createElement('button');
     closebutton.type = 'button';
@@ -114,16 +111,13 @@ function generate_notif(title, body)
     header.appendChild(theTitle);
     header.appendChild(notiftime);
     header.appendChild(closebutton);
-    inner.appendChild(header);
-    inner.appendChild(toastbody);
-    toast.appendChild(inner);
+    toast.appendChild(header);
+    toast.appendChild(toastbody);
+    document.getElementById('toaster').append(toast);
 
-    document.body.appendChild(toast);
-    $('#' + inner.id).toast('show');
+    $('#' + toast.id).toast('show');
 }
-$("#myModal").on('shown.bs.modal', function(){
-    $("#CloseButton").focus();
-});
+
 function StreamNotifs(e)
 {
     var data;
@@ -136,10 +130,48 @@ function StreamNotifs(e)
     msg = data.msg;
     generate_notif(title, msg);
 }
+
 function StartStreamNotifs(url)
 {
     if (!!window.EventSource) {
         var source = new EventSource(url);
         source.addEventListener('message', StreamNotifs, false);
     }
-}
\ No newline at end of file
+}
+
+/* Log streamer */
+function NewLogEntry(e)
+{
+    var data;
+    try {
+        data = JSON.parse(e.data);
+    } catch(e) {
+        return;
+    }
+
+    if (data.sync_option != "sync_now")
+    {
+        var sync = (data.sync_option == "no_sync") ? false : true;
+        delete data.sync_option;
+
+        data_list_table.row.add({
+            'Time':data.timestamp,
+            'Level':data.level,
+            'Subsystem':data.subsystem,
+            'Event':data.event_id,
+            'Message':data.msg,
+            'Raw':JSON.stringify(data)});
+
+        if (!sync)
+            return;
+    }
+    data_list_table.draw(true);
+    data_list_table.rows().invalidate();
+    data_list_table.searchPanes.rebuildPane();
+}
+
+function StartLogStream(url)
+{
+    var source = new EventSource(url);
+    source.addEventListener('message', NewLogEntry, false);
+}