Add custom css

This commit is contained in:
hodasemi 2023-10-05 11:20:36 +02:00
parent aff80fa0f7
commit 80b61dc854
5 changed files with 35 additions and 12 deletions

View file

@ -1,5 +1,3 @@
table, td>*:not(:last-child) {
th, margin-right: 5px;
td {
border: 1px solid black;
} }

View file

@ -9,6 +9,7 @@ async function startup() {
); );
let table = document.createElement('table'); let table = document.createElement('table');
table.className = "pure-table pure-table-bordered";
let json = JSON.parse(await response.json()); let json = JSON.parse(await response.json());
console.log(json); console.log(json);
@ -54,9 +55,11 @@ async function startup() {
// create device name column // create device name column
let device_name_entry = document.createElement('td'); let device_name_entry = document.createElement('td');
let device_name = document.createElement('input'); let device_name = document.createElement('input');
device_name.className = "pure-u-2";
device_name.value = device_descriptor; device_name.value = device_descriptor;
device_name.readOnly = true; device_name.readOnly = true;
let device_name_edit = document.createElement('button'); let device_name_edit = document.createElement('button');
device_name_edit.className = "pure-button";
device_name_edit.onclick = async () => { device_name_edit.onclick = async () => {
if (device_name.readOnly) { if (device_name.readOnly) {
device_name.readOnly = false; device_name.readOnly = false;
@ -88,12 +91,15 @@ async function startup() {
let device_led_state_entry = document.createElement('td'); let device_led_state_entry = document.createElement('td');
let device_led_state = document.createElement('label'); let device_led_state = document.createElement('label');
device_led_state.innerText = device_state["led"]; device_led_state.innerText = device_state["led"];
device_led_state.className = "pure-u-2";
device_led_state.id = "led_" + device_id; device_led_state.id = "led_" + device_id;
let device_led_on = document.createElement('button'); let device_led_on = document.createElement('button');
device_led_on.innerText = "On" device_led_on.innerText = "On";
device_led_on.className = "pure-button";
device_led_on.onclick = async () => { await led_on(device_id) }; device_led_on.onclick = async () => { await led_on(device_id) };
let device_led_off = document.createElement('button'); let device_led_off = document.createElement('button');
device_led_off.innerText = "Off" device_led_off.innerText = "Off"
device_led_off.className = "pure-button";
device_led_off.onclick = async () => { await led_off(device_id) }; device_led_off.onclick = async () => { await led_off(device_id) };
device_led_state_entry.appendChild(device_led_state); device_led_state_entry.appendChild(device_led_state);
@ -105,6 +111,7 @@ async function startup() {
let device_power_state_entry = document.createElement('td'); let device_power_state_entry = document.createElement('td');
let device_power_state = document.createElement('label'); let device_power_state = document.createElement('label');
device_power_state.innerText = device_state["power"]; device_power_state.innerText = device_state["power"];
device_power_state.className = "pure-u-2";
device_power_state.id = "power_" + device_id; device_power_state.id = "power_" + device_id;
device_power_state_entry.appendChild(device_power_state); device_power_state_entry.appendChild(device_power_state);
@ -112,9 +119,11 @@ async function startup() {
if (devices[i][2] == true && device_state["power_draw"] < 15) { if (devices[i][2] == true && device_state["power_draw"] < 15) {
let device_power_on = document.createElement('button'); let device_power_on = document.createElement('button');
device_power_on.innerText = "On" device_power_on.innerText = "On"
device_power_on.className = "pure-button";
device_power_on.onclick = async () => { await power_on(device_id) }; device_power_on.onclick = async () => { await power_on(device_id) };
let device_power_off = document.createElement('button'); let device_power_off = document.createElement('button');
device_power_off.innerText = "Off" device_power_off.innerText = "Off"
device_power_off.className = "pure-button";
device_power_off.onclick = async () => { await power_off(device_id) }; device_power_off.onclick = async () => { await power_off(device_id) };
device_power_state_entry.appendChild(device_power_on); device_power_state_entry.appendChild(device_power_on);
@ -126,8 +135,10 @@ async function startup() {
// create device power draw column // create device power draw column
let device_power_draw_entry = document.createElement('td'); let device_power_draw_entry = document.createElement('td');
let device_power_draw = document.createElement('label'); let device_power_draw = document.createElement('label');
device_power_draw.className = "pure-u-2";
device_power_draw.innerText = device_state["power_draw"] + " W"; device_power_draw.innerText = device_state["power_draw"] + " W";
let device_power_draw_graph_button = document.createElement('button'); let device_power_draw_graph_button = document.createElement('button');
device_power_draw_graph_button.className = "pure-button";
device_power_draw_graph_button.onclick = async () => { await render_graph(device_id, device_descriptor) }; device_power_draw_graph_button.onclick = async () => { await render_graph(device_id, device_descriptor) };
let device_power_draw_graph_button_icon = document.createElement('i'); let device_power_draw_graph_button_icon = document.createElement('i');
device_power_draw_graph_button_icon.className = "fa fa-line-chart"; device_power_draw_graph_button_icon.className = "fa fa-line-chart";

View file

@ -9,6 +9,8 @@
<title>Smart Homeserver</title> <title>Smart Homeserver</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fork-awesome@1.2.0/css/fork-awesome.min.css" <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fork-awesome@1.2.0/css/fork-awesome.min.css"
integrity="sha256-XoaMnoYC5TH6/+ihMEnospgm0J1PM/nioxbOUdnM8HY=" crossorigin="anonymous"> integrity="sha256-XoaMnoYC5TH6/+ihMEnospgm0J1PM/nioxbOUdnM8HY=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@3.0.0/build/pure-min.css"
integrity="sha384-X38yfunGUhNzHpBaEBsWLO+A0HDYOQi8ufWDkZ0k9e0eXz/tH3II7uKZ9msv++Ls" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.korzh.com/metroui/v4/css/metro-all.min.css"> <link rel="stylesheet" href="https://cdn.korzh.com/metroui/v4/css/metro-all.min.css">
<link href="/css/index.css" rel="stylesheet"> <link href="/css/index.css" rel="stylesheet">
</head> </head>

View file

@ -4,7 +4,7 @@ use std::{
time::{Duration, SystemTime, UNIX_EPOCH}, time::{Duration, SystemTime, UNIX_EPOCH},
}; };
use crate::{db::DataBase, web_server::plug_data_range}; use crate::{db::DataBase, midea_helper::MideaDiscovery, web_server::plug_data_range};
mod data; mod data;
mod db; mod db;
@ -57,7 +57,7 @@ async fn run_web_server(
const IP: &str = "0.0.0.0"; const IP: &str = "0.0.0.0";
const PORT: u16 = 8062; const PORT: u16 = 8062;
println!("Starting server on {IP}:{PORT}"); println!("Starting server on http://{IP}:{PORT}");
HttpServer::new(move || { HttpServer::new(move || {
App::new() App::new()
@ -89,7 +89,7 @@ async fn main() -> Result<()> {
let db_future = DataBase::new("home_server.db"); let db_future = DataBase::new("home_server.db");
let devices_future = Devices::read("devices.conf"); let devices_future = Devices::read("devices.conf");
let (db, devices) = try_join!(db_future, devices_future)?; let (db, devices, midea) = try_join!(db_future, devices_future, MideaDiscovery::discover())?;
db.register_devices(&devices)?; db.register_devices(&devices)?;
let shared_db = Arc::new(Mutex::new(db)); let shared_db = Arc::new(Mutex::new(db));
@ -100,7 +100,7 @@ async fn main() -> Result<()> {
.map(|(plug, _)| Tasmota::new(plug)) .map(|(plug, _)| Tasmota::new(plug))
.collect(); .collect();
let dishwasher = MideaDishwasher::create(shared_db.clone()) let dishwasher = MideaDishwasher::create(midea, shared_db.clone())
.await? .await?
.into_iter() .into_iter()
.map(|d| Arc::new(d)) .map(|d| Arc::new(d))

View file

@ -43,17 +43,29 @@ impl LoginInfo {
} }
} }
pub struct MideaDiscovery {
infos: Vec<DeviceInfo>,
}
impl MideaDiscovery {
pub async fn discover() -> Result<Self> {
Ok(Self {
infos: Startup::discover().await?,
})
}
}
pub struct MideaDishwasher { pub struct MideaDishwasher {
device_info: DeviceInfo, device_info: DeviceInfo,
device: Device, device: Device,
} }
impl MideaDishwasher { impl MideaDishwasher {
pub async fn create(db: Arc<Mutex<DataBase>>) -> Result<Vec<Self>> { pub async fn create(discovery: MideaDiscovery, db: Arc<Mutex<DataBase>>) -> Result<Vec<Self>> {
let mut v = Vec::new(); let mut v = Vec::new();
for device_info in Startup::discover() for device_info in discovery
.await? .infos
.into_iter() .into_iter()
.filter(|device_info| device_info.device_type == 0xE1) .filter(|device_info| device_info.device_type == 0xE1)
{ {