Add .mdb import button and modal with server-side migration runner

This commit is contained in:
2026-03-12 14:15:13 -06:00
parent d7fde71e15
commit 68300d0375
6 changed files with 365 additions and 0 deletions
+100
View File
@@ -311,3 +311,103 @@ td {
margin-top: auto;
}
.form-actions .btn-primary { flex: 1; padding: 8px; }
/* ── Import modal ── */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.4);
z-index: 200;
opacity: 0;
pointer-events: none;
transition: opacity 0.15s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -48%);
width: 480px;
max-width: calc(100vw - 2rem);
background: var(--surface);
border-radius: 6px;
box-shadow: 0 8px 32px rgba(0,0,0,0.2);
z-index: 201;
display: flex;
flex-direction: column;
opacity: 0;
pointer-events: none;
transition: opacity 0.15s, transform 0.15s;
}
.modal.open {
opacity: 1;
pointer-events: auto;
transform: translate(-50%, -50%);
}
.modal-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 16px;
background: var(--header-bg);
color: var(--header-fg);
border-radius: 6px 6px 0 0;
flex-shrink: 0;
}
.modal-header h2 { font-size: 14px; font-weight: 600; }
.modal-body {
padding: 16px;
display: flex;
flex-direction: column;
gap: 12px;
}
.modal-desc {
font-size: 12px;
color: var(--text-muted);
line-height: 1.5;
}
.modal-desc code {
font-family: monospace;
background: var(--bg);
padding: 1px 4px;
border-radius: 3px;
}
input[type="file"] {
border: 1px solid var(--border);
border-radius: 4px;
padding: 6px 8px;
font-size: 13px;
font-family: var(--font);
width: 100%;
background: var(--surface);
cursor: pointer;
}
.import-log {
font-family: monospace;
font-size: 11px;
background: #0f172a;
color: #94a3b8;
border-radius: 4px;
padding: 10px 12px;
max-height: 200px;
overflow-y: auto;
white-space: pre-wrap;
word-break: break-all;
line-height: 1.5;
}
.import-log.success { color: #86efac; }
.import-log.error { color: #fca5a5; }
.modal-footer {
display: flex;
gap: 8px;
padding: 12px 16px;
border-top: 1px solid var(--border);
}
+22
View File
@@ -30,6 +30,7 @@
Generate PDF <span id="selected-count" class="badge">0</span>
</button>
<button id="btn-new-check" class="btn-secondary">+ New Check</button>
<button id="btn-import" class="btn-secondary">Import .mdb</button>
</div>
</div>
@@ -117,6 +118,27 @@
</form>
</aside>
<!-- Import modal -->
<div id="import-modal-overlay" class="modal-overlay"></div>
<div id="import-modal" class="modal" role="dialog" aria-labelledby="import-modal-title">
<div class="modal-header">
<h2 id="import-modal-title">Import from .mdb</h2>
<button id="btn-close-import" class="btn-icon" title="Close">×</button>
</div>
<div class="modal-body">
<p class="modal-desc">Select an ezCheckPrinting <code>.mdb</code> file to import account settings, check layout, and check history. This will replace existing data.</p>
<div class="form-group">
<label for="import-file">File</label>
<input type="file" id="import-file" accept=".mdb">
</div>
<div id="import-log" class="import-log" hidden></div>
</div>
<div class="modal-footer">
<button id="btn-run-import" class="btn-primary">Import</button>
<button id="btn-cancel-import" class="btn-ghost">Cancel</button>
</div>
</div>
<script src="/js/app.js"></script>
</body>
</html>
+66
View File
@@ -337,6 +337,65 @@ async function reprintCheck(id) {
}
}
// ── Import modal ─────────────────────────────────────────────────────────────
function openImportModal() {
document.getElementById('import-file').value = '';
const log = document.getElementById('import-log');
log.hidden = true;
log.textContent = '';
log.className = 'import-log';
document.getElementById('btn-run-import').disabled = false;
document.getElementById('btn-run-import').textContent = 'Import';
document.getElementById('import-modal-overlay').classList.add('open');
document.getElementById('import-modal').classList.add('open');
}
function closeImportModal() {
document.getElementById('import-modal-overlay').classList.remove('open');
document.getElementById('import-modal').classList.remove('open');
}
async function runImport() {
const fileInput = document.getElementById('import-file');
if (!fileInput.files.length) {
alert('Select an .mdb file first.');
return;
}
const btn = document.getElementById('btn-run-import');
btn.disabled = true;
btn.textContent = 'Importing…';
const log = document.getElementById('import-log');
log.hidden = false;
log.className = 'import-log';
log.textContent = 'Running import…';
const form = new FormData();
form.append('mdbfile', fileInput.files[0]);
try {
const res = await fetch('/api/import', { method: 'POST', body: form });
const data = await res.json();
log.textContent = data.log || '';
if (res.ok) {
log.classList.add('success');
btn.textContent = 'Done';
await Promise.all([loadAccount(), loadChecks()]);
} else {
log.classList.add('error');
btn.disabled = false;
btn.textContent = 'Retry';
}
} catch (err) {
log.classList.add('error');
log.textContent = err.message;
btn.disabled = false;
btn.textContent = 'Retry';
}
}
// ── Utilities ────────────────────────────────────────────────────────────────
function escHtml(str) {
@@ -383,6 +442,13 @@ function init() {
// Generate PDF
document.getElementById('btn-generate-pdf').addEventListener('click', generatePdf);
// Import modal
document.getElementById('btn-import').addEventListener('click', openImportModal);
document.getElementById('btn-close-import').addEventListener('click', closeImportModal);
document.getElementById('btn-cancel-import').addEventListener('click', closeImportModal);
document.getElementById('import-modal-overlay').addEventListener('click', closeImportModal);
document.getElementById('btn-run-import').addEventListener('click', runImport);
// Initial data load
loadAccount();
loadChecks();