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,10 +1,8 @@
use std::fmt;
use domain::{
ConfigRepository, EventPublisher, DomainEvent,
WidgetConfig, WidgetId,
DataSource, DataSourceId, DataSourceValidationError,
Layout, LayoutPreset, LayoutPresetId,
ConfigRepository, DataSource, DataSourceId, DataSourceValidationError, DomainEvent,
EventPublisher, Layout, LayoutPreset, LayoutPresetId, WidgetConfig, WidgetId,
};
use std::fmt;
pub struct ConfigService<'a, C, E> {
config: &'a C,
@@ -34,78 +32,173 @@ where
Self { config, events }
}
pub async fn create_widget(&self, widget: WidgetConfig) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config.save_widget(&widget).await.map_err(ConfigError::Repository)?;
self.events.publish(DomainEvent::WidgetCreated { id: widget.id }).await.map_err(ConfigError::Event)?;
pub async fn create_widget(
&self,
widget: WidgetConfig,
) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config
.save_widget(&widget)
.await
.map_err(ConfigError::Repository)?;
self.events
.publish(DomainEvent::WidgetCreated { id: widget.id })
.await
.map_err(ConfigError::Event)?;
Ok(())
}
pub async fn update_widget(&self, widget: WidgetConfig) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config.save_widget(&widget).await.map_err(ConfigError::Repository)?;
self.events.publish(DomainEvent::WidgetUpdated { id: widget.id }).await.map_err(ConfigError::Event)?;
pub async fn update_widget(
&self,
widget: WidgetConfig,
) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config
.save_widget(&widget)
.await
.map_err(ConfigError::Repository)?;
self.events
.publish(DomainEvent::WidgetUpdated { id: widget.id })
.await
.map_err(ConfigError::Event)?;
Ok(())
}
pub async fn delete_widget(&self, id: WidgetId) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config.delete_widget(id).await.map_err(ConfigError::Repository)?;
self.events.publish(DomainEvent::WidgetDeleted { id }).await.map_err(ConfigError::Event)?;
self.config
.delete_widget(id)
.await
.map_err(ConfigError::Repository)?;
self.events
.publish(DomainEvent::WidgetDeleted { id })
.await
.map_err(ConfigError::Event)?;
Ok(())
}
pub async fn create_data_source(&self, source: DataSource) -> Result<(), ConfigError<C::Error, E::Error>> {
pub async fn create_data_source(
&self,
source: DataSource,
) -> Result<(), ConfigError<C::Error, E::Error>> {
let errors = source.validate();
if !errors.is_empty() {
return Err(ConfigError::Validation(errors));
}
self.config.save_data_source(&source).await.map_err(ConfigError::Repository)?;
self.events.publish(DomainEvent::DataSourceAdded { id: source.id }).await.map_err(ConfigError::Event)?;
self.config
.save_data_source(&source)
.await
.map_err(ConfigError::Repository)?;
self.events
.publish(DomainEvent::DataSourceAdded { id: source.id })
.await
.map_err(ConfigError::Event)?;
Ok(())
}
pub async fn update_data_source(&self, source: DataSource) -> Result<(), ConfigError<C::Error, E::Error>> {
pub async fn update_data_source(
&self,
source: DataSource,
) -> Result<(), ConfigError<C::Error, E::Error>> {
let errors = source.validate();
if !errors.is_empty() {
return Err(ConfigError::Validation(errors));
}
self.config.save_data_source(&source).await.map_err(ConfigError::Repository)?;
self.events.publish(DomainEvent::DataSourceUpdated { id: source.id }).await.map_err(ConfigError::Event)?;
self.config
.save_data_source(&source)
.await
.map_err(ConfigError::Repository)?;
self.events
.publish(DomainEvent::DataSourceUpdated { id: source.id })
.await
.map_err(ConfigError::Event)?;
Ok(())
}
pub async fn delete_data_source(&self, id: DataSourceId) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config.delete_data_source(id).await.map_err(ConfigError::Repository)?;
self.events.publish(DomainEvent::DataSourceRemoved { id }).await.map_err(ConfigError::Event)?;
pub async fn delete_data_source(
&self,
id: DataSourceId,
) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config
.delete_data_source(id)
.await
.map_err(ConfigError::Repository)?;
self.events
.publish(DomainEvent::DataSourceRemoved { id })
.await
.map_err(ConfigError::Event)?;
Ok(())
}
pub async fn update_layout(&self, layout: Layout) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config.save_layout(&layout).await.map_err(ConfigError::Repository)?;
self.events.publish(DomainEvent::LayoutChanged { layout }).await.map_err(ConfigError::Event)?;
pub async fn update_layout(
&self,
layout: Layout,
) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config
.save_layout(&layout)
.await
.map_err(ConfigError::Repository)?;
self.events
.publish(DomainEvent::LayoutChanged { layout })
.await
.map_err(ConfigError::Event)?;
Ok(())
}
pub async fn save_preset(&self, preset: LayoutPreset) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config.save_preset(&preset).await.map_err(ConfigError::Repository)?;
self.events.publish(DomainEvent::LayoutPresetSaved { id: preset.id }).await.map_err(ConfigError::Event)?;
pub async fn save_preset(
&self,
preset: LayoutPreset,
) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config
.save_preset(&preset)
.await
.map_err(ConfigError::Repository)?;
self.events
.publish(DomainEvent::LayoutPresetSaved { id: preset.id })
.await
.map_err(ConfigError::Event)?;
Ok(())
}
pub async fn load_preset(&self, id: LayoutPresetId) -> Result<(), ConfigError<C::Error, E::Error>> {
let preset = self.config.get_preset(id).await
pub async fn load_preset(
&self,
id: LayoutPresetId,
) -> Result<(), ConfigError<C::Error, E::Error>> {
let preset = self
.config
.get_preset(id)
.await
.map_err(ConfigError::Repository)?
.ok_or(ConfigError::NotFound)?;
self.events.publish(DomainEvent::LayoutPresetLoaded { id }).await.map_err(ConfigError::Event)?;
self.events
.publish(DomainEvent::LayoutPresetLoaded { id })
.await
.map_err(ConfigError::Event)?;
self.config.save_layout(&preset.layout).await.map_err(ConfigError::Repository)?;
self.events.publish(DomainEvent::LayoutChanged { layout: preset.layout }).await.map_err(ConfigError::Event)?;
self.config
.save_layout(&preset.layout)
.await
.map_err(ConfigError::Repository)?;
self.events
.publish(DomainEvent::LayoutChanged {
layout: preset.layout,
})
.await
.map_err(ConfigError::Event)?;
Ok(())
}
pub async fn delete_preset(&self, id: LayoutPresetId) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config.delete_preset(id).await.map_err(ConfigError::Repository)?;
self.events.publish(DomainEvent::LayoutPresetDeleted { id }).await.map_err(ConfigError::Event)?;
pub async fn delete_preset(
&self,
id: LayoutPresetId,
) -> Result<(), ConfigError<C::Error, E::Error>> {
self.config
.delete_preset(id)
.await
.map_err(ConfigError::Repository)?;
self.events
.publish(DomainEvent::LayoutPresetDeleted { id })
.await
.map_err(ConfigError::Event)?;
Ok(())
}
}

