From a8c25f1faa941f3465975d36678fba2586d60bbe Mon Sep 17 00:00:00 2001 From: johnnyq Date: Fri, 20 Nov 2026 18:43:29 -0500 Subject: [PATCH] Show desktop notifications in the bell panel as a switch that says whether they are on, off or blocked in this browser, skip the permission prompt when the browser already allows them, and keep the switch in step across tabs --- CHANGELOG.md | 4 +-- css/itflow_custom.css | 31 ++++++++++++++--- js/notifications.js | 8 +++-- js/ticket_pulse.js | 78 +++++++++++++++++++++++++++++-------------- 4 files changed, 87 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48228d926..7ffcdc624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -156,7 +156,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Tickets: a ticket the client has written on since you last opened it is in bold on the tickets list - a reply from them, or a ticket they raised by email, in the portal or by text. Opening the ticket or its quick look takes the bold away, and so does Bulk Action > Mark as read. Each agent has their own; tickets from before the update count as read. - Tickets: rest the pointer on a ticket's Activity on the tickets list to see its last reply - who, when and what it said. - The tickets list's browser tab shows how many open tickets are assigned to you, such as "(3) Real MSP - Tickets" - kept up to date in the background, so you see it from another tab. -- Desktop notifications: Turn on desktop notifications, at the bottom of the bell's panel, and a ticket assigned to you or a client's reply on one of yours shows as a notification on your computer while you're away from ITFlow. Each browser has its own switch, and asks your permission first. +- Desktop notifications: turn on the Desktop notifications switch at the bottom of the bell's panel, and a ticket assigned to you or a client's reply on one of yours shows as a notification on your computer while you're away from ITFlow. Each browser has its own switch, and asks your permission first. The panel shows whether they're on, off or blocked in the browser you're using. - Documents: Edit opens a document on a page of its own, with the editor filling the window and its toolbar always in view - long documents no longer squeeze into a window over the page. - Documents: Copy, in a document's menu, copies it for the same client or another - content, summary, tags and pictures, out of the client portal and linked to nothing. - Documents: a document with three headings or more has a Contents list beside it, to jump to a section - Knowledge Base articles too. @@ -392,7 +392,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - `js/pretty_content.js` marks a `.prettyContent` picture shown smaller than it is (not one in a link) `itflow-zoomable` and opens it in a fixed layer on click; Escape closes the layer without closing a window under it. - Tickets: database 4.0.2 adds `ticket_reads` (ticket, agent, `read_at`; ticket 0 is the agent's starting point, made by `ticketReadsSince()` the first time their list loads). `functions/ticket_read.php` has `ticketReadsReady()`, `ticketMarkRead()` (from `agent/ticket.php`, the quick look and the new `bulk_mark_tickets_read`), `ticketUnreadSql()` - a Client reply, or a ticket raised by Email, Portal or Text, newer than the agent's read or starting point, on a ticket not closed, selected as `ticket_unread` on the list view - and `ticketReadsCleanup()`, run nightly for closed or deleted tickets and archived agents. On the list, open subjects that have been read are no longer semibold; unread ones are bold. - Tickets: list rows carry `data-ticket-id` and `data-ticket-sig`, a hash of what the row shows. `agent/js/tickets_live.js` fetches the same address once a minute while the tab is visible, swaps in rows whose signature changed (not ticked, no menu open), marks rows no longer there `itflow-row-gone`, counts new ones in `[data-tickets-live-bar]` and copies the pills' counts. `agent/js/ticket_reply_peek.js` shows `agent/ajax.php?ticket_reply_peek` - the last reply, or the details when there is none, as `emailPlainText()` - in a Bootstrap popover over `[data-reply-peek]`. -- `js/ticket_pulse.js` (every agent page, for Support) asks `agent/ajax.php?ticket_pulse` once a minute per browser - localStorage keeps the answer and a lock, and other tabs pick it up from the `storage` event - and puts the count of open tickets assigned to the agent (`TICKET_OPEN_SQL` and `ticketAssignedSql()`, as the Mine view) in front of `document.title` on `agent/tickets.php` - other pages keep their title. With desktop notifications on (localStorage, per agent and browser, switched from `[data-desktop-notify]` in the bell's panel) it also asks for the assigned tickets not closed and Client replies on them after the last `reply_max`, works out newly assigned ones against the last answer, asks `about=` for up to five, and shows a `Notification` for each - not while an ITFlow tab has had the focus in the last 10 seconds, nor after a gap of more than 10 minutes. +- `js/ticket_pulse.js` (every agent page, for Support) asks `agent/ajax.php?ticket_pulse` once a minute per browser - localStorage keeps the answer and a lock, and other tabs pick it up from the `storage` event - and puts the count of open tickets assigned to the agent (`TICKET_OPEN_SQL` and `ticketAssignedSql()`, as the Mine view) in front of `document.title` on `agent/tickets.php` - other pages keep their title. With desktop notifications on (localStorage, per agent and browser, switched from the `[data-desktop-switch]` checkbox in the bell's `[data-desktop-notify]` row, which `label()` keeps in step with the browser's permission and with other tabs through the `storage` event) it also asks for the assigned tickets not closed and Client replies on them after the last `reply_max`, works out newly assigned ones against the last answer, asks `about=` for up to five, and shows a `Notification` for each - not while an ITFlow tab has had the focus in the last 10 seconds, nor after a gap of more than 10 minutes. - Documents: `agent/document_edit.php` is Edit on a page, posting `edit_document` as the window did, with `document_form.php`'s editor as `.tinymce-page` - a second TinyMCE set-up in `js/app.js` sharing the document editor's options (`itflowDocumentEditor`), without autoresize and sized to the window on init and resize. The document page, Files' menus and "Start writing" link to it; other places still open `document_edit.php` the window. `copy_document` (`agent/modals/document/document_copy.php`) uses new `documentCopy()` in `functions/files.php`, which copies `uploads/documents/` and rewrites the content's paths to the copy's, as `kbArticleFromDocument()` does. `toggle_document_favorite` sets the existing, unused `document_favorite`, which `clientOverviewFavorites()` now lists as `documents`. - Documents: new `functions/text_diff.php` - `textDiffLines()` (HTML to lines through `emailPlainText()`, pictures as `[Picture]`, table cells joined with |), `textDiffOps()` (longest common subsequence after matching the shared start and end, capped at 250,000 cells), `textDiffWordsHtml()` and `textDiffHtml()`, which pairs taken-out and put-in lines that `similar_text()` puts at 50% or more and folds unchanged lines more than two from a change. Shown by `agent/modals/document/document_changes.php` (`document_id`, and `version_id` or none for the last edit). `js/document_contents.js` builds `[data-document-contents]` from the `h1`-`h4` in `.itflow-document-body` when there are three or more, giving each an id. - Files: `upload_files` takes `file_paths[]`, each file's path under the folder chosen, and `folderForUploadPath()` finds or makes its folders (matching names case-insensitively, ten levels at most); with `upload_json` it answers `{uploaded, skipped, folders}` instead of a flash, and `upload_folder_done` makes the flash from the totals. `file_upload.php` sends a folder (`webkitdirectory`, or dropped entries walked with `webkitGetAsEntry`) 20 files or 100 MB at a time, leaving out `.DS_Store`, `Thumbs.db`, `desktop.ini` and hidden folders; `agent/js/files.js` hands it dropped folders through `input.itflowWalk` and `input.itflowTakeFolder`. `download_folder_zip` (GET) and `bulk_download_files` build a `ZipArchive` in the temp folder with `filesZipSend()` and `filesZipFolderItems()` - files by their stored name, documents as purified HTML pages, names made safe and numbered when they clash, 2 GB at most. `files_rename` in `agent/ajax.php` renames from the list. diff --git a/css/itflow_custom.css b/css/itflow_custom.css index be657055e..9415fdcd9 100644 --- a/css/itflow_custom.css +++ b/css/itflow_custom.css @@ -2833,13 +2833,34 @@ body { .itflow-notify-foot:hover { background-color: rgba(var(--bs-emphasis-color-rgb), .05); } -/* Desktop notifications on or off, under the link (js/ticket_pulse.js) */ +/* Desktop notifications on, off or blocked here, with a switch, under the link (js/ticket_pulse.js) */ .itflow-notify-desktop { - width: 100%; + display: flex; + align-items: center; + gap: .6rem; + margin: 0; + text-align: left; + color: var(--bs-body-color); + cursor: pointer; +} +.itflow-notify-desktop > .fa-desktop { color: var(--bs-secondary-color); - background: none; - border: 0; - border-top: 1px solid var(--bs-border-color); +} +.itflow-notify-desktop.is-on > .fa-desktop { + color: var(--bs-success); +} +.itflow-notify-desktop-text { + display: flex; + flex-direction: column; + flex: 1 1 auto; + min-width: 0; + line-height: 1.3; +} +.itflow-notify-desktop-text > .small { + color: var(--bs-secondary-color); +} +.itflow-notify-desktop:has(:disabled) { + cursor: default; } /* The full page lists the same rows inside a card */ diff --git a/js/notifications.js b/js/notifications.js index 96d1115ab..c3c5737a7 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -300,8 +300,12 @@ '' + '
' + 'View all notifications' + - // Desktop notifications in this browser - js/ticket_pulse.js labels it and turns them on and off - ''; + // Desktop notifications in this browser - on, off or blocked, with a switch (js/ticket_pulse.js) + ''; list = panel.querySelector('.itflow-notify-list'); diff --git a/js/ticket_pulse.js b/js/ticket_pulse.js index 283ed9b5d..188f04a71 100644 --- a/js/ticket_pulse.js +++ b/js/ticket_pulse.js @@ -7,8 +7,9 @@ * keeps going in the background, which is the point: the count shows on that tab while you are in * another one. Other pages keep their own title. * - * Desktop notifications are each browser's own choice, turned on and off from the bell's panel - * ([data-desktop-notify] - js/notifications.js draws it), which asks the browser's permission. + * Desktop notifications are each browser's own choice, turned on and off with the switch at the + * foot of the bell's panel ([data-desktop-notify] - js/notifications.js draws it), which says + * whether they are on, off or blocked here, and asks the browser's permission the first time. * Once on, a ticket newly assigned to you and a client's reply on one of yours show as desktop * notifications - but only while no ITFlow tab has the focus: when you are already in ITFlow the * bell and the title say enough. Clicking one opens the ticket. Text only, from textContent-safe @@ -173,18 +174,34 @@ /* ---------- the switch in the bell's panel ---------- */ - function label(button) { + // Where they stand here: on, off, or blocked by the browser - the switch shows it + function label(row) { if (!supported()) { - button.hidden = true; + row.hidden = true; return; } - button.hidden = false; - button.textContent = ''; - const i = document.createElement('i'); - i.className = 'fas fa-fw fa-desktop me-1'; - i.setAttribute('aria-hidden', 'true'); - button.append(i, desktopOn() ? 'Turn off desktop notifications' - : (Notification.permission === 'denied' ? 'Desktop notifications are blocked in this browser' : 'Turn on desktop notifications')); + const on = desktopOn(); + const blocked = !on && Notification.permission === 'denied'; + const box = row.querySelector('[data-desktop-switch]'); + const state = row.querySelector('[data-desktop-state]'); + row.hidden = false; + row.classList.toggle('is-on', on); + box.checked = on; + box.disabled = blocked; + state.textContent = on ? 'On in this browser' + : (blocked ? 'Blocked by this browser - allow them in its settings for this site' : 'Off in this browser'); + } + + function labelAll() { + document.querySelectorAll('[data-desktop-notify]').forEach(label); + } + + function turnOn(row) { + store(DESKTOP, '1'); + label(row); + toast('Desktop notifications are on in this browser'); + show('Desktop notifications are on', 'Tickets assigned to you and client replies on yours show here while you are away from ITFlow.', 'itflow-desktop-on'); + ask(true); } function toast(text, type) { @@ -195,36 +212,47 @@ document.addEventListener('shown.bs.dropdown', function (e) { const bell = e.target.closest && e.target.closest('#itflowNotify'); - const button = bell && bell.querySelector('[data-desktop-notify]'); - if (button) { - label(button); + const row = bell && bell.querySelector('[data-desktop-notify]'); + if (row) { + label(row); } }); - document.addEventListener('click', function (e) { - const button = e.target.closest('[data-desktop-notify]'); - if (!button || !supported()) { + // Turned on or off in another tab + window.addEventListener('storage', function (e) { + if (e.key === DESKTOP) { + labelAll(); + } + }); + + document.addEventListener('change', function (e) { + const box = e.target.closest && e.target.closest('[data-desktop-switch]'); + const row = box && box.closest('[data-desktop-notify]'); + if (!row || !supported()) { return; } - e.preventDefault(); - if (desktopOn()) { + if (!box.checked) { store(DESKTOP, '0'); - label(button); + label(row); toast('Desktop notifications are off in this browser'); return; } if (Notification.permission === 'denied') { + label(row); toast('This browser blocks notifications from ITFlow - allow them in its settings for this site, then try again', 'warning'); return; } + // Allowed already - no need to ask again + if (Notification.permission === 'granted') { + turnOn(row); + return; + } Notification.requestPermission().then(function (permission) { if (permission === 'granted') { - store(DESKTOP, '1'); - toast('Desktop notifications are on in this browser'); - show('Desktop notifications are on', 'Tickets assigned to you and client replies on yours show here while you are away from ITFlow.', 'itflow-desktop-on'); - ask(true); + turnOn(row); + } else { + label(row); } - label(button); }); });