Skip to content

Commit

Permalink
Make notifications update top panel
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Apr 27, 2024
1 parent 05f2f1c commit c7769ea
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
38 changes: 38 additions & 0 deletions ui/src/js/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
const httpsEnabled = window.location.protocol == "https:";
const url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + "/notifications";

const template = document.querySelector("#notificationTemplate")

let socket = new WebSocket(url)

const alertBadge = document.getElementById("numNotifications");
Expand Down Expand Up @@ -35,6 +37,42 @@ socket.onmessage = function (e) {
background: msg.Color,
}
}).showToast();

if (dropDownlist.querySelector("#" + msg.ID) != null) {
// The event already exists in the notification
return
}

/*
<template id="notificationTemplate">
<a class="notification dropdown-item d-flex align-items-center" id="external">
<div>
<div class="small text-gray-500" id="date"></div>
<span class="font-weight-bold" id="heading"></span>
<div id="message"></div>
</div>
</a>
</template>
*/

const clone = template.content.cloneNode(true);
clone.querySelector("#date").textContent = msg.Time
clone.querySelector("#heading").textContent = msg.Heading

let messages = clone.querySelector("#message")

for (let i = 0; i < msg.Message.length; i++) {
let p = document.createElement("p")
p.textContent = msg.Message[i]

messages.appendChild(p)
}

dropDownlist.appendChild(clone);

alertBadge.textContent = dropDownlist.querySelectorAll(".notification").length
alertBadge.hidden = false
}


Expand Down
5 changes: 3 additions & 2 deletions ui/templates/menus.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</head>

<template id="notificationTemplate">
<a class="dropdown-item d-flex align-items-center" id="external" target="_blank" rel="noopener noreferrer">
<a class="notification dropdown-item d-flex align-items-center" id="external">
<div>
<div class="small text-gray-500" id="date"></div>
<span class="font-weight-bold" id="heading"></span>
Expand All @@ -49,6 +49,7 @@
</a>
</template>


<body id="page-top">
<!-- Main CSRF guard so that JS can read this value and use it -->
{{ csrfToken }}
Expand Down Expand Up @@ -229,7 +230,7 @@ <h6 class="collapse-header">Tools:</h6>
aria-labelledby="alertsDropdown" id="notificationsDropDown">

{{range $val := notifications}}
<a id={{$val.ID}} class="notification dropdown-item d-flex align-items-center"
<a id="{{$val.ID}}" class="notification dropdown-item d-flex align-items-center"
href="{{$val.Url}}" {{if $val.OpenNewTab}}target="_blank" rel="noopener noreferrer"
{{end}}>
<div>
Expand Down

0 comments on commit c7769ea

Please sign in to comment.