View File

@@ -1,15 +1,18 @@
use std::collections::HashMap;
use domain::{DataSourceId, Value, WidgetConfig, WidgetId, WidgetState};
use std::collections::HashMap;
#[derive(Default)]
pub struct DataProjection {
current: HashMap<WidgetId, WidgetState>,
}
impl DataProjection {
pub fn new() -> Self {
Self {
current: HashMap::new(),
}
Self::default()
}
pub fn get_state(&self, widget_id: WidgetId) -> Option<&WidgetState> {
self.current.get(&widget_id)
}
pub fn apply_poll_result(
@@ -27,9 +30,10 @@ impl DataProjection {
let new_state = config.extract(raw);
let is_changed = self.current
let is_changed = self
.current
.get(&config.id)
.map_or(true, |prev| *prev != new_state);
.is_none_or(|prev| *prev != new_state);
if is_changed {
self.current.insert(config.id, new_state.clone());

View File

@@ -1,13 +1,12 @@
mod support;
use std::time::Duration;
use domain::{
ConfigRepository, DisplayHint, DomainEvent, KeyMapping, WidgetConfig,
DataSource, DataSourceConfig, DataSourceType,
Layout, LayoutNode, ContainerNode, LayoutChild, Direction, Sizing,
LayoutPreset,
};
use application::ConfigService;
use domain::{
ConfigRepository, ContainerNode, DataSource, DataSourceConfig, DataSourceType, Direction,
DisplayHint, DomainEvent, KeyMapping, Layout, LayoutChild, LayoutNode, LayoutPreset, Sizing,
WidgetConfig,
};
use std::time::Duration;
use support::{InMemoryConfigRepository, InMemoryEventPublisher};
#[tokio::test]
@@ -21,9 +20,10 @@ async fn create_widget_persists_and_emits_event() {
"weather".into(),
DisplayHint::IconValue,
1,
vec![
KeyMapping { source_path: "$.temp".into(), target_key: "temperature".into() },
],
vec![KeyMapping {
source_path: "$.temp".into(),
target_key: "temperature".into(),
}],
);
service.create_widget(config).await.unwrap();
@@ -99,8 +99,14 @@ async fn update_layout_persists_and_emits_event() {
gap: 4,
padding: 2,
children: vec![
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(1) },
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(2) },
LayoutChild {
sizing: Sizing::Flex(1),
node: LayoutNode::Leaf(1),
},
LayoutChild {
sizing: Sizing::Flex(1),
node: LayoutNode::Leaf(2),
},
],
}),
};
@@ -111,7 +117,10 @@ async fn update_layout_persists_and_emits_event() {
assert_eq!(stored, Some(layout));
assert_eq!(events.emitted().len(), 1);
assert!(matches!(events.emitted()[0], DomainEvent::LayoutChanged { .. }));
assert!(matches!(
events.emitted()[0],
DomainEvent::LayoutChanged { .. }
));
}
#[tokio::test]
@@ -125,9 +134,10 @@ async fn load_preset_replaces_active_layout() {
direction: Direction::Column,
gap: 0,
padding: 0,
children: vec![
LayoutChild { sizing: Sizing::Flex(1), node: LayoutNode::Leaf(5) },
],
children: vec![LayoutChild {
sizing: Sizing::Flex(1),
node: LayoutNode::Leaf(5),
}],
}),
};
@@ -146,6 +156,9 @@ async fn load_preset_replaces_active_layout() {
let emitted = events.emitted();
assert_eq!(emitted.len(), 2);
assert!(matches!(emitted[0], DomainEvent::LayoutPresetLoaded { id: 1 }));
assert!(matches!(
emitted[0],
DomainEvent::LayoutPresetLoaded { id: 1 }
));
assert!(matches!(emitted[1], DomainEvent::LayoutChanged { .. }));
}

