added lightschedule to frontend
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -552,6 +552,7 @@ name = "hemma_web"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"chrono",
|
||||||
"common",
|
"common",
|
||||||
"css_typegen",
|
"css_typegen",
|
||||||
"lighter_lib",
|
"lighter_lib",
|
||||||
|
|||||||
@ -14,6 +14,7 @@ serde = { version = "1", features = ['derive'] }
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
anyhow = "*"
|
anyhow = "*"
|
||||||
ron = "0.7.1"
|
ron = "0.7.1"
|
||||||
|
chrono = { version = "0.4.20", features = ["serde"] }
|
||||||
|
|
||||||
[dependencies.css_typegen]
|
[dependencies.css_typegen]
|
||||||
git = "https://github.com/hulthe/css_typegen.git"
|
git = "https://github.com/hulthe/css_typegen.git"
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
use crate::components::color_picker::{ColorPicker, ColorPickerMsg};
|
use crate::components::color_picker::{ColorPicker, ColorPickerMsg};
|
||||||
use crate::css::C;
|
use crate::css::C;
|
||||||
|
use chrono::{NaiveTime, Weekday};
|
||||||
use common::{BulbGroup, BulbGroupShape, BulbMap, ClientMessage, ServerMessage};
|
use common::{BulbGroup, BulbGroupShape, BulbMap, ClientMessage, ServerMessage};
|
||||||
use lighter_lib::{BulbId, BulbMode};
|
use lighter_lib::{BulbId, BulbMode};
|
||||||
use seed::prelude::*;
|
use seed::prelude::*;
|
||||||
use seed::{attrs, button, div, C};
|
use seed::{attrs, button, div, input, C};
|
||||||
use seed_router::Page;
|
use seed_router::Page;
|
||||||
use std::collections::{BTreeMap, HashSet};
|
use std::collections::{BTreeMap, HashSet};
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
@ -32,6 +33,7 @@ pub enum Msg {
|
|||||||
DeselectGroups,
|
DeselectGroups,
|
||||||
ColorPicker(ColorPickerMsg),
|
ColorPicker(ColorPickerMsg),
|
||||||
SetBulbPower(bool),
|
SetBulbPower(bool),
|
||||||
|
LightTime(String, Weekday),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Page for Model {
|
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>) {
|
fn update(&mut self, msg: Self::Msg, orders: &mut impl Orders<Self::Msg>) {
|
||||||
match msg {
|
match msg {
|
||||||
Msg::ServerMessage(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
|
*self.bulb_states.entry(id).or_default() = new_mode
|
||||||
//color_picker.set_color(mode.color);
|
//color_picker.set_color(mode.color);
|
||||||
}
|
}
|
||||||
@ -108,8 +110,21 @@ impl Page for Model {
|
|||||||
orders.notify(message);
|
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))| {
|
//let view_bulb = |(id, (mode, color_picker)): (&BulbId, &(BulbMode, ColorPicker))| {
|
||||||
@ -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
|
let (_color, power) = self
|
||||||
.selected_groups
|
.selected_groups
|
||||||
.iter()
|
.iter()
|
||||||
@ -224,6 +251,16 @@ impl Page for Model {
|
|||||||
div![attrs! { At::Id => "lever_face" }],
|
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),
|
||||||
|
],
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -259,3 +259,25 @@ body {
|
|||||||
|
|
||||||
transition: margin 0.1s ease-out;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user