Refactor case detail and document view
Introduce a `DocumentTemplate` struct for rendering the document view, replacing inline HTML. Introduce a `CaseFlags` struct to encapsulate the logic for determining various UI states of a case (e.g., `has_document`, `analyzing`, `can_close`, `llm_missing`). Update `handle_case_detail` to use `compute_flags` for populating the `CaseDetailTemplate`. Update `scan_user_cases` to compute `analyzing` and `has_document` flags for the `UserCaseView`. Add new template logic in `case_detail.html` to display actions based on `CaseFlags`. Add new template logic in `my_cases.html` to display `analyzing` and `done-doc` labels for cases. Create a new `document.html` template. Add a helper function `any_document_exists` to check for the presence of a document file.
This commit is contained in:
@@ -2,6 +2,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use askama::Template;
|
||||
use axum::extract::{Path as AxumPath, State};
|
||||
use axum::response::{Html, Redirect};
|
||||
use time::format_description::well_known::Rfc3339;
|
||||
@@ -15,6 +16,14 @@ use crate::config::Config;
|
||||
use crate::error::AppError;
|
||||
use crate::routes::user_web::locate_case;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "document.html")]
|
||||
struct DocumentTemplate {
|
||||
case_id: String,
|
||||
version: u32,
|
||||
content: String,
|
||||
}
|
||||
|
||||
/// POST /web/cases/{case_id}/close
|
||||
///
|
||||
/// Persist an `analysis_input_v1.json` for the case and enqueue an analyze
|
||||
@@ -152,14 +161,14 @@ pub async fn handle_document_view(
|
||||
.await
|
||||
.ok_or_else(|| AppError::NotFound("Noch kein Dokument erzeugt".into()))?;
|
||||
|
||||
// Minimal inline HTML for step 4; replaced with a proper template in step 7.
|
||||
let escaped = content
|
||||
.replace('&', "&")
|
||||
.replace('<', "<")
|
||||
.replace('>', ">");
|
||||
Ok(Html(format!(
|
||||
"<!doctype html><html><head><meta charset=\"utf-8\"><title>Dokument v{version}</title></head><body><pre>{escaped}</pre><p><a href=\"/web/cases/{case_id}\">Zurück</a></p></body></html>"
|
||||
)))
|
||||
DocumentTemplate {
|
||||
case_id,
|
||||
version,
|
||||
content,
|
||||
}
|
||||
.render()
|
||||
.map(Html)
|
||||
.map_err(|e| AppError::Internal(format!("Template render failed: {e}")))
|
||||
}
|
||||
|
||||
/// Return `(path, mtime)` for every `.m4a` file directly under `case_dir`,
|
||||
|
||||
Reference in New Issue
Block a user