Add secondary title mapping and handling options

This commit is contained in:
Dandaedre 2026-11-04 16:40:24 +01:00
parent 993db72668
commit d148c1e55c
8 changed files with 240 additions and 13 deletions

View File

@ -57,7 +57,9 @@ fn role(header: &str) -> Option<&'static str> {
}
}
fn role_label(role: &str) -> &str {
if role == "start_end" {
if role == "secondary_title" {
"secondary title"
} else if role == "start_end" {
"start–end"
} else {
role
@ -305,13 +307,22 @@ fn infer_inner(
let mut selected = std::collections::BTreeMap::new();
for (r, col) in &profile.columns {
if !["start", "start_end", "end", "duration", "title"].contains(&r.as_str()) {
if ![
"start",
"start_end",
"end",
"duration",
"title",
"secondary_title",
]
.contains(&r.as_str())
{
diagnostics.push(err(
"INVALID_MAPPING",
table,
header,
0,
format!("Unknown role {r}; use start, start_end, end, duration or title"),
format!("Unknown role {r}; use start, start_end, end, duration, title or secondary_title"),
));
continue;
}
@ -347,6 +358,7 @@ fn infer_inner(
}
let candidates: Vec<_> = (0..width)
.filter(|c| !excluded.contains(c))
.filter(|c| !selected.values().any(|v| v == c))
.filter(|c| role(&table.cell(header, *c).text) == Some(r))
.collect();
if candidates.len() == 1 {
@ -453,6 +465,7 @@ fn infer_inner(
if !selected.contains_key("title") {
let cols: Vec<_> = (0..width)
.filter(|c| !excluded.contains(c))
.filter(|c| !selected.values().any(|v| v == c))
.filter(|c| normalize(&table.cell(header, *c).text) == "cue")
.collect();
if cols.len() == 1 {
@ -517,6 +530,21 @@ fn infer_inner(
evidence.push(format!("Column {} defaults to {usage}", column_name(c)));
}
}
let secondary_mode = profile.secondary_title_mode.as_deref().unwrap_or("either");
if !["either", "merge", "notes", "metadata"].contains(&secondary_mode) {
diagnostics.push(err(
"INVALID_SECONDARY_TITLE_MODE",
table,
header,
selected["title"],
"Secondary title handling must be either, merge, notes or metadata",
));
}
if let Some(&column) = selected.get("secondary_title")
&& matches!(secondary_mode, "notes" | "metadata")
{
column_usage.insert(column_name(column), secondary_mode.into());
}
let column_labels = column_usage
.keys()
.map(|letter| {
@ -633,7 +661,7 @@ fn infer_inner(
}
for &row in &rows {
for (&r, &col) in &selected {
if r == "title" {
if matches!(r, "title" | "secondary_title") {
continue;
}
let cell = table.cell(row, col);
@ -694,6 +722,8 @@ fn infer_inner(
end,
duration: dur,
title: selected["title"],
secondary_title: selected.get("secondary_title").copied(),
secondary_title_mode: profile.secondary_title_mode.clone(),
duration_unit: unit,
duration_mode: profile.duration_mode.clone(),
duration_separator: profile.duration_separator.clone(),

View File

@ -63,6 +63,25 @@ impl ExportChoice {
}
}
fn secondary_title_controls(ui: &mut egui::Ui, profile: &mut Profile, id: egui::Id) {
ui.indent(id, |ui| {
ui.horizontal_wrapped(|ui| {
ui.weak("Secondary title handling");
let mut mode = profile.secondary_title_mode.clone().unwrap_or_else(|| "either".into());
let choices = [("either", "Either"), ("merge", "Merge"), ("notes", "Notes"), ("metadata", "Metadata")];
let label = choices.iter().find(|(value, _)| *value == mode).map_or("Either", |(_, label)| *label);
egui::ComboBox::from_id_salt(id.with("mode"))
.selected_text(label)
.show_ui(ui, |ui| {
for (value, label) in choices {
ui.selectable_value(&mut mode, value.into(), label);
}
}).response.on_hover_text("Either uses the main title, falling back to the secondary when empty. Merge joins both titles. Notes adds the secondary to event notes. Metadata creates a custom field using its column header.");
profile.secondary_title_mode = (mode != "either").then_some(mode);
});
});
}
fn duration_mode_label(mode: &str) -> &'static str {
match mode {
"minimum" => "Minimum",
@ -480,13 +499,21 @@ impl App {
});
let width = table.rows.iter().map(Vec::len).max().unwrap_or(0);
egui::Grid::new("mapping_controls").show(ui, |ui| {
for role in ["start", "start_end", "end", "duration", "title"] {
for role in [
"start",
"start_end",
"end",
"duration",
"title",
"secondary_title",
] {
ui.label(match role {
"start" => "Start",
"start_end" => "Start–end",
"end" => "End",
"duration" => "Duration",
"title" => "Title",
"secondary_title" => "Secondary title",
_ => role,
});
let mut col = profile.columns.get(role).cloned().unwrap_or_default();
@ -525,6 +552,9 @@ impl App {
}
}
});
if profile.columns.contains_key("secondary_title") {
secondary_title_controls(ui, &mut profile, egui::Id::new("setup_secondary_title"));
}
let duration_available = profile.columns.contains_key("duration")
|| self
.analysis
@ -570,7 +600,7 @@ impl App {
self.decisions_changed();
}
}
ui.label("Optional JSON profile: columns (start/start_end/end/duration/title), column_usage (notes/metadata/ignore), duration_unit, duration_mode, duration_split, duration_separator, row_kinds, titles, starts, ends, durations, untimed_as_notes, ignore_warnings. Column letters and source rows are shown in diagnostics.");
ui.label("Optional JSON profile: columns (start/start_end/end/duration/title/secondary_title), column_usage (notes/metadata/ignore), secondary_title_mode, duration_unit, duration_mode, duration_split, duration_separator, row_kinds, titles, starts, ends, durations, untimed_as_notes, ignore_warnings. Column letters and source rows are shown in diagnostics.");
if ui
.add(
egui::TextEdit::multiline(&mut self.profile)

View File

@ -547,6 +547,7 @@ fn ignored_row(
let retained = mapping.is_none_or(|map| {
column == map.start
|| column == map.title
|| map.secondary_title == Some(column)
|| map.end == Some(column)
|| map.duration == Some(column)
|| map
@ -591,6 +592,7 @@ fn column_settings_changed(current: &Profile, analyzed: &Profile) -> bool {
|| current.column_usage != analyzed.column_usage
|| current.expected_headers != analyzed.expected_headers
|| current.duration_unit != analyzed.duration_unit
|| current.secondary_title_mode != analyzed.secondary_title_mode
|| current.duration_mode != analyzed.duration_mode
|| current.duration_separator != analyzed.duration_separator
|| current.duration_split != analyzed.duration_split
@ -1375,6 +1377,7 @@ impl App {
("End", m.end),
("Duration", m.duration),
("Title", Some(m.title)),
("Secondary title", m.secondary_title),
] {
if let Some(column) = column {
ui.label(format!("{role}: {}", column_name(column)));
@ -1578,6 +1581,8 @@ impl App {
if m.start_end { "Start–end" } else { "Start" }
} else if m.title == c {
"Title"
} else if m.secondary_title == Some(c) {
"Secondary title"
} else if m.end == Some(c) {
"End"
} else if m.duration == Some(c) {
@ -1600,6 +1605,7 @@ impl App {
"end" => "End",
"duration" => "Duration",
"title" => "Title",
"secondary_title" => "Secondary title",
"notes" => "Notes",
"metadata" => "Metadata",
"ignore" => "Ignore",
@ -1620,6 +1626,7 @@ impl App {
("end", "End"),
("duration", "Duration"),
("title", "Title"),
("secondary_title", "Secondary title"),
] {
ui.selectable_value(&mut chosen, role.into(), label);
}
@ -1655,6 +1662,9 @@ impl App {
.collect::<Vec<_>>()
.join(" / ");
ui.label(samples);
if column_choice(&profile, c) == Some("secondary_title") {
super::secondary_title_controls(ui, &mut profile, egui::Id::new(("secondary_title", c)));
}
let duration_selected = column_choice(&profile, c) == Some("duration")
|| (column_choice(&profile, c).is_none()
&& mapping
@ -3446,6 +3456,58 @@ mod tests {
assert!(labels.iter().any(|(text, _)| text == "Separator"));
}
#[test]
fn secondary_title_handling_is_selectable_and_marks_pending_changes() {
let mut app = sample();
app.review_view = ReviewView::Columns;
for (i, row) in app.tables[0].rows.iter_mut().enumerate() {
row.push(crate::model::Cell {
text: if i == 0 { "Presentation" } else { "Secondary" }.into(),
..Default::default()
});
}
let profile = Profile {
columns: BTreeMap::from([("secondary_title".into(), "D".into())]),
..Default::default()
};
app.profile = serde_json::to_string(&profile).unwrap();
app.analyzed_profile = Some(profile);
let ctx = egui::Context::default();
configure_style(&ctx);
let size = [1000.0, 1100.0];
render(&mut app, &ctx, size, vec![]);
let labels = render(&mut app, &ctx, size, vec![]);
assert!(
labels
.iter()
.any(|(text, _)| text == "Secondary title handling")
);
let choice = labels
.iter()
.find(|(text, _)| text == "Either")
.unwrap()
.1
.center();
click_size(&mut app, &ctx, choice, size);
let labels = render(&mut app, &ctx, size, vec![]);
let merge = labels
.iter()
.find(|(text, _)| text == "Merge")
.unwrap()
.1
.center();
click_size(&mut app, &ctx, merge, size);
let profile: Profile = serde_json::from_str(&app.profile).unwrap();
assert_eq!(profile.secondary_title_mode.as_deref(), Some("merge"));
assert!(app.dirty);
let labels = render(&mut app, &ctx, size, vec![]);
assert!(
labels
.iter()
.any(|(text, _)| text == "Pending column changes")
);
}
#[test]
fn column_help_stays_hidden_until_the_tab_is_hovered() {
let mut app = sample();

View File

@ -67,6 +67,8 @@ pub struct Profile {
/// Column letter -> notes, metadata (Ontime custom field), or ignore.
pub column_usage: BTreeMap<String, String>,
pub expected_headers: BTreeMap<String, String>,
/// either (main title first), merge, notes, or metadata.
pub secondary_title_mode: Option<String>,
/// minutes, seconds, hh:mm, mm:ss, or excel.
pub duration_unit: Option<String>,
/// strict, minimum, maximum, sum, or margin (legacy split is accepted).
@ -110,6 +112,10 @@ pub struct Mapping {
pub end: Option<usize>,
pub duration: Option<usize>,
pub title: usize,
#[serde(default)]
pub secondary_title: Option<usize>,
#[serde(default)]
pub secondary_title_mode: Option<String>,
pub duration_unit: Option<String>,
#[serde(default)]
pub duration_mode: Option<String>,

View File

@ -75,11 +75,23 @@ fn supplied_span(table: &Table, row: usize, map: &Mapping, profile: &Profile) ->
.map(|plan| plan.events.iter().sum::<i64>() + plan.margin)
}
fn supplied_title(table: &Table, row: usize, map: &Mapping, profile: &Profile) -> String {
profile
.titles
.get(&(row + 1))
.cloned()
.unwrap_or_else(|| table.cell(row, map.title).text)
if let Some(title) = profile.titles.get(&(row + 1)) {
return title.clone();
}
let title = table.cell(row, map.title).text;
let secondary = map
.secondary_title
.map(|c| table.cell(row, c).text)
.unwrap_or_default();
match map.secondary_title_mode.as_deref().unwrap_or("either") {
"either" if title.trim().is_empty() => secondary,
"merge" => [title, secondary]
.into_iter()
.filter(|value| !value.trim().is_empty())
.collect::<Vec<_>>()
.join(" — "),
_ => title,
}
}
fn override_clock(values: &std::collections::BTreeMap<usize, String>, row: usize) -> Option<i64> {
values.get(&(row + 1)).and_then(|text| {
@ -93,6 +105,7 @@ fn mapped_has_content(table: &Table, row: usize, map: &Mapping) -> bool {
table.rows[row].iter().enumerate().any(|(col, cell)| {
let role = col == map.start
|| col == map.title
|| map.secondary_title == Some(col)
|| map.end == Some(col)
|| map.duration == Some(col);
let retained = map
@ -146,7 +159,7 @@ pub fn identify_gaps(table: &Table, map: &Mapping, profile: &Profile) -> Vec<Gap
.map(|c| c.text.clone())
.unwrap_or_default()
} else {
table.cell(r, map.title).text
supplied_title(table, r, map, profile)
};
let kind = profile.row_kinds.get(&(r + 1));
let explicit = kind.is_some_and(|k| k == "gap");

View File

@ -1398,3 +1398,76 @@ fn split_combines_with_each_duration_policy_and_keeps_each_margin() {
.any(|d| d.code == "INCONSISTENT_COLUMN_MEANING")
);
}
#[test]
fn secondary_title_policies_preserve_distinct_export_destinations() {
let t = table(&[
&["Start", "Duration", "Title", "Presentation"],
&["09:00", "5 min", "Session", "Talk"],
&["09:05", "5 min", "Closing", ""],
]);
for mode in ["either", "merge", "notes", "metadata"] {
let profile = Profile {
columns: BTreeMap::from([("secondary_title".into(), "D".into())]),
secondary_title_mode: Some(mode.into()),
..Default::default()
};
let a = analyze(&t, &profile);
assert!(a.diagnostics.is_empty(), "{mode}: {:?}", a.diagnostics);
let r = a.rundown.unwrap();
assert_eq!(
r.entries[0].title,
if mode == "merge" {
"Session — Talk"
} else {
"Session"
}
);
assert_eq!(r.entries[1].title, "Closing");
let json = export::ontime(&r).unwrap();
let event = &json["rundowns"]["default"]["entries"][&r.entries[0].id];
assert_eq!(event["note"], if mode == "notes" { "Talk" } else { "" });
if mode == "metadata" {
assert_eq!(event["custom"]["presentation"], "Talk");
} else {
assert!(event["custom"].as_object().unwrap().is_empty());
}
assert_eq!(
r.mapping.column_usage.get("D").map(String::as_str),
match mode {
"notes" => Some("notes"),
"metadata" => Some("metadata"),
_ => None,
}
);
}
}
#[test]
fn secondary_title_fallback_respects_empty_cells_and_explicit_corrections() {
let t = table(&[
&["Start", "Duration", "Title", "Title"],
&["09:00", "5 min", "", "Fallback"],
&["09:05", "5 min", "Main", "Secondary"],
]);
let mut profile = Profile {
columns: BTreeMap::from([("secondary_title".into(), "D".into())]),
..Default::default()
};
let a = analyze(&t, &profile);
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
let r = a.rundown.unwrap();
assert_eq!(r.entries[0].title, "Fallback");
assert_eq!(r.entries[1].title, "Main");
profile.titles.insert(2, "Corrected".into());
profile.secondary_title_mode = Some("merge".into());
let a = analyze(&t, &profile);
assert_eq!(a.rundown.unwrap().entries[0].title, "Corrected");
profile.secondary_title_mode = Some("invalid".into());
assert!(
analyze(&t, &profile)
.diagnostics
.iter()
.any(|d| d.code == "INVALID_SECONDARY_TITLE_MODE")
);
}

View File

@ -300,6 +300,8 @@ errors must remain visible with direct corrective actions.
maximum, sum and margin extraction policies, plus an independent split toggle. Let a Start mapping select
only the first clock in a mixed range; retain margin gaps and split entries in
the IR.
- [x] Add a secondary title role with Either, Merge, Notes and Metadata handling,
shared across CLI profiles, GUI review and exports.
- [x] Stage 2: identify untimed gaps and populate draft IR constraints. Test named
and unnamed breaks, unknown boundaries and distinction from timed break cues.
- [x] Stage 3: construct the complete IR from times and gap constraints. Test

View File

@ -126,6 +126,11 @@ visually distinct from labels and ordinary actions; the active tab uses the stro
margin. A separate **Split into multiple entries** toggle applies that choice
to each separated group; Add margin then creates a gap after each entry. Selecting one duration column explicitly resolves
duplicate TIMER headers.
**Secondary title** selects another title source with a nested handling menu:
**Either** uses the main title when present and the secondary when it is empty;
**Merge** joins both nonempty titles with an em dash; **Notes** adds the secondary
to event notes; **Metadata** creates a custom field named from its column header.
Explicit row title corrections take precedence over Either and Merge.
**Notes** appends a column's values to Ontime event notes. **Metadata**
creates an Ontime custom field named from the source header. **Ignore** excludes
the column from inference and Ontime output. Several columns can use any of these
@ -281,7 +286,7 @@ Pass `--profile mapping.json`, or load/edit the same JSON in the desktop app:
This illustrates options, not a profile to apply blindly to the supplied files.
Rows are one-based original worksheet rows; columns use Excel letters. Supported
roles are `start`, `start_end`, `end`, `duration` and `title`. A `start_end`
roles are `start`, `start_end`, `end`, `duration`, `title` and `secondary_title`. A `start_end`
column requires a complete clock range such as `08h00 - 08h30` in every relevant
timed cell and supplies both values without a separate `end` mapping. A `start`
mapping extracts only the first clock when its cell also contains an end clock.
@ -293,6 +298,12 @@ are errors. `titles`, `starts`, `ends` and `durations` are keyed by one-based so
corrected cells are excluded from whole-column validation while all remaining
explicit mappings still undergo it.
Map a secondary title using `"columns": {"title": "D", "secondary_title": "E"}`.
`secondary_title_mode` accepts `either` (default), `merge`, `notes` or `metadata`.
Notes and metadata use the same destinations in Ontime JSON and XLSX as ordinary
Notes and Metadata columns. The primary title column remains required; rows with
both titles empty still need correction.
`duration_mode` is optional and remains attached to the single `duration` role.
`minimum`, `maximum` and `sum` select from explicit duration values in mixed text.
`margin` uses the largest value in each duration group for the event and preserves