forked from wlkns-dev/stimmwerk
Entwickler-Reiter „Roadmap“ (#1035): ROADMAP.md lesen, Kennzahlen, Filter, Sprung per ID
Nur in Debug-Builds erreichbar (--tab roadmap). Parser mit Tests, auch gegen die echte ROADMAP.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -7,6 +7,7 @@ mod grip_view;
|
||||
mod home_view;
|
||||
mod metro_view;
|
||||
mod review_view;
|
||||
mod roadmap_view;
|
||||
mod roll;
|
||||
mod voice_view;
|
||||
|
||||
@ -71,6 +72,8 @@ enum Mode {
|
||||
Review,
|
||||
Voice,
|
||||
Calib,
|
||||
/// Nur in Debug-Builds erreichbar (Entscheidung #1048).
|
||||
Roadmap,
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
@ -112,6 +115,7 @@ pub struct App {
|
||||
/// Probe-Modus im Chart-Tab: Wiedergabe ohne Wertung und Aufnahme, mit Spulen.
|
||||
practice: Option<chart_view::Practice>,
|
||||
metro: metro_view::MetroState,
|
||||
roadmap: roadmap_view::RoadmapState,
|
||||
/// Gefundene Songs für die Auswahl.
|
||||
charts: Vec<chart_view::ChartEntry>,
|
||||
/// Gewählte Passage (Index in `chart.sections`); `None` = ganzes Lied.
|
||||
@ -208,6 +212,7 @@ impl App {
|
||||
calib: CalibState::new(),
|
||||
practice: None,
|
||||
metro: metro_view::MetroState::new(),
|
||||
roadmap: roadmap_view::RoadmapState::new(),
|
||||
charts: Vec::new(),
|
||||
section: None,
|
||||
practice_loop: true,
|
||||
@ -289,6 +294,7 @@ impl App {
|
||||
"verlauf" => Mode::History,
|
||||
"stimmfinder" | "voice" => Mode::Voice,
|
||||
"kalibrierung" | "abgleich" => Mode::Calib,
|
||||
"roadmap" if cfg!(debug_assertions) => Mode::Roadmap,
|
||||
_ => Mode::Tuner,
|
||||
};
|
||||
self.last_mode = self.mode;
|
||||
@ -606,6 +612,9 @@ impl eframe::App for App {
|
||||
if self.review.is_some() {
|
||||
ui.selectable_value(&mut self.mode, Mode::Review, "Auswertung");
|
||||
}
|
||||
if cfg!(debug_assertions) {
|
||||
ui.selectable_value(&mut self.mode, Mode::Roadmap, "Roadmap");
|
||||
}
|
||||
});
|
||||
// Hinweise und Fehlermeldungen gut sichtbar oben.
|
||||
if !self.messages.is_empty() {
|
||||
@ -641,6 +650,7 @@ impl eframe::App for App {
|
||||
Mode::Review => self.review_ui(ui),
|
||||
Mode::Voice => self.voice_ui(ui),
|
||||
Mode::Calib => self.calib_ui(ui),
|
||||
Mode::Roadmap => self.roadmap_ui(ui),
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
294
src/ui/roadmap_view.rs
Normal file
294
src/ui/roadmap_view.rs
Normal file
@ -0,0 +1,294 @@
|
||||
//! Entwickler-Reiter „Roadmap“: zeigt `ROADMAP.md` mit Kennzahlen, Filter und Sprung per ID.
|
||||
//! 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 crate::roadmap::{Item, Roadmap, Section};
|
||||
use eframe::egui::{self, Color32, RichText, Stroke};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub(super) struct RoadmapState {
|
||||
path: PathBuf,
|
||||
roadmap: Option<Roadmap>,
|
||||
error: Option<String>,
|
||||
filter: String,
|
||||
section: Option<Section>,
|
||||
/// Eingabefeld „Gehe zu #“.
|
||||
goto_text: String,
|
||||
/// Eintrag, zu dem gesprungen wurde (hervorgehoben, einmal ins Bild gerollt).
|
||||
goto: Option<u32>,
|
||||
scroll_pending: bool,
|
||||
}
|
||||
|
||||
impl RoadmapState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
path: PathBuf::from("ROADMAP.md"),
|
||||
roadmap: None,
|
||||
error: None,
|
||||
filter: String::new(),
|
||||
section: None,
|
||||
goto_text: String::new(),
|
||||
goto: None,
|
||||
scroll_pending: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn load(&mut self) {
|
||||
match std::fs::read_to_string(&self.path) {
|
||||
Ok(text) => {
|
||||
self.roadmap = Some(Roadmap::parse(&text));
|
||||
self.error = None;
|
||||
}
|
||||
Err(e) => {
|
||||
self.roadmap = None;
|
||||
self.error = Some(format!(
|
||||
"{} nicht lesbar ({e}). Die App im Repository-Ordner starten (make run).",
|
||||
self.path.display()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Springt zu einem Eintrag: Filter zurücksetzen, Eintrag hervorheben und ins Bild rollen.
|
||||
fn jump(&mut self, id: u32) {
|
||||
self.filter.clear();
|
||||
self.section = None;
|
||||
self.goto = Some(id);
|
||||
self.scroll_pending = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn status_color(status: Option<char>) -> Color32 {
|
||||
match status {
|
||||
Some('✓') => LED_GREEN,
|
||||
Some('◐') => LED_YELLOW,
|
||||
Some('✗') => LED_RED,
|
||||
_ => ENGRAVING,
|
||||
}
|
||||
}
|
||||
|
||||
fn matches(item: &Item, section: Option<Section>, filter: &str) -> bool {
|
||||
if section.is_some_and(|s| s != item.section) {
|
||||
return false;
|
||||
}
|
||||
let f = filter.trim().to_lowercase();
|
||||
if f.is_empty() {
|
||||
return true;
|
||||
}
|
||||
let f = f.trim_start_matches('#');
|
||||
format!("{} {} {}", item.id, item.title, item.detail)
|
||||
.to_lowercase()
|
||||
.contains(f)
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub(super) fn roadmap_ui(&mut self, ui: &mut egui::Ui) {
|
||||
if self.roadmap.roadmap.is_none() && self.roadmap.error.is_none() {
|
||||
self.roadmap.load();
|
||||
}
|
||||
let st = &mut self.roadmap;
|
||||
let mut jump_to: Option<u32> = None;
|
||||
|
||||
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 let Some(e) = &st.error {
|
||||
ui.colored_label(LED_RED, e);
|
||||
}
|
||||
if let Some(r) = &st.roadmap {
|
||||
ui.label(format!("Stand: {}", r.stand));
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for s in Section::ALL {
|
||||
ui.label(RichText::new(format!("{} {}", s.label(), r.count(s))).strong());
|
||||
}
|
||||
ui.separator();
|
||||
for (mark, name) in [
|
||||
('✓', "geprüft"),
|
||||
('◐', "gebaut"),
|
||||
('✗', "offen"),
|
||||
('?', "unklar"),
|
||||
] {
|
||||
ui.label(
|
||||
RichText::new(format!("{mark} {} {name}", r.count_status(mark)))
|
||||
.color(status_color(Some(mark))),
|
||||
);
|
||||
}
|
||||
if let Some(n) = r.next_id {
|
||||
ui.separator();
|
||||
ui.label(format!("nächste ID #{n}"));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let Some(r) = st.roadmap.clone() else { return };
|
||||
ui.add_space(6.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label("Filter");
|
||||
ui.add(
|
||||
egui::TextEdit::singleline(&mut st.filter)
|
||||
.desired_width(160.0)
|
||||
.hint_text("Text oder ID"),
|
||||
);
|
||||
ui.selectable_value(&mut st.section, None, "Alle");
|
||||
for s in Section::ALL {
|
||||
ui.selectable_value(&mut st.section, Some(s), s.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::<u32>() {
|
||||
Ok(id) if r.find(id).is_some() => jump_to = 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);
|
||||
|
||||
let mut shown = 0;
|
||||
for item in r
|
||||
.items
|
||||
.iter()
|
||||
.filter(|i| matches(i, st.section, &st.filter))
|
||||
{
|
||||
shown += 1;
|
||||
let highlighted = st.goto == Some(item.id);
|
||||
let frame = egui::Frame::new()
|
||||
.fill(PLATE_BG)
|
||||
.stroke(Stroke::new(
|
||||
if highlighted { 2.0 } else { 1.0 },
|
||||
if highlighted { AMBER } else { PLATE_EDGE },
|
||||
))
|
||||
.corner_radius(6.0)
|
||||
.inner_margin(egui::Margin::symmetric(10, 6));
|
||||
let out = frame.show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(
|
||||
RichText::new(format!("#{}", item.id))
|
||||
.monospace()
|
||||
.strong()
|
||||
.color(AMBER),
|
||||
);
|
||||
if let Some(s) = item.status {
|
||||
ui.label(
|
||||
RichText::new(s.to_string())
|
||||
.strong()
|
||||
.color(status_color(item.status)),
|
||||
);
|
||||
}
|
||||
ui.label(RichText::new(&item.title).strong());
|
||||
let group = if item.group.is_empty() {
|
||||
item.section.label().to_string()
|
||||
} else {
|
||||
item.group.clone()
|
||||
};
|
||||
ui.label(RichText::new(group).small().color(ENGRAVING));
|
||||
});
|
||||
if !item.detail.is_empty() {
|
||||
ui.label(&item.detail);
|
||||
}
|
||||
if !item.refs.is_empty() {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("→").color(ENGRAVING));
|
||||
for &id in &item.refs {
|
||||
let known = r.find(id).is_some();
|
||||
if ui
|
||||
.add_enabled(known, egui::Button::new(format!("#{id}")).small())
|
||||
.clicked()
|
||||
{
|
||||
jump_to = Some(id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if highlighted && st.scroll_pending {
|
||||
out.response.scroll_to_me(Some(egui::Align::Center));
|
||||
st.scroll_pending = false;
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
}
|
||||
if shown == 0 {
|
||||
ui.label(RichText::new("Nichts gefunden.").color(ENGRAVING));
|
||||
}
|
||||
if let Some(id) = jump_to {
|
||||
st.jump(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn item(id: u32, section: Section, title: &str, detail: &str) -> Item {
|
||||
Item {
|
||||
id,
|
||||
section,
|
||||
group: String::new(),
|
||||
title: title.into(),
|
||||
status: None,
|
||||
detail: detail.into(),
|
||||
refs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_matches_id_title_and_detail_case_insensitive() {
|
||||
let i = item(1031, Section::Todo, "Paket installieren", "Nutzer: Pacman");
|
||||
assert!(matches(&i, None, ""));
|
||||
assert!(matches(&i, None, "#1031"));
|
||||
assert!(matches(&i, None, "1031"));
|
||||
assert!(matches(&i, None, "paket"));
|
||||
assert!(matches(&i, None, "PACMAN"));
|
||||
assert!(!matches(&i, None, "klicktest"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn section_filter_excludes_other_sections() {
|
||||
let i = item(1, Section::Risiko, "x", "");
|
||||
assert!(matches(&i, Some(Section::Risiko), ""));
|
||||
assert!(!matches(&i, Some(Section::Todo), ""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn jump_clears_filters_and_marks_item() {
|
||||
let mut st = RoadmapState::new();
|
||||
st.filter = "abc".into();
|
||||
st.section = Some(Section::Todo);
|
||||
st.jump(1044);
|
||||
assert_eq!(
|
||||
(st.filter.as_str(), st.section, st.goto, st.scroll_pending),
|
||||
("", None, Some(1044), true)
|
||||
);
|
||||
}
|
||||
|
||||
#[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 run")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user