Allow inferred gap selection and inspection
This commit is contained in:
parent
7c6a028210
commit
a6c05d112c
|
|
@ -56,6 +56,7 @@ struct App {
|
|||
row_filter: RowFilter,
|
||||
show_issue_details: bool,
|
||||
selected_row: Option<usize>,
|
||||
selected_gap: Option<String>,
|
||||
jump_row: Option<usize>,
|
||||
review_scroll: Option<f32>,
|
||||
row_details: bool,
|
||||
|
|
@ -90,6 +91,7 @@ impl Default for App {
|
|||
row_filter: RowFilter::Included,
|
||||
show_issue_details: false,
|
||||
selected_row: None,
|
||||
selected_gap: None,
|
||||
jump_row: None,
|
||||
review_scroll: None,
|
||||
row_details: false,
|
||||
|
|
@ -106,6 +108,7 @@ impl App {
|
|||
self.dirty = false;
|
||||
self.issue_index = 0;
|
||||
self.selected_row = None;
|
||||
self.selected_gap = None;
|
||||
self.jump_row = None;
|
||||
self.review_scroll = None;
|
||||
self.row_filter = RowFilter::Included;
|
||||
|
|
@ -232,6 +235,7 @@ impl App {
|
|||
self.dirty = false;
|
||||
self.issue_index = 0;
|
||||
self.selected_row = a.diagnostics.first().and_then(review::diagnostic_row);
|
||||
self.selected_gap = None;
|
||||
self.jump_row = self.selected_row;
|
||||
self.review_view = if a.mapping.is_none() {
|
||||
ReviewView::Columns
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ fn needs_information(d: &Diagnostic) -> bool {
|
|||
)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct PreviewRow {
|
||||
row: usize,
|
||||
start: String,
|
||||
|
|
@ -368,6 +369,7 @@ impl App {
|
|||
.and_then(|a| a.diagnostics.get(index))
|
||||
.and_then(diagnostic_row);
|
||||
self.selected_row = row;
|
||||
self.selected_gap = None;
|
||||
self.jump_row = row;
|
||||
if let Some(row) = row {
|
||||
let profile: Profile = serde_json::from_str(&self.profile).unwrap_or_default();
|
||||
|
|
@ -497,10 +499,12 @@ impl App {
|
|||
if let Some(row) = diagnostic_row(&d) {
|
||||
if ui.small_button(format!("Show row {row}")).clicked() {
|
||||
self.selected_row = Some(row);
|
||||
self.selected_gap = None;
|
||||
self.jump_row = Some(row);
|
||||
}
|
||||
if ui.small_button("Full row…").clicked() {
|
||||
self.selected_row = Some(row);
|
||||
self.selected_gap = None;
|
||||
self.row_details = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -548,10 +552,45 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
fn gap_resolution_control(ui: &mut egui::Ui, profile: &mut Profile, key: &str) {
|
||||
let mut action = profile
|
||||
.gap_resolutions
|
||||
.get(key)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "keep".into());
|
||||
egui::ComboBox::from_id_salt(("gap_resolution", key))
|
||||
.width(95.0)
|
||||
.selected_text(match action.as_str() {
|
||||
"extend_previous" => "Extend prev.",
|
||||
"add_to_next" => "Add to next",
|
||||
_ => "Keep gap",
|
||||
})
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut action, "keep".into(), "Keep gap");
|
||||
ui.selectable_value(
|
||||
&mut action,
|
||||
"extend_previous".into(),
|
||||
"Extend previous timing",
|
||||
);
|
||||
ui.selectable_value(&mut action, "add_to_next".into(), "Add to next timing");
|
||||
})
|
||||
.response
|
||||
.on_hover_text("Keep gap leaves this interval untimed. Extend previous timing lengthens the preceding event. Add to next timing starts the next event earlier and preserves its end. Apply & recheck updates the schedule and export.");
|
||||
if action == "keep" {
|
||||
profile.gap_resolutions.remove(key);
|
||||
} else {
|
||||
profile.gap_resolutions.insert(key.into(), action);
|
||||
}
|
||||
}
|
||||
|
||||
fn row_window(&mut self, ctx: &egui::Context) {
|
||||
if !self.row_details {
|
||||
return;
|
||||
}
|
||||
if let Some(key) = self.selected_gap.clone() {
|
||||
self.gap_window(ctx, &key);
|
||||
return;
|
||||
}
|
||||
let Some(row) = self.selected_row else {
|
||||
return;
|
||||
};
|
||||
|
|
@ -682,6 +721,93 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
fn gap_window(&mut self, ctx: &egui::Context, key: &str) {
|
||||
let preview = self.analysis.as_ref().and_then(|a| {
|
||||
let table = self.tables.iter().find(|t| t.name == a.sheet);
|
||||
preview_rows(a, table)
|
||||
.into_iter()
|
||||
.find(|row| row.row == 0 && row.gap_key.as_deref() == Some(key))
|
||||
});
|
||||
let Some(preview) = preview else {
|
||||
self.row_details = false;
|
||||
self.selected_gap = None;
|
||||
return;
|
||||
};
|
||||
let mut profile: Profile = serde_json::from_str(&self.profile).unwrap_or_default();
|
||||
let before = serde_json::to_string(&profile).unwrap();
|
||||
let mut open = self.row_details;
|
||||
egui::Window::new(format!("Gap · {}", self.sheet))
|
||||
.id(egui::Id::new("gap_details"))
|
||||
.open(&mut open)
|
||||
.default_width(480.0)
|
||||
.resizable(true)
|
||||
.vscroll(true)
|
||||
.show(ctx, |ui| {
|
||||
ui.heading(&preview.title);
|
||||
ui.label("Inferred schedule interval · no source row or timer");
|
||||
if self.dirty {
|
||||
ui.colored_label(
|
||||
PREVIEW_AMBER,
|
||||
"Pending changes · timing and diagnostics are from the last analysis",
|
||||
);
|
||||
}
|
||||
egui::Frame::group(ui.style()).show(ui, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for (label, value) in [
|
||||
("Start", &preview.start),
|
||||
("End", &preview.end),
|
||||
("Elapsed", &preview.duration),
|
||||
] {
|
||||
ui.vertical(|ui| {
|
||||
ui.small(label);
|
||||
ui.strong(value);
|
||||
});
|
||||
ui.add_space(20.0);
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.heading("Gap resolution");
|
||||
ui.push_id("gap_inspector", |ui| {
|
||||
Self::gap_resolution_control(ui, &mut profile, key);
|
||||
});
|
||||
ui.small("Keep gap leaves this interval without an Ontime timer. Apply & recheck after changing the allocation.");
|
||||
if let Some(a) = &self.analysis {
|
||||
if !preview.issues.is_empty() {
|
||||
ui.heading("Needs attention");
|
||||
}
|
||||
for index in &preview.issues {
|
||||
let d = &a.diagnostics[*index];
|
||||
let color = if needs_information(d) {
|
||||
PREVIEW_AMBER
|
||||
} else {
|
||||
PREVIEW_RED
|
||||
};
|
||||
egui::Frame::group(ui.style()).show(ui, |ui| {
|
||||
ui.colored_label(color, d.code.replace('_', " "));
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
d.message
|
||||
.split("\nRow preview:")
|
||||
.next()
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.wrap(),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
if !preview.decisions.is_empty() {
|
||||
ui.heading("Timing information");
|
||||
ui.add(egui::Label::new(&preview.decisions).wrap());
|
||||
}
|
||||
});
|
||||
self.row_details = open;
|
||||
if before != serde_json::to_string(&profile).unwrap() {
|
||||
self.profile = serde_json::to_string_pretty(&profile).unwrap();
|
||||
self.decisions_changed();
|
||||
}
|
||||
}
|
||||
|
||||
fn columns_view(&mut self, ui: &mut egui::Ui) {
|
||||
ui.label("Review detected roles or choose a correction.");
|
||||
ui.collapsing("Column role help", |ui| {
|
||||
|
|
@ -849,7 +975,9 @@ impl App {
|
|||
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 ui.add_enabled(self.selected_row.is_some(), egui::Button::new("Edit row…")).clicked() {
|
||||
let selection = self.selected_row.is_some() || self.selected_gap.is_some();
|
||||
let edit_label = if self.selected_gap.is_some() { "Edit gap…" } else { "Edit row…" };
|
||||
if ui.add_enabled(selection, egui::Button::new(edit_label)).clicked() {
|
||||
self.row_details = true;
|
||||
}
|
||||
ignore_all = ui.add_enabled(!ignorable.is_empty(), egui::Button::new(format!("Ignore all unresolved ({})", ignorable.len())))
|
||||
|
|
@ -903,11 +1031,15 @@ impl App {
|
|||
let mut jump_offset = None;
|
||||
let mut resolve = None;
|
||||
let mut details = None;
|
||||
let mut gap_details = None;
|
||||
let selected: Vec<_> = std::iter::once(false)
|
||||
.chain(
|
||||
rows.iter()
|
||||
.map(|row| row.row > 0 && self.selected_row == Some(row.row)),
|
||||
)
|
||||
.chain(rows.iter().map(|row| {
|
||||
if row.row == 0 {
|
||||
row.gap_key.as_ref() == self.selected_gap.as_ref()
|
||||
} else {
|
||||
self.selected_row == Some(row.row)
|
||||
}
|
||||
}))
|
||||
.collect();
|
||||
let backgrounds: Vec<_> = std::iter::once(None)
|
||||
.chain(rows.iter().map(|row| {
|
||||
|
|
@ -996,8 +1128,12 @@ impl App {
|
|||
.sense(egui::Sense::click()),
|
||||
)
|
||||
}).inner;
|
||||
if response.double_clicked() && row.row > 0 {
|
||||
details = Some(row.row);
|
||||
if response.double_clicked() {
|
||||
if row.row > 0 {
|
||||
details = Some(row.row);
|
||||
} else {
|
||||
gap_details = row.gap_key.clone();
|
||||
}
|
||||
}
|
||||
if jump == Some(row.row) {
|
||||
jump_visible = ui.clip_rect().contains_rect(response.rect);
|
||||
|
|
@ -1060,6 +1196,10 @@ impl App {
|
|||
explanation.push_str(
|
||||
"\n\nDouble-click anywhere on this row to edit it and view original cells.",
|
||||
);
|
||||
} else {
|
||||
explanation.push_str(
|
||||
"\n\nDouble-click anywhere on this gap to view its timing and resolution.",
|
||||
);
|
||||
}
|
||||
if ui
|
||||
.add(
|
||||
|
|
@ -1068,9 +1208,13 @@ impl App {
|
|||
.sense(egui::Sense::click()),
|
||||
)
|
||||
.on_hover_text(&explanation)
|
||||
.double_clicked() && row.row > 0
|
||||
.double_clicked()
|
||||
{
|
||||
details = Some(row.row);
|
||||
if row.row > 0 {
|
||||
details = Some(row.row);
|
||||
} else {
|
||||
gap_details = row.gap_key.clone();
|
||||
}
|
||||
}
|
||||
if !row.issues.is_empty() {
|
||||
let index = row
|
||||
|
|
@ -1087,6 +1231,7 @@ impl App {
|
|||
if ui.small_button(RichText::new(if error { "Error" } else { "Details" }).color(color))
|
||||
.on_hover_text(&explanation).clicked() {
|
||||
if row.row > 0 { details = Some(row.row); }
|
||||
else if let Some(key) = &row.gap_key { gap_details = Some(key.clone()); }
|
||||
else { resolve = Some(*index); }
|
||||
}
|
||||
});
|
||||
|
|
@ -1096,21 +1241,7 @@ impl App {
|
|||
ui.set_width(105.0);
|
||||
ui.set_min_height(row_height);
|
||||
if let Some(key) = &row.gap_key {
|
||||
let mut action = profile.gap_resolutions.get(key).cloned().unwrap_or_else(|| "keep".into());
|
||||
egui::ComboBox::from_id_salt(("gap_resolution", key))
|
||||
.width(95.0)
|
||||
.selected_text(match action.as_str() {
|
||||
"extend_previous" => "Extend prev.",
|
||||
"add_to_next" => "Add to next",
|
||||
_ => "Keep gap",
|
||||
})
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut action, "keep".into(), "Keep gap");
|
||||
ui.selectable_value(&mut action, "extend_previous".into(), "Extend previous timing");
|
||||
ui.selectable_value(&mut action, "add_to_next".into(), "Add to next timing");
|
||||
}).response.on_hover_text("Keep gap leaves this interval untimed. Extend previous timing lengthens the preceding event. Add to next timing starts the next event earlier and preserves its end. Apply & recheck updates the schedule and export.");
|
||||
if action == "keep" { profile.gap_resolutions.remove(key); }
|
||||
else { profile.gap_resolutions.insert(key.clone(), action); }
|
||||
Self::gap_resolution_control(ui, &mut profile, key);
|
||||
return;
|
||||
}
|
||||
ui.push_id(("schedule_kind", row.row), |ui| {
|
||||
|
|
@ -1135,14 +1266,24 @@ impl App {
|
|||
egui::pos2(controls.response.rect.right(), ui.cursor().top() - ui.spacing().item_spacing.y * 0.5));
|
||||
// Observe the entire row without placing an input-catching widget over
|
||||
// dropdowns or buttons. Layer-aware hit testing excludes open windows.
|
||||
if row.row > 0 && ui.rect_contains_pointer(row_rect) {
|
||||
if ui.rect_contains_pointer(row_rect) {
|
||||
if ui.input(|i| i.pointer.primary_clicked()) {
|
||||
self.selected_row = Some(row.row);
|
||||
if row.row > 0 {
|
||||
self.selected_row = Some(row.row);
|
||||
self.selected_gap = None;
|
||||
} else {
|
||||
self.selected_row = None;
|
||||
self.selected_gap = row.gap_key.clone();
|
||||
}
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
if !ui.rect_contains_pointer(controls.response.rect)
|
||||
&& ui.input(|i| i.pointer.button_double_clicked(egui::PointerButton::Primary)) {
|
||||
details = Some(row.row);
|
||||
if row.row > 0 {
|
||||
details = Some(row.row);
|
||||
} else {
|
||||
gap_details = row.gap_key.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1161,6 +1302,12 @@ impl App {
|
|||
}
|
||||
if let Some(row) = details {
|
||||
self.selected_row = Some(row);
|
||||
self.selected_gap = None;
|
||||
self.row_details = true;
|
||||
}
|
||||
if let Some(key) = gap_details {
|
||||
self.selected_row = None;
|
||||
self.selected_gap = Some(key);
|
||||
self.row_details = true;
|
||||
}
|
||||
if before != serde_json::to_string(&profile).unwrap() {
|
||||
|
|
@ -1292,6 +1439,7 @@ mod tests {
|
|||
let analysis = analyze(&Profile::default());
|
||||
let rows = preview_rows(&analysis, Some(&app.tables[0]));
|
||||
let gap = rows.iter().position(|r| r.gap).unwrap();
|
||||
let inferred_key = rows[gap].gap_key.clone().unwrap();
|
||||
assert_eq!(rows[gap].row, 0);
|
||||
assert_eq!(rows[gap + 1].row, 15);
|
||||
assert_eq!(rows[gap].start, display(9 * 3_600_000 + 5 * 60_000));
|
||||
|
|
@ -1320,6 +1468,32 @@ mod tests {
|
|||
let labels = render(&mut app, &ctx, [860.0, 900.0], vec![]);
|
||||
assert!(labels.iter().any(|(s, _)| s == "Keep gap"));
|
||||
assert!(!app.dirty);
|
||||
let gap_title = labels
|
||||
.iter()
|
||||
.find(|(s, _)| s == "Unallocated schedule gap")
|
||||
.unwrap()
|
||||
.1
|
||||
.center();
|
||||
click_size(&mut app, &ctx, gap_title, [860.0, 900.0]);
|
||||
assert_eq!(app.selected_gap.as_deref(), Some(inferred_key.as_str()));
|
||||
assert_eq!(app.selected_row, None);
|
||||
let labels = render(&mut app, &ctx, [860.0, 900.0], vec![]);
|
||||
let edit = labels
|
||||
.iter()
|
||||
.find(|(s, _)| s == "Edit gap…")
|
||||
.unwrap()
|
||||
.1
|
||||
.center();
|
||||
click_size(&mut app, &ctx, edit, [860.0, 900.0]);
|
||||
assert!(app.row_details);
|
||||
let labels = render(&mut app, &ctx, [860.0, 900.0], vec![]);
|
||||
assert!(
|
||||
labels
|
||||
.iter()
|
||||
.any(|(s, _)| s == "Inferred schedule interval · no source row or timer")
|
||||
);
|
||||
app.row_details = false;
|
||||
let labels = render(&mut app, &ctx, [860.0, 900.0], vec![]);
|
||||
let button = labels
|
||||
.iter()
|
||||
.find(|(s, _)| s == "Keep gap")
|
||||
|
|
|
|||
|
|
@ -57,9 +57,10 @@ Review has two views:
|
|||
|
||||
- **Schedule & corrections** combines the schedule preview and row editing in one
|
||||
table. Start/end/duration, titles, colored issues and row types are visible
|
||||
together. Click anywhere on a source row to target it for editing; a subtle tint marks
|
||||
the selected row while retaining its status color.
|
||||
**Edit row…** opens the selected row editor, including duration correction. **All rows** includes ignored rows;
|
||||
together. Click anywhere on a source row or inferred gap to select it; a subtle tint marks
|
||||
the selection while retaining its status color. **Edit row…** opens the selected source
|
||||
row editor, including duration correction. **Edit gap…** opens an inferred gap's timing,
|
||||
diagnostics and allocation choice even though it has no source cells. **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 and gaps for context. Ignored rows can be restored using All rows.
|
||||
|
|
|
|||
Loading…
Reference in New Issue