Highlight ready exports and add alternate format actions

This commit is contained in:
Dandaedre 2026-11-05 10:09:06 +01:00
parent facdf28467
commit ba6d7b8938
2 changed files with 112 additions and 10 deletions

View File

@ -351,6 +351,49 @@ impl App {
});
});
}
fn export_ready(&self) -> bool {
self.rx.is_none()
&& !self.dirty
&& self
.analysis
.as_ref()
.is_some_and(|a| a.completed_stage == 4 && a.diagnostics.is_empty())
&& !self.output.is_empty()
}
fn export_as(&mut self, choice: ExportChoice) {
let current = self
.completed
.as_ref()
.cloned()
.unwrap_or_else(|| PathBuf::from(&self.output));
let name = current.file_name().unwrap_or_default().to_string_lossy();
let stem = [".ontime.json", ".ontime.xlsx", ".neutral.json"]
.iter()
.find_map(|suffix| name.strip_suffix(suffix))
.unwrap_or_else(|| {
current
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("rundown")
});
let mut dialog =
rfd::FileDialog::new().set_file_name(format!("{stem}.{}", choice.extension()));
if let Some(parent) = current.parent() {
dialog = dialog.set_directory(parent);
}
dialog = if choice == ExportChoice::OntimeXlsx {
dialog.add_filter("Excel workbook", &["xlsx"])
} else {
dialog.add_filter("JSON", &["json"])
};
if let Some(path) = dialog.save_file() {
self.export_choice = choice;
self.output = path.to_string_lossy().into_owned();
self.export();
}
}
fn export(&mut self) {
if self.dirty {
self.error = Some("Apply & recheck your changes before exporting".into());
@ -954,7 +997,9 @@ impl App {
ui.ctx().copy_text(p.display().to_string());
}
});
ui.add(egui::Label::new(if p.extension().and_then(|extension| extension.to_str()) == Some("xlsx") {
ui.add(egui::Label::new(if self.export_choice == ExportChoice::NeutralJson {
"This neutral JSON contains the intermediate representation for inspection or use with other tools. Use Ontime project JSON to import into Ontime."
} else if p.extension().and_then(|extension| extension.to_str()) == Some("xlsx") {
"Import the .xlsx file with Ontime's spreadsheet importer and map the displayed columns. Review the schedule before running the show."
} else {
"Import the .ontime.json project in Ontime. Review the schedule before running the show."
@ -962,6 +1007,22 @@ impl App {
} else {
ui.label("No export published yet.");
}
ui.add_space(8.0);
ui.separator();
ui.heading("Export another format");
ui.add_enabled_ui(self.export_ready(), |ui| {
ui.horizontal_wrapped(|ui| {
for (choice, label) in [
(ExportChoice::OntimeJson, "Ontime JSON…"),
(ExportChoice::OntimeXlsx, "Ontime XLSX…"),
(ExportChoice::NeutralJson, "Neutral JSON…"),
] {
if ui.button(label).on_hover_text("Choose a destination for another export of this validated rundown").clicked() {
self.export_as(choice);
}
}
});
});
}
}
}
@ -1060,13 +1121,14 @@ impl App {
{
self.analyze();
}
let ready = !self.dirty
&& self
.analysis
.as_ref()
.is_some_and(|a| a.completed_stage == 4 && a.diagnostics.is_empty())
&& !self.output.is_empty();
if ui.add_enabled(ready, egui::Button::new("Export")).clicked() {
let ready = self.export_ready();
let button = if ready {
egui::Button::new(RichText::new("Export").color(Color32::WHITE).strong())
.fill(Color32::from_rgb(35, 125, 77))
} else {
egui::Button::new("Export")
};
if ui.add_enabled(ready, button).clicked() {
self.export();
}
}
@ -1273,6 +1335,42 @@ mod tests {
wait(&mut app);
}
#[test]
fn result_format_actions_require_a_valid_current_analysis() {
let mut app = App {
output: "show.ontime.json".into(),
..Default::default()
};
assert!(!app.export_ready());
app.analysis = Some(pipeline::analyze(
&reader::read(&fixture()).unwrap()[0],
&Profile::default(),
&AtomicBool::new(false),
|_, _| {},
));
assert!(app.export_ready());
app.tab = Tab::Results;
app.completed = Some(PathBuf::from(&app.output));
let labels = frame(&mut app, 860.0, 620.0);
for label in ["Ontime JSON…", "Ontime XLSX…", "Neutral JSON…"] {
assert!(labels.iter().any(|text| text == label));
}
app.dirty = true;
assert!(!app.export_ready());
app.dirty = false;
app.analysis.as_mut().unwrap().completed_stage = 3;
assert!(!app.export_ready());
app.analysis.as_mut().unwrap().completed_stage = 4;
app.analysis
.as_mut()
.unwrap()
.diagnostics
.push(crate::model::Diagnostic::new(
4, "OVERLAP", "row 2", "Overlap",
));
assert!(!app.export_ready());
}
#[test]
fn export_choice_updates_default_output_extension() {
let mut app = App::default();

View File

@ -200,8 +200,12 @@ errors; correct the source when available controls cannot express the intended f
CLI errors for rows without a timing also include a labeled source preview.
**Save resolutions…** opens the save/load/remember controls without taking space away
from the correction table. **Results** offers Open, Open output folder and Copy
path. **Details** contains status, completed analysis stage count and the full IR,
from the correction table. **Export** turns green when all checks pass and no edits
are pending. **Results** offers Open, Open output folder and Copy path, plus
**Ontime JSON…**, **Ontime XLSX…**, and **Neutral JSON…** buttons to save another
format. Each opens a destination dialog beside the previous export; cancelling
leaves the current export unchanged. These actions require a validated rundown.
**Details** contains status, completed analysis stage count and the full IR,
including original rows. Cancel is observed between analysis stages and before
publishing an export; reading a workbook or an active stage finishes first.