]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Try getting bootstrap toasts working
authorValerie Pond <redacted>
Thu, 13 Apr 2023 14:06:16 +0000 (15:06 +0100)
committerValerie Pond <redacted>
Thu, 13 Apr 2023 14:06:16 +0000 (15:06 +0100)
api/notification.php
api/users.php [new file with mode: 0644]
js/unrealircd-admin.js
users/index.php

index 42c23fc7b441610f2038ded105b6dbfa469baf71..40eee2bcd37d7ac2fe00d83c33e6d9201348467b 100644 (file)
@@ -3,7 +3,6 @@ include "../common.php";
 include "../connection.php";
 
 
-session_start();
 if (!isset($_SESSION['id']))
     die("Access denied");
 
@@ -34,9 +33,9 @@ ob_end_flush();
 if (function_exists('fastcgi_finish_request'))
     fastcgi_finish_request();
 
-$sources = ["!debug","all"];
+
+$sources = (isset($_GET['s']) && !empty($_GET['s'])) ? split($_GET['s'],",") : ["!debug","all"];
 $rpc->log()->subscribe($sources);
-echo $rpc->error;
 for(;;)
 {
     $res = $rpc->eventloop();
diff --git a/api/users.php b/api/users.php
new file mode 100644 (file)
index 0000000..c0a3009
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+require_once "../common.php";
+require_once "../connection.php";
+
+header('Content-Type: application/json');
+
+if (!isset($_SESSION['id']))
+    die("Access denied");
+
+if (!isset($_GET) || empty($_GET))
+{
+    if ($list = $rpc->user()->getAll())
+        echo json_encode($list);
+    else
+        echo json_encode(["error" => "No users found"]);
+    die();
+}
+elseif (isset($_GET['lookup']))
+{
+    if ($user = $rpc->user()->get($_GET['lookup']))
+        echo json_encode($user);
+    else
+        echo json_encode(["error" => "User not found"]);
+    die();
+}
+
+else // we're filtering
+{
+    if (!($list = $rpc->user()->getAll()))
+    {
+        echo json_encode(["error" => "No users found"]);
+        die();
+    }
+
+    $return_list = [];
+    
+    if (isset($_GET['nick']) && !empty($_GET['nick']) && $nick = strtolower($_GET['nick']))
+    {
+        foreach ($list as $user)
+        {
+            if (strstr(strtolower($user->name), $nick))
+                $return_list[] = $user;
+        }
+    }
+    if (isset($_GET['hostname']) && !empty($_GET['hostname']) && $nick = strtolower($_GET['hostname']))
+    {
+        foreach ($list as $user)
+        {
+            if (strstr(strtolower($user->name), $nick))
+                $return_list[] = $user;
+        }
+    }
+    echo json_encode($return_list);
+    
+}
\ No newline at end of file
index 2fbe970b7dad0e49243d99c05c36ee8d3d70e1f9..c68f11a074f5ed6e1b1e40d413865f3b4414390c 100644 (file)
@@ -62,21 +62,3 @@ function toggle_checkbox(source) {
         checkboxes[i].checked = source.checked;
     }
 }
-
-function generate_bs_notif(id, title, body)
-{
-    document.write('<div class="position-fixed bottom-0 right-0 p-3" style="z-index: 5; right: 0; bottom: 50px;">');
-    document.write('    <div id="' + id + '" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true" data-delay="10000">');
-    document.write('        <div class="toast-header">');
-    document.write('            <strong class="mr-auto">' + title + '</strong>');
-    document.write('            <small>11 mins ago</small>');
-    document.write('            <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">');
-    document.write('                <span aria-hidden="true">&times;</span>');
-    document.write('            </button>');
-    document.write('        </div>');
-    document.write('        <div class="toast-body">');
-    document.write(body);
-    document.write('        </div>');
-    document.write('        </div>');
-    document.write('</div>');
-}
\ No newline at end of file
index bed62b65ec6789c76e4685004304acafb9419ba6..01f875844e442fff213a3c35ba75e3bc7ca7d6d2 100644 (file)
@@ -323,10 +323,12 @@ Click on a username to view more information.
                        width: 250px;
                        background: #1b1a1a;
                        border-radius: 5px;
-                       display: none;
+                       transform: scale(0);
+                       transform-origin: top left;
                }
                #rclickmenu.visible {
-                       display: block;
+                       transform: scale(1);
+                       transition: transform 120ms ease-in-out;
                }
                #rclickmenu .item {
                        padding: 8px 10px;
