diff --git a/crates/rundown-converter/src/gui.rs b/crates/rundown-converter/src/gui.rs index 967f702..fcb3943 100644 --- a/crates/rundown-converter/src/gui.rs +++ b/crates/rundown-converter/src/gui.rs @@ -6,7 +6,7 @@ use crate::{ time::display, }; use eframe::egui::{self, Color32, RichText}; -use review::ReviewView; +use review::{ReviewView, RowFilter}; use std::{ path::PathBuf, sync::{ @@ -52,9 +52,11 @@ struct App { review_view: ReviewView, dirty: bool, issue_index: usize, - issues_only: bool, + row_filter: RowFilter, + show_issue_details: bool, selected_row: Option, jump_row: Option, + review_scroll: Option, row_details: bool, resolutions_open: bool, profile_path: Option, @@ -83,9 +85,11 @@ impl Default for App { review_view: ReviewView::Rows, dirty: false, issue_index: 0, - issues_only: true, + row_filter: RowFilter::Included, + show_issue_details: false, selected_row: None, jump_row: None, + review_scroll: None, row_details: false, resolutions_open: false, profile_path: None, @@ -101,6 +105,9 @@ impl App { self.issue_index = 0; self.selected_row = None; self.jump_row = None; + self.review_scroll = None; + self.row_filter = RowFilter::Included; + self.show_issue_details = false; self.completed = None; self.error = None; } @@ -224,11 +231,7 @@ impl App { 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.review_view = ReviewView::Rows; self.analysis = Some(*a); } Update::Exported(p) => { diff --git a/crates/rundown-converter/src/gui/review.rs b/crates/rundown-converter/src/gui/review.rs index b0a165d..a18d832 100644 --- a/crates/rundown-converter/src/gui/review.rs +++ b/crates/rundown-converter/src/gui/review.rs @@ -6,10 +6,17 @@ use std::collections::BTreeSet; pub(super) enum ReviewView { #[default] Rows, - Preview, Columns, } +#[derive(Default, PartialEq, Clone, Copy)] +pub(super) enum RowFilter { + All, + #[default] + Included, + Attention, +} + pub(super) fn diagnostic_row(d: &Diagnostic) -> Option { let (_, location) = d.location.rsplit_once('!')?; let row = if let Some(row) = location.strip_prefix("row ") { @@ -54,6 +61,7 @@ struct PreviewRow { source_only: bool, issues: Vec, decisions: String, + kind: String, } /// Combine timed draft entries and omitted problem rows without changing the IR. @@ -62,8 +70,9 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec { let mut represented = BTreeSet::new(); if let Some(r) = &a.rundown { for e in &r.entries { - let sources: BTreeSet<_> = e.source_rows.iter().map(|s| s.row).collect(); - represented.extend(&sources); + if let Some(first) = e.source_rows.first() { + represented.insert(first.row); + } rows.push(PreviewRow { row: e.source_rows.first().map_or(0, |s| s.row), start: format!( @@ -83,18 +92,31 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec { .diagnostics .iter() .enumerate() - .filter(|(_, d)| diagnostic_row(d).is_some_and(|r| sources.contains(&r))) + .filter(|(_, d)| diagnostic_row(d) == e.source_rows.first().map(|s| s.row)) .map(|(i, _)| i) .collect(), decisions: e.decisions.join("\n"), + kind: e.kind.clone(), }); } } if let Some(table) = table { - for d in &a.diagnostics { - let Some(row) = diagnostic_row(d).filter(|r| *r <= table.rows.len()) else { + let header = a + .mapping + .as_ref() + .map(|m| m.header_row) + .or_else(|| { + detect::inspect(table, &Profile::default()) + .1 + .first() + .and_then(|s| s.strip_prefix("Header row ")) + .and_then(|s| s.parse().ok()) + }) + .unwrap_or(1); + for row in header + 1..=table.rows.len() { + if table.rows[row - 1].iter().all(|c| c.text.trim().is_empty()) { continue; - }; + } if !represented.insert(row) { continue; } @@ -132,13 +154,57 @@ fn preview_rows(a: &Analysis, table: Option<&Table>) -> Vec { .map(|(i, _)| i) .collect(), decisions: String::new(), + kind: a + .rundown + .as_ref() + .and_then(|r| { + if r.gaps + .iter() + .any(|g| g.source_rows.iter().any(|s| s.row == row)) + { + return Some("Gap · no timer".into()); + } + r.entries + .iter() + .find(|e| e.source_rows.iter().skip(1).any(|s| s.row == row)) + .map(|e| format!("Note for row {}", e.source_rows[0].row)) + }) + .unwrap_or_else(|| "Source row · not a timer".into()), }); } } + if let Some(rundown) = &a.rundown { + for row in &mut rows { + if let Some(gap) = rundown + .gaps + .iter() + .find(|g| g.source_rows.iter().any(|s| s.row == row.row)) + { + row.start = gap.start_ms.map(display).unwrap_or_else(|| "?".into()); + row.end = gap.end_ms.map(display).unwrap_or_else(|| "?".into()); + row.duration = "—".into(); + } + } + } rows.sort_by_key(|r| r.row); rows } +fn ignored_row(row: usize, table: Option<&Table>, profile: &Profile) -> bool { + profile.row_kinds.get(&row).is_some_and(|k| k == "ignore") + || table.is_some_and(|t| { + row > 0 && row <= t.rows.len() && !detect::has_content(t, row - 1, profile) + }) +} + +fn show_row(row: &PreviewRow, filter: RowFilter, table: Option<&Table>, profile: &Profile) -> bool { + match filter { + RowFilter::All => true, + RowFilter::Included => !ignored_row(row.row, table, profile), + RowFilter::Attention => !row.issues.is_empty(), + } +} + impl App { pub(super) fn decisions_changed(&mut self) { self.dirty = true; @@ -147,13 +213,6 @@ impl App { 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 @@ -163,6 +222,13 @@ impl App { .and_then(diagnostic_row); self.selected_row = row; self.jump_row = row; + if let Some(row) = row { + let profile: Profile = serde_json::from_str(&self.profile).unwrap_or_default(); + let table = self.tables.iter().find(|t| t.name == self.sheet); + if self.row_filter == RowFilter::Included && ignored_row(row, table, &profile) { + self.row_filter = RowFilter::All; + } + } } pub(super) fn review(&mut self, ui: &mut egui::Ui) { @@ -191,11 +257,10 @@ impl App { }); } 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", + ReviewView::Rows, + "Schedule & corrections", ); ui.selectable_value(&mut self.review_view, ReviewView::Columns, "Columns"); if ui.button("Resolutions…").clicked() { @@ -204,27 +269,7 @@ impl App { }); 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: highlighted rows need attention before export."); - } - egui::ScrollArea::both() - .id_salt("schedule_preview_scroll") - .auto_shrink([false, false]) - .show(ui, |ui| self.schedule_preview(ui)); - } + ReviewView::Rows => self.schedule_preview(ui), ReviewView::Columns => { egui::ScrollArea::vertical() .id_salt("columns_scroll") @@ -324,198 +369,6 @@ impl App { 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)) @@ -570,7 +423,7 @@ impl App { .vscroll(true) .show(ctx, |ui| { ui.label( - "Original source values. Edit the row's meaning and duration in Resolve rows.", + "Original source values. Edit the row's meaning and duration in Schedule & corrections.", ); for (c, cell) in cells .iter() @@ -693,192 +546,278 @@ impl App { } fn schedule_preview(&mut self, ui: &mut egui::Ui) { - let Some(a) = &self.analysis else { - ui.label("Apply & recheck to update the schedule. Export is blocked until these decisions pass validation."); + ui.horizontal_wrapped(|ui| { + ui.selectable_value(&mut self.row_filter, RowFilter::All, "All rows"); + ui.selectable_value(&mut self.row_filter, RowFilter::Included, "Included rows") + .on_hover_text("Includes events, notes, markers and breaks. Excludes ignored rows and rows containing only ignored columns."); + ui.selectable_value(&mut self.row_filter, RowFilter::Attention, "Needs attention"); + let count = self.analysis.as_ref().map_or(0, |a| a.diagnostics.len()); + ui.toggle_value(&mut self.show_issue_details, format!("Issues ({count})")); + }); + if self.show_issue_details { + self.issue_navigator(ui); + } + let Ok(mut profile) = serde_json::from_str::(&self.profile) else { + ui.label("Correct the profile JSON in Columns before editing rows."); + return; + }; + let before = serde_json::to_string(&profile).unwrap(); + let Some(a) = &self.analysis else { + ui.label("Analyze the sheet to see the schedule and edit its rows."); return; }; - ui.heading(format!("Schedule preview · {}", a.sheet)); ui.horizontal_wrapped(|ui| { - ui.colored_label(PREVIEW_AMBER, "Unresolved: missing information"); - ui.colored_label(PREVIEW_RED, "Error: inconsistent or invalid data"); + ui.colored_label(PREVIEW_AMBER, "Unresolved"); + ui.colored_label(PREVIEW_RED, "Error"); + ui.weak("Ignored"); + ui.small("? unknown · * inferred · edits require recheck"); }); - ui.label("Click a highlighted status to resolve it. ? means unknown; source-only rows are not timers."); let table = self.tables.iter().find(|t| t.name == a.sheet); - let rows = preview_rows(a, table); + let all_rows = preview_rows(a, table); + let rows: Vec<_> = all_rows + .iter() + .filter(|r| show_row(r, self.row_filter, table, &profile)) + .collect(); + if rows.is_empty() { + ui.label(if self.row_filter == RowFilter::Attention { + "No source rows need attention. Sheet or gap issues, if any, are available under Issues." + } else { "No rows match this filter. Choose All rows to review exclusions." }); + } + let compact = ui.available_width() < 760.0; + let title_width = if compact { + (ui.available_width() - 300.0).clamp(180.0, 320.0) + } else { + (ui.available_width() - 370.0).clamp(240.0, 450.0) + }; + let jump = self.jump_row; + let mut jump_visible = !rows.iter().any(|r| Some(r.row) == jump); + let mut jump_offset = None; let mut resolve = None; let mut details = None; let backgrounds: Vec<_> = std::iter::once(None) .chain(rows.iter().map(|row| { - if row + if ignored_row(row.row, table, &profile) { + Some(Color32::from_rgb(34, 35, 39)) + } else if row .issues .iter() .any(|i| !needs_information(&a.diagnostics[*i])) { Some(Color32::from_rgb(58, 30, 33)) - } else if row.source_only || !row.issues.is_empty() { + } else if !row.issues.is_empty() { Some(Color32::from_rgb(52, 43, 27)) } else { None } })) .collect(); - egui::Grid::new("schedule") - .with_row_color(move |row, style| { - backgrounds - .get(row) - .copied() - .flatten() - .or_else(|| (row > 0 && row % 2 == 0).then_some(style.visuals.faint_bg_color)) - }) - .show(ui, |ui| { - for label in [ - "Row", - "Start", - "End", - "Duration", - "Title / source contents", - "Status", - ] { - ui.strong(label); - } - ui.end_row(); - for row in &rows { - let error = row - .issues - .iter() - .any(|i| !needs_information(&a.diagnostics[*i])); - let color = if error { - PREVIEW_RED - } else if row.source_only || !row.issues.is_empty() { - PREVIEW_AMBER + let mut scroll = egui::ScrollArea::both() + .id_salt("merged_schedule") + .auto_shrink([false, false]); + if let Some(offset) = self.review_scroll.take() { + scroll = scroll.vertical_scroll_offset(offset); + } + scroll.show(ui, |ui| { + let content_top = ui.min_rect().top(); + egui::Grid::new("schedule") + .spacing(egui::vec2(10.0, 12.0)) + .with_row_color(move |row, style| { + backgrounds.get(row).copied().flatten().or_else(|| { + (row > 0 && row % 2 == 0).then_some(style.visuals.faint_bg_color) + }) + }) + .show(ui, |ui| { + ui.strong("Row"); + if compact { + ui.strong("Timing"); } else { - ui.visuals().text_color() - }; - for text in [ - row.row.to_string(), - row.start.clone(), - row.end.clone(), - row.duration.clone(), - ] { - ui.colored_label(color, text); + for label in ["Start", "End", "Duration"] { + ui.strong(label); + } } - ui.vertical(|ui| { - ui.set_width(260.0); - if ui - .add( - egui::Label::new(RichText::new(short(&row.title, 80)).color(color)) - .wrap() - .sense(egui::Sense::click()), - ) - .on_hover_text(&row.title) - .clicked() - { + ui.strong("Title, source contents & issues"); + ui.strong("Corrections"); + ui.end_row(); + for row in &rows { + let ignored = ignored_row(row.row, table, &profile); + let error = row + .issues + .iter() + .any(|i| !needs_information(&a.diagnostics[*i])); + let color = if ignored { + ui.visuals().weak_text_color() + } else if error { + PREVIEW_RED + } else if !row.issues.is_empty() { + PREVIEW_AMBER + } else { + ui.visuals().text_color() + }; + let response = ui.add( + egui::Label::new(RichText::new(row.row.to_string()).color(color)) + .sense(egui::Sense::click()), + ); + if response.clicked() { details = Some(row.row); } - if row.source_only { - ui.small("Source row · not a timer"); + if jump == Some(row.row) { + jump_visible = ui.clip_rect().contains_rect(response.rect); + jump_offset = Some( + (response.rect.center().y + - content_top + - ui.clip_rect().height() / 2.0) + .max(0.0), + ); } - if let Some(index) = row.issues.first() { - let message = a.diagnostics[*index] - .message - .split("\nRow preview:") - .next() - .unwrap_or_default(); - ui.label(RichText::new(short(message, 95)).small().color(color)) - .on_hover_text(message); + if compact { + ui.vertical(|ui| { + ui.set_width(105.0); + for (label, value) in [ + ("Start", &row.start), + ("End", &row.end), + ("Dur.", &row.duration), + ] { + ui.colored_label(color, format!("{label} {value}")); + } + }); + } else { + for value in [&row.start, &row.end, &row.duration] { + ui.colored_label(color, value); + } } - }); - if row.issues.is_empty() { - ui.label(if row.source_only { - "Unresolved" - } else if row.duration == "Marker" { - "Marker" - } else { - "Timed" - }) - .on_hover_text(&row.decisions); - } else { - let index = row - .issues - .iter() - .find(|i| !needs_information(&a.diagnostics[**i])) - .unwrap_or(&row.issues[0]); - let label = if error { - "Error · resolve" - } else { - "Unresolved · resolve" - }; - let explanation = row - .issues - .iter() - .map(|i| { - format!( - "{} — {}\n{}", - a.diagnostics[*i].code, - a.diagnostics[*i].location, - a.diagnostics[*i].message + ui.vertical(|ui| { + ui.set_width(title_width); + if ui + .add( + egui::Label::new(RichText::new(&row.title).color(color)) + .wrap() + .sense(egui::Sense::click()), ) - }) - .collect::>() - .join("\n\n"); - if ui - .button(RichText::new(label).color(color)) - .on_hover_text(explanation) - .clicked() - { - resolve = Some(*index); - } + .on_hover_text("Open all original cells") + .clicked() + { + details = Some(row.row); + } + let status = if ignored { + "Ignored" + } else if row.source_only { + &row.kind + } else if row.kind == "marker" { + "Marker" + } else { + "Timed" + }; + ui.small(RichText::new(status).color(color)) + .on_hover_text(&row.decisions); + if let Some(table) = table { + let contents = table + .rows + .get(row.row.saturating_sub(1)) + .map(|cells| { + cells + .iter() + .enumerate() + .filter(|(_, c)| { + !c.text.trim().is_empty() && c.text != row.title + }) + .map(|(col, c)| { + format!("{}: {}", column_name(col), c.text) + }) + .collect::>() + .join(" · ") + }) + .unwrap_or_default(); + if !contents.is_empty() { + ui.label( + RichText::new(short(&contents, 220)) + .size(12.0) + .color(color), + ) + .on_hover_text(contents); + } + } + if !row.issues.is_empty() { + let index = row + .issues + .iter() + .find(|i| !needs_information(&a.diagnostics[**i])) + .unwrap_or(&row.issues[0]); + let d = &a.diagnostics[*index]; + let message = + d.message.split("\nRow preview:").next().unwrap_or_default(); + ui.label(RichText::new(short(message, 140)).small().color(color)) + .on_hover_text(message); + if ui + .small_button( + RichText::new(if error { + "Error · details" + } else { + "Unresolved · details" + }) + .color(color), + ) + .clicked() + { + resolve = Some(*index); + } + } + }); + ui.vertical(|ui| { + ui.set_width(105.0); + ui.push_id(("schedule_kind", row.row), |ui| { + Self::row_kind_control(ui, &mut profile, row.row) + }); + let mut duration = + profile.durations.get(&row.row).cloned().unwrap_or_default(); + if ui + .add( + egui::TextEdit::singleline(&mut duration) + .id_salt(("schedule_duration", row.row)) + .desired_width(95.0) + .hint_text("e.g. 2 min"), + ) + .on_hover_text("Duration correction; blank uses the source value") + .changed() + { + if duration.trim().is_empty() { + profile.durations.remove(&row.row); + } else { + profile.durations.insert(row.row, duration); + } + } + }); + ui.end_row(); } - ui.end_row(); + }); + if let Some(r) = &a.rundown { + 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 + )); } - }); - ui.small("* Inferred start. Hover Timed for timing decisions. Highlighted rows retain their original position."); - // Sheet-level and gap diagnostics must remain reachable even without a source-row address. - for (i, d) in a - .diagnostics - .iter() - .enumerate() - .filter(|(i, _)| !rows.iter().any(|r| r.issues.contains(i))) - { - let color = if needs_information(d) { - PREVIEW_AMBER - } else { - PREVIEW_RED - }; - if ui - .button( - RichText::new(format!("{} · {} · resolve", d.code, d.location)).color(color), - ) - .on_hover_text(&d.message) - .clicked() - { - resolve = Some(i); - } - } - if let Some(r) = &a.rundown { - 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 - )); } + }); + if jump_visible { + self.jump_row = None; + } else { + self.review_scroll = jump_offset; + ui.ctx().request_repaint(); } if let Some(index) = resolve { - let stage = a.diagnostics[index].stage; - let header = a.mapping.as_ref().map_or(1, |m| m.header_row); self.choose_issue(index); - self.review_view = if stage == 1 && self.selected_row.is_none_or(|r| r <= header) { - ReviewView::Columns - } else { - ReviewView::Rows - }; + self.show_issue_details = true; } if let Some(row) = details { self.selected_row = Some(row); self.row_details = true; } + if before != serde_json::to_string(&profile).unwrap() { + self.profile = serde_json::to_string_pretty(&profile).unwrap(); + self.decisions_changed(); + } } } @@ -997,15 +936,13 @@ mod tests { #[test] fn compact_review_keeps_corrections_visible_and_clickable() { let mut app = sample(); + app.row_filter = RowFilter::Attention; 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 == "Stage direction 0")); + assert!(labels.iter().any(|(s, _)| s == "Start ?")); assert!(labels.iter().any(|(s, _)| s == "Apply & recheck")); let auto = labels.iter().find(|(s, _)| s == "Auto").unwrap().1.center(); click(&mut app, &ctx, auto); @@ -1030,7 +967,7 @@ mod tests { 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 •"), + labels.iter().any(|(s, _)| s == "11"), "Issue navigation should reveal its row" ); app.row_details = true; @@ -1038,7 +975,7 @@ mod tests { app.row_details = false; app.review_view = ReviewView::Columns; render(&mut app, &ctx, [560.0, 400.0], vec![]); - app.review_view = ReviewView::Preview; + app.review_view = ReviewView::Rows; render(&mut app, &ctx, [560.0, 400.0], vec![]); } @@ -1056,6 +993,7 @@ mod tests { ); } let mut app = sample(); + app.show_issue_details = true; app.analysis.as_mut().unwrap().diagnostics = vec![Diagnostic::new( 1, "AMBIGUOUS_COLUMN", @@ -1131,14 +1069,14 @@ mod tests { 2, "Preview must not invent IR events" ); - app.review_view = ReviewView::Preview; + app.review_view = ReviewView::Rows; let ctx = egui::Context::default(); configure_style(&ctx); render(&mut app, &ctx, [860.0, 900.0], vec![]); let labels = render(&mut app, &ctx, [860.0, 900.0], vec![]); let resolve = labels .iter() - .find(|(s, _)| s == "Unresolved · resolve") + .find(|(s, _)| s == "Unresolved · details") .unwrap() .1 .center(); @@ -1158,21 +1096,24 @@ mod tests { }; let a = pipeline::analyze(table, &profile, &AtomicBool::new(false), |_, _| {}); let rows = preview_rows(&a, Some(table)); - assert_eq!(rows.len(), 2); - assert!(!rows[1].source_only); + assert_eq!(rows.iter().filter(|r| !r.source_only).count(), 2); + assert_eq!(rows.len(), 14); + assert!(!rows.last().unwrap().source_only); assert!( - rows[1] + rows.last() + .unwrap() .issues .iter() .any(|i| !needs_information(&a.diagnostics[*i])) ); app.analysis = Some(a); - app.review_view = ReviewView::Preview; + app.row_filter = RowFilter::Attention; + app.review_view = ReviewView::Rows; let ctx = egui::Context::default(); configure_style(&ctx); render(&mut app, &ctx, [860.0, 900.0], vec![]); let labels = render(&mut app, &ctx, [860.0, 900.0], vec![]); - assert!(labels.iter().any(|(s, _)| s == "Error · resolve")); + assert!(labels.iter().any(|(s, _)| s == "Error · details")); app.tables[0].rows[1][0].text = "invalid clock".into(); let a = pipeline::analyze(&app.tables[0], &profile, &AtomicBool::new(false), |_, _| {}); assert!(a.rundown.is_none()); @@ -1182,4 +1123,65 @@ mod tests { assert_eq!(rows[0].start, "?"); assert!(!needs_information(&a.diagnostics[rows[0].issues[0]])); } + #[test] + fn filters_keep_notes_and_restore_ignored_rows_after_recheck() { + let mut app = sample(); + let profile = Profile { + row_kinds: [(3, "ignore".into()), (4, "note".into())] + .into_iter() + .collect(), + ..Default::default() + }; + let a = pipeline::analyze(&app.tables[0], &profile, &AtomicBool::new(false), |_, _| {}); + let rows = preview_rows(&a, Some(&app.tables[0])); + let numbers = |filter| { + rows.iter() + .filter(|r| show_row(r, filter, Some(&app.tables[0]), &profile)) + .map(|r| r.row) + .collect::>() + }; + assert_eq!(numbers(RowFilter::All), (2..=15).collect::>()); + assert!(!numbers(RowFilter::Included).contains(&3)); + assert!(numbers(RowFilter::Included).contains(&4)); + assert!(!numbers(RowFilter::Attention).contains(&4)); + assert!(numbers(RowFilter::Attention).contains(&5)); + assert_eq!( + rows.iter().find(|r| r.row == 4).unwrap().kind, + "Note for row 2" + ); + app.profile = serde_json::to_string(&profile).unwrap(); + app.analysis = Some(a); + app.row_filter = RowFilter::All; + let ctx = egui::Context::default(); + configure_style(&ctx); + render(&mut app, &ctx, [860.0, 900.0], vec![]); + let labels = render(&mut app, &ctx, [860.0, 900.0], vec![]); + assert!(labels.iter().any(|(s, _)| s == "Stage direction 0")); + let ignore = labels + .iter() + .find(|(s, _)| s == "ignore") + .unwrap() + .1 + .center(); + click_size(&mut app, &ctx, ignore, [860.0, 900.0]); + let menu = render(&mut app, &ctx, [860.0, 900.0], vec![]); + let auto = menu + .iter() + .rev() + .find(|(s, _)| s == "Auto") + .unwrap() + .1 + .center(); + click_size(&mut app, &ctx, auto, [860.0, 900.0]); + let restored: Profile = serde_json::from_str(&app.profile).unwrap(); + assert!(!restored.row_kinds.contains_key(&3)); + assert!(!ignored_row(3, Some(&app.tables[0]), &restored)); + assert!(app.dirty); + let mut columns_ignored = Profile::default(); + columns_ignored + .column_usage + .insert("C".into(), "ignore".into()); + assert!(ignored_row(3, Some(&app.tables[0]), &columns_ignored)); + assert!(!ignored_row(2, Some(&app.tables[0]), &columns_ignored)); + } } diff --git a/docs/rundown-converter-plan.md b/docs/rundown-converter-plan.md index a01f6fe..5416107 100644 --- a/docs/rundown-converter-plan.md +++ b/docs/rundown-converter-plan.md @@ -256,6 +256,9 @@ errors must remain visible with direct corrective actions. 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. +- [x] Merge schedule preview and row corrections with All rows / Included rows / + Needs attention filters, preserving ignored rows for restoration and displaying + attached notes individually without duplicating their timers. - [ ] 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 f05ef67..15642bc 100644 --- a/docs/rundown-converter.md +++ b/docs/rundown-converter.md @@ -33,21 +33,22 @@ 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 has three focused views: +click **Analyze rundown**. Review has two views: -- **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** combines timed entries and unresolved source rows in their - original order. Amber rows need clarification; red rows contain invalid or - inconsistent data. Text status labels accompany the colors. Source-only rows - are explicitly not timers, and unknown values show `?`. Hover an issue for its - full explanation or click its status to resolve it. Click a title for original - cells. Sheet-level and gap issues remain listed beneath the table. Draft and - out-of-date schedules are labeled; they cannot be exported. +- **Schedule & corrections** combines the schedule preview and row editing in one + table. Start/end/duration, source contents, colored issues, row meaning and + duration corrections are visible together. **All rows** includes ignored rows; + **Included rows** hides ignored rows and rows containing only ignored columns, + while keeping notes, markers and breaks; **Needs attention** shows rows with + diagnostics from the last analysis. Ignored rows can be restored using All rows. + Notes attached to another event keep their own source row and identify their + parent timer instead of duplicating it. Amber means unresolved, red means an + error, and gray means ignored. Unknown values show `?`. + Click a row number/title to read all original cells. **Issues** opens the issue + navigator, including sheet-level and gap errors; row issue buttons open the + relevant explanation. The table fills the remaining space. On narrow windows, + timing values stack so corrections remain accessible. Changes require recheck; + the timing preview and diagnostics continue to show the previous analysis. - **Columns** shows inference evidence, per-column role dropdowns, and sample values. Selecting one duration column explicitly resolves duplicate TIMER headers. **Metadata** keeps a column as Ontime notes without treating its values