remove some warnings, add configuration pane

master
Florent Becker 2022-04-14 18:24:22 +02:00
parent 0834a86d49
commit 0feca4f8da
7 changed files with 147 additions and 28 deletions

View File

@ -31,7 +31,9 @@ js-sys = "0.3"
[dependencies.web-sys] [dependencies.web-sys]
version = "0.3" version = "0.3"
features = [ features = [
'console',
'Document', 'Document',
'DomTokenList',
'Element', 'Element',
'HtmlCollection', 'HtmlCollection',
'HtmlInputElement', 'HtmlInputElement',

View File

@ -2,7 +2,7 @@
pkgs.callPackage ./Cargo.nix { pkgs.callPackage ./Cargo.nix {
defaultCrateOverrides = pkgs.defaultCrateOverrides // { defaultCrateOverrides = pkgs.defaultCrateOverrides // {
lixiangyuan = attrs: { kikikoz = attrs: {
buildInputs = [ pkgs.wasm-pack ]; buildInputs = [ pkgs.wasm-pack ];
}; };
}; };

78
flake.lock Normal file
View File

@ -0,0 +1,78 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1637014545,
"narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1649809588,
"narHash": "sha256-f6sgDj9A8FXTVyA2zkxA66YX+j6BftxE9VHTeIMhEKE=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "ff9efb0724de5ae0f9db9df2debefced7eb1571d",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1637453606,
"narHash": "sha256-Gy6cwUswft9xqsjWxFYEnx/63/qzaFUwatcbV5GF/GQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8afc4e543663ca0a6a4f496262cd05233737e732",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1649903781,
"narHash": "sha256-m+3EZo0a4iS8IwHQhkM/riPuFpu76505xKqmN9j5O+E=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "e45696bedc4a13a5970376b8fc09660fdd0e6f6c",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

View File

@ -14,8 +14,7 @@
inherit system; inherit system;
overlays = [ rust-overlay.overlay ]; overlays = [ rust-overlay.overlay ];
}; };
in (({ pkgs, ... }: in pkgs.mkShell {
pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
cargo cargo
cargo-watch cargo-watch
@ -31,6 +30,6 @@
]; ];
shellHook = ""; shellHook = "";
}) { pkgs = pkgs; }); };
}; };
} }

View File

@ -13,12 +13,16 @@
window.ajoute = ajoute; window.ajoute = ajoute;
window.ajoute_kp = ajoute_kp; window.ajoute_kp = ajoute_kp;
window.next = next; window.next = next;
window.intervalle_orateurice = intervalle_orateurice;
window.setInterval(intervalle_orateurice, 1000); window.setInterval(intervalle_orateurice, 1000);
</script> </script>
<link rel="stylesheet" href="kikikoz.css"/> <link rel="stylesheet" href="kikikoz.css"/>
</head> </head>
<body> <body>
<h1>Kikikoz</h1> <main>
<h1>Kikikoz</h1>
<button>Configuration</button>
<p class="orateurice"> <p class="orateurice">
<span id="orateurice" class="personne" onclick="intervalle_orateurice()">Personne</span> <span id="compte"></span> <button onclick="next()">Hop!</button> <span id="orateurice" class="personne" onclick="intervalle_orateurice()">Personne</span> <span id="compte"></span> <button onclick="next()">Hop!</button>
</p> </p>
@ -42,6 +46,11 @@
<button onclick='ajoute("queue_b")'>+</button></p> <button onclick='ajoute("queue_b")'>+</button></p>
</section> </section>
</section> </section>
</main>
<aside id="configuration">
<h2>Configuration</h2>
<p> Pas d'options pour le moment, revenez dans une version ultérieure.</p>
</aside>
</body> </body>
</html> </html>

View File

@ -1,5 +1,6 @@
body { body {
background-color: aliceblue; background-color: aliceblue;
display: flex;
} }
p.orateurice { p.orateurice {
@ -7,6 +8,10 @@ p.orateurice {
text-align: center; text-align: center;
} }
li.dernier_arrive {
font-style: italic;
}
.personne { .personne {
color: darkgrey; color: darkgrey;
} }
@ -43,3 +48,15 @@ section#queues {
h1 { h1 {
text-align: center; text-align: center;
} }
main {
flex-grow: 1;
}
aside#configuration {
max-width: 30%;
background-color: lightgrey;
padding: 15px;
border-radius: 5px;
height: 100%;
}

