Layout mapper L.8: superuser review screen (completes the L.1-L.8 plan)
New AdminLayoutReviewView.vue (/admin/layouts), rendered by App.vue outside the normal authStore-gated shell entirely - a PocketBase superuser is never a `users` record. Its own inline login against pbAdmin's `_superusers` collection; lists every private mapping across every owner (a superuser session bypasses collection rules); each row expands into a read-only SourceDocumentPanel inspection (reusing L.7's labeled-strip pattern) plus an Approve action that promotes straight to shared, independent of the two-user confirmation hook. adminLayoutsService.js gains getSourceDocument()/sourceFileUrl(), both routed through pbAdmin since the mapping's sourceDocument belongs to its owner, not the superuser. Verified end to end against the real running stack (15 assertions via the actual service files, not reimplementations): a fresh app user's private mapping is visible to and approvable by the real superuser, its source file round-trips byte-for-byte, and a completely independent third-party user immediately resolves the now-shared mapping via findByFingerprintHash. npm run build passes; app container rebuilt. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
292c13e819
commit
c18492bee4
132
CLAUDE.md
132
CLAUDE.md
|
|
@ -31,7 +31,7 @@ to rough effort:
|
|||
|---|---|---|
|
||||
| **1** | Extraction + 6 checks + Excel export, dual-engine, measurement harness | **In progress — see gaps below** |
|
||||
| 2 | Review screen, suggested-fix patterns, OCR, 2nd+ bank support | OCR routing + working Docling-fallback (`raw_ocr_extract.py`) built and verified against a real multi-page scan 2026-10-11 — one known single-page edge case remains unreliable, see "OCR / scanned statements" below — **review screen (R.1-R.5) complete as of 2026-10-13** (see "Review screen"/"R.2"/"R.3"/"R.4"/"R.5" under Key decisions & lessons) — R.1 (source-position capture + the pdf.js highlighting viewer), R.2 (plain-language flags + jump-to-flagged navigation), R.3 (the suggested-fix engine - debit/credit swap, transposed digits, OCR digit misread), R.4 (structural row edits - flip sign, insert, split, merge, delete, behind a "more actions" menu), and R.5 (edit log + acknowledge/accept workflow + an optional Excel "Edits" sheet) all shipped; "date format swapped" and a separate "bulk column fix" both investigated and found not to apply to this pipeline's own data shape (see R.3/R.4's own entries) |
|
||||
| 3 | Layout mapper (fingerprinting, versioning, drift detection) | **Pulled forward and in progress as of 2026-10-14** (see "Layout mapper" under Key decisions & lessons) - staged L.1-L.8, full spec scope (§6/§6.1/§9) plus a superuser-review promotion path beyond what's written. L.1 (a modular "layout quirks" tier for mechanical geometric oddities, ahead of the mapper itself) shipped - fixed a real new statement (an Equals Money account) whose header label wrapped across physical lines, plus two more real differences the same statement surfaced (a "$"-prefixed money format, an ISO-shaped date format). L.2 (fingerprinting + the forced-mapping backend contract, no UI/PocketBase yet) shipped - also surfaced and fixed a real gap (a forced mapping had no page-boundary concept, swallowing a cover page's own letterhead into the first transaction; fixed with a new `start_page` field). L.3 (the `layoutMappings`/`layoutMappingVersions` PocketBase schema + the auto-promotion hook) shipped - found and fixed a real rule gap during testing (an owner could self-promote their own mapping to "shared" via a plain update; PocketBase rules gate who can update, not which fields). L.4 (the frontend fingerprint-lookup orchestration, including a real, clickable confirm dialog in `ExtractorView.vue` - not deferred to L.6) shipped - found and fixed two real bugs in the near-match comparator while testing it against the spec's own documented example (per-line vs per-field label text; a 70% overlap threshold that was too strict for that very example, corrected to 50%). L.5 (multi-highlight `SourceDocumentPanel` + a new click-and-drag region tool, `useRegionDraw.js`) shipped. **L.6 (`ManualMappingView.vue`, the core deliverable) shipped** - the full save-once-apply-forever loop proven end to end against a real synthetic statement; also caught and fixed a real, consequential bug along the way (forced-mapping column zones were unpadded, so a word landing a fraction of a point past a raw boundary - or a human's own imprecise mouse drag - could silently exclude a whole transaction with no error). **L.7 (the Layouts page + drift detection) shipped** - found and fixed two MORE real bugs in the same "computed correctly this session, never actually persisted" category: `startPage` and a new `headerBottom` (the real header row text on the mapped page itself, not just whole pages before it) were both missing from what got saved, meaning every future auto-apply of a saved mapping would have silently corrupted data again. Drift detection now also wired into every recheck, not just the original extraction. L.8 (the superuser review screen) not started yet |
|
||||
| 3 | Layout mapper (fingerprinting, versioning, drift detection) | **Pulled forward and in progress as of 2026-10-14** (see "Layout mapper" under Key decisions & lessons) - staged L.1-L.8, full spec scope (§6/§6.1/§9) plus a superuser-review promotion path beyond what's written. L.1 (a modular "layout quirks" tier for mechanical geometric oddities, ahead of the mapper itself) shipped - fixed a real new statement (an Equals Money account) whose header label wrapped across physical lines, plus two more real differences the same statement surfaced (a "$"-prefixed money format, an ISO-shaped date format). L.2 (fingerprinting + the forced-mapping backend contract, no UI/PocketBase yet) shipped - also surfaced and fixed a real gap (a forced mapping had no page-boundary concept, swallowing a cover page's own letterhead into the first transaction; fixed with a new `start_page` field). L.3 (the `layoutMappings`/`layoutMappingVersions` PocketBase schema + the auto-promotion hook) shipped - found and fixed a real rule gap during testing (an owner could self-promote their own mapping to "shared" via a plain update; PocketBase rules gate who can update, not which fields). L.4 (the frontend fingerprint-lookup orchestration, including a real, clickable confirm dialog in `ExtractorView.vue` - not deferred to L.6) shipped - found and fixed two real bugs in the near-match comparator while testing it against the spec's own documented example (per-line vs per-field label text; a 70% overlap threshold that was too strict for that very example, corrected to 50%). L.5 (multi-highlight `SourceDocumentPanel` + a new click-and-drag region tool, `useRegionDraw.js`) shipped. **L.6 (`ManualMappingView.vue`, the core deliverable) shipped** - the full save-once-apply-forever loop proven end to end against a real synthetic statement; also caught and fixed a real, consequential bug along the way (forced-mapping column zones were unpadded, so a word landing a fraction of a point past a raw boundary - or a human's own imprecise mouse drag - could silently exclude a whole transaction with no error). **L.7 (the Layouts page + drift detection) shipped** - found and fixed two MORE real bugs in the same "computed correctly this session, never actually persisted" category: `startPage` and a new `headerBottom` (the real header row text on the mapped page itself, not just whole pages before it) were both missing from what got saved, meaning every future auto-apply of a saved mapping would have silently corrupted data again. Drift detection now also wired into every recheck, not just the original extraction. **L.8 (the superuser review screen) shipped 2026-10-15 - completes the full L.1-L.8 plan.** |
|
||||
| 4 | Multi-tenant practice/client accounts, Frappe data model | Not started |
|
||||
| 5 | Free front door, public accuracy page | Not started |
|
||||
| 6 | Append mode, credit cards, multi-account statements | Not started |
|
||||
|
|
@ -368,13 +368,25 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co
|
|||
App.vue — the auth gate, then the full app shell: AppHeader +
|
||||
ProjectSidebar + routed view + AppFooter (see "Enterprise
|
||||
app-shell redesign" under Key decisions & lessons -
|
||||
modeled on docs/sample_ui.png, same enterprise-light theme)
|
||||
modeled on docs/sample_ui.png, same enterprise-light theme).
|
||||
As of layout mapper L.8 (2026-10-15), checked FIRST,
|
||||
ahead of the auth gate: any route starting with `/admin`
|
||||
renders its own `<RouterView>` directly, bypassing
|
||||
LoginView/authStore/the whole shell entirely - a
|
||||
PocketBase superuser is never a `users` record, so
|
||||
`/admin/layouts` (AdminLayoutReviewView.vue) has no
|
||||
relationship to the app's own login at all.
|
||||
/assets/main.css — started as the original CSS moved verbatim; grown
|
||||
substantially since (table/sidebar/account-bar/app-shell
|
||||
sections each added for their own stage - see Key
|
||||
decisions & lessons for which)
|
||||
/router/index.js — one route today ('/' -> ExtractorView), kept as a real
|
||||
router per the standards doc's structure
|
||||
/router/index.js — kept as a real router per the standards doc's
|
||||
structure. Four routes as of the layout mapper work:
|
||||
'/' -> ExtractorView, '/map-layout' -> ManualMappingView
|
||||
(L.6), '/layouts' -> LayoutsView (L.7), '/admin/layouts'
|
||||
-> AdminLayoutReviewView (L.8 - rendered by App.vue
|
||||
OUTSIDE the normal authStore-gated shell entirely, see
|
||||
below)
|
||||
/stores (Pinia)
|
||||
extractionStore.js — a LIST of documents (`documents`, each `{pbId, docKey,
|
||||
fileName, project, previewUrl, isImage, result,
|
||||
|
|
@ -527,9 +539,13 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co
|
|||
`rollbackToVersion`, and promoted `checksPassed` from a
|
||||
private `useBatchExtraction.js` helper to a shared
|
||||
export so drift detection has one definition, not three).
|
||||
adminLayoutsService.js (NEW 2026-10-14 — the superuser's own
|
||||
`listPending`/`approve`, ahead of L.8's actual review
|
||||
screen; uses pbAdmin, never the app user's own `pb`).
|
||||
adminLayoutsService.js (NEW 2026-10-14, extended
|
||||
2026-10-15 for L.8 — the superuser's own `login`/
|
||||
`logout`/`isLoggedIn`/`listPending`/`approve`, plus
|
||||
`getSourceDocument`/`sourceFileUrl` (L.8 - resolves a
|
||||
mapping's own sourceDocument/file through pbAdmin, since
|
||||
a superuser session never shares the app user's `pb`
|
||||
client); uses pbAdmin throughout, never `pb`.
|
||||
/composables — useFileUpload (pure staging concern only as of Stage
|
||||
B.3 — `chosenFiles` accumulate-not-replace with dedup,
|
||||
drag/drop handlers; no longer owns `loadDocuments`, moved
|
||||
|
|
@ -645,6 +661,22 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co
|
|||
scope deviation and the two more real bugs (startPage/
|
||||
headerBottom never being persisted) this stage's own
|
||||
end-to-end testing caught.
|
||||
/views/AdminLayoutReviewView.vue — NEW 2026-10-15, layout mapper L.8 (the plan's
|
||||
final stage) — routed at /admin/layouts, rendered by
|
||||
App.vue OUTSIDE the normal authStore-gated shell entirely
|
||||
(no AppHeader/ProjectSidebar/AppFooter — a PocketBase
|
||||
superuser is never a `users` record). Its own tiny inline
|
||||
login form against `pbAdmin.collection('_superusers')
|
||||
.authWithPassword(...)`; once signed in, every
|
||||
`status = "private"` mapping across every owner (a real
|
||||
superuser session bypasses PocketBase's rules
|
||||
automatically), each expanding into a read-only
|
||||
SourceDocumentPanel with every columnMap field drawn as a
|
||||
labeled vertical strip (same Inspect pattern L.7's
|
||||
LayoutsView.vue already established) plus dateFormat/
|
||||
signConvention/ignoredRowRules as plain text, and an
|
||||
Approve button (via ConfirmModal) that promotes straight
|
||||
to shared.
|
||||
```
|
||||
**One real bug caught and fixed during this restructure, server-side:** the production
|
||||
`Dockerfile` serves `frontend/dist` from Flask via a catch-all route
|
||||
|
|
@ -2496,6 +2528,92 @@ FontAwesome set before use. **Not machine-verified:** the actual List/Inspect/
|
|||
Test/Retire UI click-through in a real browser - same standing limitation as
|
||||
every other UI stage this session.
|
||||
|
||||
**L.8 shipped 2026-10-15: the superuser review screen - the final stage, this
|
||||
completes the full L.1-L.8 layout mapper plan.** New
|
||||
`frontend/src/views/AdminLayoutReviewView.vue`, routed at `/admin/layouts`, and a
|
||||
new check in `App.vue` (`route.path.startsWith('/admin')`, checked FIRST, ahead
|
||||
of the normal `authStore.isAuthenticated` gate) that renders that route's own
|
||||
`<RouterView>` directly - no `AppHeader`/`ProjectSidebar`/`AppFooter`/`LoginView`
|
||||
at all. Deliberate: a real PocketBase superuser lives in the separate
|
||||
`_superusers` auth collection, not `users` - there is no "logged in as the app"
|
||||
state for this screen to share or be gated by. The view has its own tiny inline
|
||||
login form against `pbAdmin.collection('_superusers').authWithPassword(...)`
|
||||
(`adminLayoutsService.login()`), authenticating on `pbAdmin`
|
||||
(`pocketbaseAdminRepository.js`, already built in L.4) - entirely independent of
|
||||
the app user's own `pb.authStore` on the same machine.
|
||||
|
||||
Once signed in, `adminLayoutsService.listPending()` lists every `status =
|
||||
"private"` mapping across EVERY owner in one call - no per-user filtering code
|
||||
needed anywhere, since a real superuser session bypasses every PocketBase
|
||||
collection rule automatically (confirmed, not assumed: the same `listRule` that
|
||||
restricts an ordinary user to `owner = @request.auth.id || status = "shared"`
|
||||
simply doesn't apply to a `_superusers` session). Each row expands into the same
|
||||
Inspect pattern L.7's `LayoutsView.vue` already established - a read-only
|
||||
`SourceDocumentPanel` with every `columnMap` field drawn as a labeled, full-height
|
||||
vertical strip, plus `dateFormat`/`signConvention`/`ignoredRowRules` as plain
|
||||
text - except the source document and file URL are resolved through two NEW
|
||||
`adminLayoutsService.js` functions, `getSourceDocument()`/`sourceFileUrl()`,
|
||||
both routed through `pbAdmin` rather than `documentsService.js`'s own `pb`-backed
|
||||
versions: the mapping's `sourceDocument` record belongs to its owner, not the
|
||||
superuser, so the app user's own client (which may not even be logged in on this
|
||||
machine at all) could never fetch it - only a real superuser session can, the
|
||||
same rule-bypass reasoning as `listPending()`. **Approve** calls
|
||||
`adminLayoutsService.approve(id)` (built in L.4 already) - sets `status:
|
||||
"shared"`, `promotedReason: "superuser_approved"`, `approvedBySuperuser: <the
|
||||
real superuser's own email>`, `promotedAt: now` - behind the same `ConfirmModal`
|
||||
pattern every other consequential action in this app already uses.
|
||||
|
||||
No backend Python was touched this stage - this is the one layout-mapper stage
|
||||
that is pure frontend routing/UI over infrastructure (fingerprinting, the schema,
|
||||
the hook, `pbAdmin`, `listPending`/`approve`) every earlier stage already built
|
||||
and proved correct.
|
||||
|
||||
**Verified, all real, against the real rebuilt container - a hand-written Node
|
||||
script executing the ACTUAL, already-committed service files (never
|
||||
reimplementations: `authService.js`, `documentsService.js`,
|
||||
`layoutMappingsService.js`, `adminLayoutsService.js`, both real `pb`/`pbAdmin`
|
||||
client instances), 15 assertions, using the real superuser credentials already
|
||||
configured via `pocketbase/configure-secrets.sh`:** signed up a fresh app user,
|
||||
saved a real source document (a real file upload, not a stub), created a
|
||||
still-`private` mapping pointing at it; signed in as the real superuser and
|
||||
confirmed `listPending()` surfaces that mapping; confirmed
|
||||
`getSourceDocument()`/`sourceFileUrl()` fetch the owner-only document record and
|
||||
its real file bytes - compared byte-for-byte against the original upload, not
|
||||
just "the request succeeded"; called `approve()` and confirmed on the
|
||||
RE-FETCHED, persisted record (not the update call's own echoed response) that
|
||||
`status`/`promotedReason`/`approvedBySuperuser`/`promotedAt` are all correct, and
|
||||
that the mapping no longer appears in a fresh `listPending()` call; signed the
|
||||
superuser out and confirmed the session actually cleared; **then signed up a
|
||||
COMPLETELY independent third-party user and confirmed `findByFingerprintHash`
|
||||
resolves the now-shared mapping for them immediately** - proving this promotion
|
||||
path works entirely on its own, independent of L.3's two-different-owner hook
|
||||
path. All 15 assertions passed on the first run. Test data (the mapping, the
|
||||
document, both signed-up users and their auto-created default projects) was
|
||||
deleted from the real running PocketBase afterward via direct superuser REST
|
||||
calls, in dependency order (mapping → document → each user's own default
|
||||
project → the user), so none of it lingers as real app data.
|
||||
`npm run build` passes; every icon class used (`fa-user-shield`,
|
||||
`fa-right-to-bracket`, `fa-right-from-bracket`, `fa-chevron-down`/`-right`,
|
||||
`fa-spinner`, `fa-check`, `fa-circle-info`) confirmed present in the installed
|
||||
FontAwesome set before use; the `app` container was rebuilt and is serving the
|
||||
new bundle. `backend/measure.py` was not re-run this stage - zero backend Python
|
||||
was touched, so the standing per-stage rule (re-run after any change to
|
||||
`table_extract.py`/`extraction_service.py`/`pipeline_service.py`) doesn't apply
|
||||
here; `git status` confirms the only modified/new files this stage are
|
||||
`App.vue`, `router/index.js`, `main.css`, `adminLayoutsService.js`, and the new
|
||||
`AdminLayoutReviewView.vue`. **Not machine-verified:** the actual login form,
|
||||
the expand/Inspect click-through, and the Approve confirm modal in a real
|
||||
browser - same standing limitation as every other UI-only stage this session.
|
||||
|
||||
**This closes out the full layout mapper plan (L.1-L.8).** What started as one
|
||||
real bug report (a never-seen Equals Money statement failing extraction) now has
|
||||
a complete four-tier pipeline - keyword/geometry auto-detection, a code-based
|
||||
quirks module for mechanical oddities, fingerprint-based auto-apply with drift
|
||||
detection, and a manual mapping screen as the true last resort - plus a shared
|
||||
library two independent users' matching mappings promote into automatically, or
|
||||
a real PocketBase superuser can push there directly after reviewing it against
|
||||
the actual source document.
|
||||
|
||||
**Governing rule: never silently correct or exclude data.** This shows up in several
|
||||
concrete places, not just as an abstract principle:
|
||||
- A row with an unusual status (e.g. HSBC's "Cancelled" wires) stays in the output and is
|
||||
|
|
|
|||
|
|
@ -10,20 +10,28 @@
|
|||
* mirrors the PocketBase SDK's own auth state (which persists/restores
|
||||
* the session token itself) into the Pinia store every other component
|
||||
* reads.
|
||||
*
|
||||
* Any /admin-prefixed route (the layout mapper's superuser review screen,
|
||||
* L.8) renders OUTSIDE this entire gate - a PocketBase superuser is never
|
||||
* a `users` record, so it has no relationship to authStore/LoginView/the
|
||||
* normal app shell at all. Checked first, before the normal auth gate.
|
||||
*/
|
||||
import { onMounted } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useAuthStore } from './stores/authStore'
|
||||
import LoginView from './views/LoginView.vue'
|
||||
import AppHeader from './components/AppHeader.vue'
|
||||
import AppFooter from './components/AppFooter.vue'
|
||||
import ProjectSidebar from './components/ProjectSidebar.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const authStore = useAuthStore()
|
||||
onMounted(authStore.syncWithAuthStore)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<LoginView v-if="!authStore.isAuthenticated" />
|
||||
<RouterView v-if="route.path.startsWith('/admin')" />
|
||||
<LoginView v-else-if="!authStore.isAuthenticated" />
|
||||
<div v-else class="app-shell">
|
||||
<AppHeader />
|
||||
<div class="app-body">
|
||||
|
|
|
|||
|
|
@ -974,3 +974,10 @@ tr.editing td{ background:rgba(37,99,235,.03); }
|
|||
.layout-row-head i.fa-chevron-down, .layout-row-head i.fa-chevron-right{ color:var(--t4); font-size:11px; flex-shrink:0; }
|
||||
.layout-row-name{ font-weight:600; }
|
||||
.layout-row-detail{ margin-top:18px; padding-top:18px; border-top:1px solid var(--border-2); }
|
||||
|
||||
/* AdminLayoutReviewView.vue (layout mapper L.8) - rendered directly by
|
||||
App.vue outside the normal app-shell/.app-content (no header/sidebar/
|
||||
footer), so this just needs the page's own min-height - the bare
|
||||
main{...} rule above already provides the max-width/centering/padding
|
||||
every other top-level page gets for free. */
|
||||
.admin-shell{ min-height:100vh; }
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { createRouter, createWebHistory } from 'vue-router'
|
|||
import ExtractorView from '../views/ExtractorView.vue'
|
||||
import ManualMappingView from '../views/ManualMappingView.vue'
|
||||
import LayoutsView from '../views/LayoutsView.vue'
|
||||
import AdminLayoutReviewView from '../views/AdminLayoutReviewView.vue'
|
||||
|
||||
export default createRouter({
|
||||
history: createWebHistory(),
|
||||
|
|
@ -17,5 +18,10 @@ export default createRouter({
|
|||
// Layout mapper work (L.7) - every saved mapping the user can see,
|
||||
// reached via AppHeader.vue's own "Layouts" nav link.
|
||||
{ path: '/layouts', name: 'layouts', component: LayoutsView },
|
||||
// Layout mapper work (L.8) - the PocketBase superuser's own review
|
||||
// screen. App.vue renders any /admin-prefixed route outside the
|
||||
// normal authStore-gated shell entirely - a superuser is never a
|
||||
// `users` record, so this route needs no relation to app login.
|
||||
{ path: '/admin/layouts', name: 'admin-layouts', component: AdminLayoutReviewView },
|
||||
],
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
/**
|
||||
* The PocketBase superuser's own entry points for reviewing a new,
|
||||
* still-private layout mapping and approving it straight to "shared" -
|
||||
* the layout mapper's own review screen (L.8, not built yet) is the
|
||||
* only planned consumer. Uses pbAdmin (pocketbaseAdminRepository.js),
|
||||
* never the app user's own `pb` client - a superuser session lives in
|
||||
* its own PocketBase auth collection (`_superusers`), entirely separate
|
||||
* from the app's `users` collection.
|
||||
* AdminLayoutReviewView.vue (layout mapper L.8) is the only consumer.
|
||||
* Uses pbAdmin (pocketbaseAdminRepository.js), never the app user's own
|
||||
* `pb` client - a superuser session lives in its own PocketBase auth
|
||||
* collection (`_superusers`), entirely separate from the app's `users`
|
||||
* collection, so this never touches or is affected by whatever app user
|
||||
* (if any) is logged in on the same machine.
|
||||
*/
|
||||
import { pbAdmin } from '../repositories/pocketbaseAdminRepository'
|
||||
|
||||
|
|
@ -38,3 +39,13 @@ export async function approve(id) {
|
|||
promotedAt: new Date().toISOString(),
|
||||
})
|
||||
}
|
||||
|
||||
/** A mapping's own sourceDocument record, as the superuser - bypasses the owner-only rule documentsService.js's own pb client would be blocked by (a superuser session never shares that client or its session at all). */
|
||||
export async function getSourceDocument(documentId) {
|
||||
return pbAdmin.collection('documents').getOne(documentId)
|
||||
}
|
||||
|
||||
/** Same shape as documentsService.sourceFileUrl, but resolved through the superuser's own pbAdmin client - needed since that document record was fetched as the superuser, not the (possibly nonexistent) logged-in app user. */
|
||||
export function sourceFileUrl(record) {
|
||||
return record?.sourceFile ? pbAdmin.files.getURL(record, record.sourceFile) : null
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,222 @@
|
|||
<script setup>
|
||||
/**
|
||||
* AdminLayoutReviewView.vue
|
||||
*
|
||||
* The layout mapper's superuser review screen (L.8) - lets a real
|
||||
* PocketBase superuser inspect a still-private mapping against its
|
||||
* actual source document and approve it straight to "shared," instead
|
||||
* of only ever waiting for a second independent user to confirm it
|
||||
* (the promote_shared_layout_mapping.pb.js hook's own path - see
|
||||
* CLAUDE.md's "Layout mapper" entry). Deliberately a SEPARATE surface
|
||||
* from the rest of this app:
|
||||
* - Routed at /admin/layouts, rendered by App.vue OUTSIDE the normal
|
||||
* authenticated shell entirely (no AppHeader/ProjectSidebar/
|
||||
* AppFooter, no authStore gate) - a superuser is never a `users`
|
||||
* record, so the app's own login has nothing to do with this.
|
||||
* - Its own tiny inline login form against
|
||||
* `pbAdmin.collection('_superusers').authWithPassword(...)` -
|
||||
* `pbAdmin` (pocketbaseAdminRepository.js) is a SECOND, separate
|
||||
* PocketBase client instance; signing in here never touches or is
|
||||
* affected by whatever app user (if any) is logged in on the same
|
||||
* machine, since `pb.authStore` and `pbAdmin.authStore` are
|
||||
* entirely independent.
|
||||
*
|
||||
* A real superuser session bypasses every PocketBase collection rule
|
||||
* automatically, so `listPending()` sees every owner's own private
|
||||
* mappings in one call - no special-casing needed on the backend side
|
||||
* at all for this to work.
|
||||
*/
|
||||
import { nextTick, reactive, ref } from 'vue'
|
||||
import * as adminLayoutsService from '../services/adminLayoutsService'
|
||||
import SourceDocumentPanel from '../components/SourceDocumentPanel.vue'
|
||||
import ConfirmModal from '../components/ConfirmModal.vue'
|
||||
|
||||
const IMAGE_FILE_RE = /\.(jpe?g|png)$/i
|
||||
const FIELD_COLORS = {
|
||||
date: '#2563EB', description: '#7C3AED', debit: '#DC2626',
|
||||
credit: '#16A34A', amount: '#D97706', balance: '#0891B2',
|
||||
}
|
||||
|
||||
// ── Login (this screen's own, entirely separate from the app's) ─────
|
||||
const email = ref('')
|
||||
const password = ref('')
|
||||
const loginError = ref('')
|
||||
const loggingIn = ref(false)
|
||||
const loggedIn = ref(adminLayoutsService.isLoggedIn())
|
||||
|
||||
async function handleLogin() {
|
||||
loggingIn.value = true
|
||||
loginError.value = ''
|
||||
try {
|
||||
await adminLayoutsService.login(email.value, password.value)
|
||||
loggedIn.value = true
|
||||
await loadPending()
|
||||
} catch (e) {
|
||||
loginError.value = 'Could not sign in: ' + e.message
|
||||
}
|
||||
loggingIn.value = false
|
||||
}
|
||||
function handleLogout() {
|
||||
adminLayoutsService.logout()
|
||||
loggedIn.value = false
|
||||
pending.value = []
|
||||
expandedId.value = null
|
||||
}
|
||||
|
||||
// ── Pending mappings ─────────────────────────────────────────────────
|
||||
const pending = ref([])
|
||||
const loading = ref(false)
|
||||
const loadError = ref('')
|
||||
|
||||
async function loadPending() {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
pending.value = await adminLayoutsService.listPending()
|
||||
} catch (e) {
|
||||
loadError.value = 'Could not load pending mappings: ' + e.message
|
||||
}
|
||||
loading.value = false
|
||||
}
|
||||
if (loggedIn.value) loadPending()
|
||||
|
||||
// ── Expand/review - the actual "inspect against the real source" ────
|
||||
const expandedId = ref(null)
|
||||
const sourcePanelRef = ref(null)
|
||||
const inspectUrl = ref(null)
|
||||
const inspectIsImage = ref(false)
|
||||
|
||||
async function toggleExpand(mapping) {
|
||||
if (expandedId.value === mapping.id) {
|
||||
expandedId.value = null
|
||||
return
|
||||
}
|
||||
expandedId.value = mapping.id
|
||||
inspectUrl.value = null
|
||||
if (mapping.sourceDocument) {
|
||||
try {
|
||||
const doc = await adminLayoutsService.getSourceDocument(mapping.sourceDocument)
|
||||
inspectIsImage.value = IMAGE_FILE_RE.test(doc.fileName)
|
||||
inspectUrl.value = adminLayoutsService.sourceFileUrl(doc)
|
||||
await nextTick()
|
||||
sourcePanelRef.value?.showHighlights(inspectHighlights(mapping))
|
||||
} catch (e) {
|
||||
inspectUrl.value = null
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Every mapped column drawn as a tall, labeled vertical strip - columnMap only ever stores an [x0,x1] range, no vertical extent, so a full-height strip is the honest picture of "this column," not a guess at one specific row (same reasoning as LayoutsView.vue's own Inspect). */
|
||||
function inspectHighlights(mapping) {
|
||||
return Object.entries(mapping.columnMap || {}).map(([field, range]) => ({
|
||||
page: 1, bbox: { x0: range[0], x1: range[1], top: 0, bottom: 1000 },
|
||||
label: field, color: FIELD_COLORS[field] || '#2563EB',
|
||||
}))
|
||||
}
|
||||
|
||||
// ── Approve ───────────────────────────────────────────────────────────
|
||||
const approving = reactive({})
|
||||
const pendingApprove = ref(null)
|
||||
function requestApprove(mapping) {
|
||||
pendingApprove.value = mapping
|
||||
}
|
||||
async function confirmApprove() {
|
||||
const mapping = pendingApprove.value
|
||||
pendingApprove.value = null
|
||||
approving[mapping.id] = true
|
||||
try {
|
||||
await adminLayoutsService.approve(mapping.id)
|
||||
pending.value = pending.value.filter((m) => m.id !== mapping.id)
|
||||
if (expandedId.value === mapping.id) expandedId.value = null
|
||||
} catch (e) {
|
||||
loadError.value = 'Could not approve this mapping: ' + e.message
|
||||
}
|
||||
approving[mapping.id] = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main :class="loggedIn ? 'admin-shell' : 'login-page'">
|
||||
<div v-if="!loggedIn" class="card login-card">
|
||||
<h2><i class="fa-solid fa-user-shield"></i>Layout review (superuser)</h2>
|
||||
<p class="sub" style="margin-bottom:18px;">
|
||||
Sign in with the real PocketBase superuser account to review pending layout
|
||||
mappings against their source documents and approve them straight to shared.
|
||||
</p>
|
||||
<form @submit.prevent="handleLogin">
|
||||
<div class="fields" style="margin-bottom:14px; flex-direction:column;">
|
||||
<div><label>Email</label><input v-model="email" type="email" autocomplete="username" required></div>
|
||||
<div><label>Password</label><input v-model="password" type="password" autocomplete="current-password" required></div>
|
||||
</div>
|
||||
<div v-if="loginError" class="error-note visible">{{ loginError }}</div>
|
||||
<button type="submit" class="btn btn-primary" style="width:100%; margin-top:14px;" :disabled="loggingIn">
|
||||
<i class="fa-solid" :class="loggingIn ? 'fa-spinner fa-spin' : 'fa-right-to-bracket'"></i>
|
||||
{{ loggingIn ? 'Signing in…' : 'Sign in' }}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="eyebrow">Layout mapper</div>
|
||||
<h1>Pending layout review</h1>
|
||||
<div class="sub">
|
||||
Every mapping still awaiting a second independent user's confirmation - review
|
||||
it against its real source document and approve it straight to shared.
|
||||
</div>
|
||||
|
||||
<button type="button" class="btn btn-ghost" style="margin-bottom:18px;" @click="handleLogout">
|
||||
<i class="fa-solid fa-right-from-bracket"></i> Sign out
|
||||
</button>
|
||||
|
||||
<div v-if="loadError" class="error-note visible">{{ loadError }}</div>
|
||||
<div v-if="loading" class="card"><p class="note">Loading…</p></div>
|
||||
<div v-else-if="!pending.length" class="card"><p class="note">Nothing is waiting for review right now.</p></div>
|
||||
|
||||
<div v-for="mapping in pending" :key="mapping.id" class="card">
|
||||
<div class="layout-row-head" @click="toggleExpand(mapping)">
|
||||
<i class="fa-solid" :class="expandedId === mapping.id ? 'fa-chevron-down' : 'fa-chevron-right'"></i>
|
||||
<span class="layout-row-name">{{ mapping.name }}</span>
|
||||
<span class="note" style="margin:0 0 0 auto;">created {{ mapping.created }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="expandedId === mapping.id" class="layout-row-detail">
|
||||
<div class="mapper-grid">
|
||||
<div class="mapper-source-card" style="height:60vh;">
|
||||
<SourceDocumentPanel v-if="inspectUrl" ref="sourcePanelRef" :preview-url="inspectUrl" :is-image="inspectIsImage" />
|
||||
<p v-else class="note">No source document is on file for this mapping.</p>
|
||||
</div>
|
||||
<div class="mapper-toolbar">
|
||||
<div class="card">
|
||||
<h2>Mapping details</h2>
|
||||
<p class="note">
|
||||
Date format: {{ mapping.dateFormat }} ·
|
||||
Debit already signed: {{ mapping.signConvention?.debitSelfSigned ? 'yes' : 'no' }} ·
|
||||
Starts on page {{ mapping.startPage || 1 }}
|
||||
</p>
|
||||
<p v-if="mapping.ignoredRowRules?.length" class="note">Ignores rows containing: {{ mapping.ignoredRowRules.join(', ') }}</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<button
|
||||
type="button" class="btn btn-primary" :disabled="approving[mapping.id]"
|
||||
@click="requestApprove(mapping)"
|
||||
>
|
||||
<i class="fa-solid" :class="approving[mapping.id] ? 'fa-spinner fa-spin' : 'fa-check'"></i>
|
||||
Approve - push to shared
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<ConfirmModal
|
||||
:visible="!!pendingApprove"
|
||||
title="Approve this layout?"
|
||||
:message="`Promote “${pendingApprove?.name}” straight to shared? Every future matching upload, from any user, will auto-apply it immediately.`"
|
||||
confirm-label="Approve"
|
||||
confirm-icon="fa-check"
|
||||
@confirm="confirmApprove"
|
||||
@cancel="pendingApprove = null"
|
||||
/>
|
||||
</main>
|
||||
</template>
|
||||
Loading…
Reference in New Issue