View File

@@ -1,8 +1,6 @@
use std::collections::BTreeMap;
use domain::{
DisplayHint, KeyMapping, Value, WidgetConfig, WidgetId, WidgetState,
};
use application::DataProjection;
use domain::{DisplayHint, KeyMapping, Value, WidgetConfig, WidgetId, WidgetState};
use std::collections::BTreeMap;
fn weather_widget() -> WidgetConfig {
WidgetConfig::new(
@@ -11,8 +9,14 @@ fn weather_widget() -> WidgetConfig {
DisplayHint::IconValue,
10,
vec![
KeyMapping { source_path: "$.temp".into(), target_key: "temperature".into() },
KeyMapping { source_path: "$.icon".into(), target_key: "icon".into() },
KeyMapping {
source_path: "$.temp".into(),
target_key: "temperature".into(),
},
KeyMapping {
source_path: "$.icon".into(),
target_key: "icon".into(),
},
],
)
}
@@ -33,7 +37,10 @@ fn apply_poll_result_detects_new_widget_state() {
assert_eq!(changed.len(), 1);
assert_eq!(changed[0].0, 1);
assert_eq!(changed[0].1.data.get("temperature"), Some(&Value::Number(5.4)));
assert_eq!(
changed[0].1.data.get("temperature"),
Some(&Value::Number(5.4))
);
}
#[test]
@@ -56,7 +63,10 @@ fn apply_poll_result_detects_changed_value() {
let changed = projection.apply_poll_result(10, &weather_response(6.1), &widgets);
assert_eq!(changed.len(), 1);
assert_eq!(changed[0].1.data.get("temperature"), Some(&Value::Number(6.1)));
assert_eq!(
changed[0].1.data.get("temperature"),
Some(&Value::Number(6.1))
);
}
#[test]
@@ -69,9 +79,10 @@ fn apply_poll_result_only_updates_widgets_bound_to_source() {
"portfolio".into(),
DisplayHint::KeyValue,
20,
vec![
KeyMapping { source_path: "$.value".into(), target_key: "amount".into() },
],
vec![KeyMapping {
source_path: "$.value".into(),
target_key: "amount".into(),
}],
),
];

View File

@@ -1,10 +1,9 @@
use std::sync::Mutex;
use std::collections::HashMap;
use domain::{
ConfigRepository, EventPublisher,
DataSource, DataSourceId, Layout, LayoutPreset, LayoutPresetId,
WidgetConfig, WidgetId, DomainEvent,
ConfigRepository, DataSource, DataSourceId, DomainEvent, EventPublisher, Layout, LayoutPreset,
LayoutPresetId, WidgetConfig, WidgetId,
};
use std::collections::HashMap;
use std::sync::Mutex;
pub struct InMemoryConfigRepository {
widgets: Mutex<HashMap<WidgetId, WidgetConfig>>,
@@ -45,7 +44,10 @@ impl ConfigRepository for InMemoryConfigRepository {
}
async fn save_widget(&self, config: &WidgetConfig) -> Result<(), Self::Error> {
self.widgets.lock().unwrap().insert(config.id, config.clone());
self.widgets
.lock()
.unwrap()
.insert(config.id, config.clone());
Ok(())
}
@@ -59,11 +61,20 @@ impl ConfigRepository for InMemoryConfigRepository {
}
async fn list_data_sources(&self) -> Result<Vec<DataSource>, Self::Error> {
Ok(self.data_sources.lock().unwrap().values().cloned().collect())
Ok(self
.data_sources
.lock()
.unwrap()
.values()
.cloned()
.collect())
}
async fn save_data_source(&self, source: &DataSource) -> Result<(), Self::Error> {
self.data_sources.lock().unwrap().insert(source.id, source.clone());
self.data_sources
.lock()
.unwrap()
.insert(source.id, source.clone());
Ok(())
}
@@ -90,7 +101,10 @@ impl ConfigRepository for InMemoryConfigRepository {
}
async fn save_preset(&self, preset: &LayoutPreset) -> Result<(), Self::Error> {
self.presets.lock().unwrap().insert(preset.id, preset.clone());
self.presets
.lock()
.unwrap()
.insert(preset.id, preset.clone());
Ok(())
}