View File

@ -1,5 +1,3 @@
mod utils;
use js_sys::Date; use js_sys::Date;
use rand::prelude::*; use rand::prelude::*;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
@ -16,29 +14,37 @@ extern "C" {
fn alert(s: &str); fn alert(s: &str);
} }
fn le_document() -> web_sys::Document {
let window = web_sys::window().expect("pas de window");
window.document().expect("pas_de_document")
}
#[wasm_bindgen] #[wasm_bindgen]
pub fn intervalle_orateurice() { pub fn intervalle_orateurice() {
let document = le_document(); let document = le_document();
let now: f64 = Date::new_0().get_time(); let now: f64 = Date::new_0().get_time();
let prochain = document.get_element_by_id("orateurice").expect("blu"); let prochain = document
let compte = document.get_element_by_id("compte").expect("blaou"); .get_element_by_id("orateurice")
match js_sys::Reflect::get(&prochain, &JsValue::from("debut")) { .expect("pas de prochain");
Err(_) => return, let compte = document.get_element_by_id("compte");
Ok(date_debut) => { match compte {
let date_debut = date_debut.as_f64().expect("tut tut"); None => return,
let diff = ((now - date_debut) / 1000.0) as u64; Some(compte) => match js_sys::Reflect::get(&prochain, &JsValue::from("debut")) {
let sec = diff % 60; Err(_) => return,
let min = diff / 60; Ok(date_debut) => {
compte.set_inner_html(&format!("{}:{:02}", min, sec)); if date_debut == JsValue::UNDEFINED {
} return;
};
let date_debut = date_debut.as_f64().expect("tut tut");
let diff = ((now - date_debut) / 1000.0) as u64;
let sec = diff % 60;
let min = diff / 60;
compte.set_inner_html(&format!("{}:{:02}", min, sec));
}
},
} }
} }
fn le_document() -> web_sys::Document {
let window = web_sys::window().expect("no global `window` exists");
window.document().expect("should have a document on window")
}
#[wasm_bindgen] #[wasm_bindgen]
pub fn next() { pub fn next() {
let document = le_document(); let document = le_document();
@ -66,12 +72,13 @@ pub fn next() {
let nom_prochain = li.text_content().expect(""); let nom_prochain = li.text_content().expect("");
let temps_debut = Date::new_0().get_time(); let temps_debut = Date::new_0().get_time();
prochain.set_text_content(Some(nom_prochain.as_str())); prochain.set_text_content(Some(nom_prochain.as_str()));
js_sys::Reflect::set( let _ = js_sys::Reflect::set(
&prochain, &prochain,
&JsValue::from("debut"), &JsValue::from("debut"),
&JsValue::from(temps_debut), &JsValue::from(temps_debut),
); )
li.parent_element().expect("").remove_child(&li); .unwrap();
li.parent_element().expect("").remove_child(&li).unwrap();
prochain.set_class_name(""); prochain.set_class_name("");
} }
None => { None => {
@ -113,12 +120,19 @@ pub fn ajoute(id: &str) {
let n = lis.length(); let n = lis.length();
let mut rng = thread_rng(); let mut rng = thread_rng();
let k = rng.gen_range(0, n + 1); let k = rng.gen_range(0, n + 1);
let old_new_lis = document.get_elements_by_class_name("dernier_arrive");
for i in 0..old_new_lis.length() {
if let Some(li) = old_new_lis.item(i) {
li.class_list().remove_1("dernier_arrive").unwrap();
}
}
let new_li = document.create_element("li").unwrap(); let new_li = document.create_element("li").unwrap();
new_li.set_inner_html(&content); new_li.set_inner_html(&content);
new_li.set_class_name("dernier_arrive");
if k == n { if k == n {
ol.append_child(&new_li); ol.append_child(&new_li).unwrap();
} else { } else {
let li = lis.item(k).unwrap(); let li = lis.item(k).unwrap();
li.after_with_node_1(&new_li); li.after_with_node_1(&new_li).unwrap();
} }
} }