Merge pull request #7 from JoshHeaps/mobileUi
Deploy Media Server / build (push) Successful in 39s
Deploy Media Server / deploy (push) Failing after 7s

Add document viewer
This commit is contained in:
Josh Heaps
2026-02-12 09:55:24 -07:00
committed by GitHub
3 changed files with 245 additions and 0 deletions
@@ -273,6 +273,18 @@
</div> </div>
</div> </div>
<!-- Document Viewer Modal -->
<div class="doc-viewer-overlay" id="docViewerOverlay" style="display:none" onclick="medDocsCloseViewer(event)">
<div class="doc-viewer-modal" onclick="event.stopPropagation()">
<div class="doc-viewer-header">
<span class="doc-viewer-title" id="docViewerTitle"></span>
<button class="doc-viewer-close" onclick="medDocsCloseViewer()" title="Close">&times;</button>
</div>
<div class="doc-viewer-body" id="docViewerBody">
</div>
</div>
</div>
@section Scripts { @section Scripts {
<script src="~/js/medical-docs/state.js" asp-append-version="true"></script> <script src="~/js/medical-docs/state.js" asp-append-version="true"></script>
<script src="~/js/medical-docs/tabs.js" asp-append-version="true"></script> <script src="~/js/medical-docs/tabs.js" asp-append-version="true"></script>
@@ -1369,6 +1369,131 @@
line-height: 1.6; line-height: 1.6;
} }
/* ======================== */
/* Document Viewer Modal */
/* ======================== */
.doc-viewer-overlay {
position: fixed;
inset: 0;
z-index: 1000;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(4px);
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.doc-viewer-modal {
background: var(--bg-primary);
border: 1px solid var(--border-primary);
border-radius: 12px;
display: flex;
flex-direction: column;
max-width: 90vw;
max-height: 90vh;
width: auto;
min-width: 300px;
overflow: hidden;
}
.doc-viewer-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 16px;
border-bottom: 1px solid var(--border-primary);
flex-shrink: 0;
}
.doc-viewer-title {
font-size: 14px;
font-weight: 500;
color: var(--text-primary);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
}
.doc-viewer-close {
background: none;
border: none;
color: var(--text-secondary);
font-size: 24px;
line-height: 1;
cursor: pointer;
padding: 0 4px;
flex-shrink: 0;
margin-left: 12px;
transition: color 0.2s ease;
}
.doc-viewer-close:hover {
color: var(--text-primary);
}
.doc-viewer-body {
padding: 16px;
overflow: auto;
display: flex;
align-items: center;
justify-content: center;
flex: 1;
min-height: 0;
}
.doc-viewer-loading,
.doc-viewer-error {
color: var(--text-secondary);
font-size: 14px;
padding: 40px 20px;
text-align: center;
}
.doc-viewer-error {
color: var(--danger);
}
.doc-viewer-image {
max-width: 100%;
max-height: calc(90vh - 80px);
object-fit: contain;
border-radius: 4px;
}
.doc-viewer-audio {
width: 100%;
min-width: 300px;
max-width: 500px;
}
.doc-viewer-pdf {
width: 80vw;
height: calc(90vh - 80px);
max-width: 100%;
border: none;
border-radius: 4px;
}
.doc-viewer-text {
font-family: inherit;
font-size: 14px;
color: var(--text-primary);
background: var(--bg-secondary);
border: 1px solid var(--border-primary);
border-radius: 6px;
padding: 16px;
max-height: calc(90vh - 120px);
overflow-y: auto;
white-space: pre-wrap;
word-wrap: break-word;
width: 100%;
margin: 0;
line-height: 1.6;
}
/* ======================== */ /* ======================== */
/* Responsive (<=768px) */ /* Responsive (<=768px) */
/* ======================== */ /* ======================== */
@@ -1532,6 +1657,23 @@
.doc-detail-row-inline > div[style*="grid-column"] { .doc-detail-row-inline > div[style*="grid-column"] {
grid-column: auto !important; grid-column: auto !important;
} }
.doc-viewer-overlay {
padding: 0;
}
.doc-viewer-modal {
max-width: 100vw;
max-height: 100vh;
width: 100vw;
height: 100vh;
border-radius: 0;
}
.doc-viewer-pdf {
width: 100%;
height: calc(100vh - 80px);
}
} }
/* ======================== */ /* ======================== */
@@ -78,6 +78,18 @@
select.value = currentVal; select.value = currentVal;
}; };
// --- Viewer ---
app.getViewerType = function (doc) {
if (doc.documentType === 'note') return 'text';
const mime = (doc.mimeType || '').toLowerCase();
if (mime.startsWith('image/')) return 'image';
if (mime.startsWith('audio/')) return 'audio';
if (mime.startsWith('text/')) return 'text';
if (mime === 'application/pdf') return 'pdf';
return null;
};
// --- Documents --- // --- Documents ---
app.loadDocuments = async function () { app.loadDocuments = async function () {
@@ -135,6 +147,11 @@
const aiStatusBadge = app.getAiStatusBadge(doc); const aiStatusBadge = app.getAiStatusBadge(doc);
const viewerType = app.getViewerType(doc);
const viewBtn = viewerType
? `<button onclick="event.stopPropagation(); medDocsView(${doc.id})">View</button>`
: '';
const downloadBtn = doc.documentType === 'file' const downloadBtn = doc.documentType === 'file'
? `<button onclick="event.stopPropagation(); medDocsDownload(${doc.id}, '${app.escapeAttr(doc.fileName || 'download')}')">Download</button>` ? `<button onclick="event.stopPropagation(); medDocsDownload(${doc.id}, '${app.escapeAttr(doc.fileName || 'download')}')">Download</button>`
: ''; : '';
@@ -166,6 +183,7 @@
</div> </div>
<div class="doc-actions" onclick="event.stopPropagation()"> <div class="doc-actions" onclick="event.stopPropagation()">
${processBtn} ${processBtn}
${viewBtn}
${downloadBtn} ${downloadBtn}
<button class="delete-btn" onclick="medDocsDelete(${doc.id})">Delete</button> <button class="delete-btn" onclick="medDocsDelete(${doc.id})">Delete</button>
</div> </div>
@@ -293,6 +311,79 @@
document.body.removeChild(a); document.body.removeChild(a);
}; };
// --- Document Viewer ---
let currentBlobUrl = null;
window.medDocsView = async function (id) {
const doc = state.currentDocuments.find(d => d.id === id);
if (!doc) return;
const viewerType = app.getViewerType(doc);
if (!viewerType) return;
const overlay = document.getElementById('docViewerOverlay');
const title = document.getElementById('docViewerTitle');
const body = document.getElementById('docViewerBody');
title.textContent = doc.title || doc.fileName || 'Untitled';
body.innerHTML = '<div class="doc-viewer-loading">Loading...</div>';
overlay.style.display = '';
document.body.style.overflow = 'hidden';
if (doc.documentType === 'note') {
body.innerHTML = `<pre class="doc-viewer-text">${app.escapeHtml(doc.description || '')}</pre>`;
return;
}
try {
const res = await fetch(`${app.API}/documents/${id}/download`);
if (!res.ok) {
body.innerHTML = '<div class="doc-viewer-error">Failed to load document.</div>';
return;
}
const blob = await res.blob();
currentBlobUrl = URL.createObjectURL(blob);
if (viewerType === 'image') {
body.innerHTML = `<img class="doc-viewer-image" src="${currentBlobUrl}" alt="${app.escapeAttr(doc.title || doc.fileName || '')}" />`;
} else if (viewerType === 'audio') {
body.innerHTML = `<audio class="doc-viewer-audio" controls src="${currentBlobUrl}"></audio>`;
} else if (viewerType === 'pdf') {
body.innerHTML = `<iframe class="doc-viewer-pdf" src="${currentBlobUrl}"></iframe>`;
} else if (viewerType === 'text') {
const text = await blob.text();
body.innerHTML = `<pre class="doc-viewer-text">${app.escapeHtml(text)}</pre>`;
URL.revokeObjectURL(currentBlobUrl);
currentBlobUrl = null;
}
} catch {
body.innerHTML = '<div class="doc-viewer-error">Error loading document.</div>';
}
};
window.medDocsCloseViewer = function (event) {
if (event && event.target !== event.currentTarget) return;
const overlay = document.getElementById('docViewerOverlay');
overlay.style.display = 'none';
document.getElementById('docViewerBody').innerHTML = '';
document.body.style.overflow = '';
if (currentBlobUrl) {
URL.revokeObjectURL(currentBlobUrl);
currentBlobUrl = null;
}
};
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') {
const overlay = document.getElementById('docViewerOverlay');
if (overlay && overlay.style.display !== 'none') {
window.medDocsCloseViewer();
}
}
});
window.medDocsDelete = async function (id) { window.medDocsDelete = async function (id) {
if (!confirm('Delete this document? This cannot be undone.')) return; if (!confirm('Delete this document? This cannot be undone.')) return;