Group column roles into nested timing title and metadata choices
This commit is contained in:
parent
03bb0a459b
commit
5cc792a386
|
|
@ -678,6 +678,35 @@ fn column_choice(profile: &Profile, column: usize) -> Option<&str> {
|
|||
.or_else(|| profile.usage(column))
|
||||
}
|
||||
|
||||
fn role_family(role: &str) -> &str {
|
||||
match role {
|
||||
"start" | "start_end" | "end" => "Timing",
|
||||
"title" | "secondary_title" => "Title",
|
||||
"metadata" | "notes" => "Metadata",
|
||||
"duration" => "Duration",
|
||||
"ignore" => "Ignore",
|
||||
_ => "Auto",
|
||||
}
|
||||
}
|
||||
|
||||
fn family_roles(family: &str) -> &'static [(&'static str, &'static str)] {
|
||||
match family {
|
||||
"Timing" => &[
|
||||
("start", "Start"),
|
||||
("start_end", "Start–end"),
|
||||
("end", "End"),
|
||||
],
|
||||
"Title" => &[
|
||||
("title", "Primary title"),
|
||||
("secondary_title", "Secondary title"),
|
||||
],
|
||||
"Metadata" => &[("metadata", "Custom Ontime field"), ("notes", "Notes")],
|
||||
"Duration" => &[("duration", "Duration")],
|
||||
"Ignore" => &[("ignore", "Ignore")],
|
||||
_ => &[("", "Auto")],
|
||||
}
|
||||
}
|
||||
|
||||
fn column_settings_changed(current: &Profile, analyzed: &Profile) -> bool {
|
||||
current.header_row != analyzed.header_row
|
||||
|| current.columns != analyzed.columns
|
||||
|
|
@ -1597,10 +1626,10 @@ impl App {
|
|||
.map(|error| {
|
||||
if error.code == "MISSING_COLUMN" {
|
||||
if error.message.starts_with("Cannot infer title;") {
|
||||
return ("Title column missing", "Choose Title in the role dropdown of the appropriate column below.");
|
||||
return ("Title column missing", "Choose Title → Primary title for the appropriate column below.");
|
||||
}
|
||||
if error.message.starts_with("Cannot infer start;") {
|
||||
return ("Start column missing", "Choose Start or Start–end in the role dropdown of the appropriate column below.");
|
||||
return ("Start column missing", "Choose Timing → Start or Start–end for the appropriate column below.");
|
||||
}
|
||||
}
|
||||
column_issue_advice(&error.code, duration)
|
||||
|
|
@ -1828,44 +1857,53 @@ impl App {
|
|||
}
|
||||
}
|
||||
});
|
||||
let mut family = role_family(&chosen).to_string();
|
||||
let old_family = family.clone();
|
||||
let selected = if chosen.is_empty() {
|
||||
detected_role
|
||||
.map_or_else(|| "Auto".into(), |role| format!("Auto ({role})"))
|
||||
detected_role.map_or_else(|| "Auto".into(), |role| format!("Auto ({role})"))
|
||||
} else {
|
||||
match chosen.as_str() {
|
||||
"start" => "Start",
|
||||
"start_end" => "Start–end",
|
||||
"end" => "End",
|
||||
"duration" => "Duration",
|
||||
"title" => "Title",
|
||||
"secondary_title" => "Secondary title",
|
||||
"notes" => "Notes",
|
||||
"metadata" => "Metadata",
|
||||
"ignore" => "Ignore",
|
||||
_ => &chosen,
|
||||
}
|
||||
.into()
|
||||
family.clone()
|
||||
};
|
||||
ui.vertical(|ui| {
|
||||
egui::ComboBox::from_id_salt(("column", c))
|
||||
.selected_text(selected)
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut chosen, String::new(), "Auto");
|
||||
for (role, label) in [
|
||||
("ignore", "Ignore"),
|
||||
("notes", "Notes"),
|
||||
("metadata", "Metadata"),
|
||||
("start", "Start"),
|
||||
("start_end", "Start–end"),
|
||||
("end", "End"),
|
||||
("duration", "Duration"),
|
||||
("title", "Title"),
|
||||
("secondary_title", "Secondary title"),
|
||||
] {
|
||||
ui.selectable_value(&mut chosen, role.into(), label);
|
||||
for label in ["Auto", "Ignore", "Timing", "Duration", "Title", "Metadata"] {
|
||||
ui.selectable_value(&mut family, label.into(), label);
|
||||
}
|
||||
})
|
||||
.response
|
||||
.on_hover_text("Ignore excludes this column. Notes appends its values to Ontime notes. Metadata creates an Ontime custom field.");
|
||||
});
|
||||
if family != old_family {
|
||||
let options = family_roles(&family);
|
||||
// Choose an available specific role, never replacing a primary title
|
||||
// merely because a second column was assigned to the Title family.
|
||||
chosen = options.iter().find(|(role, _)| {
|
||||
if family == "Metadata" { return true; }
|
||||
!profile.columns.iter().any(|(assigned, letter)| {
|
||||
(assigned == role || (matches!(assigned.as_str(), "start" | "start_end") && matches!(*role, "start" | "start_end"))) && crate::model::column_index(letter) != Some(c)
|
||||
}) && !suggestions.iter().any(|(other, suggestion)| {
|
||||
*other != c && column_choice(&profile, *other).is_none()
|
||||
&& matches!((*role, *suggestion),
|
||||
("title", "Title") | ("secondary_title", "Secondary title") |
|
||||
("start" | "start_end", "Start" | "Start–end") |
|
||||
("end", "End") | ("duration", "Duration"))
|
||||
})
|
||||
}).unwrap_or(&options[0]).0.into();
|
||||
}
|
||||
let options = family_roles(&family);
|
||||
if options.len() > 1 {
|
||||
ui.indent(("column_subrole", c), |ui| {
|
||||
let label = options.iter().find(|(role, _)| *role == chosen)
|
||||
.map_or(options[0].1, |(_, label)| *label);
|
||||
egui::ComboBox::from_id_salt(("column_specific_role", c))
|
||||
.selected_text(label)
|
||||
.show_ui(ui, |ui| {
|
||||
for (role, label) in options {
|
||||
ui.selectable_value(&mut chosen, (*role).into(), *label);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
if chosen != old {
|
||||
profile
|
||||
.columns
|
||||
|
|
@ -3824,8 +3862,9 @@ mod tests {
|
|||
);
|
||||
assert!(labels.iter().any(|(text, _)| text == "Pending apply"));
|
||||
for (current, choice, expected) in [
|
||||
("Start", "Notes", Some("notes")),
|
||||
("Notes", "Metadata", Some("metadata")),
|
||||
("Timing", "Metadata", Some("metadata")),
|
||||
("Custom Ontime field", "Notes", Some("notes")),
|
||||
("Notes", "Custom Ontime field", Some("metadata")),
|
||||
("Metadata", "Ignore", Some("ignore")),
|
||||
("Ignore", "Auto", None),
|
||||
] {
|
||||
|
|
@ -3871,6 +3910,55 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn title_family_can_assign_a_secondary_without_replacing_primary() {
|
||||
let mut app = sample();
|
||||
app.review_view = ReviewView::Columns;
|
||||
for row in &mut app.tables[0].rows {
|
||||
row.push(crate::model::Cell {
|
||||
text: "Extra".into(),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
let profile = Profile {
|
||||
columns: BTreeMap::from([("title".into(), "C".into())]),
|
||||
column_usage: BTreeMap::from([("D".into(), "ignore".into())]),
|
||||
..Profile::default()
|
||||
};
|
||||
app.profile = serde_json::to_string(&profile).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
configure_style(&ctx);
|
||||
let size = [1100.0, 1200.0];
|
||||
render(&mut app, &ctx, size, vec![]);
|
||||
let labels = render(&mut app, &ctx, size, vec![]);
|
||||
let button = labels
|
||||
.iter()
|
||||
.find(|(text, _)| text == "Ignore")
|
||||
.unwrap()
|
||||
.1
|
||||
.center();
|
||||
click_size(&mut app, &ctx, button, size);
|
||||
let menu = render(&mut app, &ctx, size, vec![]);
|
||||
let option = menu
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|(text, _)| text == "Title")
|
||||
.unwrap()
|
||||
.1
|
||||
.center();
|
||||
click_size(&mut app, &ctx, option, size);
|
||||
let profile: Profile = serde_json::from_str(&app.profile).unwrap();
|
||||
assert_eq!(profile.columns.get("title").map(String::as_str), Some("C"));
|
||||
assert_eq!(
|
||||
profile.columns.get("secondary_title").map(String::as_str),
|
||||
Some("D")
|
||||
);
|
||||
assert!(crate::detect::infer(&app.tables[0], &profile).is_ok());
|
||||
let labels = render(&mut app, &ctx, size, vec![]);
|
||||
assert!(labels.iter().any(|(text, _)| text == "Primary title"));
|
||||
assert!(labels.iter().any(|(text, _)| text == "Secondary title"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn column_menu_can_select_combined_start_end_role() {
|
||||
let mut app = sample();
|
||||
|
|
@ -3888,6 +3976,23 @@ mod tests {
|
|||
.center();
|
||||
click_size(&mut app, &ctx, button, size);
|
||||
let menu = render(&mut app, &ctx, size, vec![]);
|
||||
let family = menu
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|(text, _)| text == "Timing")
|
||||
.unwrap()
|
||||
.1
|
||||
.center();
|
||||
click_size(&mut app, &ctx, family, size);
|
||||
let labels = render(&mut app, &ctx, size, vec![]);
|
||||
let subtype = labels
|
||||
.iter()
|
||||
.find(|(text, _)| text == "Start")
|
||||
.unwrap()
|
||||
.1
|
||||
.center();
|
||||
click_size(&mut app, &ctx, subtype, size);
|
||||
let menu = render(&mut app, &ctx, size, vec![]);
|
||||
let option = menu
|
||||
.iter()
|
||||
.rev()
|
||||
|
|
|
|||
|
|
@ -122,7 +122,14 @@ visually distinct from labels and ordinary actions; the active tab uses the stro
|
|||
Changes require recheck;
|
||||
the timing preview and diagnostics continue to show the previous analysis.
|
||||
- **Columns** shows a concise verified mapping summary, green detected roles,
|
||||
per-column role dropdowns, and sample values. **Suggested: …** shows useful
|
||||
per-column role dropdowns, and sample values. The main choices are **Auto**,
|
||||
**Ignore**, **Timing**, **Duration**, **Title**, and **Metadata**. Indented
|
||||
dropdowns select **Start / Start–end / End**, **Primary title / Secondary title**,
|
||||
or **Custom Ontime field / Notes** respectively. Role uniqueness applies to
|
||||
these specific choices, so two Title columns can supply primary and secondary
|
||||
titles. Selecting Title on another column prefers the unused secondary role.
|
||||
Saved profiles retain their existing specific role names.
|
||||
**Suggested: …** shows useful
|
||||
automatic recommendations even after a manual choice. Problems are grouped by
|
||||
affected column, with short explanations and suggested corrections instead of
|
||||
repeating each invalid cell. **Review column…** or **Choose duration handling…**
|
||||
|
|
|
|||
Loading…
Reference in New Issue