//! Entwickler-Reiter „Roadmap“: `ROADMAP.md` mit Kennzahlen, Reitern, Filtern, Verweisen und den Klicktests. //! Aufbau nach dem Vorbild der Roadmap-Ansicht von studio-ec; was hier nicht erkannt wird, fehlt (die Datei bleibt die //! einzige Quelle). Nur in Debug-Builds erreichbar (Entscheidung #1048); das Paket enthält ihn nicht. use super::App; use super::gear::{AMBER, ENGRAVING, LED_GREEN, LED_RED, LED_YELLOW, PLATE_BG, PLATE_EDGE, panel}; use super::klicktest_view::{KlickState, klicktest_ui}; use crate::roadmap::{Item, Roadmap, Section, Version, VersionState, is_decided}; use eframe::egui::text::{LayoutJob, TextFormat}; use eframe::egui::{self, Color32, FontId, RichText, Sense, Stroke}; use std::path::PathBuf; use std::sync::Arc; use std::time::{Duration, Instant}; /// So lange leuchtet eine Karte nach einem Sprung auf. const FLASH: Duration = Duration::from_millis(1800); /// So lange zeigt ein kopierter ID-Chip ein Häkchen. const COPIED: Duration = Duration::from_millis(1500); #[derive(Clone, Copy, PartialEq, Eq, Debug)] enum Tab { Todo, Stand, Decisions, Versions, Risks, Rules, Orders, Tests, } impl Tab { /// Reihenfolge wie in der Vorlage: Todo, Stand, Entscheidungen, Roadmap, Risiken, Leitplanken, Aufträge, Tests. const ALL: [Tab; 8] = [ Tab::Todo, Tab::Stand, Tab::Decisions, Tab::Versions, Tab::Risks, Tab::Rules, Tab::Orders, Tab::Tests, ]; fn label(self) -> &'static str { match self { Tab::Todo => "Todo", Tab::Stand => "Stand", Tab::Decisions => "Entscheidungen", Tab::Versions => "Versionspakete", Tab::Risks => "Risiken", Tab::Rules => "Leitplanken", Tab::Orders => "Aufträge", Tab::Tests => "Tests", } } fn for_section(s: Section) -> Tab { match s { Section::Stand => Tab::Stand, Section::Todo | Section::Erledigt => Tab::Todo, Section::Entscheidung => Tab::Decisions, Section::Risiko => Tab::Risks, Section::Auftrag => Tab::Orders, } } } #[derive(Clone, Copy, PartialEq, Eq)] enum DecFilter { All, Open, Decided, } pub(super) struct RoadmapState { tab: Tab, klick: KlickState, path: PathBuf, roadmap: Option>, error: Option, loaded_at: String, status_filter: Option, query: String, /// Priorität im Todo-Reiter („P1“, „P2“ …); `None` = alle. prio: Option, decisions: DecFilter, /// Eingabefeld „Gehe zu #“. goto_text: String, /// Eintrag, zu dem gesprungen wurde (leuchtet kurz auf, wird einmal ins Bild gerollt). goto: Option, flash_until: Option, scroll_pending: bool, copied: Option<(u32, Instant)>, } impl RoadmapState { pub fn new() -> Self { Self { tab: Tab::Todo, klick: KlickState::new(), path: PathBuf::from("ROADMAP.md"), roadmap: None, error: None, loaded_at: String::new(), status_filter: None, query: String::new(), prio: None, decisions: DecFilter::All, goto_text: String::new(), goto: None, flash_until: None, scroll_pending: false, copied: None, } } /// Öffnet die Klicktest-Ansicht (`--tab klicktests`). pub fn show_klicktests(&mut self) { self.tab = Tab::Tests; } /// Öffnet einen Reiter nach Namen (`--tab roadmap:stand`); unbekannte Namen lassen den Reiter unverändert. pub fn show_tab(&mut self, name: &str) { let wanted = name.to_lowercase(); let tab = match wanted.as_str() { "todo" => Some(Tab::Todo), "stand" => Some(Tab::Stand), "entscheidungen" => Some(Tab::Decisions), "versionspakete" | "versionen" => Some(Tab::Versions), "risiken" => Some(Tab::Risks), "leitplanken" => Some(Tab::Rules), "auftraege" | "aufträge" => Some(Tab::Orders), "tests" | "klicktests" => Some(Tab::Tests), // Entwicklungshilfe: Tests-Reiter mit gleich geöffnetem Testlauf des nächsten offenen manuellen Tests. "testlauf" => { self.klick.ensure_loaded(); self.klick.next_open(); Some(Tab::Tests) } _ => None, }; if let Some(t) = tab { self.tab = t; } } fn load(&mut self) { match std::fs::read_to_string(&self.path) { Ok(text) => { self.roadmap = Some(Arc::new(Roadmap::parse(&text))); self.error = None; self.loaded_at = chrono::Local::now().format("%H:%M:%S").to_string(); } Err(e) => { self.roadmap = None; self.error = Some(format!( "{} nicht lesbar ({e}). Die App im Repository-Ordner starten (make dev).", self.path.display() )); } } self.klick.load(); } /// Springt zu einem Eintrag: Reiter wechseln, Filter zurücksetzen, Karte hervorheben und ins Bild rollen. fn jump(&mut self, id: u32) { let Some(item) = self.roadmap.as_ref().and_then(|r| r.find(id)) else { return; }; self.tab = Tab::for_section(item.section); self.status_filter = None; self.query.clear(); self.prio = None; self.decisions = DecFilter::All; self.goto = Some(id); self.flash_until = Some(Instant::now() + FLASH); self.scroll_pending = true; } fn flashing(&self) -> bool { self.flash_until.is_some_and(|t| Instant::now() < t) } } /// Flüchtiger Zustand während eines Bildes; wird am Ende in `RoadmapState` zurückgeschrieben. struct Cx { jump: Option, copied: Option<(u32, Instant)>, goto: Option, flashing: bool, scroll: bool, } impl Cx { fn highlight(&self, id: u32) -> bool { self.goto == Some(id) && self.flashing } } // --------------------------------------------------------------------------------------------------------------- // Reine Hilfen (getestet) /// Zerlegt Markdown-Text in Stücke (Text, fett, Code): `**fett**` und `` `Code` ``. fn md_segments(text: &str) -> Vec<(String, bool, bool)> { let mut out = Vec::new(); let (mut bold, mut code) = (false, false); let mut buf = String::new(); let mut chars = text.chars().peekable(); let flush = |buf: &mut String, out: &mut Vec<(String, bool, bool)>, bold: bool, code: bool| { if !buf.is_empty() { out.push((std::mem::take(buf), bold, code)); } }; while let Some(c) = chars.next() { if c == '*' && chars.peek() == Some(&'*') && !code { chars.next(); flush(&mut buf, &mut out, bold, code); bold = !bold; } else if c == '`' { flush(&mut buf, &mut out, bold, code); code = !code; } else { buf.push(c); } } flush(&mut buf, &mut out, bold, code); out } /// Text eines Versionspakets ohne die ID-Liste und das Wort „Todo:“ (die IDs erscheinen als Chips). fn version_text(text: &str) -> String { let mut out = String::new(); let mut rest = text; while let Some(p) = rest.find('#') { let digits = rest[p + 1..] .chars() .take_while(char::is_ascii_digit) .count(); out.push_str(&rest[..p]); rest = if digits >= 3 { rest[p + 1 + digits..].trim_start_matches([',', ' ']) } else { out.push('#'); &rest[p + 1..] }; } out.push_str(rest); out.replace("Todo:", "").trim().to_string() } /// (erledigt, gebaut, gesamt) der Einträge eines Pakets. fn version_counts(r: &Roadmap, v: &Version) -> (usize, usize, usize) { let done = v.ids.iter().filter(|&&i| r.is_done(i)).count(); let built = v .ids .iter() .filter(|&&i| !r.is_done(i) && r.is_built(i)) .count(); (done, built, v.ids.len()) } /// Prioritäten der Todo-Gruppen („P1“, „P2“ …) in der Reihenfolge der Datei, ohne Wiederholung. fn priorities(items: &[&Item]) -> Vec { let mut out: Vec = Vec::new(); for i in items { let p = i.group.split(" – ").next().unwrap_or("").trim().to_string(); if !p.is_empty() && !out.contains(&p) { out.push(p); } } out } fn matches_query(item: &Item, query: &str) -> bool { let q = query.trim().to_lowercase(); if q.is_empty() { return true; } let q = q.trim_start_matches('#'); format!("{} {} {}", item.id, item.title, item.detail) .to_lowercase() .contains(q) } /// ◐ wird in manchen Schriften als Halbmond-Splitter gezeichnet; deshalb ein Bruch als Zeichen (wie in der Vorlage). fn status_symbol(s: Option) -> &'static str { match s { Some('✓') => "✓", Some('◐') => "½", Some('✗') => "✗", Some('?') => "?", _ => "–", } } fn status_color(status: Option) -> Color32 { match status { Some('✓') => LED_GREEN, Some('◐') => LED_YELLOW, Some('✗') => LED_RED, _ => ENGRAVING, } } // --------------------------------------------------------------------------------------------------------------- // Bausteine /// Text mit `**fett**` und `` `Code` `` als umbrechendes Label. pub(super) fn md_label(ui: &mut egui::Ui, text: &str) { let mut job = LayoutJob::default(); job.wrap.max_width = ui.available_width(); for (seg, bold, code) in md_segments(text) { let format = TextFormat { font_id: if code { FontId::monospace(13.0) } else { FontId::proportional(14.0) }, color: if code { AMBER } else if bold { Color32::from_gray(250) } else { Color32::from_gray(215) }, background: if code { Color32::from_gray(42) } else { Color32::TRANSPARENT }, ..Default::default() }; job.append(&seg, 0.0, format); } ui.label(job); } fn card_frame(highlight: bool, dim: bool) -> egui::Frame { egui::Frame::new() .fill(if dim { PLATE_BG.gamma_multiply(0.8) } else { PLATE_BG }) .stroke(Stroke::new( if highlight { 2.0 } else { 1.0 }, if highlight { AMBER } else { PLATE_EDGE }, )) .corner_radius(6.0) .inner_margin(egui::Margin::symmetric(10, 6)) } /// ID als Chip; ein Klick kopiert `#NNNN` in die Zwischenablage. fn id_chip(ui: &mut egui::Ui, cx: &mut Cx, id: u32) { let recently = cx .copied .is_some_and(|(c, t)| c == id && t.elapsed() < COPIED); let text = if recently { format!("#{id} ✓") } else { format!("#{id}") }; let resp = ui .add(egui::Button::new(RichText::new(text).monospace().small().color(AMBER)).small()) .on_hover_text("ID kopieren"); if resp.clicked() { ui.ctx().copy_text(format!("#{id}")); cx.copied = Some((id, Instant::now())); } if recently { ui.ctx().request_repaint_after(COPIED); } } /// Verweise („→ #…“) als Chips mit Titel; ein Klick springt zum Eintrag. `mark`: nach erledigt/gebaut einfärben. fn ref_chips(ui: &mut egui::Ui, r: &Roadmap, cx: &mut Cx, label: &str, ids: &[u32], mark: bool) { if ids.is_empty() { return; } ui.horizontal_wrapped(|ui| { ui.label(RichText::new(label).small().color(ENGRAVING)); for &id in ids { let known = r.find(id); let title = known.map(|i| short(&i.title, 30)).unwrap_or_default(); let color = if !mark { Color32::from_gray(200) } else if r.is_done(id) { LED_GREEN } else if r.is_built(id) { LED_YELLOW } else { Color32::from_gray(200) }; let text = if title.is_empty() { format!("#{id}") } else { format!("#{id} {title}") }; let resp = ui.add_enabled( known.is_some(), egui::Button::new(RichText::new(text).small().color(color)).small(), ); if resp.clicked() { cx.jump = Some(id); } } }); } fn short(s: &str, max: usize) -> String { let plain: String = s.chars().filter(|c| !matches!(c, '*' | '`')).collect(); if plain.chars().count() <= max { plain } else { format!( "{} …", plain.chars().take(max).collect::().trim_end() ) } } fn pill(ui: &mut egui::Ui, text: &str, color: Color32) { ui.label( RichText::new(format!(" {text} ")) .small() .strong() .color(Color32::BLACK) .background_color(color), ); } /// Kennzahlenkarte; gibt zurück, ob sie angeklickt wurde. fn stat_card(ui: &mut egui::Ui, value: &str, label: &str, color: Color32, selected: bool) -> bool { let frame = egui::Frame::new() .fill(PLATE_BG) .stroke(Stroke::new( if selected { 2.0 } else { 1.0 }, if selected { AMBER } else { PLATE_EDGE }, )) .corner_radius(8.0) .inner_margin(egui::Margin::symmetric(12, 6)); let out = frame.show(ui, |ui| { ui.set_min_width(96.0); ui.label(RichText::new(value).size(22.0).strong().color(color)); ui.label(RichText::new(label).small().color(ENGRAVING)); }); let resp = ui.interact( out.response.rect, ui.scope_id().with(("stat", label)), Sense::click(), ); resp.on_hover_cursor(egui::CursorIcon::PointingHand) .clicked() } fn chip(ui: &mut egui::Ui, text: &str, on: bool) -> bool { ui.selectable_label(on, RichText::new(text).small()) .clicked() } /// Karte eines Eintrags: ID-Chip, Titel, aufklappbar mit Text und Verweisen. fn item_card(ui: &mut egui::Ui, r: &Roadmap, cx: &mut Cx, item: &Item, dim: bool) { let highlight = cx.highlight(item.id); let out = card_frame(highlight, dim).show(ui, |ui| { ui.set_width(ui.available_width()); let has_body = !item.detail.is_empty() || !item.refs.is_empty(); let header = |ui: &mut egui::Ui, cx: &mut Cx| { id_chip(ui, cx, item.id); md_label(ui, &format!("**{}**", item.title.replace("**", ""))); }; if !has_body { ui.horizontal_wrapped(|ui| header(ui, cx)); return; } let id = ui.make_persistent_id(("roadmap-card", item.id)); let mut state = egui::collapsing_header::CollapsingState::load_with_default_open(ui.ctx(), id, false); if highlight && cx.scroll { state.set_open(true); } state .show_header(ui, |ui| { ui.horizontal_wrapped(|ui| header(ui, cx)); }) .body(|ui| { if !item.detail.is_empty() { md_label(ui, &item.detail); } ref_chips(ui, r, cx, "voran:", &item.refs, false); }); }); if highlight && cx.scroll { out.response.scroll_to_me(Some(egui::Align::Center)); } ui.add_space(4.0); } // --------------------------------------------------------------------------------------------------------------- // Reiter fn todo_tab(ui: &mut egui::Ui, st: &mut RoadmapState, r: &Roadmap, cx: &mut Cx) { let open: Vec<&Item> = r .items .iter() .filter(|i| i.section == Section::Todo) .collect(); let prios = priorities(&open); ui.horizontal_wrapped(|ui| { if chip(ui, &format!("Alle ({})", open.len()), st.prio.is_none()) { st.prio = None; } for p in &prios { let n = open .iter() .filter(|i| i.group.starts_with(p.as_str())) .count(); if chip( ui, &format!("{p} ({n})"), st.prio.as_deref() == Some(p.as_str()), ) { st.prio = if st.prio.as_deref() == Some(p.as_str()) { None } else { Some(p.clone()) }; } } }); ui.add_space(4.0); let mut last_group = String::new(); for item in open .iter() .filter(|i| st.prio.as_deref().is_none_or(|p| i.group.starts_with(p))) { if item.group != last_group { ui.add_space(6.0); ui.label(RichText::new(&item.group).strong().color(ENGRAVING)); last_group = item.group.clone(); } item_card(ui, r, cx, item, false); } let finished: Vec<&Item> = r .items .iter() .filter(|i| i.section == Section::Erledigt) .collect(); if !finished.is_empty() { ui.add_space(8.0); ui.label( RichText::new("Erledigt (einzeln)") .strong() .color(ENGRAVING), ); for item in finished { item_card(ui, r, cx, item, true); } } if !r.done_days.is_empty() { ui.add_space(8.0); ui.label( RichText::new("Erledigt nach Tagen") .strong() .color(ENGRAVING), ); for d in &r.done_days { card_frame(false, true).show(ui, |ui| { ui.set_width(ui.available_width()); ui.label( RichText::new(format!("✓ {}", d.title)) .strong() .color(LED_GREEN), ); md_label(ui, &d.text); }); ui.add_space(4.0); } } } fn stand_tab(ui: &mut egui::Ui, st: &mut RoadmapState, r: &Roadmap, cx: &mut Cx) { let rows: Vec<&Item> = r .items .iter() .filter(|i| i.section == Section::Stand) .collect(); ui.horizontal_wrapped(|ui| { if chip( ui, &format!("Alle ({})", rows.len()), st.status_filter.is_none(), ) { st.status_filter = None; } for mark in ['✓', '◐', '✗', '?'] { let n = rows.iter().filter(|i| i.status == Some(mark)).count(); if chip( ui, &format!("{} {n}", status_symbol(Some(mark))), st.status_filter == Some(mark), ) { st.status_filter = if st.status_filter == Some(mark) { None } else { Some(mark) }; } } ui.add( egui::TextEdit::singleline(&mut st.query) .desired_width(180.0) .hint_text("Suchen"), ); }); ui.add_space(4.0); let shown: Vec<&Item> = rows .into_iter() .filter(|i| { st.status_filter.is_none_or(|m| i.status == Some(m)) && matches_query(i, &st.query) }) .collect(); if shown.is_empty() { ui.label(RichText::new("Nichts gefunden.").color(ENGRAVING)); } for item in shown { let highlight = cx.highlight(item.id); let out = card_frame(highlight, false).show(ui, |ui| { ui.set_width(ui.available_width()); ui.horizontal_wrapped(|ui| { id_chip(ui, cx, item.id); ui.label( RichText::new(status_symbol(item.status)) .strong() .color(status_color(item.status)), ); md_label(ui, &format!("**{}**", item.title.replace("**", ""))); }); if !item.detail.is_empty() { md_label(ui, &item.detail); } let todos: Vec = r.todos_for(item.id).iter().map(|t| t.id).collect(); ref_chips(ui, r, cx, "offene Todos:", &todos, false); let tests = st.klick.covering(item.id); if !tests.is_empty() { ui.horizontal_wrapped(|ui| { ui.label(RichText::new("Tests:").small().color(ENGRAVING)); for (name, ok, total) in tests { let color = if ok == total { LED_GREEN } else { Color32::from_gray(200) }; let text = RichText::new(format!("{name} {ok}/{total}")) .small() .color(color); if ui .add(egui::Button::new(text).small()) .on_hover_text("Zu den Klicktests") .clicked() { st.tab = Tab::Tests; } } }); } }); if highlight && cx.scroll { out.response.scroll_to_me(Some(egui::Align::Center)); } ui.add_space(4.0); } } fn decisions_tab(ui: &mut egui::Ui, st: &mut RoadmapState, r: &Roadmap, cx: &mut Cx) { let all: Vec<&Item> = r .items .iter() .filter(|i| i.section == Section::Entscheidung) .collect(); let open = all.iter().filter(|i| !is_decided(i)).count(); ui.horizontal_wrapped(|ui| { if chip( ui, &format!("Alle {}", all.len()), st.decisions == DecFilter::All, ) { st.decisions = DecFilter::All; } if chip( ui, &format!("Offen {open}"), st.decisions == DecFilter::Open, ) { st.decisions = DecFilter::Open; } if chip( ui, &format!("Entschieden {}", all.len() - open), st.decisions == DecFilter::Decided, ) { st.decisions = DecFilter::Decided; } }); ui.add_space(4.0); let mut shown: Vec<&Item> = all .into_iter() .filter(|i| match st.decisions { DecFilter::All => true, DecFilter::Open => !is_decided(i), DecFilter::Decided => is_decided(i), }) .collect(); // Offene zuerst (stabil: Reihenfolge der Datei bleibt innerhalb der Gruppen). shown.sort_by_key(|i| is_decided(i)); for item in shown { let highlight = cx.highlight(item.id); let out = card_frame(highlight, is_decided(item)).show(ui, |ui| { ui.set_width(ui.available_width()); ui.horizontal_wrapped(|ui| { id_chip(ui, cx, item.id); if is_decided(item) { pill(ui, "entschieden", LED_GREEN); } else { pill(ui, "offen", LED_RED); } let text = if item.detail.is_empty() { item.title.clone() } else { format!("{}. {}", item.title, item.detail) }; md_label(ui, &text); }); ref_chips(ui, r, cx, "voran:", &item.refs, false); }); if highlight && cx.scroll { out.response.scroll_to_me(Some(egui::Align::Center)); } ui.add_space(4.0); } } fn versions_tab(ui: &mut egui::Ui, r: &Roadmap, cx: &mut Cx) { if r.versions.is_empty() { ui.label(RichText::new("Keine Versionspakete in der Datei.").color(ENGRAVING)); return; } for v in &r.versions { card_frame(false, false).show(ui, |ui| { ui.set_width(ui.available_width()); ui.horizontal_wrapped(|ui| { ui.label(RichText::new(&v.name).size(20.0).strong().color(AMBER)); ui.label(RichText::new(&v.title).strong()); match r.version_state(v) { VersionState::Released => pill(ui, "veröffentlicht", LED_GREEN), VersionState::InProgress => pill(ui, "in Arbeit", AMBER), VersionState::Planned => pill(ui, "Planung", Color32::from_gray(150)), } }); let text = version_text(&v.text); if !text.is_empty() { md_label(ui, &text); } let (done, built, total) = version_counts(r, v); ui.label( RichText::new(format!( "{done} von {total} erledigt, {built} gebaut, noch nicht geprüft" )) .small() .color(ENGRAVING), ); ref_chips(ui, r, cx, "Einträge:", &v.ids, true); }); ui.add_space(6.0); } } fn list_tab(ui: &mut egui::Ui, r: &Roadmap, cx: &mut Cx, section: Section) { let items: Vec<&Item> = r.items.iter().filter(|i| i.section == section).collect(); if items.is_empty() { ui.label(RichText::new("Keine Einträge.").color(ENGRAVING)); } for item in items { let highlight = cx.highlight(item.id); let out = card_frame(highlight, false).show(ui, |ui| { ui.set_width(ui.available_width()); ui.horizontal_wrapped(|ui| { id_chip(ui, cx, item.id); let text = if item.detail.is_empty() { item.title.clone() } else { format!("**{}** {}", item.title, item.detail) }; md_label(ui, &text); }); ref_chips(ui, r, cx, "voran:", &item.refs, false); }); if highlight && cx.scroll { out.response.scroll_to_me(Some(egui::Align::Center)); } ui.add_space(4.0); } } fn rules_tab(ui: &mut egui::Ui, r: &Roadmap) { if r.rules.is_empty() { ui.label(RichText::new("Keine Leitplanken in der Datei.").color(ENGRAVING)); } for rule in &r.rules { card_frame(false, false).show(ui, |ui| { ui.set_width(ui.available_width()); md_label(ui, rule); }); ui.add_space(4.0); } } impl App { pub(super) fn roadmap_ui(&mut self, ui: &mut egui::Ui) { let st = &mut self.roadmap; if st.roadmap.is_none() && st.error.is_none() { st.load(); } st.klick.ensure_loaded(); panel(ui, "Roadmap (nur Entwicklung)", |ui| { ui.horizontal_wrapped(|ui| { if ui.button("Neu laden").clicked() { st.load(); } ui.label(RichText::new(st.path.display().to_string()).color(ENGRAVING)); if !st.loaded_at.is_empty() { ui.label( RichText::new(format!("geladen {}", st.loaded_at)) .small() .color(ENGRAVING), ); } if let Some(n) = st.roadmap.as_ref().and_then(|r| r.next_id) { ui.label( RichText::new(format!("nächste ID #{n}")) .small() .color(ENGRAVING), ); } }); if let Some(e) = &st.error { ui.colored_label(LED_RED, e); } if let Some(r) = &st.roadmap { md_label(ui, &format!("Stand: {}", r.stand)); } }); let Some(r) = st.roadmap.clone() else { return }; ui.add_space(6.0); let mut cx = Cx { jump: None, copied: st.copied, goto: st.goto, flashing: st.flashing(), scroll: st.scroll_pending, }; // Kennzahlenkarten ui.horizontal_wrapped(|ui| { for (mark, name) in [ ('✓', "geprüft"), ('◐', "gebaut"), ('✗', "offen"), ('?', "unklar"), ] { let selected = st.tab == Tab::Stand && st.status_filter == Some(mark); if stat_card( ui, &r.count_status(mark).to_string(), &format!("{} {name}", status_symbol(Some(mark))), status_color(Some(mark)), selected, ) { st.tab = Tab::Stand; st.status_filter = if selected { None } else { Some(mark) }; } } let (total, ok, _bad, _never) = st.klick.counts(); if total > 0 && stat_card( ui, &format!("{ok}/{total}"), "Tests ✓", LED_GREEN, st.tab == Tab::Tests, ) { st.tab = Tab::Tests; } let todo = r .items .iter() .filter(|i| i.section == Section::Todo) .count(); if stat_card(ui, &todo.to_string(), "Todo", AMBER, st.tab == Tab::Todo) { st.tab = Tab::Todo; } }); ui.add_space(6.0); // Reiter und „Gehe zu #“ ui.horizontal_wrapped(|ui| { for tab in Tab::ALL { ui.selectable_value(&mut st.tab, tab, tab.label()); } ui.separator(); ui.label("Gehe zu #"); let resp = ui.add(egui::TextEdit::singleline(&mut st.goto_text).desired_width(60.0)); if resp.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) { match st.goto_text.trim().trim_start_matches('#').parse::() { Ok(id) if r.find(id).is_some() => cx.jump = Some(id), _ => { st.error = Some(format!( "Keine ID „{}“ in der Roadmap.", st.goto_text.trim() )) } } } }); if st.goto_text.is_empty() && st .error .as_deref() .is_some_and(|e| e.starts_with("Keine ID")) { st.error = None; } ui.add_space(6.0); match st.tab { Tab::Todo => todo_tab(ui, st, &r, &mut cx), Tab::Stand => stand_tab(ui, st, &r, &mut cx), Tab::Decisions => decisions_tab(ui, st, &r, &mut cx), Tab::Versions => versions_tab(ui, &r, &mut cx), Tab::Risks => list_tab(ui, &r, &mut cx, Section::Risiko), Tab::Rules => rules_tab(ui, &r), Tab::Orders => list_tab(ui, &r, &mut cx, Section::Auftrag), Tab::Tests => { if let Some(id) = klicktest_ui(ui, &mut st.klick) { cx.jump = Some(id); } } } // Zustand zurückschreiben; einen Sprung erst jetzt ausführen (Reiter und Filter wechseln im nächsten Bild). st.copied = cx.copied; if cx.scroll && cx.goto.is_some() { st.scroll_pending = false; } if st.flashing() { ui.ctx().request_repaint_after(Duration::from_millis(100)); } if let Some(id) = cx.jump { st.jump(id); } } } #[cfg(test)] mod tests { use super::*; fn item(id: u32, section: Section, group: &str, title: &str, detail: &str) -> Item { Item { id, section, group: group.into(), title: title.into(), status: None, detail: detail.into(), refs: vec![], } } #[test] fn markdown_segments_split_bold_and_code() { assert_eq!( md_segments("a **fett** und `code` Ende"), vec![ ("a ".into(), false, false), ("fett".into(), true, false), (" und ".into(), false, false), ("code".into(), false, true), (" Ende".into(), false, false), ] ); assert_eq!( md_segments("`a **b** c`"), vec![("a **b** c".into(), false, true)], "in Code kein Fett" ); assert_eq!(md_segments("ohne"), vec![("ohne".into(), false, false)]); assert!(md_segments("").is_empty()); } #[test] fn version_text_drops_ids_and_todo_word() { assert_eq!( version_text("Paket und CI. #1019, #1020, #1031"), "Paket und CI." ); assert_eq!( version_text("Todo: #1004, #1005. Ziel: ruhig."), ". Ziel: ruhig." ); assert_eq!( version_text("Kein #1 Problem bei #12 und #1234"), "Kein #1 Problem bei #12 und" ); } #[test] fn version_counts_separate_done_and_built() { let r = Roadmap::parse( "## 2. Stand\n| #1001 | A | ✓ | |\n| #1002 | B | ◐ | |\n| #1003 | C | ✗ | |\n\n## 6. Versionspakete\n**0.1 – X.** Text #1001, #1002, #1003\n", ); assert_eq!(version_counts(&r, &r.versions[0]), (1, 1, 3)); } #[test] fn priorities_are_unique_and_ordered() { let a = item(1, Section::Todo, "P1 – Release", "x", ""); let b = item(2, Section::Todo, "P1 – Abnahme", "x", ""); let c = item(3, Section::Todo, "P2 – Fehler", "x", ""); assert_eq!(priorities(&[&a, &b, &c]), vec!["P1", "P2"]); } #[test] fn query_matches_id_title_and_detail() { let i = item( 1031, Section::Todo, "", "Paket installieren", "Nutzer: Pacman", ); for q in ["", "#1031", "1031", "paket", "PACMAN"] { assert!(matches_query(&i, q), "{q}"); } assert!(!matches_query(&i, "klicktest")); } #[test] fn status_symbol_uses_a_fraction_for_half_built() { assert_eq!(status_symbol(Some('◐')), "½"); assert_eq!(status_symbol(None), "–"); } #[test] fn tabs_follow_the_template_order_and_sections_map_to_tabs() { let labels: Vec<&str> = Tab::ALL.iter().map(|t| t.label()).collect(); assert_eq!( labels, [ "Todo", "Stand", "Entscheidungen", "Versionspakete", "Risiken", "Leitplanken", "Aufträge", "Tests" ] ); assert_eq!(Tab::for_section(Section::Erledigt), Tab::Todo); assert_eq!(Tab::for_section(Section::Entscheidung), Tab::Decisions); } fn state_with(text: &str) -> RoadmapState { let mut st = RoadmapState::new(); st.roadmap = Some(Arc::new(Roadmap::parse(text))); st } #[test] fn jump_switches_tab_resets_filters_and_marks_the_item() { let mut st = state_with("## 2. Stand\n| #1001 | A | ✓ | |\n\n## 5. Risiken\n- [#1002] Risiko.\n"); st.status_filter = Some('✗'); st.query = "abc".into(); st.jump(1002); assert_eq!( (st.tab, st.goto, st.scroll_pending), (Tab::Risks, Some(1002), true) ); assert!(st.query.is_empty() && st.status_filter.is_none() && st.flashing()); st.jump(9999); assert_eq!(st.goto, Some(1002), "unbekannte ID ändert nichts"); st.jump(1001); assert_eq!(st.tab, Tab::Stand); } #[test] fn show_tab_selects_tabs_by_name() { let mut st = RoadmapState::new(); for (name, tab) in [ ("Stand", Tab::Stand), ("versionspakete", Tab::Versions), ("Auftraege", Tab::Orders), ] { st.show_tab(name); assert_eq!(st.tab, tab, "{name}"); } st.show_tab("unbekannt"); assert_eq!(st.tab, Tab::Orders, "unbekannter Name ändert nichts"); } #[test] fn missing_file_gives_hint_not_panic() { let mut st = RoadmapState::new(); st.path = PathBuf::from("/nonexistent/ROADMAP.md"); st.load(); assert!(st.roadmap.is_none()); assert!(st.error.as_deref().is_some_and(|e| e.contains("make dev"))); } }