per-source polling, initial client state, webhook, preview, client tracking

- per-source poll intervals: spawn task per source with own interval,
  manager re-checks sources every 30s for add/remove
- initial screen update on TCP connect: send layout + widget states
- client tracking: ClientRegistry port, GET /api/clients, dashboard list
- webhook adapter: POST /api/webhook/{source_id} feeds data into projection
- widget preview: GET /api/widgets/{id}/preview returns current state
- serve SPA from Axum: ServeDir + index.html fallback via KFRAME_SPA_DIR
- layout builder delete confirmation with AlertDialog
- form validation: required fields disable save button
- guide page at /guide
- fix architecture: ClientDto to api-types, ClientRegistry + WidgetStateReader
  ports in domain, DataProjection has internal Mutex, no adapter cross-deps
- ESP32: full screen clear on layout change (stale pixel fix)
This commit is contained in:
2026-06-19 00:42:31 +02:00
parent 26ebfad3a2
commit 1d7b5324d6
39 changed files with 1232 additions and 158 deletions

View File

@@ -6,11 +6,13 @@ use axum::{
http::StatusCode,
response::Json,
};
use domain::{ConfigRepository, EventPublisher};
use domain::{ConfigRepository, EventPublisher, WidgetStateReader};
type S<C, E> = State<AppState<C, E>>;
type S<C, E, W, B, R> = State<AppState<C, E, W, B, R>>;
pub async fn list_widgets<C, E>(State(state): S<C, E>) -> Result<Json<Vec<WidgetDto>>, StatusCode>
pub async fn list_widgets<C, E, W, B, R>(
State(state): S<C, E, W, B, R>,
) -> Result<Json<Vec<WidgetDto>>, StatusCode>
where
C: ConfigRepository,
C::Error: std::fmt::Debug,
@@ -25,8 +27,8 @@ where
Ok(Json(widgets.iter().map(WidgetDto::from).collect()))
}
pub async fn get_widget<C, E>(
State(state): S<C, E>,
pub async fn get_widget<C, E, W, B, R>(
State(state): S<C, E, W, B, R>,
Path(id): Path<u16>,
) -> Result<Json<WidgetDto>, StatusCode>
where
@@ -46,8 +48,8 @@ where
}
}
pub async fn create_widget<C, E>(
State(state): S<C, E>,
pub async fn create_widget<C, E, W, B, R>(
State(state): S<C, E, W, B, R>,
Json(body): Json<CreateWidgetDto>,
) -> Result<StatusCode, (StatusCode, String)>
where
@@ -66,8 +68,8 @@ where
Ok(StatusCode::CREATED)
}
pub async fn update_widget<C, E>(
State(state): S<C, E>,
pub async fn update_widget<C, E, W, B, R>(
State(state): S<C, E, W, B, R>,
Path(_id): Path<u16>,
Json(body): Json<CreateWidgetDto>,
) -> Result<StatusCode, (StatusCode, String)>
@@ -87,8 +89,8 @@ where
Ok(StatusCode::OK)
}
pub async fn delete_widget<C, E>(
State(state): S<C, E>,
pub async fn delete_widget<C, E, W, B, R>(
State(state): S<C, E, W, B, R>,
Path(id): Path<u16>,
) -> Result<StatusCode, StatusCode>
where
@@ -103,3 +105,46 @@ where
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Ok(StatusCode::NO_CONTENT)
}
pub async fn preview_widget<C, E, W, B, R>(
State(state): S<C, E, W, B, R>,
Path(id): Path<u16>,
) -> Result<Json<serde_json::Value>, StatusCode>
where
C: ConfigRepository,
C::Error: std::fmt::Debug,
E: EventPublisher,
E::Error: std::fmt::Debug,
W: WidgetStateReader,
{
match state.widget_states.get_widget_state(id).await {
Some(ws) => {
let map: serde_json::Map<String, serde_json::Value> = ws
.data
.iter()
.map(|(k, v)| (k.clone(), domain_value_to_json(v)))
.collect();
Ok(Json(serde_json::Value::Object(map)))
}
None => Err(StatusCode::NOT_FOUND),
}
}
fn domain_value_to_json(v: &domain::Value) -> serde_json::Value {
match v {
domain::Value::Null => serde_json::Value::Null,
domain::Value::Bool(b) => serde_json::Value::Bool(*b),
domain::Value::Number(n) => serde_json::json!(n),
domain::Value::String(s) => serde_json::Value::String(s.clone()),
domain::Value::Array(arr) => {
serde_json::Value::Array(arr.iter().map(domain_value_to_json).collect())
}
domain::Value::Object(obj) => {
let map = obj
.iter()
.map(|(k, v)| (k.clone(), domain_value_to_json(v)))
.collect();
serde_json::Value::Object(map)
}
}
}