From a96507e2b34440f364f29358be552eccc755c55e Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 3 Nov 2026 14:14:47 +0100 Subject: [PATCH] Redesign rundown review around focused issue resolution --- crates/rundown-converter/src/gui.rs | 274 ++----- crates/rundown-converter/src/gui/review.rs | 803 +++++++++++++++++++++ docs/rundown-converter-plan.md | 4 + docs/rundown-converter.md | 51 +- 4 files changed, 900 insertions(+), 232 deletions(-) create mode 100644 crates/rundown-converter/src/gui/review.rs diff --git a/crates/rundown-converter/src/gui.rs b/crates/rundown-converter/src/gui.rs index d63be16..bc41765 100644 --- a/crates/rundown-converter/src/gui.rs +++ b/crates/rundown-converter/src/gui.rs @@ -1,3 +1,4 @@ +mod review; use crate::{ detect, export, model::{Analysis, Profile, Table, column_name}, @@ -5,6 +6,7 @@ use crate::{ time::display, }; use eframe::egui::{self, Color32, RichText}; +use review::ReviewView; use std::{ path::PathBuf, sync::{ @@ -47,6 +49,14 @@ struct App { neutral: bool, completed: Option, settings: bool, + review_view: ReviewView, + dirty: bool, + issue_index: usize, + issues_only: bool, + selected_row: Option, + jump_row: Option, + row_details: bool, + resolutions_open: bool, profile_path: Option, replace_profile: bool, resolution_dir: Option, @@ -70,6 +80,14 @@ impl Default for App { neutral: false, completed: None, settings: false, + review_view: ReviewView::Rows, + dirty: false, + issue_index: 0, + issues_only: true, + selected_row: None, + jump_row: None, + row_details: false, + resolutions_open: false, profile_path: None, replace_profile: false, resolution_dir: resolution::directory(), @@ -79,6 +97,10 @@ impl Default for App { impl App { fn invalidate(&mut self) { self.analysis = None; + self.dirty = false; + self.issue_index = 0; + self.selected_row = None; + self.jump_row = None; self.completed = None; self.error = None; } @@ -145,6 +167,10 @@ impl App { }); } fn export(&mut self) { + if self.dirty { + self.error = Some("Apply & recheck your changes before exporting".into()); + return; + } let Some(a) = self.analysis.clone() else { return; }; @@ -194,6 +220,15 @@ impl App { "Resolve highlighted issues before exporting" } .into(); + self.dirty = false; + self.issue_index = 0; + self.selected_row = a.diagnostics.first().and_then(review::diagnostic_row); + self.jump_row = self.selected_row; + self.review_view = if a.diagnostics.is_empty() { + ReviewView::Preview + } else { + ReviewView::Rows + }; self.analysis = Some(*a); } Update::Exported(p) => { @@ -299,7 +334,7 @@ impl App { ); if before != serde_json::to_string(&profile).unwrap() { self.profile = serde_json::to_string_pretty(&profile).unwrap(); - self.invalidate(); + self.decisions_changed(); } } ui.label("Optional JSON profile: columns (start/end/duration/title), duration_unit, row_kinds, durations, untimed_as_notes. Column letters and source rows are shown in diagnostics."); @@ -312,7 +347,7 @@ impl App { ) .changed() { - self.invalidate(); + self.decisions_changed(); } } @@ -345,16 +380,18 @@ impl App { let profile = resolution::load(&path)?; self.profile = serde_json::to_string_pretty(&profile)?; self.profile_path = Some(path); - self.invalidate(); + self.decisions_changed(); self.status = "Resolution loaded; apply and recheck before export".into(); Ok(()) } fn remember(&mut self) -> anyhow::Result<()> { anyhow::ensure!( - self.analysis - .as_ref() - .is_some_and(|a| a.completed_stage == 4 && a.diagnostics.is_empty()), + !self.dirty + && self + .analysis + .as_ref() + .is_some_and(|a| a.completed_stage == 4 && a.diagnostics.is_empty()), "Validate the resolution before remembering it" ); let path = self.memory_path()?; @@ -366,8 +403,7 @@ impl App { } fn resolution_controls(&mut self, ui: &mut egui::Ui) { - ui.heading("Review and resolve"); - ui.label("Edit decisions below, then Apply & recheck. Source documents remain unchanged."); + ui.label("Save and reuse clarification decisions. Original documents remain unchanged."); ui.horizontal_wrapped(|ui| { if ui.button("Load resolution…").clicked() && let Some(path) = rfd::FileDialog::new() @@ -403,17 +439,18 @@ impl App { if ui.button("Reset decisions").clicked() { self.profile = "{}".into(); self.profile_path = None; - self.invalidate(); + self.decisions_changed(); } }); if let Some(path) = &self.profile_path { ui.label(format!("Resolution: {}", path.display())); } ui.horizontal_wrapped(|ui| { - let ready = self - .analysis - .as_ref() - .is_some_and(|a| a.completed_stage == 4 && a.diagnostics.is_empty()); + let ready = !self.dirty + && self + .analysis + .as_ref() + .is_some_and(|a| a.completed_stage == 4 && a.diagnostics.is_empty()); if ui .add_enabled(ready, egui::Button::new("Remember resolution")) .clicked() @@ -445,135 +482,6 @@ impl App { ui.small("Remembered decisions match the complete sheet, including row order and timing formats. Reuse always requires validation."); } - fn source_table(&mut self, ui: &mut egui::Ui) { - let Some(table) = self.tables.iter().find(|t| t.name == self.sheet) else { - return; - }; - let Ok(mut profile) = serde_json::from_str::(&self.profile) else { - return; - }; - let before = serde_json::to_string(&profile).unwrap(); - let (mapping, evidence) = detect::inspect(table, &profile); - for text in &evidence { - ui.label(text); - } - let header = profile - .header_row - .or_else(|| { - evidence - .first() - .and_then(|s| s.strip_prefix("Header row ")) - .and_then(|s| s.parse().ok()) - }) - .unwrap_or(1) - .clamp(1, table.rows.len().max(1)); - let width = table.rows.iter().map(Vec::len).max().unwrap_or(0); - ui.separator(); - ui.strong("Source rows and resolution decisions"); - ui.label("Choose a column role to resolve ambiguity. Auto leaves inference in charge. Duration corrections need units (e.g. 2 min); blank restores the source value."); - egui::ScrollArea::both() - .max_height(320.0) - .id_salt("source_scroll") - .show(ui, |ui| { - egui::Grid::new("source_resolution") - .striped(true) - .show(ui, |ui| { - ui.strong("Row"); - ui.strong("Row meaning"); - ui.strong("Duration correction"); - for c in 0..width { - ui.vertical(|ui| { - let col = column_name(c); - ui.strong(format!("{col} · {}", table.cell(header - 1, c).text)); - let mut chosen = profile - .columns - .iter() - .find(|(_, v)| **v == col) - .map(|(k, _)| k.clone()) - .unwrap_or_default(); - let old = chosen.clone(); - egui::ComboBox::from_id_salt(("column_role", c)) - .selected_text(if chosen.is_empty() { "Auto" } else { &chosen }) - .show_ui(ui, |ui| { - ui.selectable_value(&mut chosen, String::new(), "Auto"); - for role in ["start", "end", "duration", "title"] { - ui.selectable_value(&mut chosen, role.into(), role); - } - }); - if chosen != old { - profile.columns.retain(|_, v| *v != col); - if !chosen.is_empty() { - profile.columns.insert(chosen, col); - } - } - if let Ok(m) = &mapping { - let role = if m.start == c { - "start" - } else if m.title == c { - "title" - } else if m.end == Some(c) { - "end" - } else if m.duration == Some(c) { - "duration" - } else { - "metadata" - }; - ui.small(format!("Detected: {role}")); - } - }); - } - ui.end_row(); - for row in header..table.rows.len() { - let number = row + 1; - ui.label(number.to_string()); - let mut kind = - profile.row_kinds.get(&number).cloned().unwrap_or_default(); - egui::ComboBox::from_id_salt(("row_kind", number)) - .selected_text(if kind.is_empty() { "Auto" } else { &kind }) - .show_ui(ui, |ui| { - ui.selectable_value(&mut kind, String::new(), "Auto"); - for k in ["event", "gap", "marker", "note", "ignore"] { - ui.selectable_value(&mut kind, k.into(), k); - } - }); - if kind.is_empty() { - profile.row_kinds.remove(&number); - } else { - profile.row_kinds.insert(number, kind); - } - let mut duration = - profile.durations.get(&number).cloned().unwrap_or_default(); - if ui - .add( - egui::TextEdit::singleline(&mut duration) - .id_salt(("duration", number)) - .desired_width(100.0) - .hint_text("Source value"), - ) - .changed() - { - if duration.trim().is_empty() { - profile.durations.remove(&number); - } else { - profile.durations.insert(number, duration); - } - } - for c in 0..width { - let value = table.cell(row, c).text; - ui.add(egui::Label::new(&value).truncate()) - .on_hover_text(value); - } - ui.end_row(); - } - }); - }); - if before != serde_json::to_string(&profile).unwrap() { - self.profile = serde_json::to_string_pretty(&profile).unwrap(); - self.invalidate(); - self.status = "Decisions changed; apply and recheck".into(); - } - } - fn pane(&mut self, ui: &mut egui::Ui) { match self.tab { Tab::Setup => { @@ -642,64 +550,7 @@ impl App { self.mapping_controls(ui); } } - Tab::Review => { - self.resolution_controls(ui); - self.mapping_controls(ui); - if let Some(a) = &self.analysis { - for d in &a.diagnostics { - ui.colored_label( - Color32::from_rgb(220, 130, 65), - format!("{} — {}\n{}", d.code, d.location, d.message), - ); - ui.add_space(6.0); - } - } - self.source_table(ui); - if let Some(a) = &self.analysis { - ui.heading(format!("Schedule preview · {}", a.sheet)); - if let Some(r) = &a.rundown { - ui.separator(); - ui.label(format!( - "{} entries · {} untimed gaps", - r.entries.len(), - r.gaps.len() - )); - egui::Grid::new("schedule").striped(true).show(ui, |ui| { - for label in ["Row", "Start", "End", "Duration", "Title"] { - ui.strong(label); - } - ui.end_row(); - for e in &r.entries { - ui.label(e.source_rows.first().map_or(0, |s| s.row).to_string()); - ui.label(format!( - "{}{}", - display(e.start_ms), - if e.explicit_start { "" } else { " *" } - )); - ui.label(display(e.end_ms)); - ui.label(if e.kind == "marker" { - "Marker".into() - } else { - display(e.duration_ms) - }); - ui.label(&e.title).on_hover_text(e.decisions.join("\n")); - ui.end_row(); - } - }); - ui.label("* Inferred start. Hover a title for timing decisions."); - for g in &r.gaps { - ui.label(format!( - "Gap: {} → {} · {} (no timer)", - g.start_ms.map(display).unwrap_or("?".into()), - g.end_ms.map(display).unwrap_or("?".into()), - g.title - )); - } - } - } else { - ui.label("Apply & recheck to update the schedule. Export is blocked until these decisions pass validation."); - } - } + Tab::Review => self.review(ui), Tab::Details => { ui.heading("Analysis status"); ui.label(&self.status); @@ -713,7 +564,7 @@ impl App { ui.separator(); ui.heading("Intermediate representation"); if let Some(r) = &a.rundown { - if !a.diagnostics.is_empty() { + if self.dirty || !a.diagnostics.is_empty() { ui.label("Draft only: resolve the issues in Review before exporting."); } ui.monospace(serde_json::to_string_pretty(r).unwrap_or_default()); @@ -812,10 +663,11 @@ impl App { { self.analyze(); } - let ready = self - .analysis - .as_ref() - .is_some_and(|a| a.completed_stage == 4 && a.diagnostics.is_empty()) + let ready = !self.dirty + && self + .analysis + .as_ref() + .is_some_and(|a| a.completed_stage == 4 && a.diagnostics.is_empty()) && !self.output.is_empty(); if ui.add_enabled(ready, egui::Button::new("Export")).clicked() { self.export(); @@ -824,9 +676,13 @@ impl App { }); }); egui::CentralPanel::default().show(ctx, |ui| { - egui::ScrollArea::both().show(ui, |ui| { - ui.add_enabled_ui(!busy, |ui| self.pane(ui)); - }); + if self.tab == Tab::Review { + ui.add_enabled_ui(!busy, |ui| self.review(ui)); + } else { + egui::ScrollArea::both().show(ui, |ui| { + ui.add_enabled_ui(!busy, |ui| self.pane(ui)); + }); + } }); if busy { ctx.request_repaint_after(Duration::from_millis(50)); @@ -1026,7 +882,7 @@ mod tests { wait(&mut app); assert_eq!(app.memory_path().unwrap(), memory); app.load_profile(memory).unwrap(); - assert!(app.analysis.is_none()); + assert!(app.dirty); app.analyze(); wait(&mut app); assert!(app.analysis.as_ref().unwrap().diagnostics.is_empty()); diff --git a/crates/rundown-converter/src/gui/review.rs b/crates/rundown-converter/src/gui/review.rs new file mode 100644 index 0000000..05b613d --- /dev/null +++ b/crates/rundown-converter/src/gui/review.rs @@ -0,0 +1,803 @@ +use super::*; +use crate::model::Diagnostic; +use std::collections::BTreeSet; + +#[derive(Default, PartialEq)] +pub(super) enum ReviewView { + #[default] + Rows, + Preview, + Columns, +} + +pub(super) fn diagnostic_row(d: &Diagnostic) -> Option { + let (_, location) = d.location.rsplit_once('!')?; + let row = if let Some(row) = location.strip_prefix("row ") { + row.parse().ok()? + } else { + let digits = location.trim_start_matches(|c: char| c.is_ascii_alphabetic()); + if digits == location { + return None; + } + digits.parse().ok()? + }; + (row > 0).then_some(row) +} + +fn short(text: &str, count: usize) -> String { + let text = text.split_whitespace().collect::>().join(" "); + let mut result: String = text.chars().take(count).collect(); + if result.len() < text.len() { + result.push('…'); + } + result +} + +impl App { + pub(super) fn decisions_changed(&mut self) { + self.dirty = true; + self.completed = None; + self.error = None; + self.status = "Decisions changed; apply and recheck".into(); + } + + fn issue_rows(&self) -> BTreeSet { + self.analysis + .as_ref() + .map(|a| a.diagnostics.iter().filter_map(diagnostic_row).collect()) + .unwrap_or_default() + } + + fn choose_issue(&mut self, index: usize) { + self.issue_index = index; + let row = self + .analysis + .as_ref() + .and_then(|a| a.diagnostics.get(index)) + .and_then(diagnostic_row); + self.selected_row = row; + self.jump_row = row; + } + + pub(super) fn review(&mut self, ui: &mut egui::Ui) { + ui.spacing_mut().item_spacing.y = 6.0; + let compact = ui.available_height() < 480.0; + if !compact || self.dirty { + ui.horizontal_wrapped(|ui| { + ui.heading(if self.sheet.is_empty() { + "Review" + } else { + &self.sheet + }); + if self.dirty { + ui.colored_label( + Color32::from_rgb(230, 187, 100), + "Changes pending · recheck to update", + ); + } else if let Some(a) = &self.analysis { + let count = a.diagnostics.len(); + ui.label(if count == 0 { + "Ready to export".into() + } else { + format!("{count} issues to resolve") + }); + } + }); + } + ui.horizontal_wrapped(|ui| { + ui.selectable_value(&mut self.review_view, ReviewView::Rows, "Resolve rows"); + ui.selectable_value( + &mut self.review_view, + ReviewView::Preview, + "Schedule preview", + ); + ui.selectable_value(&mut self.review_view, ReviewView::Columns, "Columns"); + if ui.button("Resolutions…").clicked() { + self.resolutions_open = true; + } + }); + ui.separator(); + match self.review_view { + ReviewView::Rows => { + self.issue_navigator(ui); + self.resolution_rows(ui); + } + ReviewView::Preview => { + if self.dirty { + ui.label( + "Previous analysis. Apply & recheck to see your changes in this schedule.", + ); + } else if self + .analysis + .as_ref() + .is_some_and(|a| !a.diagnostics.is_empty()) + { + ui.label("Draft schedule: unresolved rows may be missing. Resolve the issues before export."); + } + egui::ScrollArea::both() + .id_salt("schedule_preview_scroll") + .auto_shrink([false, false]) + .show(ui, |ui| self.schedule_preview(ui)); + } + ReviewView::Columns => { + egui::ScrollArea::vertical() + .id_salt("columns_scroll") + .auto_shrink([false, false]) + .show(ui, |ui| self.columns_view(ui)); + } + } + let mut open = self.resolutions_open; + egui::Window::new("Saved resolutions") + .open(&mut open) + .default_width(560.0) + .resizable(true) + .vscroll(true) + .show(ui.ctx(), |ui| { + ui.add_enabled_ui(self.rx.is_none(), |ui| self.resolution_controls(ui)); + }); + self.resolutions_open = open; + self.row_window(ui.ctx()); + } + + fn issue_navigator(&mut self, ui: &mut egui::Ui) { + let Some(a) = &self.analysis else { + ui.label("Analyze the sheet to find rows that need clarification."); + return; + }; + if a.diagnostics.is_empty() { + return; + } + let count = a.diagnostics.len(); + let mut selected = self.issue_index.min(count - 1); + ui.horizontal(|ui| { + if ui + .add_enabled(selected > 0, egui::Button::new("‹")) + .on_hover_text("Previous issue") + .clicked() + { + selected -= 1; + } + if ui + .add_enabled(selected + 1 < count, egui::Button::new("›")) + .on_hover_text("Next issue") + .clicked() + { + selected += 1; + } + egui::ComboBox::from_id_salt("issue_picker") + .width((ui.available_width() - 30.0).max(180.0)) + .selected_text(format!( + "{} / {count} · {}", + selected + 1, + short(&a.diagnostics[selected].location, 35) + )) + .show_ui(ui, |ui| { + for (i, d) in a.diagnostics.iter().enumerate() { + ui.selectable_value( + &mut selected, + i, + format!( + "{} · {} · {}", + i + 1, + d.location, + short(&d.code.replace('_', " ").to_lowercase(), 40) + ), + ); + } + }); + }); + let compact = ui.available_height() < 360.0; + let d = a.diagnostics[selected].clone(); + if selected != self.issue_index { + self.choose_issue(selected); + } + egui::Frame::new().fill(Color32::from_rgb(47, 40, 31)).inner_margin(8.0).corner_radius(5.0).show(ui, |ui| { + ui.set_width(ui.available_width()); + ui.horizontal_wrapped(|ui| { + ui.strong(d.code.replace('_', " ").to_lowercase()); + if let Some(row) = diagnostic_row(&d) { + if ui.small_button(format!("Show row {row}")).clicked() { + self.selected_row = Some(row); + self.jump_row = Some(row); + } + if ui.small_button("Full row…").clicked() { + self.selected_row = Some(row); + self.row_details = true; + } + } + if d.stage == 1 && ui.small_button("Review columns").clicked() { self.review_view = ReviewView::Columns; } + }); + // The source contents sit in the table / row inspector, not in every error card. + let explanation = d.message.split("\nRow preview:").next().unwrap_or(&d.message); + let explanation = if d.code == "UNTIMED_ROW" { + if compact { "Choose a meaning below, or enter an event duration." } + else { "This row has no timing. Choose Note, Marker or Gap below, or supply a duration if it is an event." } + } else { explanation }; + egui::ScrollArea::vertical().id_salt("issue_explanation").max_height(48.0).show(ui, |ui| { ui.label(explanation); }); + }); + ui.add_space(4.0); + } + + fn resolution_rows(&mut self, ui: &mut egui::Ui) { + ui.spacing_mut().item_spacing.y = 4.0; + let Some(table) = self.tables.iter().find(|t| t.name == self.sheet) else { + return; + }; + let Ok(mut profile) = serde_json::from_str::(&self.profile) else { + ui.label( + "The profile is not valid JSON. Open Columns to correct it or load a resolution.", + ); + return; + }; + let before = serde_json::to_string(&profile).unwrap(); + let (mapping, evidence) = detect::inspect(table, &profile); + let header = profile + .header_row + .or_else(|| { + evidence + .first() + .and_then(|s| s.strip_prefix("Header row ")) + .and_then(|s| s.parse().ok()) + }) + .unwrap_or(1) + .clamp(1, table.rows.len().max(1)); + let title_col = mapping.as_ref().ok().map(|m| m.title).or_else(|| { + self.analysis + .as_ref() + .and_then(|a| a.mapping.as_ref().map(|m| m.title)) + }); + let issue_rows: BTreeSet<_> = self + .issue_rows() + .into_iter() + .filter(|r| *r > header && *r <= table.rows.len()) + .collect(); + let filter = self.issues_only && !issue_rows.is_empty(); + let rows: Vec<_> = (header + 1..=table.rows.len()) + .filter(|r| !filter || issue_rows.contains(r)) + .collect(); + ui.horizontal(|ui| { + ui.selectable_value(&mut self.issues_only, false, "All rows"); + ui.add_enabled_ui(!issue_rows.is_empty(), |ui| { + ui.selectable_value( + &mut self.issues_only, + true, + format!("Needs attention ({})", issue_rows.len()), + ); + }); + ui.label(format!("{} shown", rows.len())); + }); + let spacing = ui.spacing().item_spacing.x; + let summary_width = + (ui.available_width() - 40.0 - 100.0 - 105.0 - spacing * 3.0 - 14.0).max(90.0); + ui.horizontal(|ui| { + for (label, width) in [ + ("Row", 40.0), + ("Source contents", summary_width), + ("Meaning", 100.0), + ("Duration", 105.0), + ] { + ui.allocate_ui_with_layout( + egui::vec2(width, 22.0), + egui::Layout::left_to_right(egui::Align::Center), + |ui| { + ui.set_min_width(width); + ui.strong(label); + }, + ); + } + }); + let row_height = 36.0; + let mut scroll = egui::ScrollArea::vertical() + .id_salt("resolve_rows") + .auto_shrink([false, false]); + if let Some(row) = self.jump_row.take() + && let Some(index) = rows.iter().position(|r| *r == row) + { + scroll = scroll + .vertical_scroll_offset(index as f32 * (row_height + ui.spacing().item_spacing.y)); + } + scroll.show_rows(ui, row_height, rows.len(), |ui, range| { + for index in range { + let number = rows[index]; + ui.push_id(number, |ui| { + let selected = self.selected_row == Some(number); + let (rect, _) = ui.allocate_exact_size( + egui::vec2(ui.available_width(), row_height), + egui::Sense::hover(), + ); + let fill = if selected { + Color32::from_rgb(51, 44, 80) + } else if index % 2 == 0 { + Color32::from_rgb(30, 32, 37) + } else { + Color32::TRANSPARENT + }; + ui.painter().rect_filled(rect, 3.0, fill); + ui.scope_builder( + egui::UiBuilder::new() + .max_rect(rect) + .layout(egui::Layout::left_to_right(egui::Align::Center)), + |ui| { + let label = if issue_rows.contains(&number) { + format!("{number} •") + } else { + number.to_string() + }; + if ui + .add_sized( + [40.0, row_height], + egui::Button::new(label).frame(false), + ) + .clicked() + { + self.selected_row = Some(number); + self.row_details = true; + } + let title = title_col + .map(|c| table.cell(number - 1, c).text) + .filter(|t| !t.trim().is_empty()); + let contents = table.rows[number - 1] + .iter() + .enumerate() + .filter(|(_, c)| !c.text.trim().is_empty()) + .map(|(i, c)| format!("{}: {}", column_name(i), c.text)) + .collect::>() + .join(" · "); + ui.allocate_ui_with_layout( + egui::vec2(summary_width, row_height), + egui::Layout::top_down(egui::Align::Min), + |ui| { + ui.set_min_width(summary_width); + ui.spacing_mut().item_spacing.y = 3.0; + if ui + .add( + egui::Label::new(title.as_deref().unwrap_or(&contents)) + .truncate() + .sense(egui::Sense::click()), + ) + .on_hover_text(&contents) + .clicked() + { + self.selected_row = Some(number); + self.row_details = true; + } + if title.is_some() { + ui.add( + egui::Label::new( + RichText::new(&contents).size(12.0).weak(), + ) + .truncate(), + ); + } + }, + ); + ui.allocate_ui_with_layout( + egui::vec2(100.0, row_height), + egui::Layout::left_to_right(egui::Align::Center), + |ui| { + ui.set_min_width(100.0); + Self::row_kind_control(ui, &mut profile, number); + }, + ); + let mut duration = + profile.durations.get(&number).cloned().unwrap_or_default(); + if ui + .add( + egui::TextEdit::singleline(&mut duration) + .id_salt(("duration", number)) + .desired_width(95.0) + .hint_text("e.g. 2 min"), + ) + .on_hover_text( + "Explicit duration correction. Leave blank to use the source.", + ) + .changed() + { + if duration.trim().is_empty() { + profile.durations.remove(&number); + } else { + profile.durations.insert(number, duration); + } + } + }, + ); + }); + } + }); + if before != serde_json::to_string(&profile).unwrap() { + self.profile = serde_json::to_string_pretty(&profile).unwrap(); + self.decisions_changed(); + } + } + + fn row_kind_control(ui: &mut egui::Ui, profile: &mut Profile, number: usize) { + let mut kind = profile.row_kinds.get(&number).cloned().unwrap_or_default(); + egui::ComboBox::from_id_salt(("kind", number)) + .width(90.0) + .selected_text(if kind.is_empty() { "Auto" } else { &kind }) + .show_ui(ui, |ui| { + ui.selectable_value(&mut kind, String::new(), "Auto"); + for (value, label) in [ + ("event", "Event"), + ("gap", "Gap / break"), + ("marker", "Marker"), + ("note", "Note"), + ("ignore", "Ignore"), + ] { + ui.selectable_value(&mut kind, value.into(), label); + } + }); + if kind.is_empty() { + profile.row_kinds.remove(&number); + } else { + profile.row_kinds.insert(number, kind); + } + } + + fn row_window(&mut self, ctx: &egui::Context) { + let Some(row) = self.selected_row else { + return; + }; + let Some(table) = self.tables.iter().find(|t| t.name == self.sheet) else { + return; + }; + let Some(cells) = table.rows.get(row.saturating_sub(1)) else { + return; + }; + let profile: Profile = serde_json::from_str(&self.profile).unwrap_or_default(); + let evidence = detect::inspect(table, &profile).1; + let header = profile + .header_row + .or_else(|| { + evidence + .first() + .and_then(|s| s.strip_prefix("Header row ")) + .and_then(|s| s.parse::().ok()) + }) + .unwrap_or(1) + .max(1); + let mut open = self.row_details; + egui::Window::new(format!("Source row {row}")) + .id(egui::Id::new("row_details")) + .open(&mut open) + .default_width(500.0) + .vscroll(true) + .show(ctx, |ui| { + ui.label( + "Original source values. Edit the row's meaning and duration in Resolve rows.", + ); + for (c, cell) in cells + .iter() + .enumerate() + .filter(|(_, c)| !c.text.is_empty() || c.formula.is_some()) + { + ui.separator(); + ui.strong(format!( + "{} · {}", + column_name(c), + table.cell(header - 1, c).text + )); + ui.label(&cell.text); + if let Some(formula) = &cell.formula { + ui.small(format!("Formula: {formula}")); + } + } + }); + self.row_details = open; + } + + fn columns_view(&mut self, ui: &mut egui::Ui) { + ui.heading("Column meanings"); + ui.label("Choose the intended role when inference is ambiguous. Every timing cell is still validated."); + self.mapping_controls(ui); + if let (Some(table), Ok(mut profile)) = ( + self.tables.iter().find(|t| t.name == self.sheet), + serde_json::from_str::(&self.profile), + ) { + let before = serde_json::to_string(&profile).unwrap(); + let (mapping, evidence) = detect::inspect(table, &profile); + for text in &evidence { + ui.label(text); + } + let header = profile + .header_row + .or_else(|| { + evidence + .first() + .and_then(|s| s.strip_prefix("Header row ")) + .and_then(|s| s.parse().ok()) + }) + .unwrap_or(1) + .clamp(1, table.rows.len().max(1)); + let width = table.rows.iter().map(Vec::len).max().unwrap_or(0); + for c in 0..width { + ui.separator(); + ui.horizontal_wrapped(|ui| { + ui.strong(format!( + "{} · {}", + column_name(c), + table.cell(header - 1, c).text + )); + let col = column_name(c); + let mut chosen = profile + .columns + .iter() + .find(|(_, v)| **v == col) + .map(|(k, _)| k.clone()) + .unwrap_or_default(); + let old = chosen.clone(); + egui::ComboBox::from_id_salt(("column", c)) + .selected_text(if chosen.is_empty() { "Auto" } else { &chosen }) + .show_ui(ui, |ui| { + ui.selectable_value(&mut chosen, String::new(), "Auto"); + for role in ["start", "end", "duration", "title"] { + ui.selectable_value(&mut chosen, role.into(), role); + } + }); + if chosen != old { + profile.columns.retain(|_, v| *v != col); + if !chosen.is_empty() { + profile.columns.insert(chosen, col); + } + } + if let Ok(m) = &mapping { + let role = if m.start == c { + "start" + } else if m.title == c { + "title" + } else if m.end == Some(c) { + "end" + } else if m.duration == Some(c) { + "duration" + } else { + "metadata" + }; + ui.weak(format!("Detected: {role}")); + } + }); + let samples = table + .rows + .iter() + .skip(header) + .filter_map(|r| r.get(c)) + .filter(|v| !v.text.trim().is_empty()) + .take(3) + .map(|v| short(&v.text, 65)) + .collect::>() + .join(" / "); + ui.label(samples); + } + if before != serde_json::to_string(&profile).unwrap() { + self.profile = serde_json::to_string_pretty(&profile).unwrap(); + self.decisions_changed(); + } + } + } + + fn schedule_preview(&mut self, ui: &mut egui::Ui) { + if let Some(a) = &self.analysis { + ui.heading(format!("Schedule preview · {}", a.sheet)); + if let Some(r) = &a.rundown { + ui.separator(); + ui.label(format!( + "{} entries · {} untimed gaps", + r.entries.len(), + r.gaps.len() + )); + egui::Grid::new("schedule").striped(true).show(ui, |ui| { + for label in ["Row", "Start", "End", "Duration", "Title"] { + ui.strong(label); + } + ui.end_row(); + for e in &r.entries { + ui.label(e.source_rows.first().map_or(0, |s| s.row).to_string()); + ui.label(format!( + "{}{}", + display(e.start_ms), + if e.explicit_start { "" } else { " *" } + )); + ui.label(display(e.end_ms)); + ui.label(if e.kind == "marker" { + "Marker".into() + } else { + display(e.duration_ms) + }); + ui.label(&e.title).on_hover_text(e.decisions.join("\n")); + ui.end_row(); + } + }); + ui.label("* Inferred start. Hover a title for timing decisions."); + for g in &r.gaps { + ui.label(format!( + "Gap: {} → {} · {} (no timer)", + g.start_ms.map(display).unwrap_or("?".into()), + g.end_ms.map(display).unwrap_or("?".into()), + g.title + )); + } + } + } else { + ui.label("Apply & recheck to update the schedule. Export is blocked until these decisions pass validation."); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn sample() -> App { + let cells = |values: &[&str]| { + values + .iter() + .map(|text| crate::model::Cell { + text: (*text).into(), + ..Default::default() + }) + .collect() + }; + let mut table = Table { + name: "Show".into(), + rows: vec![ + cells(&["Start", "Duration", "Title"]), + cells(&["09:00", "5 min", "Opening"]), + ], + merges: vec![], + }; + for n in 0..12 { + table + .rows + .push(cells(&["", "", &format!("Stage direction {n}")])); + } + table.rows.push(cells(&["09:05", "5 min", "Closing"])); + let analysis = pipeline::analyze( + &table, + &Profile::default(), + &AtomicBool::new(false), + |_, _| {}, + ); + App { + sheet: table.name.clone(), + tables: vec![table], + analysis: Some(analysis), + tab: Tab::Review, + selected_row: Some(3), + ..Default::default() + } + } + + fn render( + app: &mut App, + ctx: &egui::Context, + size: [f32; 2], + events: Vec, + ) -> Vec<(String, egui::Rect)> { + let output = ctx.run( + egui::RawInput { + screen_rect: Some(egui::Rect::from_min_size( + egui::Pos2::ZERO, + egui::vec2(size[0], size[1]), + )), + events, + ..Default::default() + }, + |ctx| app.draw(ctx), + ); + fn texts(shape: &egui::Shape, clip: egui::Rect, out: &mut Vec<(String, egui::Rect)>) { + match shape { + egui::Shape::Text(t) => { + let rect = t.galley.rect.translate(t.pos.to_vec2()); + if clip.contains_rect(rect) { + out.push((t.galley.job.text.clone(), rect)); + } + } + egui::Shape::Vec(shapes) => { + for s in shapes { + texts(s, clip, out); + } + } + _ => {} + } + } + let mut labels = vec![]; + for shape in output.shapes { + texts(&shape.shape, shape.clip_rect, &mut labels); + } + labels + } + + fn click(app: &mut App, ctx: &egui::Context, pos: egui::Pos2) -> Vec<(String, egui::Rect)> { + let events = vec![ + egui::Event::PointerMoved(pos), + egui::Event::PointerButton { + pos, + button: egui::PointerButton::Primary, + pressed: true, + modifiers: Default::default(), + }, + egui::Event::PointerButton { + pos, + button: egui::PointerButton::Primary, + pressed: false, + modifiers: Default::default(), + }, + ]; + render(app, ctx, [560.0, 400.0], events) + } + + #[test] + fn compact_review_keeps_corrections_visible_and_clickable() { + let mut app = sample(); + let ctx = egui::Context::default(); + configure_style(&ctx); + render(&mut app, &ctx, [560.0, 400.0], vec![]); + let labels = render(&mut app, &ctx, [560.0, 400.0], vec![]); + let visible_rows = labels.iter().filter(|(s, _)| s.ends_with(" •")).count(); + assert!( + visible_rows >= 4, + "Only {visible_rows} source rows visible in compact review" + ); + assert!(labels.iter().any(|(s, _)| s == "Apply & recheck")); + let auto = labels.iter().find(|(s, _)| s == "Auto").unwrap().1.center(); + click(&mut app, &ctx, auto); + let menu = render(&mut app, &ctx, [560.0, 400.0], vec![]); + let note = menu + .iter() + .find(|(s, _)| s == "Note") + .expect("Row meaning menu should open") + .1 + .center(); + click(&mut app, &ctx, note); + let profile: Profile = serde_json::from_str(&app.profile).unwrap(); + assert_eq!(profile.row_kinds[&3], "note"); + assert!(app.dirty); + assert_eq!(app.analysis.as_ref().unwrap().diagnostics.len(), 12); + app.export(); + assert!(app.rx.is_none()); + assert!(app.error.as_ref().unwrap().contains("recheck")); + app.error = None; + app.choose_issue(8); + assert_eq!(app.selected_row, Some(11)); + render(&mut app, &ctx, [560.0, 400.0], vec![]); + let labels = render(&mut app, &ctx, [560.0, 400.0], vec![]); + assert!( + labels.iter().any(|(s, _)| s == "11 •"), + "Issue navigation should reveal its row" + ); + app.row_details = true; + render(&mut app, &ctx, [560.0, 400.0], vec![]); + app.row_details = false; + app.review_view = ReviewView::Columns; + render(&mut app, &ctx, [560.0, 400.0], vec![]); + app.review_view = ReviewView::Preview; + render(&mut app, &ctx, [560.0, 400.0], vec![]); + } + + #[test] + fn issue_locations_and_mapping_errors_do_not_hide_data_rows() { + for (location, expected) in [ + ("Show!row 8", Some(8)), + ("Show!AA12", Some(12)), + ("Show!row 0", None), + ("Show", None), + ] { + assert_eq!( + diagnostic_row(&Diagnostic::new(1, "TEST", location, "test")), + expected + ); + } + let mut app = sample(); + app.analysis.as_mut().unwrap().diagnostics = vec![Diagnostic::new( + 1, + "AMBIGUOUS_COLUMN", + "Show!B1", + "Select a duration column", + )]; + let ctx = egui::Context::default(); + configure_style(&ctx); + render(&mut app, &ctx, [860.0, 620.0], vec![]); + let labels = render(&mut app, &ctx, [860.0, 620.0], vec![]); + assert!(labels.iter().any(|(s, _)| s == "Opening")); + assert!(labels.iter().any(|(s, _)| s == "Review columns")); + } +} diff --git a/docs/rundown-converter-plan.md b/docs/rundown-converter-plan.md index 33215ac..a01f6fe 100644 --- a/docs/rundown-converter-plan.md +++ b/docs/rundown-converter-plan.md @@ -252,6 +252,10 @@ errors must remain visible with direct corrective actions. add column-role dropdowns, row classifications and duration corrections. - [x] Save/overwrite/save-as portable resolution profiles and explicitly remember, reuse or forget validated resolutions matched to the complete sheet. +- [x] Redesign Review into Resolve rows / Schedule preview / Columns, with one + issue at a time, row navigation/filtering, a full-height correction table and + separate saved-resolution controls. Preserve pending edits and previous results + until recheck; verify compact layout and dropdown interaction. - [ ] Add recent-file persistence, direct start/end/title editing and comprehensive native GUI interaction checks. - [ ] Inventory supplied examples by format/layout; record intended interpretations diff --git a/docs/rundown-converter.md b/docs/rundown-converter.md index fe2a884..880f244 100644 --- a/docs/rundown-converter.md +++ b/docs/rundown-converter.md @@ -33,30 +33,35 @@ directories must already exist. Exit codes: 0 success, 1 read/profile/write fail CLI logs are plain text on stderr; JSON results go to stdout. In the desktop app, choose or drop one file, read its sheets, select a sheet and -click **Analyze rundown**. **Review** shows source rows, timing decisions, gaps and -blocking errors; **Export** is enabled only after validation. Review keeps the -source table available even when column inference fails, with the evidence -collected before the error. Choose a role from a column's dropdown to resolve -ambiguity; selecting one duration column explicitly resolves duplicate TIMER -headers. **Auto** restores inference, rather than ignoring a column. Expand -**Remap columns, header and units / advanced profile** for role-to-column -selectors, header row, duration units and the JSON editor (also in Setup). +click **Analyze rundown**. Review has three focused views: -In the source table, choose each row's meaning or enter a duration correction -with units, such as `2 min`. Blank corrections restore the source value. Click -**Apply & recheck** to rebuild and validate the schedule; editing decisions blocks -export until validation succeeds. Missing durations and untimed-row decisions -can be resolved here. Untimed-row errors include a preview of nonempty source -cells, labeled with their column letters and headers (long values are shortened). Unsupported interpretations, invalid start/end values, -conflicting timings and unresolved overlaps still produce explicit errors; -correct the source when the available controls cannot express the intended fix. -The schedule preview below the source table shows the resulting timers and gaps. - **Results** offers Open, Open output folder and Copy path. **Details** contains -the current status, completed analysis stage count and full intermediate -representation, including original rows. Incomplete representations are labeled -as drafts; actionable errors stay in Review. Cancel is -observed between analysis stages and before publishing an export; reading a -workbook or an active stage finishes before it takes effect. +- **Resolve rows** shows one issue at a time with previous/next buttons and an + issue picker. **Needs attention** filters to affected source rows; **All rows** + restores the full list. Selecting an issue brings its row into view. The table + fills the available space and keeps its column headings visible while scrolling. + Choose a row meaning or enter a duration with units, such as `2 min`. Click a + row number/title or **Full row…** to read all original cells with their headers. +- **Schedule preview** gives the resulting timers and gaps their own view. Draft + and out-of-date schedules are labeled; they cannot be exported. +- **Columns** shows inference evidence, per-column role dropdowns, and sample + values. Selecting one duration column explicitly resolves duplicate TIMER + headers. **Auto** restores inference. Expand **Remap columns, header and units / + advanced profile** for header row, duration units and JSON settings (also in Setup). + +Click **Apply & recheck** after corrections. Pending edits retain the issue list +and previous preview so you can resolve several rows without losing your place; +export and remembering a resolution remain blocked until validation succeeds. +Blank duration corrections restore source values. Missing durations and untimed +row decisions can be resolved here. Unsupported interpretations, invalid +start/end values, conflicting timings and unresolved overlaps retain explicit +errors; correct the source when available controls cannot express the intended fix. +CLI untimed-row errors also include a labeled source preview. + +**Resolutions…** opens the save/load/remember controls without taking space away +from the correction table. **Results** offers Open, Open output folder and Copy +path. **Details** contains status, completed analysis stage count and the full IR, +including original rows. Cancel is observed between analysis stages and before +publishing an export; reading a workbook or an active stage finishes first. ## Purpose