From f777bb212cf1ef41bc8e53e090c15261fe4fa164 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sun, 29 Nov 2026 13:28:40 -0500 Subject: [PATCH] Documents and articles outside the agent app read like the document page: the portal document and Help article pages, shared links and the public help center lay out what they say as on the agent document page, with a long one's Contents beside it in view as you scroll and marking the section being read, or above it on a phone; pictures open full size when clicked; a section picked from Contents stays marked, on the agent page too; 26.12.3 changelog entries --- CHANGELOG.md | 2 + client/document.php | 12 +-- client/includes/footer.php | 4 + client/kb_article.php | 11 +-- css/itflow_custom.css | 32 +++++++ functions/files.php | 20 +++++ guest/kb.php | 13 +-- guest/share.php | 3 +- js/document_contents.js | 167 +++++++++++++++++++++++-------------- js/guest_share.js | 4 + 10 files changed, 189 insertions(+), 79 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 438db4c27..60a0d2953 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Update from Maintenance > Update as usual - this release has three database chan - Markdown files: the menu beside Upload on a client's Files has Import Markdown Files, which makes a document from each .md file picked, named by the heading it starts with or its file name. A document's page has a Markdown button beside PDF, which downloads it as a .md file - rich text documents too. - Markdown pasted into a document's rich text editor - copied from GitHub, VS Code, Obsidian or an AI chat - goes in as formatting. Ctrl+Shift+V pastes it as it is. - A document's page is easier to read: headings in proportion to the text with room between sections, and tables, code and quotes that look part of it. Under its name are its folder, its template, Markdown when it's written in it, and its review - due, or when it's next due - whose menu has Mark Reviewed and how often. The buttons are Edit, Share and Export (PDF, Markdown or Print), with the rest in the ⋮ menu, now including Template. Beside it, Contents marks the section you're reading, and Linked, Versions and History are tabs of one card: Linked shows each kind of record with its count, opening to the list. +- Documents and articles read outside ITFlow look like a document's page: in the client portal (a document, and a Help article), on a shared link and on the public help center, headings are in proportion to the text, tables, code and quotes look part of it, and a picture shown smaller than it is opens full size when clicked. A long one - three headings or more - has its Contents beside it, in view as you scroll and marking the section being read, or above it on a phone. Picking a heading in Contents marks that one, not the one just under it - on a document's page in ITFlow too. - A document's PDF, and a Knowledge Base article's, look like your invoices and the documentation PDF: your logo and company details at the top, then its name with the client, its folder (an article's category) and when it was last updated and by whom, and its summary. Each later page has the client and the name at the top, and every page your company, Confidential (Knowledge Base for an article) and the date at the foot, with the page number. Tables have lines, code is shaded, a checklist shows its boxes, symbols such as ✓ and → show, and a document with headings has them as bookmarks beside the PDF. - Pictures in tickets are kept as files: a screenshot pasted or dropped into a ticket, a reply or a note - by your team, in the client portal or through the API - and the pictures in a client's email are kept with the ticket as files instead of inside its text. A ticket full of screenshots opens quickly, and so do the tickets list and the client portal. Pictures show where they were put and stay out of the ticket's list of files, and emails carry them as before. - Pictures already inside tickets move to files in the background - the new Ticket Pictures job in Maintenance > Cron does a batch every minute until every ticket is done, then keeps an eye on new ones. @@ -51,6 +52,7 @@ Update from Maintenance > Update as usual - this release has three database chan - New cron job ticket_pictures (cron/ticket_pictures.php, every minute): ticketPicturesSweep() goes through tickets then replies whose text has data:image/, 500 ids at a time, for up to 25 seconds a run. - A picture that can't be saved - the folder not writable, the attachment row not going in - stays as data in the text; ticketPicturesFailed() counts them, ticketPicturesSweep() carries on past a ticket or reply that fails, and the Ticket Pictures job logs a warning (Cron-Ticket-Pictures) when there were any. bulk_add_client_ticket keeps its pictures as files straight away; deleting a client deletes its tickets with ticketDeleteForGood(). - functions/document_pdf.php: DocumentPdf (TCPDF) and documentPdfRender() draw the document and Knowledge Base article PDFs (export_document in agent/post/document.php, export_kb_article in agent/post/kb.php), from documentPdfDocument() / documentPdfKbArticle(), and are sent with billingPdfSend(). documentPdfParts() splits the purified HTML at its top-level headings (inside a Markdown document's wrapper) for the bookmarks, and puts table lines, header cells and code shading in inline styles, which TCPDF reads where it ignores the style block. clientExportPdfImages() is clientExportPdfDocumentHtml()'s image step on its own, for uploads/documents or uploads/kb, and now turns a WebP picture into a PNG. +- documentReadHtml() (functions/files.php) lays out a document or article outside the agent app - client/document.php, client/kb_article.php, guest/kb.php and guest/share.php - with .itflow-prose, and the Contents beside it in an .itflow-document-read grid (css/itflow_custom.css). js/document_contents.js reads [data-document-body] as well as .itflow-document-body, runs again from window.itflowDocumentContents() (js/guest_share.js, once a shared document is in), leaves the address alone with data-document-contents-keep-address (a shared link's secret is after its #), and keeps a section picked from the list marked while the page scrolls to it. The portal footer loads it when a page sets $portal_document_contents. ## [26.12.2] diff --git a/client/document.php b/client/document.php index 4e107e3e7..6c3cdd4b6 100644 --- a/client/document.php +++ b/client/document.php @@ -1,9 +1,10 @@ ')) !== '') { ?> -
- -
+ +
'This document is empty', 'text' => '', 'icon' => 'fa-file-alt', 'filtered' => false]) ?> diff --git a/client/includes/footer.php b/client/includes/footer.php index 5e29b7fb2..8e96f2160 100644 --- a/client/includes/footer.php +++ b/client/includes/footer.php @@ -30,6 +30,10 @@ + + + + diff --git a/client/kb_article.php b/client/kb_article.php index 2f7afd122..4b4ccfb3b 100644 --- a/client/kb_article.php +++ b/client/kb_article.php @@ -1,8 +1,10 @@
')) !== '') { ?> -
- -
+ +
'This article is empty', 'text' => '', 'icon' => 'fa-book', 'filtered' => false]) ?> diff --git a/css/itflow_custom.css b/css/itflow_custom.css index 9518c9be7..31708774c 100644 --- a/css/itflow_custom.css +++ b/css/itflow_custom.css @@ -9593,6 +9593,38 @@ a.itflow-portal-request:focus-visible { .itflow-portal-document > :last-child { margin-bottom: 0; } +/* A document or article read outside the agent app (documentReadHtml() - the portal, a shared link, + the public help center): laid out as on the document page, with a long one's Contents beside it, + in view as you scroll, or above it on a phone (js/document_contents.js) */ +.itflow-document-read { + display: grid; + grid-template-columns: minmax(0, 1fr); + gap: 1rem; +} +.itflow-document-read-nav { + padding: .6rem 1.1rem; +} +.itflow-document-read .itflow-prose :is(h1, h2, h3, h4) { + scroll-margin-top: calc(var(--itflow-portal-header-height, 0px) + 1rem); +} +@media screen and (min-width: 992px) { + .itflow-document-read:has(> .itflow-document-read-contents:not([hidden])) { + grid-template-columns: minmax(0, 1fr) 15rem; + } + .itflow-document-read-body { + grid-row: 1; + grid-column: 1; + } + .itflow-document-read-contents { + grid-row: 1; + grid-column: 2; + align-self: start; + position: sticky; + top: calc(var(--itflow-portal-header-height, 0px) + 1rem); + max-height: calc(100vh - var(--itflow-portal-header-height, 0px) - 2rem); + overflow-y: auto; + } +} @media (max-width: 575.98px) { .itflow-portal-ticket > .itflow-portal-tile { display: none; diff --git a/functions/files.php b/functions/files.php index 77b8de8ef..e53f81b8a 100644 --- a/functions/files.php +++ b/functions/files.php @@ -892,3 +892,23 @@ function documentHtmlPurify($html) { } return $purifier->purify((string) $html); } + +/** + * A document or Knowledge Base article to read outside the agent app - the client portal, a shared + * link, the public help center: what it says ($html, purified already) laid out as on the agent's + * document page (.itflow-prose), and beside it the Contents of a long one (js/document_contents.js), + * which sits above it on a phone. $panel is the class of the box it is in; $attributes go on what + * it says (a shared link fills it in later). With $keep_address the Contents leaves the address as + * it is - a shared link's secret is after its #. + */ +function documentReadHtml($html, $panel = 'itflow-portal-panel itflow-portal-panel-body', $attributes = '', $keep_address = false) { + return '
' + . '' + . '
' + . '
' . $html . '
' + . '
' + . '
'; +} diff --git a/guest/kb.php b/guest/kb.php index e6d3c4e08..eafd6f9bb 100644 --- a/guest/kb.php +++ b/guest/kb.php @@ -6,8 +6,9 @@ * while Admin > Settings > Knowledge Base has it on (kbPublicOn()), and only * published, unarchived articles set to Anyone (kbPublicSql()). * - * Laid out like the client portal, with your logo, so it looks like yours. - * An article's own tables and colours are inline styles, already through + * Laid out like the client portal, with your logo, so it looks like yours, + * and an article as on the agent's document page, with the Contents of a long + * one beside it (documentReadHtml()). An article's own tables and colours are inline styles, already through * HTMLPurifier (documentHtmlPurify()), so styles are let in; scripts are not. * * Each visit counts as a read (kbCountView()), "Was this helpful?" goes under @@ -203,9 +204,7 @@ $title = $article ? $article['kb_article_title'] . ' | ' : '';
')) !== '') { ?> -
- -
+ + + + + diff --git a/guest/share.php b/guest/share.php index 127a43387..f271d8b2a 100644 --- a/guest/share.php +++ b/guest/share.php @@ -178,7 +178,7 @@ $item_id = intval($_GET['id'] ?? 0); -
+
@@ -251,6 +251,7 @@ $item_id = intval($_GET['id'] ?? 0); + diff --git a/js/document_contents.js b/js/document_contents.js index a6903b44c..98126e209 100644 --- a/js/document_contents.js +++ b/js/document_contents.js @@ -1,76 +1,35 @@ /* * ITFlow - a contents list for a long document or Knowledge Base article (agent/document.php, - * agent/kb_article.php): its headings, in the [data-document-contents] card beside it, each one - * a link down to it. Only when it has three headings or more - a short one doesn't need it. + * agent/kb_article.php, and outside the agent app documentReadHtml() - the client portal, a shared + * link, the public help center): its headings, in the [data-document-contents] card beside it, each + * one a link down to it. Only when it has three headings or more - a short one doesn't need it. * Headings without an id get one, so a link to a section can be shared. The section being read is * marked in the list as the page scrolls. * + * window.itflowDocumentContents() makes it again, for what is filled in after the page has loaded - + * a shared link's document (js/guest_share.js). A card with data-document-contents-keep-address + * leaves the address alone: a shared link's secret is after its #. + * * A link with data-document-tab (the document page's "2 earlier versions") opens that tab of the * card beside the document, and goes to it. */ (function () { 'use strict'; - const card = document.querySelector('[data-document-contents]'); - const body = document.querySelector('.itflow-document-body'); - if (!card || !body) { - return; - } - const headings = Array.prototype.filter.call(body.querySelectorAll('h1, h2, h3, h4'), function (h) { - return h.textContent.trim() !== ''; - }); - if (headings.length < 3) { - return; - } - - // Indent from the highest level the document actually uses - const top = Math.min.apply(null, headings.map(function (h) { return Number(h.tagName[1]); })); - const used = {}; - const list = document.createElement('ol'); - list.className = 'list-unstyled mb-0'; - - headings.forEach(function (h, i) { - if (!h.id) { - let slug = 'section-' + h.textContent.trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60); - if (slug === 'section-' || used[slug] || document.getElementById(slug)) { - slug = 'section-' + (i + 1); - } - h.id = slug; - } - used[h.id] = true; - const li = document.createElement('li'); - li.className = 'itflow-document-contents-level-' + (Number(h.tagName[1]) - top); - const a = document.createElement('a'); - a.href = '#' + h.id; - a.textContent = h.textContent.trim(); - a.addEventListener('click', function (e) { - e.preventDefault(); - h.scrollIntoView({ behavior: 'smooth', block: 'start' }); - history.replaceState(null, '', '#' + h.id); - }); - li.appendChild(a); - list.appendChild(li); - }); - - card.querySelector('nav').appendChild(list); - card.hidden = false; - - // Opened at a section's link - if (location.hash) { - const target = document.getElementById(decodeURIComponent(location.hash.slice(1))); - if (target && body.contains(target)) { - target.scrollIntoView({ block: 'start' }); - } - } - - // The section being read is marked in the list - the last heading above the top quarter of the window - const links = {}; - list.querySelectorAll('a').forEach(function (a) { - links[a.getAttribute('href').slice(1)] = a; - }); + let headings = []; + let links = {}; + let listening = false; let queued = false; + let picked = null; + let picked_until = 0; + + // The section being read is marked in the list - the last heading above the top quarter of the window, + // or the one just picked from the list while the page scrolls to it, as the next may be close under it const mark = function () { queued = false; + if (!headings.length) { + return; + } let current = headings[0]; const line = window.innerHeight * 0.25; headings.forEach(function (h) { @@ -78,6 +37,9 @@ current = h; } }); + if (picked && Date.now() < picked_until && headings.indexOf(picked) !== -1) { + current = picked; + } Object.keys(links).forEach(function (id) { links[id].classList.toggle('active', id === current.id); }); @@ -88,9 +50,90 @@ window.requestAnimationFrame(mark); } }; - window.addEventListener('scroll', queue, { passive: true }); - window.addEventListener('resize', queue); - mark(); + + const build = function () { + const card = document.querySelector('[data-document-contents]'); + const body = document.querySelector('[data-document-body], .itflow-document-body'); + if (!card || !body) { + return; + } + const nav = card.querySelector('nav'); + const old = nav.querySelector('ol'); + if (old) { + old.remove(); + } + card.hidden = true; + links = {}; + headings = Array.prototype.filter.call(body.querySelectorAll('h1, h2, h3, h4'), function (h) { + return h.textContent.trim() !== ''; + }); + if (headings.length < 3) { + headings = []; + return; + } + const keep_address = card.hasAttribute('data-document-contents-keep-address'); + + // Indent from the highest level the document actually uses + const top = Math.min.apply(null, headings.map(function (h) { return Number(h.tagName[1]); })); + const used = {}; + const list = document.createElement('ol'); + list.className = 'list-unstyled mb-0'; + + headings.forEach(function (h, i) { + if (!h.id) { + let slug = 'section-' + h.textContent.trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60); + if (slug === 'section-' || used[slug] || document.getElementById(slug)) { + slug = 'section-' + (i + 1); + } + h.id = slug; + } + used[h.id] = true; + const li = document.createElement('li'); + li.className = 'itflow-document-contents-level-' + (Number(h.tagName[1]) - top); + const a = document.createElement('a'); + a.href = '#' + h.id; + a.textContent = h.textContent.trim(); + a.addEventListener('click', function (e) { + e.preventDefault(); + picked = h; + picked_until = Date.now() + 1500; + queue(); + h.scrollIntoView({ behavior: 'smooth', block: 'start' }); + if (!keep_address) { + history.replaceState(null, '', '#' + h.id); + } + }); + li.appendChild(a); + list.appendChild(li); + links[h.id] = a; + }); + + nav.appendChild(list); + card.hidden = false; + + // Opened at a section's link + if (location.hash && !keep_address) { + let target = null; + try { + target = document.getElementById(decodeURIComponent(location.hash.slice(1))); + } catch (error) { + // Not an address of a section + } + if (target && body.contains(target)) { + target.scrollIntoView({ block: 'start' }); + } + } + + if (!listening) { + listening = true; + window.addEventListener('scroll', queue, { passive: true }); + window.addEventListener('resize', queue); + } + mark(); + }; + + window.itflowDocumentContents = build; + build(); })(); (function () { diff --git a/js/guest_share.js b/js/guest_share.js index 8ca5d373b..855aee36f 100644 --- a/js/guest_share.js +++ b/js/guest_share.js @@ -277,6 +277,10 @@ if (typeof prettyContent === 'function') { prettyContent(); } + // A long one's Contents beside it (js/document_contents.js) + if (typeof window.itflowDocumentContents === 'function') { + window.itflowDocumentContents(); + } } }