add SPA config UI, wire media/rss adapters, event-driven layout push

- React SPA: dashboard, data sources CRUD, widgets CRUD, layout builder,
  presets. TanStack Router + Query, shadcn/ui, Vite proxy to :3000
- wire media + rss adapters into polling loop, remove xtb source type
- media adapter: read username/password from headers, proper subsonic auth
- event handler: subscribe to LayoutChanged, push screen update to clients
- fix clippy warnings across workspace (Default impls, collapsible ifs,
  redundant closures, is_none_or, unused imports)
This commit is contained in:
2026-06-19 00:12:42 +02:00
parent 21c08911df
commit 26ebfad3a2
175 changed files with 12338 additions and 801 deletions

View File

@@ -1,5 +1,5 @@
use std::time::Duration;
use domain::{DataSource, DataSourceConfig, DataSourceType, DataSourceValidationError};
use std::time::Duration;
fn make_source(source_type: DataSourceType, url: Option<&str>, poll: Duration) -> DataSource {
DataSource {
@@ -38,14 +38,22 @@ fn webhook_with_zero_interval_is_valid() {
#[test]
fn poll_based_source_requires_nonzero_interval() {
let source = make_source(DataSourceType::Weather, Some("https://api.weather.com"), Duration::ZERO);
let source = make_source(
DataSourceType::Weather,
Some("https://api.weather.com"),
Duration::ZERO,
);
let errors = source.validate();
assert!(errors.contains(&DataSourceValidationError::PollIntervalRequired));
}
#[test]
fn valid_poll_source_has_no_errors() {
let source = make_source(DataSourceType::Rss, Some("https://feed.example.com"), Duration::from_secs(300));
let source = make_source(
DataSourceType::Rss,
Some("https://feed.example.com"),
Duration::from_secs(300),
);
let errors = source.validate();
assert!(errors.is_empty());
}

View File

@@ -1,5 +1,5 @@
use std::collections::BTreeMap;
use domain::{KeyMapping, Value};
use std::collections::BTreeMap;
#[test]
fn extracts_value_at_path_and_renames_key() {
@@ -8,11 +8,10 @@ fn extracts_value_at_path_and_renames_key() {
target_key: "temperature".into(),
};
let raw = Value::Object(BTreeMap::from([
("main".into(), Value::Object(BTreeMap::from([
("temp".into(), Value::Number(5.4)),
]))),
]));
let raw = Value::Object(BTreeMap::from([(
"main".into(),
Value::Object(BTreeMap::from([("temp".into(), Value::Number(5.4))])),
)]));
let result = mapping.extract(&raw);
assert_eq!(result, Some(("temperature".into(), Value::Number(5.4))));
@@ -25,9 +24,7 @@ fn returns_none_when_path_does_not_match() {
target_key: "value".into(),
};
let raw = Value::Object(BTreeMap::from([
("other".into(), Value::Number(1.0)),
]));
let raw = Value::Object(BTreeMap::from([("other".into(), Value::Number(1.0))]));
assert_eq!(mapping.extract(&raw), None);
}

View File

@@ -1,8 +1,8 @@
use std::collections::BTreeSet;
use domain::{
ContainerNode, Direction, Layout, LayoutChild, LayoutNode, LayoutValidationError, Sizing,
WidgetId,
};
use std::collections::BTreeSet;
fn leaf(id: WidgetId) -> LayoutChild {
LayoutChild {
@@ -22,14 +22,18 @@ fn row(children: Vec<LayoutChild>) -> LayoutNode {
#[test]
fn validate_returns_empty_when_all_widgets_exist() {
let layout = Layout { root: row(vec![leaf(1), leaf(2)]) };
let layout = Layout {
root: row(vec![leaf(1), leaf(2)]),
};
let known = BTreeSet::from([1, 2]);
assert!(layout.validate(&known).is_empty());
}
#[test]
fn validate_reports_unknown_widget_ids() {
let layout = Layout { root: row(vec![leaf(1), leaf(99)]) };
let layout = Layout {
root: row(vec![leaf(1), leaf(99)]),
};
let known = BTreeSet::from([1]);
let errors = layout.validate(&known);
assert_eq!(errors, vec![LayoutValidationError::UnknownWidget(99)]);
@@ -49,7 +53,9 @@ fn validate_checks_nested_containers() {
sizing: Sizing::Flex(1),
node: row(vec![leaf(1), leaf(42)]),
};
let layout = Layout { root: row(vec![inner, leaf(2)]) };
let layout = Layout {
root: row(vec![inner, leaf(2)]),
};
let known = BTreeSet::from([1, 2]);
let errors = layout.validate(&known);
assert_eq!(errors, vec![LayoutValidationError::UnknownWidget(42)]);
@@ -61,6 +67,8 @@ fn widget_ids_collects_all_leaf_ids() {
sizing: Sizing::Flex(1),
node: row(vec![leaf(3)]),
};
let layout = Layout { root: row(vec![leaf(1), inner, leaf(2)]) };
let layout = Layout {
root: row(vec![leaf(1), inner, leaf(2)]),
};
assert_eq!(layout.widget_ids(), BTreeSet::from([1, 2, 3]));
}

View File

@@ -1,5 +1,5 @@
use std::collections::BTreeMap;
use domain::Value;
use std::collections::BTreeMap;
#[test]
fn estimated_size_of_string_is_its_byte_length() {
@@ -29,37 +29,31 @@ fn estimated_size_of_nested_structure_sums_recursively() {
#[test]
fn estimated_size_of_array_sums_elements() {
let v = Value::Array(vec![
Value::String("abc".into()),
Value::Number(1.0),
]);
let v = Value::Array(vec![Value::String("abc".into()), Value::Number(1.0)]);
assert_eq!(v.estimated_size(), 11);
}
#[test]
fn get_path_returns_none_for_missing_key() {
let data = Value::Object(BTreeMap::from([
("main".into(), Value::Number(1.0)),
]));
let data = Value::Object(BTreeMap::from([("main".into(), Value::Number(1.0))]));
assert_eq!(data.get_path("$.missing"), None);
}
#[test]
fn get_path_returns_none_when_traversing_non_object() {
let data = Value::Object(BTreeMap::from([
("temp".into(), Value::Number(5.4)),
]));
let data = Value::Object(BTreeMap::from([("temp".into(), Value::Number(5.4))]));
assert_eq!(data.get_path("$.temp.nested"), None);
}
#[test]
fn get_path_accesses_array_by_index() {
let data = Value::Object(BTreeMap::from([
("items".into(), Value::Array(vec![
let data = Value::Object(BTreeMap::from([(
"items".into(),
Value::Array(vec![
Value::String("first".into()),
Value::String("second".into()),
])),
]));
]),
)]));
assert_eq!(
data.get_path("$.items[1]"),
Some(&Value::String("second".into()))
@@ -68,10 +62,9 @@ fn get_path_accesses_array_by_index() {
#[test]
fn get_path_traverses_nested_object() {
let data = Value::Object(BTreeMap::from([
("main".into(), Value::Object(BTreeMap::from([
("temp".into(), Value::Number(5.4)),
]))),
]));
let data = Value::Object(BTreeMap::from([(
"main".into(),
Value::Object(BTreeMap::from([("temp".into(), Value::Number(5.4))])),
)]));
assert_eq!(data.get_path("$.main.temp"), Some(&Value::Number(5.4)));
}

View File

@@ -1,5 +1,5 @@
use std::collections::BTreeMap;
use domain::{DisplayHint, KeyMapping, Value, WidgetConfig};
use std::collections::BTreeMap;
#[test]
fn extract_applies_all_mappings_to_produce_widget_state() {
@@ -9,27 +9,39 @@ fn extract_applies_all_mappings_to_produce_widget_state() {
display_hint: DisplayHint::IconValue,
data_source_id: 1,
mappings: vec![
KeyMapping { source_path: "$.main.temp".into(), target_key: "temperature".into() },
KeyMapping { source_path: "$.weather[0].icon".into(), target_key: "icon".into() },
KeyMapping {
source_path: "$.main.temp".into(),
target_key: "temperature".into(),
},
KeyMapping {
source_path: "$.weather[0].icon".into(),
target_key: "icon".into(),
},
],
max_data_size: 2048,
};
let raw = Value::Object(BTreeMap::from([
("main".into(), Value::Object(BTreeMap::from([
("temp".into(), Value::Number(5.4)),
]))),
("weather".into(), Value::Array(vec![
Value::Object(BTreeMap::from([
("icon".into(), Value::String("cloud_rain".into())),
])),
])),
(
"main".into(),
Value::Object(BTreeMap::from([("temp".into(), Value::Number(5.4))])),
),
(
"weather".into(),
Value::Array(vec![Value::Object(BTreeMap::from([(
"icon".into(),
Value::String("cloud_rain".into()),
)]))]),
),
]));
let state = config.extract(&raw);
assert_eq!(state.data.get("temperature"), Some(&Value::Number(5.4)));
assert_eq!(state.data.get("icon"), Some(&Value::String("cloud_rain".into())));
assert_eq!(
state.data.get("icon"),
Some(&Value::String("cloud_rain".into()))
);
assert_eq!(state.error, None);
}
@@ -41,15 +53,14 @@ fn extract_truncates_string_values_exceeding_max_data_size() {
name: "news".into(),
display_hint: DisplayHint::TextBlock,
data_source_id: 1,
mappings: vec![
KeyMapping { source_path: "$.text".into(), target_key: "body".into() },
],
mappings: vec![KeyMapping {
source_path: "$.text".into(),
target_key: "body".into(),
}],
max_data_size: 100,
};
let raw = Value::Object(BTreeMap::from([
("text".into(), Value::String(long_text)),
]));
let raw = Value::Object(BTreeMap::from([("text".into(), Value::String(long_text))]));
let state = config.extract(&raw);
match state.data.get("body") {
@@ -66,9 +77,18 @@ fn extract_respects_max_data_size_across_total_state() {
display_hint: DisplayHint::TextBlock,
data_source_id: 1,
mappings: vec![
KeyMapping { source_path: "$.a".into(), target_key: "a".into() },
KeyMapping { source_path: "$.b".into(), target_key: "b".into() },
KeyMapping { source_path: "$.c".into(), target_key: "c".into() },
KeyMapping {
source_path: "$.a".into(),
target_key: "a".into(),
},
KeyMapping {
source_path: "$.b".into(),
target_key: "b".into(),
},
KeyMapping {
source_path: "$.c".into(),
target_key: "c".into(),
},
],
max_data_size: 50,
};
@@ -92,15 +112,19 @@ fn extract_skips_mappings_that_dont_match() {
display_hint: DisplayHint::IconValue,
data_source_id: 1,
mappings: vec![
KeyMapping { source_path: "$.temp".into(), target_key: "temperature".into() },
KeyMapping { source_path: "$.missing".into(), target_key: "gone".into() },
KeyMapping {
source_path: "$.temp".into(),
target_key: "temperature".into(),
},
KeyMapping {
source_path: "$.missing".into(),
target_key: "gone".into(),
},
],
max_data_size: 2048,
};
let raw = Value::Object(BTreeMap::from([
("temp".into(), Value::Number(5.4)),
]));
let raw = Value::Object(BTreeMap::from([("temp".into(), Value::Number(5.4))]));
let state = config.extract(&raw);