Add secondary title merging with the previous primary title

This commit is contained in:
Dandaedre 2026-11-05 09:13:21 +01:00
parent 2b70b6272e
commit 03bb0a459b
7 changed files with 79 additions and 9 deletions

View File

@ -598,13 +598,13 @@ fn infer_inner(
}
}
let secondary_mode = profile.secondary_title_mode.as_deref().unwrap_or("either");
if !["either", "merge", "notes", "metadata"].contains(&secondary_mode) {
if !["either", "merge", "merge_previous", "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",
"Secondary title handling must be either, merge, merge_previous, notes or metadata",
));
}
if let Some(&column) = selected.get("secondary_title")

View File

@ -68,7 +68,7 @@ fn secondary_title_controls(ui: &mut egui::Ui, profile: &mut Profile, id: egui::
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 choices = [("either", "Either"), ("merge", "Merge"), ("merge_previous", "Merge with previous title"), ("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)
@ -76,7 +76,7 @@ fn secondary_title_controls(ui: &mut egui::Ui, profile: &mut Profile, id: egui::
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.");
}).response.on_hover_text("Either uses the main title, falling back to the secondary when empty. Merge joins both titles. Merge with previous title reuses the latest nonempty primary title when blank, joining it to the secondary with a hyphen. 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);
});
});

View File

@ -167,7 +167,7 @@ fn column_issue_advice(code: &str, duration: bool) -> (&'static str, &'static st
),
"INVALID_SECONDARY_TITLE_MODE" => (
"Invalid secondary title handling",
"Choose Either, Merge, Notes or Metadata.",
"Choose Either, Merge, Merge with previous title, Notes or Metadata.",
),
"PROFILE_HEADER_CHANGED" => (
"Saved header no longer matches",

View File

@ -67,7 +67,7 @@ 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.
/// either (main title first), merge, merge_previous (carry primary title forward), notes, or metadata.
pub secondary_title_mode: Option<String>,
/// minutes, seconds, hh:mm, mm:ss, or excel.
pub duration_unit: Option<String>,

View File

@ -79,13 +79,31 @@ fn supplied_title(table: &Table, row: usize, map: &Mapping, profile: &Profile) -
if let Some(title) = profile.titles.get(&(row + 1)) {
return title.clone();
}
let title = table.cell(row, map.title).text;
let mut title = table.cell(row, map.title).text;
if map.secondary_title_mode.as_deref() == Some("merge_previous") && title.trim().is_empty() {
title = (map.header_row..row)
.rev()
.filter(|previous| {
profile
.row_kinds
.get(&(previous + 1))
.is_none_or(|kind| kind != "ignore")
})
.map(|previous| table.cell(previous, map.title).text)
.find(|value| !value.trim().is_empty())
.unwrap_or_default();
}
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_previous" => [title, secondary]
.into_iter()
.filter(|value| !value.trim().is_empty())
.collect::<Vec<_>>()
.join(" - "),
"merge" => [title, secondary]
.into_iter()
.filter(|value| !value.trim().is_empty())

View File

@ -1454,6 +1454,53 @@ fn secondary_title_policies_preserve_distinct_export_destinations() {
}
}
#[test]
fn secondary_title_merge_previous_carries_only_primary_titles() {
let t = table(&[
&["Start", "Duration", "Title", "Subtitle"],
&["09:00", "5 min", "", "Before first title"],
&["09:05", "5 min", "Session A", "Talk 1"],
&["09:10", "5 min", "", "Talk 2"],
&["", "", "Ignored title", ""],
&["09:15", "5 min", "", "Talk 3"],
&["09:20", "5 min", "Session B", "Talk 4"],
&["09:25", "5 min", "", "Talk 5"],
]);
let profile = Profile {
columns: BTreeMap::from([("secondary_title".into(), "D".into())]),
secondary_title_mode: Some("merge_previous".into()),
row_kinds: BTreeMap::from([(5, "ignore".into())]),
titles: BTreeMap::from([(4, "Corrected row title".into())]),
..Profile::default()
};
let profile = serde_json::from_str(&serde_json::to_string(&profile).unwrap()).unwrap();
let a = analyze(&t, &profile);
assert!(a.diagnostics.is_empty(), "{:?}", a.diagnostics);
let rundown = a.rundown.unwrap();
assert_eq!(
rundown
.entries
.iter()
.map(|e| e.title.as_str())
.collect::<Vec<_>>(),
[
"Before first title",
"Session A - Talk 1",
"Corrected row title",
"Session A - Talk 3",
"Session B - Talk 4",
"Session B - Talk 5",
]
);
let json = export::ontime(&rundown).unwrap();
for entry in &rundown.entries {
assert_eq!(
json["rundowns"]["default"]["entries"][&entry.id]["title"],
entry.title
);
}
}
#[test]
fn secondary_title_fallback_respects_empty_cells_and_explicit_corrections() {
let t = table(&[

View File

@ -157,7 +157,12 @@ visually distinct from labels and ordinary actions; the active tab uses the stro
**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.
**Merge with previous title** reuses the latest nonempty primary title when
the current one is blank: `Session - Talk 1`, `Session - Talk 2`. A new primary
title starts a new sequence; explicitly ignored rows do not supply titles.
Before the first primary title, it uses the secondary alone.
Explicit row title corrections take precedence over all title handling modes
and do not change the primary title carried into subsequent rows.
**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
@ -328,7 +333,7 @@ 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`.
`secondary_title_mode` accepts `either` (default), `merge`, `merge_previous`, `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.