@@ -341,9 +343,10 @@ Click on a username to view more information.
                }
        </style>
 
-       <div id='rclickmenu'>
+       <div id='rclickmenu' class="nav-item list-group">
                <div id="rclick_opt1" class="item list-group-item-action">View details</div>
                <div id="rclick_opt2" class="item list-group-item-action">Kill</div>
+               <div id="rclick_opt3" class="item list-group-item-action">Copy
        </div>
 
 <?php /* ?>
@@ -369,9 +372,92 @@ Click on a username to view more information.
 
 <script>
     
+
+       function generate_notif(title, body)
+       {
+               /* generate a random number between 1000 and 90000 to use as an id */
+               const min = 1000;
+               const max = 90000;
+               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');
+
+               const header = document.createElement('div');
+               header.classList.add('toast-header');
+
+               const theTitle = document.createElement('strong');
+               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 closebutton = document.createElement('button');
+               closebutton.type = 'button';
+               closebutton.classList.add('ml-2', 'mb-1', 'close');
+               closebutton.setAttribute('data-dismiss', 'toast');
+               closebutton.ariaLabel = 'Close';
+
+               const closebuttonspan = document.createElement('span');
+               closebuttonspan.ariaHidden = 'true';
+               closebuttonspan.innerHTML = "&times;";
+
+               const toastbody = document.createElement('div');
+               toastbody.classList.add('toast-body');
+               toastbody.textContent = body;
+
+
+               /* put it all together */
+               closebutton.appendChild(closebuttonspan);
+               header.appendChild(theTitle);
+               header.appendChild(notiftime);
+               header.appendChild(closebutton);
+               inner.appendChild(header);
+               inner.appendChild(toastbody);
+               toast.appendChild(inner);
+
+               document.body.appendChild(toast);
+               $('#' + inner.id).toast('show');
+       }
     $("#myModal").on('shown.bs.modal', function(){
         $("#CloseButton").focus();
     });
+       function StreamNotifs(e)
+       {
+               var data;
+               try {
+                       data = JSON.parse(e.data);
+               } catch(e) {
+                       return;
+               }
+               title = data.subsystem + '.' + data.event_id;
+               msg = data.msg;
+               generate_notif(title, msg);
+
+               
+       }
+       function StartStreamNotifs()
+       {
+               var base_url = '<?php echo get_config("base_url") ?>';
+               if (!!window.EventSource) {
+                       var source = new EventSource(base_url + 'api/notification.php');
+                       source.addEventListener('message', StreamNotifs, false);
+               }
+       }
+       StartStreamNotifs();
+
 
        function resize_check()
        {
@@ -391,11 +477,12 @@ Click on a username to view more information.
        });
        var rclickmenu = document.getElementById('rclickmenu');
        var scopes = document.querySelectorAll('.userselector');
-       var usertable = document.querySelector('body');
-       usertable.addEventListener("click", (e) =>
+       document.addEventListener("click", (e) =>
        {
-               rclickmenu.classList.remove("visible");
-               rclickmenu.style.display = 'none';
+               if (e.target.offsetParent != rclickmenu)
+               {
+                       rclickmenu.classList.remove("visible");
+               }
        });
        scopes.forEach((scope) => {
                scope.addEventListener("contextmenu", (event) =>
@@ -403,14 +490,19 @@ Click on a username to view more information.
                        event.preventDefault();
                        var { clientX: mouseX, clientY: mouseY } = event;
                        var name = $('#' + scope.id).attr('value')
-                       document.getElementById("rclick_opt1").innerHTML = '<a style="text-decoration: none" href="<?php echo get_config("base_url"); ?>users/details.php?nick=' + scope.id + '">View details for ' + name + '</a>';
+                       document.getElementById("rclick_opt1").innerHTML = 'View details for ' + name;
                        rclickmenu.style.top = `${mouseY}px`;
                        rclickmenu.style.left = `${mouseX}px`;
-                       rclickmenu.classList.add("visible");
-                       rclickmenu.style.display = '';
+                       rclickmenu.classList.remove("visible");
+                       setTimeout(() => { rclickmenu.classList.add("visible"); });
                });
-               
        });
+       document.addEventListener('keydown', (event) => {
+       if (event.key === 'Escape')
+       {
+               rclickmenu.classList.remove("visible");
+       }
+});
 </script>
 
 <?php require_once UPATH.'/footer.php'; ?>