Document page modernized: headings in proportion to the text with styled tables, code and quotes; folder, template, Markdown and the review under the name, the review's menu with Mark Reviewed and how often; Edit, Share and an Export menu for PDF, Markdown and Print, Template moved to the more menu; Contents marks the section being read; Linked, Versions and History as tabs of one card, Linked as counts that open to their lists; linkGroupsHtml compact mode; 26.12.3 changelog entries

This commit is contained in:
johnnyq
2026-11-29 01:06:42 -05:00
parent 8b4fa5a1a0
commit 6cdbe60747
5 changed files with 362 additions and 150 deletions

View File

@@ -18,6 +18,7 @@ Update from Maintenance > Update as usual - this release has two database change
- Documents in Markdown: a document can be written in Markdown instead of the rich text editor - pick Markdown above the editor in New Document or Edit, write in the box, and Preview shows how it will look. Headings, lists, checklists, tables, code, quotes and links all work, and a picture pasted or dropped into the box is added to the document. Switching between Markdown and rich text converts what is already written, either way; switching to Markdown says when some formatting, such as colours or merged table cells, stays as HTML in it. New Document starts in whichever you used last.
- 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.
### Bug Fixes
@@ -34,6 +35,7 @@ Update from Maintenance > Update as usual - this release has two database change
- Database 4.2.3: documents.document_markdown and document_versions.document_version_markdown (longtext, NULL for rich text). A Markdown document's document_content is still the HTML every page shows, rendered from it on each save, so readers are unchanged; documentMarkdownReady(), documentMarkdownSql() and documentMarkdownSet() keep the writers working before the update.
- functions/markdown.php: markdownToHtml() (league/commonmark 2.10 GitHubFlavoredMarkdownConverter, raw HTML allowed and then passed through documentHtmlPurify(), task boxes drawn as spans, tables given the app's table classes, all in div.itflow-markdown), htmlToMarkdown() (league/html-to-markdown 5.2 with tables; tables with merged cells and sized pictures kept as HTML), markdownSaveImages(), markdownImportSplit() (front matter title, leading heading) and documentMarkdownFile(). Both libraries and their dependencies (league/config, dflydev/dot-access-data, nette/schema, nette/utils, psr/event-dispatcher) are in libs/vendor through libs/composer.json.
- agent/ajax.php markdown_to_html and html_to_markdown back js/document_markdown.js (loaded in includes/footer.php): the form's Rich text / Markdown switch, Write / Preview, pasted pictures held as pasted:N until Preview or Save, the remembered format for New Document, and the Markdown paste handler for .tinymce and .tinymce-page editors. New handlers export_document_markdown and import_markdown_documents in agent/post/document.php; versions, version restore, documentCopy() and the API's document create and update carry the Markdown (document_markdown in the API), and the API's create and update escape each value once.
- The document page (agent/document.php): .itflow-prose in css/itflow_custom.css styles what it says; linkGroupsHtml() (functions/links.php) takes $compact - groups that open to their rows, open already with five links or fewer, no Link per group or empty groups - and $total; js/document_contents.js marks the section in view and opens a tab of the side card from a[data-document-tab].
## [26.12.2]

View File

@@ -87,28 +87,63 @@ $page_title = $row['document_name'];
<div class="card-body d-flex flex-wrap align-items-start gap-3">
<?= documentTile('lg') ?>
<div class="min-w-0 flex-grow-1">
<h1 class="h3 mb-1 d-flex flex-wrap align-items-center column-gap-2">
<h1 class="h4 fw-semibold mb-1 d-flex flex-wrap align-items-center column-gap-2">
<span class="text-break"><?= $document_name ?></span>
<?php if (intval($row['document_favorite'])) { ?><i class="fas fa-star text-warning fs-6" title="Favorite - on the client's overview"></i><?php } ?>
<?php if ($document_archived) { ?><span class="badge rounded-pill text-bg-secondary fw-normal fs-6">Archived</span><?php } ?>
<?php if ($document_visible) { ?><span class="badge rounded-pill bg-info-subtle text-info-emphasis fw-normal fs-6" title="Technical contacts can read this in the client portal">Portal</span><?php } ?>
<?php if ($review && $review['due']) { ?><span class="badge rounded-pill bg-warning-subtle text-warning-emphasis border border-warning-subtle fw-normal fs-6" title="Due <?= date('M j, Y', strtotime($review['next'])) ?>"><i class="fas fa-calendar-check me-1"></i>Review due</span><?php } ?>
</h1>
<?php if ($document_description) { ?>
<div class="text-body-secondary"><?= $document_description ?></div>
<?php } ?>
<?php if ($document_tags_display) { ?>
<div class="mt-1"><?= $document_tags_display ?></div>
<?php } ?>
<!-- Where it lives, where it came from, when it's next looked over -->
<div class="small text-body-secondary d-flex flex-wrap align-items-center column-gap-3 row-gap-1 mt-2 itflow-document-facts">
<a class="text-reset text-truncate" href="files.php?client_id=<?= $client_id ?>&folder_id=<?= $document_folder_id ?>" title="Folder"><i class="fas fa-fw fa-folder me-1"></i><?= escapeHtml($folder_path ? implode(' / ', array_column($folder_path, 'folder_name')) : 'Top level') ?></a>
<?php if ($row['document_template_name'] !== null) { ?>
<span title="The template it was made from"><i class="fas fa-fw fa-puzzle-piece me-1"></i><?= $session_is_admin ? '<a class="text-reset" href="/admin/document_template.php?document_template_id=' . intval($row['document_template_id']) . '">' . escapeHtml($row['document_template_name']) . '</a>' : escapeHtml($row['document_template_name']) ?></span>
<?php } ?>
<?php if (intval($row['document_is_markdown'])) { ?>
<span title="Written in Markdown - Edit shows the Markdown"><i class="fab fa-fw fa-markdown me-1"></i>Markdown</span>
<?php } ?>
<?php
// Its review - due, or when it's next due - and for an agent who may change it, the choices
$review_text = $review ? ($review['due'] ? 'Review due since ' . date('M j, Y', strtotime($review['next'])) : 'Next review ' . date('M j, Y', strtotime($review['next']))) : 'No review schedule';
$review_can_set = $can_edit && !$document_archived && documentReviewOwnReady();
if ($review_can_set) {
$review_choices = ($template_review_months !== null ? ['template' => "As its template says - " . lcfirst(DOCUMENT_TEMPLATE_REVIEW_MONTHS[$template_review_months] ?? 'never')] : [])
+ DOCUMENT_TEMPLATE_REVIEW_MONTHS;
$review_current = $row['document_review_months'] !== null ? (string) intval($row['document_review_months']) : ($template_review_months !== null ? 'template' : '0'); ?>
<span class="dropdown">
<button type="button" class="btn btn-link btn-sm p-0 text-decoration-none dropdown-toggle <?= $review && $review['due'] ? 'text-warning-emphasis fw-semibold' : 'text-reset' ?>" data-bs-toggle="dropdown" aria-expanded="false" title="Review"><i class="fas fa-fw fa-calendar-check me-1"></i><?= $review_text ?></button>
<div class="dropdown-menu">
<?php if ($review) { ?>
<span class="dropdown-item-text small text-body-secondary">
<?= $review['reviewed'] ? 'Reviewed' : (strtotime($review['last']) === strtotime($row['document_created_at']) ? 'Made' : 'Edited') ?> <?= timeAgo($review['last']) ?><?= $review['reviewed'] && $row['reviewed_by_name'] !== null ? ' by ' . escapeHtml($row['reviewed_by_name']) : '' ?>
&middot; <?= lcfirst(DOCUMENT_TEMPLATE_REVIEW_MONTHS[$review['months']] ?? '') ?><?= $review['own'] ? '' : ', as its template says' ?>
</span>
<a class="dropdown-item" href="post.php?mark_document_reviewed=<?= $document_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-check me-2"></i>Mark Reviewed</a>
<div class="dropdown-divider"></div>
<?php } ?>
<h6 class="dropdown-header">How often it's reviewed</h6>
<?php foreach ($review_choices as $months => $label) { ?>
<a class="dropdown-item<?= (string) $months === $review_current ? ' active' : '' ?>" href="post.php?set_document_review=<?= $document_id ?>&months=<?= $months ?>&csrf_token=<?= $csrf ?>"><?= escapeHtml($months === 0 && $template_review_months === null ? 'Never - not on a schedule' : $label) ?></a>
<?php } ?>
</div>
</span>
<?php } elseif ($review) { ?>
<span class="<?= $review['due'] ? 'text-warning-emphasis fw-semibold' : '' ?>"><i class="fas fa-fw fa-calendar-check me-1"></i><?= $review_text ?></span>
<?php } ?>
</div>
<div class="small text-body-secondary mt-1">
<span title="<?= formatDateTime($document_updated_at) ?>">Updated <?= timeAgo($document_updated_at) ?></span><?= $document_updated_by ? " by $document_updated_by" : '' ?>
&middot; Created <?= date('M j, Y', strtotime($row['document_created_at'])) ?><?= $row['created_by_name'] ? ' by ' . escapeHtml($row['created_by_name']) : '' ?>
<?php if ($row['document_template_name'] !== null) { ?>
&middot; From template <?= $session_is_admin ? '<a class="text-reset" href="/admin/document_template.php?document_template_id=' . intval($row['document_template_id']) . '">' . escapeHtml($row['document_template_name']) . '</a>' : escapeHtml($row['document_template_name']) ?>
<?php } ?>
<?php if (intval($row['document_is_markdown'])) { ?>&middot; <span title="Edit shows the Markdown it was written in"><i class="fab fa-markdown me-1"></i>Written in Markdown</span><?php } ?>
<?php if ($versions) { ?>&middot; <a class="text-reset" href="#documentHistory"><?= count($versions) ?> earlier version<?= count($versions) === 1 ? '' : 's' ?></a><?php } ?>
<?php if ($versions) { ?>&middot; <a class="text-reset" href="#documentVersions" data-document-tab="versions"><?= count($versions) ?> earlier version<?= count($versions) === 1 ? '' : 's' ?></a><?php } ?>
</div>
<?php if ($document_tags_display) { ?>
<div class="mt-2"><?= $document_tags_display ?></div>
<?php } ?>
</div>
<div class="d-flex flex-wrap gap-2 d-print-none">
<?php if ($can_edit && !$document_archived) { ?>
@@ -118,7 +153,7 @@ $page_title = $row['document_name'];
<?php } ?>
<?php if (!$document_archived && aiReady('Documentation')) { ?>
<button type="button" class="btn btn-outline-secondary ajax-modal" data-modal-size="lg" data-modal-url="modals/document/document_review.php?id=<?= $document_id ?>" title="AI reads it and says what to fix or check, and what is out of date">
<i class="fas fa-clipboard-check"></i><span class="d-none d-md-inline ms-2">Review with AI</span>
<i class="fas fa-clipboard-check"></i><span class="d-none d-xl-inline ms-2">Review with AI</span>
</button>
<?php } ?>
<?php if (!$document_archived && shareCanMake('Document')) { ?>
@@ -126,9 +161,17 @@ $page_title = $row['document_name'];
<i class="fas fa-share-alt me-2"></i>Share
</button>
<?php } ?>
<a class="btn btn-outline-secondary" href="post.php?export_document=<?= $document_id ?>&csrf_token=<?= $csrf ?>" title="Export as PDF"><i class="fas fa-file-pdf"></i><span class="d-none d-md-inline ms-2">PDF</span></a>
<a class="btn btn-outline-secondary" href="post.php?export_document_markdown=<?= $document_id ?>&csrf_token=<?= $csrf ?>" title="Download as a Markdown (.md) file"><i class="fab fa-markdown"></i><span class="d-none d-md-inline ms-2">Markdown</span></a>
<button type="button" class="btn btn-outline-secondary" onclick="window.print();" title="Print"><i class="fas fa-print"></i></button>
<div class="dropdown">
<button type="button" class="btn btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" title="Download or print it">
<i class="fas fa-download me-2"></i>Export
</button>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item" href="post.php?export_document=<?= $document_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-file-pdf me-2"></i>PDF</a>
<a class="dropdown-item" href="post.php?export_document_markdown=<?= $document_id ?>&csrf_token=<?= $csrf ?>"><i class="fab fa-fw fa-markdown me-2"></i>Markdown (.md)</a>
<div class="dropdown-divider"></div>
<button type="button" class="dropdown-item" onclick="window.print();"><i class="fas fa-fw fa-print me-2"></i>Print</button>
</div>
</div>
<?php if ($can_edit) { ?>
<div class="dropdown">
<button type="button" class="btn btn-outline-secondary" data-bs-toggle="dropdown" title="More actions"><i class="fas fa-ellipsis-v"></i></button>
@@ -142,6 +185,7 @@ $page_title = $row['document_name'];
<?php if ($config_client_portal_enable) { ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/document/document_edit_visibility.php?document_id=<?= $document_id ?>"><i class="fas fa-fw fa-eye<?= $document_visible ? '-slash' : '' ?> me-2"></i><?= $document_visible ? 'Hide from' : 'Show in' ?> client portal</a>
<?php } ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/document/document_template_link.php?id=<?= $document_id ?>" title="The template it counts as made from"><i class="fas fa-fw fa-puzzle-piece me-2"></i>Template</a>
<?php if (kbCan(2)) { ?>
<a class="dropdown-item" href="post.php?copy_document_to_kb=<?= $document_id ?>&csrf_token=<?= $csrf ?>" title="A draft article from it, for every client"><i class="fas fa-fw fa-book me-2"></i>Copy to Knowledge Base</a>
<?php } ?>
@@ -166,7 +210,7 @@ $page_title = $row['document_name'];
<!-- The document -->
<div class="col-lg-8">
<div class="card mb-3">
<div class="card-body prettyContent itflow-document-body">
<div class="card-body prettyContent itflow-document-body itflow-prose">
<?= documentHtmlPurify($row['document_content']) ?: '<p class="text-body-secondary">This document is empty.' . ($can_edit && !$document_archived ? ' <a href="document_edit.php?client_id=' . $client_id . '&amp;document_id=' . $document_id . '">Start writing</a>' : '') . '</p>' ?>
</div>
</div>
@@ -203,138 +247,83 @@ $page_title = $row['document_name'];
<nav class="card-body py-2" aria-label="Contents"></nav>
</div>
<!-- What goes with it -->
<div class="card mb-3">
<div class="card-header d-flex align-items-center">
<h3 class="card-title mb-0 me-auto"><i class="fas fa-fw fa-link me-2 text-body-secondary"></i>Linked</h3>
<?php if ($can_edit && !$document_archived) { ?>
<?= linkPickerButton('document', $document_id, '', 'Link', 'small', 'fas fa-plus me-1') ?>
<?php } ?>
</div>
<div class="card-body">
<?= linkGroupsHtml('document', $document_id, $client_id, $document_archived) ?>
</div>
</div>
<!-- Where it lives, and where it came from -->
<div class="card mb-3">
<div class="card-body">
<div class="itflow-glance-item" title="Template">
<i class="fas fa-fw fa-puzzle-piece"></i>
<span class="min-w-0 d-flex align-items-center">
<?php if ($row['document_template_name'] !== null) { ?>
<span class="text-truncate">From <?= $session_is_admin ? '<a href="/admin/document_template.php?document_template_id=' . intval($row['document_template_id']) . '">' . escapeHtml($row['document_template_name']) . '</a>' : escapeHtml($row['document_template_name']) ?></span>
<?php } else { ?>
<span class="text-body-secondary">Not from a template</span>
<?php } ?>
<?php if ($can_edit && !$document_archived) { ?>
<a class="itflow-copy ajax-modal" href="#" data-modal-url="modals/document/document_template_link.php?id=<?= $document_id ?>" title="Change the template it counts as made from"><i class="fas fa-pen"></i></a>
<?php } ?>
</span>
</div>
<?php if ($review || ($can_edit && !$document_archived && documentReviewOwnReady())) { ?>
<div class="itflow-glance-item<?= $review && $review['due'] ? ' text-warning-emphasis' : '' ?>" title="Review">
<i class="fas fa-fw fa-calendar-check"></i>
<span class="min-w-0">
<?php if ($review) { ?>
<span class="d-block"><?= $review['due'] ? '<strong>Review due</strong> since ' . date('M j, Y', strtotime($review['next'])) : 'Next review ' . date('M j, Y', strtotime($review['next'])) ?></span>
<span class="d-block small text-body-secondary">
<?= $review['reviewed'] ? 'Reviewed' : (strtotime($review['last']) === strtotime($row['document_created_at']) ? 'Made' : 'Edited') ?> <?= timeAgo($review['last']) ?><?= $review['reviewed'] && $row['reviewed_by_name'] !== null ? ' by ' . escapeHtml($row['reviewed_by_name']) : '' ?>
&middot; <?= lcfirst(DOCUMENT_TEMPLATE_REVIEW_MONTHS[$review['months']] ?? '') ?><?= $review['own'] ? '' : ', as its template says' ?>
</span>
<?php } else { ?>
<span class="text-body-secondary">Not reviewed on a schedule</span>
<?php } ?>
<?php if ($can_edit) { ?>
<span class="d-flex flex-wrap gap-2 mt-2">
<?php if ($review) { ?>
<a class="btn btn-sm <?= $review['due'] ? 'btn-warning' : 'btn-light border' ?>" href="post.php?mark_document_reviewed=<?= $document_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-check me-1"></i>Mark Reviewed</a>
<?php } ?>
<?php if (documentReviewOwnReady()) {
// How often - its template's, or its own
$review_choices = ($template_review_months !== null ? ['template' => "As its template says - " . lcfirst(DOCUMENT_TEMPLATE_REVIEW_MONTHS[$template_review_months] ?? 'never')] : [])
+ DOCUMENT_TEMPLATE_REVIEW_MONTHS;
$review_current = $row['document_review_months'] !== null ? (string) intval($row['document_review_months']) : ($template_review_months !== null ? 'template' : '0'); ?>
<span class="dropdown">
<button type="button" class="btn btn-sm btn-light border dropdown-toggle" data-bs-toggle="dropdown" title="How often it's reviewed"><i class="fas fa-redo-alt me-1"></i>How Often</button>
<span class="dropdown-menu">
<?php foreach ($review_choices as $months => $label) { ?>
<a class="dropdown-item<?= (string) $months === $review_current ? ' active' : '' ?>" href="post.php?set_document_review=<?= $document_id ?>&months=<?= $months ?>&csrf_token=<?= $csrf ?>"><?= escapeHtml($months === 0 && $template_review_months === null ? 'Never - not on a schedule' : $label) ?></a>
<?php } ?>
</span>
</span>
<?php } ?>
</span>
<?php } ?>
</span>
</div>
<?php } ?>
<div class="itflow-glance-item" title="Folder">
<i class="fas fa-fw fa-folder"></i>
<span class="min-w-0 d-flex align-items-center">
<a class="text-truncate" href="files.php?client_id=<?= $client_id ?>&folder_id=<?= $document_folder_id ?>"><?= escapeHtml($folder_path ? implode(' / ', array_column($folder_path, 'folder_name')) : 'Top level') ?></a>
<?php if ($can_edit && !$document_archived) { ?>
<a class="itflow-copy ajax-modal" href="#" data-modal-url="modals/document/document_move.php?id=<?= $document_id ?>" title="Move"><i class="fas fa-pen"></i></a>
<?php } ?>
</span>
</div>
<?php if ($config_client_portal_enable) { ?>
<div class="itflow-glance-item" title="Client portal">
<i class="fas fa-fw fa-eye<?= $document_visible ? '' : '-slash' ?>"></i>
<span class="d-flex align-items-center">
<?= $document_visible ? 'Shown in the client portal' : 'Not in the client portal' ?>
<?php if ($can_edit && !$document_archived) { ?>
<a class="itflow-copy ajax-modal" href="#" data-modal-url="modals/document/document_edit_visibility.php?document_id=<?= $document_id ?>" title="Change"><i class="fas fa-pen"></i></a>
<?php } ?>
</span>
</div>
<?php } ?>
</div>
</div>
<!-- Every earlier version -->
<div class="card mb-3" id="documentHistory">
<div class="card-header">
<h3 class="card-title mb-0"><i class="fas fa-fw fa-layer-group me-2 text-body-secondary"></i>Versions</h3>
</div>
<ul class="list-group list-group-flush itflow-document-history">
<li class="list-group-item d-flex align-items-center gap-2">
<div class="min-w-0 flex-grow-1">
<div class="fw-semibold small">Now</div>
<div class="small text-body-secondary">Updated <?= timeAgo($document_updated_at) ?><?= $document_updated_by ? " by $document_updated_by" : '' ?></div>
</div>
<?php if ($versions) { ?>
<!-- What the last edit changed (modals/document/document_changes.php) -->
<a class="itflow-copy ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/document/document_changes.php?document_id=<?= $document_id ?>" title="What changed"><i class="fas fa-exchange-alt"></i></a>
<?php } ?>
</li>
<?php foreach ($versions as $version) {
$version_id = intval($version['document_version_id']); ?>
<li class="list-group-item d-flex align-items-center gap-2">
<div class="min-w-0 flex-grow-1">
<a class="small fw-semibold ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/document/document_version_view.php?id=<?= $version_id ?>" title="<?= formatDateTime($version['document_version_created_at']) ?>">
<?= date('M j, Y g:i A', strtotime($version['document_version_created_at'])) ?>
</a>
<div class="small text-body-secondary text-truncate">
<?= escapeHtml($version['user_name'] ?: 'Unknown') ?>
<?php if ($version['document_version_name'] !== $row['document_name']) { ?> &middot; was "<?= escapeHtml($version['document_version_name']) ?>"<?php } ?>
</div>
</div>
<a class="itflow-copy ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/document/document_changes.php?document_id=<?= $document_id ?>&version_id=<?= $version_id ?>" title="What changed"><i class="fas fa-exchange-alt"></i></a>
<?php if ($can_delete) { ?>
<a class="itflow-copy confirm-link text-danger" href="post.php?delete_document_version=<?= $version_id ?>&csrf_token=<?= $csrf ?>" title="Delete this version" data-confirm-text="This version is removed from the history for good."><i class="fas fa-trash"></i></a>
<?php } ?>
<?php
// What goes with it, its earlier versions and who did what to it - one card, a tab each
$linked_html = linkGroupsHtml('document', $document_id, $client_id, $document_archived, true, $linked_total);
$history = auditLogHistory('Document', $document_id, 10);
?>
<div class="card mb-3 itflow-asset-related itflow-document-side" id="documentVersions">
<div class="card-header py-2">
<ul class="nav nav-pills itflow-asset-pills" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap active <?= $linked_total ? '' : 'is-empty' ?>" data-bs-toggle="pill" data-bs-target="#document-pane-linked" data-document-tab="linked" type="button" role="tab">Linked <span class="badge rounded-pill ms-1"><?= $linked_total ?></span></button>
</li>
<?php } ?>
<?php if (!$versions) { ?>
<li class="list-group-item small text-body-secondary">No earlier versions - each edit keeps the one before it here.</li>
<?php } ?>
</ul>
</div>
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap <?= $versions ? '' : 'is-empty' ?>" data-bs-toggle="pill" data-bs-target="#document-pane-versions" data-document-tab="versions" type="button" role="tab">Versions <span class="badge rounded-pill ms-1"><?= count($versions) ?></span></button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap <?= $history['count'] ? '' : 'is-empty' ?>" data-bs-toggle="pill" data-bs-target="#document-pane-history" data-document-tab="history" type="button" role="tab">History <span class="badge rounded-pill ms-1"><?= number_format($history['count']) ?></span></button>
</li>
</ul>
</div>
<div class="tab-content">
<!-- Who did what to it, from the audit log -->
<div class="d-print-none">
<?= auditLogHistoryCard(auditLogHistory('Document', $document_id, 10), ['client_id' => $client_id]) ?>
<!-- What it's about - assets, contacts, licenses and the rest -->
<div class="tab-pane fade show active" id="document-pane-linked" role="tabpanel">
<div class="card-body">
<?php if ($can_edit && !$document_archived) { ?>
<div class="d-flex align-items-center mb-2">
<span class="small text-body-secondary me-auto">What this document is about</span>
<?= linkPickerButton('document', $document_id, '', 'Link', 'btn btn-sm btn-outline-secondary', 'fas fa-plus me-1') ?>
</div>
<?php } ?>
<?= $linked_html ?>
</div>
</div>
<!-- Every earlier version -->
<div class="tab-pane fade" id="document-pane-versions" role="tabpanel">
<ul class="list-group list-group-flush itflow-document-history">
<li class="list-group-item d-flex align-items-center gap-2">
<div class="min-w-0 flex-grow-1">
<div class="fw-semibold small">Now</div>
<div class="small text-body-secondary">Updated <?= timeAgo($document_updated_at) ?><?= $document_updated_by ? " by $document_updated_by" : '' ?></div>
</div>
<?php if ($versions) { ?>
<!-- What the last edit changed (modals/document/document_changes.php) -->
<a class="itflow-copy ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/document/document_changes.php?document_id=<?= $document_id ?>" title="What changed"><i class="fas fa-exchange-alt"></i></a>
<?php } ?>
</li>
<?php foreach ($versions as $version) {
$version_id = intval($version['document_version_id']); ?>
<li class="list-group-item d-flex align-items-center gap-2">
<div class="min-w-0 flex-grow-1">
<a class="small fw-semibold ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/document/document_version_view.php?id=<?= $version_id ?>" title="<?= formatDateTime($version['document_version_created_at']) ?>">
<?= date('M j, Y g:i A', strtotime($version['document_version_created_at'])) ?>
</a>
<div class="small text-body-secondary text-truncate">
<?= escapeHtml($version['user_name'] ?: 'Unknown') ?>
<?php if ($version['document_version_name'] !== $row['document_name']) { ?> &middot; was "<?= escapeHtml($version['document_version_name']) ?>"<?php } ?>
</div>
</div>
<a class="itflow-copy ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/document/document_changes.php?document_id=<?= $document_id ?>&version_id=<?= $version_id ?>" title="What changed"><i class="fas fa-exchange-alt"></i></a>
<?php if ($can_delete) { ?>
<a class="itflow-copy confirm-link text-danger" href="post.php?delete_document_version=<?= $version_id ?>&csrf_token=<?= $csrf ?>" title="Delete this version" data-confirm-text="This version is removed from the history for good."><i class="fas fa-trash"></i></a>
<?php } ?>
</li>
<?php } ?>
<?php if (!$versions) { ?>
<li class="list-group-item small text-body-secondary">No earlier versions - each edit keeps the one before it here.</li>
<?php } ?>
</ul>
</div>
<!-- Who did what to it, from the audit log -->
<div class="tab-pane fade" id="document-pane-history" role="tabpanel">
<?= auditLogHistoryHtml($history, ['client_id' => $client_id, 'compact' => true]) ?>
</div>
</div>
</div>
</div>

View File

@@ -5392,6 +5392,52 @@ tr:hover .itflow-files-rename,
color: var(--bs-secondary-color);
font-weight: 500;
}
/* A group that opens to its rows (linkGroupsHtml() $compact - the document page) */
.itflow-link-group.is-compact + .itflow-link-group.is-compact {
margin-top: .15rem;
}
.itflow-link-group.is-compact .itflow-link-group-head {
margin-bottom: 0;
font-size: .875rem;
font-weight: 500;
letter-spacing: 0;
text-transform: none;
color: var(--bs-body-color);
}
.itflow-link-group.is-compact .itflow-link-group-head > i,
.itflow-link-group-toggle > .fa-fw {
color: var(--bs-secondary-color);
}
.itflow-link-group-toggle {
display: flex;
flex: 1 1 auto;
align-items: center;
padding: .35rem .4rem;
margin: 0 -.4rem;
border: 0;
border-radius: var(--bs-border-radius);
background: none;
color: inherit;
font: inherit;
letter-spacing: inherit;
text-transform: inherit;
text-align: left;
}
.itflow-link-group-toggle:hover {
background-color: var(--bs-tertiary-bg);
}
.itflow-link-group-chevron {
margin-left: auto;
padding-left: .5rem;
font-size: .7rem;
transition: transform .15s ease;
}
.itflow-link-group-toggle.collapsed .itflow-link-group-chevron {
transform: rotate(-90deg);
}
.itflow-link-group.is-compact ul {
padding: .1rem 0 .35rem;
}
.itflow-link-group-head a {
text-transform: none;
letter-spacing: 0;
@@ -5468,7 +5514,103 @@ tr:hover .itflow-files-rename,
border-radius: var(--bs-border-radius-lg);
overflow-wrap: anywhere;
}
/* A document written in Markdown, as it shows (functions/markdown.php markdownToHtml()) */
/* A document to read (.itflow-prose - the document page): headings in proportion to the text, room
between the parts, and tables, code and quotes that look like part of it */
.itflow-prose {
line-height: 1.65;
}
@media (min-width: 992px) {
.itflow-document-body.itflow-prose {
padding: 1.75rem 2rem;
}
}
.itflow-prose > :first-child,
.itflow-prose > .itflow-markdown > :first-child {
margin-top: 0;
}
.itflow-prose > :last-child,
.itflow-prose > .itflow-markdown > :last-child {
margin-bottom: 0;
}
.itflow-prose :is(h1, h2, h3, h4, h5, h6) {
margin: 1.75rem 0 .6rem;
font-weight: 600;
line-height: 1.3;
color: var(--bs-emphasis-color);
}
.itflow-prose h1 { font-size: 1.6rem; }
.itflow-prose h2 {
font-size: 1.3rem;
padding-bottom: .35rem;
border-bottom: 1px solid var(--bs-border-color-translucent);
}
.itflow-prose h3 { font-size: 1.12rem; }
.itflow-prose h4 { font-size: 1rem; }
.itflow-prose :is(h5, h6) {
font-size: .9rem;
text-transform: uppercase;
letter-spacing: .03em;
color: var(--bs-secondary-color);
}
.itflow-prose :is(p, ul, ol, table, pre, blockquote, figure) {
margin-bottom: 1rem;
}
.itflow-prose :is(ul, ol) {
padding-left: 1.5rem;
}
.itflow-prose li + li,
.itflow-prose li > :is(ul, ol) {
margin-top: .25rem;
}
.itflow-prose a {
text-underline-offset: .15em;
}
.itflow-prose hr {
margin: 2rem 0;
}
.itflow-prose img {
border-radius: var(--bs-border-radius);
}
.itflow-prose table {
width: auto;
max-width: 100%;
border: 1px solid var(--bs-border-color);
font-size: .925rem;
}
.itflow-prose table :is(td, th) {
padding: .4rem .65rem;
border: 1px solid var(--bs-border-color);
}
.itflow-prose table :is(th, thead td) {
background-color: var(--bs-tertiary-bg);
font-weight: 600;
}
/* Code and quotes in a document read on its page */
.itflow-prose pre,
.itflow-prose blockquote {
margin-left: 0;
}
.itflow-prose pre {
padding: .75rem 1rem;
border: 1px solid var(--bs-border-color);
border-radius: var(--bs-border-radius);
background-color: var(--bs-tertiary-bg);
white-space: pre;
overflow-x: auto;
overflow-wrap: normal;
}
.itflow-prose :not(pre) > code {
padding: .1rem .3rem;
border-radius: .25rem;
background-color: var(--bs-tertiary-bg);
color: var(--bs-emphasis-color);
}
.itflow-prose blockquote {
padding: .25rem 0 .25rem 1rem;
border-left: .25rem solid var(--bs-border-color);
color: var(--bs-secondary-color);
}
/* A document written in Markdown, wherever it shows (functions/markdown.php markdownToHtml()) */
.itflow-markdown img {
max-width: 100%;
height: auto;
@@ -5571,6 +5713,15 @@ tr:hover .itflow-files-rename,
.itflow-document-contents a:hover {
color: var(--bs-link-hover-color);
}
/* Where a document lives, its template and its review, under its name */
.itflow-document-facts .btn {
font-size: inherit;
line-height: inherit;
}
/* The section being read, marked as the page scrolls */
.itflow-document-contents a.active {
color: var(--bs-link-color);
}
.itflow-document-contents-level-0 a {
font-weight: 600;
}

View File

@@ -420,17 +420,27 @@ function linkRowHtml($to, $row, $client_id) {
* Link button and an unlink button on each row (shown on hover, like the copy
* buttons). Empty groups collapse to a single "Link a ..." line, so the card
* says what can be linked without a wall of empty headings.
*
* $compact (the document page): a group is its heading and count, opening to
* its rows - open already when there are five links or fewer in all. Linking
* is the one Link button above them, so groups have none of their own and
* empty ones aren't offered. $total is how many links there are.
*/
function linkGroupsHtml($from, $id, $client_id, $archived = false) {
function linkGroupsHtml($from, $id, $client_id, $archived = false, $compact = false, &$total = null) {
$id = intval($id);
$groups = '';
$empty = [];
$found = [];
$total = 0;
foreach (linkTypesFor($from) as $to) {
$found[$to] = linkedRecords($from, $id, $to);
$total += count($found[$to]);
}
foreach ($found as $to => $rows) {
$entity = LINK_ENTITIES[$to];
$rows = linkedRecords($from, $id, $to);
$can_edit = !$archived && linkCanEdit($from, $to);
if (!$rows) {
if ($can_edit) {
if ($can_edit && !$compact) {
$empty[] = linkPickerButton($from, $id, $to, $entity['plural'], 'btn btn-xs btn-outline-secondary', "fas {$entity['icon']} me-1");
}
continue;
@@ -443,6 +453,15 @@ function linkGroupsHtml($from, $id, $client_id, $archived = false) {
$items .= '<li class="itflow-link-row">' . linkRowHtml($to, $row, $client_id) . $unlink . '</li>';
}
$add = $can_edit ? linkPickerButton($from, $id, $to, 'Link', 'ms-auto small', 'fas fa-plus me-1', "Link {$entity['label']}") : '';
if ($compact) {
$open = $total <= 5;
$collapse_id = 'linked-' . preg_replace('/[^a-z0-9_-]/i', '', "$from-$id-$to");
$groups .= '<div class="itflow-link-group is-compact"><div class="itflow-link-group-head">'
. '<button type="button" class="itflow-link-group-toggle' . ($open ? '' : ' collapsed') . '" data-bs-toggle="collapse" data-bs-target="#' . $collapse_id . '" aria-expanded="' . ($open ? 'true' : 'false') . '" aria-controls="' . $collapse_id . '">'
. "<i class=\"fas fa-fw {$entity['icon']} me-1\"></i>{$entity['plural']}<span class=\"badge rounded-pill ms-1\">" . count($rows) . '</span><i class="fas fa-chevron-down itflow-link-group-chevron"></i></button></div>'
. '<div class="collapse' . ($open ? ' show' : '') . '" id="' . $collapse_id . '"><ul class="list-unstyled mb-0">' . $items . '</ul></div></div>';
continue;
}
$groups .= "<div class=\"itflow-link-group\"><div class=\"itflow-link-group-head\"><i class=\"fas fa-fw {$entity['icon']} me-1\"></i>{$entity['plural']}<span class=\"badge rounded-pill ms-1\">" . count($rows) . "</span>$add</div><ul class=\"list-unstyled mb-0\">$items</ul></div>";
}
if ($empty) {

View File

@@ -2,7 +2,11 @@
* 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.
* Headings without an id get one, so a link to a section can be shared.
* 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.
*
* 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';
@@ -58,4 +62,51 @@
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 queued = false;
const mark = function () {
queued = false;
let current = headings[0];
const line = window.innerHeight * 0.25;
headings.forEach(function (h) {
if (h.getBoundingClientRect().top <= line) {
current = h;
}
});
Object.keys(links).forEach(function (id) {
links[id].classList.toggle('active', id === current.id);
});
};
const queue = function () {
if (!queued) {
queued = true;
window.requestAnimationFrame(mark);
}
};
window.addEventListener('scroll', queue, { passive: true });
window.addEventListener('resize', queue);
mark();
})();
(function () {
'use strict';
document.addEventListener('click', function (e) {
const link = e.target.closest ? e.target.closest('a[data-document-tab]') : null;
if (!link) {
return;
}
const tab = document.querySelector('button[data-document-tab="' + link.getAttribute('data-document-tab') + '"]');
if (!tab || !window.bootstrap) {
return;
}
e.preventDefault();
bootstrap.Tab.getOrCreateInstance(tab).show();
tab.closest('.card').scrollIntoView({ behavior: 'smooth', block: 'start' });
});
})();