Add Ontime export settings tab with CSS overrides enabled

This commit is contained in:
Dandaedre 2026-11-05 11:07:28 +01:00
parent 9804869ea2
commit 71370ed09d
6 changed files with 290 additions and 7 deletions

View File

@ -1,5 +1,5 @@
use crate::{
model::{Analysis, Entry, Rundown, column_index, column_name},
model::{Analysis, Entry, OntimeSettings, Rundown, column_index, column_name},
pipeline::validate,
time::display,
};
@ -205,6 +205,34 @@ pub fn xlsx(rundown: &Rundown) -> Result<Vec<u8>> {
}
pub fn ontime(r: &Rundown) -> Result<Value> {
ontime_with_settings(r, &OntimeSettings::default())
}
pub fn ontime_with_settings(r: &Rundown, settings: &OntimeSettings) -> Result<Value> {
ensure!(
matches!(settings.time_format.as_str(), "12" | "24"),
"Ontime clock format must be 12 or 24"
);
ensure!(
matches!(
settings.language.as_str(),
"en" | "fr" | "de" | "it" | "pt" | "es" | "custom"
),
"Unsupported Ontime language"
);
for color in [
&settings.normal_color,
&settings.warning_color,
&settings.danger_color,
] {
ensure!(
color.starts_with('#')
&& matches!(color.len(), 7 | 9)
&& color[1..].bytes().all(|b| b.is_ascii_hexdigit()),
"Ontime colours must use #RRGGBB or #RRGGBBAA"
);
}
ensure!(
validate(r).is_empty(),
"Cannot export an inconsistent rundown"
@ -282,9 +310,9 @@ pub fn ontime(r: &Rundown) -> Result<Value> {
order.push(e.id.clone());
}
Ok(
json!({"settings":{"version":"4.0.0"},"project":{"title":r.title,"description":"Imported schedule. Explicit starts and untimed gaps preserved; manual playback. Review inferred values before the show."},
json!({"settings":{"version":"4.0.0","timeFormat":settings.time_format,"language":settings.language,"auxTimerNames":settings.aux_timer_names},"project":{"title":r.title,"description":"Imported schedule. Explicit starts and untimed gaps preserved; manual playback. Review inferred values before the show."},
"rundowns":{"default":{"id":"default","title":r.title,"entries":entries,"order":order,"flatOrder":order,"revision":0}},
"customFields":custom_fields,"urlPresets":[],"viewSettings":{},"automation":{"enabledAutomations":false,"enabledOscIn":false,"triggers":[],"automations":{}}}),
"customFields":custom_fields,"urlPresets":[],"viewSettings":{"overrideStyles":settings.override_styles,"normalColor":settings.normal_color,"warningColor":settings.warning_color,"dangerColor":settings.danger_color},"automation":{"enabledAutomations":false,"enabledOscIn":false,"triggers":[],"automations":{}}}),
)
}
/// Validate before publication, preserve existing output unless explicitly allowed.
@ -295,6 +323,26 @@ pub fn write(
neutral: bool,
overwrite: bool,
cancel: &AtomicBool,
) -> Result<()> {
write_with_settings(
a,
input,
output,
neutral,
overwrite,
cancel,
&OntimeSettings::default(),
)
}
pub fn write_with_settings(
a: &Analysis,
input: &Path,
output: &Path,
neutral: bool,
overwrite: bool,
cancel: &AtomicBool,
settings: &OntimeSettings,
) -> Result<()> {
ensure!(
a.completed_stage == 4 && a.diagnostics.is_empty(),
@ -340,7 +388,7 @@ pub fn write(
let value = if neutral {
serde_json::to_value(r)?
} else {
ontime(r)?
ontime_with_settings(r, settings)?
};
serde_json::to_writer_pretty(&mut temp, &value)?;
writeln!(temp)?;

View File

@ -30,6 +30,7 @@ enum Tab {
#[default]
Setup,
Review,
Ontime,
Results,
Details,
}
@ -431,13 +432,22 @@ impl App {
));
return;
}
let settings = match serde_json::from_str::<Profile>(&self.profile) {
Ok(profile) => profile.ontime,
Err(error) => {
self.export_failed(format!("Invalid profile: {error}"));
return;
}
};
let neutral = self.export_choice == ExportChoice::NeutralJson;
let overwrite = self.overwrite;
let tx = self.begin();
let cancel = self.cancel.clone();
self.status = "5/5 Export validated rundown".into();
std::thread::spawn(move || {
let result = export::write(&a, &input, &output, neutral, overwrite, &cancel);
let result = export::write_with_settings(
&a, &input, &output, neutral, overwrite, &cancel, &settings,
);
let _ = tx.send(match result {
Ok(()) => Update::Exported(output),
Err(e) => Update::ExportFailed(format!("{e:#}")),
@ -840,6 +850,80 @@ impl App {
});
}
fn ontime_controls(&mut self, ui: &mut egui::Ui) {
ui.heading("Ontime settings");
ui.label(
"Included in Ontime project JSON. XLSX and neutral JSON do not carry project settings.",
);
ui.small("Changes apply to your next export. Save resolutions to reuse these settings.");
let Ok(mut profile) = serde_json::from_str::<Profile>(&self.profile) else {
ui.colored_label(
Color32::YELLOW,
"Fix the invalid profile in Setup → Advanced settings first.",
);
return;
};
let before = profile.ontime.clone();
let settings = &mut profile.ontime;
ui.add_space(12.0);
ui.strong("Appearance");
ui.checkbox(&mut settings.override_styles, "Enable CSS style override");
ui.small("Uses the stylesheet installed on the Ontime instance. CSS rules may override the colours below.");
for (label, value) in [
("Normal timer", &mut settings.normal_color),
("Warning", &mut settings.warning_color),
("Danger", &mut settings.danger_color),
] {
ui.horizontal(|ui| {
let mut color = Color32::from_hex(value).unwrap_or(Color32::WHITE);
if ui.color_edit_button_srgba(&mut color).changed() {
*value = color.to_hex();
}
ui.label(label);
});
}
ui.separator();
ui.strong("Clock and language");
egui::ComboBox::from_label("Clock format")
.selected_text(format!("{} hour", settings.time_format))
.show_ui(ui, |ui| {
ui.selectable_value(&mut settings.time_format, "24".into(), "24 hour");
ui.selectable_value(&mut settings.time_format, "12".into(), "12 hour");
});
egui::ComboBox::from_label("Language")
.selected_text(&settings.language)
.show_ui(ui, |ui| {
for (code, label) in [
("en", "English"),
("fr", "French"),
("de", "German"),
("it", "Italian"),
("pt", "Portuguese"),
("es", "Spanish"),
("custom", "Installed custom translation"),
] {
ui.selectable_value(&mut settings.language, code.into(), label);
}
});
ui.separator();
ui.strong("Auxiliary timer names");
for (index, name) in settings.aux_timer_names.iter_mut().enumerate() {
ui.horizontal(|ui| {
ui.label(format!("Timer {}", index + 1));
ui.add(egui::TextEdit::singleline(name).hint_text("Default name"));
});
}
ui.add_space(12.0);
if ui.button("Restore Ontime export defaults").clicked() {
*settings = Default::default();
}
if before != profile.ontime {
self.profile = serde_json::to_string_pretty(&profile).unwrap();
self.completed = None;
self.status = "Ontime settings updated for the next JSON export".into();
}
}
fn pane(&mut self, ui: &mut egui::Ui) {
match self.tab {
Tab::Setup => {
@ -969,6 +1053,7 @@ impl App {
}
}
Tab::Review => self.review(ui),
Tab::Ontime => self.ontime_controls(ui),
Tab::Details => {
ui.heading("Analysis status");
self.analysis_summary(ui);
@ -1106,12 +1191,13 @@ impl App {
}
let busy = self.rx.is_some();
egui::TopBottomPanel::top("tabs").show(ctx, |ui| {
ui.horizontal(|ui| {
ui.horizontal_wrapped(|ui| {
ui.strong("Rundown converter");
ui.separator();
for (tab, label) in [
(Tab::Setup, "Setup"),
(Tab::Review, "Review"),
(Tab::Ontime, "Ontime settings"),
(Tab::Results, "Results"),
(Tab::Details, "Details"),
] {
@ -1535,6 +1621,30 @@ mod tests {
wait(&mut app);
assert!(app.error.is_some());
}
#[test]
fn ontime_settings_tab_renders_enabled_styles_and_preserves_ready_schedule() {
let mut app = App {
tab: Tab::Ontime,
..App::default()
};
let labels = frame(&mut app, 560.0, 700.0);
assert!(
labels
.iter()
.any(|label| label == "Enable CSS style override")
);
assert!(
serde_json::from_str::<Profile>(&app.profile)
.unwrap()
.ontime
.override_styles
);
assert!(!app.dirty);
app.profile = "invalid".into();
let labels = frame(&mut app, 560.0, 700.0);
assert!(labels.iter().any(|label| label.contains("invalid profile")));
}
#[test]
fn diagnostics_and_empty_results_render_at_larger_text_sizes() {
let mut app = App::default();

View File

@ -107,13 +107,14 @@ fn run(args: Args) -> Result<bool> {
.output
.context("convert requires --output; choose a new .ontime.json path")?;
eprintln!("5/5 Export validated rundown");
export::write(
export::write_with_settings(
&analysis,
&args.input,
&output,
args.neutral,
args.overwrite,
&cancel,
&profile.ontime,
)?;
eprintln!("Created {}", output.display());
}

View File

@ -58,9 +58,35 @@ impl Diagnostic {
}
}
}
/// Project-level Ontime export preferences, separate from the neutral schedule IR.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct OntimeSettings {
pub override_styles: bool,
pub time_format: String,
pub language: String,
pub normal_color: String,
pub warning_color: String,
pub danger_color: String,
pub aux_timer_names: [String; 3],
}
impl Default for OntimeSettings {
fn default() -> Self {
Self {
override_styles: true,
time_format: "24".into(),
language: "en".into(),
normal_color: "#ffffffcc".into(),
warning_color: "#ffa528".into(),
danger_color: "#ff7300".into(),
aux_timer_names: Default::default(),
}
}
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct Profile {
pub ontime: OntimeSettings,
/// One-based header row. Column letters are Excel-style, e.g. A or AB.
pub header_row: Option<usize>,
pub columns: BTreeMap<String, String>,

View File

@ -72,3 +72,78 @@ fn inspect_validate_convert_and_exit_codes() {
.success()
);
}
#[test]
fn ontime_project_preferences_roundtrip_through_profile_and_export() {
let dir = tempfile::tempdir().unwrap();
let output = dir.path().join("show.json");
let profile = dir.path().join("profile.json");
let settings = serde_json::json!({
"override_styles": false, "time_format": "12", "language": "fr",
"normal_color": "#112233cc", "warning_color": "#aabbcc", "danger_color": "#dd0011",
"aux_timer_names": ["Doors", "Break", "Stage"]
});
std::fs::write(
&profile,
serde_json::json!({"ontime": settings}).to_string(),
)
.unwrap();
let result = cli()
.arg("convert")
.arg(sample())
.arg("--output")
.arg(&output)
.arg("--profile")
.arg(&profile)
.output()
.unwrap();
assert!(result.status.success(), "{:?}", result);
let json: serde_json::Value = serde_json::from_slice(&std::fs::read(&output).unwrap()).unwrap();
assert_eq!(
json["viewSettings"],
serde_json::json!({"overrideStyles": false,
"normalColor": "#112233cc", "warningColor": "#aabbcc", "dangerColor": "#dd0011"})
);
assert_eq!(json["settings"]["timeFormat"], "12");
assert_eq!(json["settings"]["language"], "fr");
assert_eq!(
json["settings"]["auxTimerNames"],
serde_json::json!(["Doors", "Break", "Stage"])
);
// Old profiles inherit the enabled stylesheet default.
std::fs::write(&profile, "{}").unwrap();
let result = cli()
.arg("convert")
.arg(sample())
.arg("--output")
.arg(&output)
.arg("--profile")
.arg(&profile)
.arg("--overwrite")
.output()
.unwrap();
assert!(result.status.success());
let json: serde_json::Value = serde_json::from_slice(&std::fs::read(&output).unwrap()).unwrap();
assert_eq!(json["viewSettings"]["overrideStyles"], true);
// Invalid export settings must not replace an existing output.
let original = std::fs::read(&output).unwrap();
for bad in [
serde_json::json!({"time_format":"bad"}),
serde_json::json!({"language":"bad"}),
serde_json::json!({"normal_color":"invalid"}),
] {
std::fs::write(&profile, serde_json::json!({"ontime": bad}).to_string()).unwrap();
let result = cli()
.arg("convert")
.arg(sample())
.arg("--output")
.arg(&output)
.arg("--profile")
.arg(&profile)
.arg("--overwrite")
.output()
.unwrap();
assert!(!result.status.success());
assert_eq!(std::fs::read(&output).unwrap(), original);
}
}

View File

@ -292,6 +292,29 @@ a timer duration. An explicitly timed break cue remains distinct from such gaps.
Schedule preservation does not imply automatic playback or guarantee that an
operator will start an event on time.
## Ontime settings
The **Ontime settings** tab controls project preferences in native Ontime JSON.
**Enable CSS style override** is checked by default, including for existing profiles.
This enables the CSS already installed on the destination Ontime instance; it does
not embed or replace the stylesheet. Custom CSS can take precedence over timer colours.
Choose 12/24-hour clocks, the viewer language (or an installed custom translation),
normal/warning/danger timer colours, and names for three auxiliary timers. Other
defaults match Ontime: 24-hour clocks, English and its standard timer colours.
Changes apply to the next export without requiring schedule reanalysis. Save/reuse
resolutions to retain them. XLSX and neutral IR JSON do not contain project settings.
CLI profiles accept the same preferences under `ontime`, for example:
```json
{"ontime": {"override_styles": true, "time_format": "24", "language": "fr"}}
```
Optional fields are `normal_color`, `warning_color`, `danger_color` (hex colours),
and `aux_timer_names` (three strings). Full project imports apply these preferences;
use Ontime's Partial Load when you want to keep an existing project's settings.
## Output choice
Native Ontime JSON is the primary target: it lets the exporter control time