added lightschedule to frontend

This commit is contained in:
2022-10-24 18:40:24 +02:00
parent a42025577e
commit 01a7c7b5ec
4 changed files with 169 additions and 108 deletions

1
Cargo.lock generated
View File

@ -552,6 +552,7 @@ name = "hemma_web"
version = "0.1.0"
dependencies = [
"anyhow",
"chrono",
"common",
"css_typegen",
"lighter_lib",

View File

@ -14,6 +14,7 @@ serde = { version = "1", features = ['derive'] }
serde_json = "1"
anyhow = "*"
ron = "0.7.1"
chrono = { version = "0.4.20", features = ["serde"] }
[dependencies.css_typegen]
git = "https://github.com/hulthe/css_typegen.git"

View File

@ -1,9 +1,10 @@
use crate::components::color_picker::{ColorPicker, ColorPickerMsg};
use crate::css::C;
use chrono::{NaiveTime, Weekday};
use common::{BulbGroup, BulbGroupShape, BulbMap, ClientMessage, ServerMessage};
use lighter_lib::{BulbId, BulbMode};
use seed::prelude::*;
use seed::{attrs, button, div, C};
use seed::{attrs, button, div, input, C};
use seed_router::Page;
use std::collections::{BTreeMap, HashSet};
use std::fmt::Write;
@ -32,6 +33,7 @@ pub enum Msg {
DeselectGroups,
ColorPicker(ColorPickerMsg),
SetBulbPower(bool),
LightTime(String, Weekday),
}
impl Page for Model {
@ -47,7 +49,7 @@ impl Page for Model {
fn update(&mut self, msg: Self::Msg, orders: &mut impl Orders<Self::Msg>) {
match msg {
Msg::ServerMessage(msg) => match msg {
ServerMessage::BulbMode { id, mode: new_mode } => {
ServerMessage::BulbState { id, mode: new_mode, wake_schedule } => {
*self.bulb_states.entry(id).or_default() = new_mode
//color_picker.set_color(mode.color);
}
@ -108,10 +110,23 @@ impl Page for Model {
orders.notify(message);
});
}
Msg::LightTime(time, day) => {
if let Ok(time) = NaiveTime::parse_from_str(&time, "%H:%M") {
self.for_selected_bulbs(|id, _| {
let message = ClientMessage::SetBulbWakeTime {
id: id.clone(),
day,
time,
};
orders.notify(message);
});
}
}
}
}
fn view(&self) -> Node<Self::Msg> {
fn view(&self) -> Node<Self::Msg> {
//let view_bulb = |(id, (mode, color_picker)): (&BulbId, &(BulbMode, ColorPicker))| {
// div![
// C![C.bulb_box],
@ -185,6 +200,18 @@ impl Page for Model {
]
};
let calendar_day = |day: Weekday| {
div![
C![C.calendar_day],
day.to_string(),
input![
C![C.calendar_time_input],
attrs! {At::Placeholder => "7:30"},
input_ev(Ev::Input, move |input| Msg::LightTime(input, day))
],
]
};
let (_color, power) = self
.selected_groups
.iter()
@ -224,8 +251,18 @@ impl Page for Model {
div![attrs! { At::Id => "lever_face" }],
],
],
div![
C![C.calendar_box],
calendar_day(Weekday::Mon),
calendar_day(Weekday::Tue),
calendar_day(Weekday::Wed),
calendar_day(Weekday::Thu),
calendar_day(Weekday::Fri),
calendar_day(Weekday::Sat),
calendar_day(Weekday::Sun),
],
]
}
}
}
impl Model {

View File

@ -259,3 +259,25 @@ body {
transition: margin 0.1s ease-out;
}
.calendar_day {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: .3em;
}
.calendar_time_input {
background: #453f4b;
border: solid 0.35em #5b3f63;
border-radius: .3em;
color: white;
height: 15;
width: 5em;
align: right;
//margin-bottom: .7em;
margin-left: .5em;
}
.calendar_box {
with: 10em;
}