generated from john/python-template
63 lines
3.0 KiB
Python
63 lines
3.0 KiB
Python
"""Documents list and detail page registration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from nicegui import ui
|
|
|
|
from transcription.db.models import Document
|
|
from transcription.db.models import DocumentPerson
|
|
|
|
from .cards import archival_card
|
|
from .data_display import archival_badge
|
|
from .data_display import metadata_row
|
|
from .primitives import render_empty_state
|
|
|
|
|
|
def render_archival_metadata(document: Document, author_link: DocumentPerson | None = None) -> None:
|
|
with ui.column().classes("col-span-12 lg:col-span-4 gap-4"):
|
|
with archival_card(title="Archival Metadata"):
|
|
metadata_row("Author:", author_link.person.full_name if author_link and author_link.person else "Not set")
|
|
metadata_row("Exact Date:", document.document_date.isoformat() if document.document_date else "Not set")
|
|
metadata_row("Approx. Date:", document.document_date_raw or "Not set")
|
|
metadata_row("Location Created:", document.location_created or "Not set")
|
|
metadata_row("Archive Identifier:", document.archive_identifier or "Not set")
|
|
|
|
with ui.column().classes("w-full mt-2"):
|
|
ui.label("Archival Notes:").classes("ui-text-muted text-xs mb-1")
|
|
ui.label(document.notes or "No notes added.").classes("p-2 ui-note-box text-xs")
|
|
|
|
with archival_card(title="System Logistics"):
|
|
ui.label(f"Created: {document.created_at.isoformat()}").classes("text-[11px] ui-text-muted")
|
|
ui.label(f"Updated: {document.updated_at.isoformat()}").classes("text-[11px] ui-text-muted")
|
|
|
|
|
|
def render_doc_people_details(document: Document) -> None:
|
|
with archival_card(title="Related People"):
|
|
if not document.document_people:
|
|
render_empty_state("No linked people yet.", italic=True)
|
|
else:
|
|
with ui.column().classes("w-full gap-2"):
|
|
for link in document.document_people:
|
|
person_label = link.person.full_name if link.person is not None else "Unknown person"
|
|
with ui.row().classes("w-full justify-between items-center ui-row-surface p-2"):
|
|
ui.label(person_label).classes("text-xs font-semibold ui-text-primary")
|
|
archival_badge(link.role.value)
|
|
|
|
|
|
def render_doc_job_details(document: Document) -> None:
|
|
with archival_card(title="Pipeline Jobs"):
|
|
with ui.row().classes("w-full justify-between items-center mb-2"):
|
|
ui.label(f"{len(document.jobs)} Active Jobs").classes("text-xs ui-link-primary font-bold")
|
|
|
|
with ui.row().classes("w-full gap-2 mt-2"):
|
|
ui.button(
|
|
"View Jobs",
|
|
on_click=lambda: ui.navigate.to(f"/documents/{document.id}/jobs"),
|
|
icon="work_history",
|
|
).props("flat dense text-xs").classes("ui-link-primary")
|
|
ui.button(
|
|
"+ Add Job",
|
|
on_click=lambda: ui.navigate.to(f"/jobs/new?document_id={document.id}"),
|
|
icon="add",
|
|
).classes("ui-btn-primary text-xs")
|