diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/db.rs | 33 | ||||
-rw-r--r-- | src/main.rs | 16 | ||||
-rw-r--r-- | src/ui.rs | 90 | ||||
-rw-r--r-- | static/main.js | 48 | ||||
-rw-r--r-- | static/style.css | 2 | ||||
-rw-r--r-- | templates/chat.html | 38 | ||||
-rw-r--r-- | templates/dashboard.html | 2 | ||||
-rw-r--r-- | templates/head.html | 4 | ||||
-rw-r--r-- | templates/send.html | 14 |
11 files changed, 158 insertions, 93 deletions
@@ -444,6 +444,7 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", + "serde", "wasm-bindgen", "windows-targets 0.48.5", ] @@ -11,7 +11,7 @@ askama = { version = "0.12", features = ["with-axum"] } askama_axum = "0.4" axum = { version = "0.7", features = ["ws"] } #axum-extra = "0.7" -chrono = "0.4" +chrono = { version = "0.4", features = ["serde"] } simple_logger = "4.3" log = "0.4" serde = { version = "1.0", features = ["derive"] } @@ -34,6 +34,5 @@ tonic = { version = "0.10", features = ["tls", "tls-roots"] } async-stream = "0.3" rand = "0.8" - [[bin]] name = "fake-radio" @@ -2,7 +2,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use std::io; use log::debug; -use sqlx::SqlitePool; +use sqlx::{SqlitePool, sqlite::SqliteRow, Row}; #[derive(Clone)] pub struct Database { @@ -10,13 +10,27 @@ pub struct Database { num_frames_received : u64, } -#[derive(sqlx::FromRow, Debug)] +#[derive(Debug)] pub struct Packet { pub id : i64, - pub received_at : i64, + pub received_at: chrono::DateTime<chrono::Utc>, pub content : Vec<u8>, } +impl sqlx::FromRow<'_, SqliteRow> for Packet { + fn from_row(row: &SqliteRow) -> Result<Self, sqlx::Error> { + Ok(Self { + id: row.try_get("id")?, + received_at: { + let row : i64 = row.try_get("received_at")?; + chrono::DateTime::from_timestamp(row, 0).expect("Convert timestamp to chrono") + }, + content: row.try_get("content")?, + + }) + } +} + impl Database { pub async fn new() -> Self { { @@ -83,4 +97,17 @@ impl Database { Ok(results) } + + pub async fn get_packets_since(&mut self, unix_timestamp: i64) -> anyhow::Result<Vec<Packet>> { + let results = sqlx::query_as(r#" + SELECT id, received_at, content + FROM frames_received + WHERE received_at > ?1 + ORDER BY received_at DESC"#) + .bind(unix_timestamp) + .fetch_all(&self.pool) + .await?; + + Ok(results) + } } diff --git a/src/main.rs b/src/main.rs index 49ef58e..5eb47e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,17 +10,11 @@ mod radio; mod config; mod ui; -#[derive(Clone, serde::Serialize)] -struct WSChatMessage { - from: String, - message: String, -} - struct AppState { conf : config::Config, db : db::Database, transmit_queue : mpsc::Sender<Vec<u8>>, - ws_broadcast : broadcast::Sender<WSChatMessage>, + ws_broadcast : broadcast::Sender<ui::UIPacket>, start_time : chrono::DateTime<chrono::Utc>, } @@ -133,9 +127,11 @@ async fn main() -> std::io::Result<()> { let mut commentbuf = [0u8, 255]; if let Ok(comment) = packet.comment(&mut commentbuf) { - let m = WSChatMessage { - from: format!("{}-{}", ident.callsign, ident.ssid), - message: comment.to_owned() + let m = ui::UIPacket { + received_at: chrono::Utc::now(), + from_callsign: ident.callsign.to_string(), + from_ssid: ident.ssid, + comment: Some(comment.to_owned()) }; match ws_broadcast.send(m) { Ok(num) => debug!("Send WS message to {num}"), @@ -1,3 +1,4 @@ +use std::time::{UNIX_EPOCH, SystemTime, Duration}; use std::ops::ControlFlow; use std::net::SocketAddr; use std::str::FromStr; @@ -10,12 +11,12 @@ use axum::{ extract::State, extract::{ws::{Message, WebSocket, WebSocketUpgrade}, ConnectInfo}, http::StatusCode, - response::Html, response::IntoResponse, routing::{get, post}, }; +use chrono::serde::ts_seconds; use futures::{StreamExt, SinkExt}; -use log::{debug, info, warn}; +use log::{debug, info, warn, error}; use serde::Deserialize; use tower_http::services::ServeDir; @@ -52,6 +53,19 @@ enum ActivePage { None, } +impl ActivePage { + // Used by templates/head.html to include the correct js files in <head> + fn styles(&self) -> Vec<&'static str> { + match self { + ActivePage::Dashboard => vec![], + ActivePage::Chat => vec!["chat.js"], + ActivePage::Send => vec!["send.js"], + ActivePage::Settings => vec![], + ActivePage::None => vec![], + } + } +} + #[derive(Template)] #[template(path = "dashboard.html")] struct DashboardTemplate<'a> { @@ -63,8 +77,10 @@ struct DashboardTemplate<'a> { packets: Vec<UIPacket>, } -struct UIPacket { - pub received_at : i64, +#[derive(Clone, serde::Serialize)] +pub struct UIPacket { + #[serde(with = "ts_seconds")] + pub received_at: chrono::DateTime<chrono::Utc>, pub from_callsign : String, pub from_ssid : u8, @@ -72,20 +88,12 @@ struct UIPacket { pub comment : Option<String>, } -async fn dashboard(State(state): State<SharedState>) -> DashboardTemplate<'static> { - let (conf, mut db, node_startup_time) = { - let st = state.lock().unwrap(); - (st.conf.clone(), st.db.clone(), st.start_time.clone()) - }; +impl UIPacket { + fn received_at_iso(&self) -> String { + self.received_at.to_string() + } - let packets = match db.get_most_recent_packets(10).await { - Ok(v) => v, - Err(e) => { - warn!("Dashboard will have empty packet list: {}", e); - Vec::new() - }, - }.iter() - .filter_map(|db_packet| { + fn from_db_packet(db_packet: &crate::db::Packet) -> Option<Self> { let mut buf = [0; MAX_PACKET_LEN]; match ham_cats::packet::Packet::fully_decode(&db_packet.content, &mut buf) { Ok(p) => { @@ -113,7 +121,23 @@ async fn dashboard(State(state): State<SharedState>) -> DashboardTemplate<'stati None }, } - }) + } +} + +async fn dashboard(State(state): State<SharedState>) -> DashboardTemplate<'static> { + let (conf, mut db, node_startup_time) = { + let st = state.lock().unwrap(); + (st.conf.clone(), st.db.clone(), st.start_time.clone()) + }; + + let packets = match db.get_most_recent_packets(10).await { + Ok(v) => v, + Err(e) => { + warn!("Dashboard will have empty packet list: {}", e); + Vec::new() + }, + }.iter() + .filter_map(|p| UIPacket::from_db_packet(p)) .collect(); let node_startup_time = format!("{} UTC", @@ -135,13 +159,39 @@ struct ChatTemplate<'a> { title: &'a str, page: ActivePage, conf: config::Config, + packets: Vec<UIPacket>, } async fn chat(State(state): State<SharedState>) -> ChatTemplate<'static> { + + let (conf, mut db) = { + let st = state.lock().unwrap(); + (st.conf.clone(), st.db.clone()) + }; + + let time_start = SystemTime::now() - Duration::from_secs(6*3600); + let timestamp = time_start + .duration_since(UNIX_EPOCH) + .expect("Time went backwards"); + + let timestamp_i64 : i64 = timestamp.as_secs().try_into().unwrap(); + let packets = match db.get_packets_since(timestamp_i64).await { + Ok(packets) => { + packets.iter() + .filter_map(|p| UIPacket::from_db_packet(p)) + .collect() + }, + Err(e) => { + error!("Failed to get packets since TS: {e}"); + vec![] + } + }; + ChatTemplate { title: "Chat", - conf: state.lock().unwrap().conf.clone(), + conf, page: ActivePage::Chat, + packets } } @@ -156,7 +206,7 @@ async fn ws_handler( async fn handle_socket( mut socket: WebSocket, - mut rx: tokio::sync::broadcast::Receiver<crate::WSChatMessage>, + mut rx: tokio::sync::broadcast::Receiver<UIPacket>, who: SocketAddr) { if socket.send(Message::Ping(vec![1, 2, 3])).await.is_ok() { info!("Pinged {who}..."); diff --git a/static/main.js b/static/main.js index 7f6b110..8e8b87c 100644 --- a/static/main.js +++ b/static/main.js @@ -1,51 +1,3 @@ -async function btn_add_destination() { - const template = document.getElementById('destination_template'); - - let clon = template.content.cloneNode(true); - document.getElementById('destinations').appendChild(clon); -} - -async function btn_remove_destination(element_clicked) { - element_clicked.parentElement.remove() -} - -async function btn_send_packet() { - let data = { - 'comment': null, - //'simplex': null, - 'destinations': [], - }; - - if (document.getElementById('with_comment').checked) { - data.comment = document.getElementById('whisker_comment').value; - } - - /* not yet implemented in ham-cats - if (document.getElementById('with_simplex').checked) { - const simplex_freq_MHz = parseInt(document.getElementById('simplex_mode').value, 10); - const mode_select = document.getElementById('simplex_mode') - const i = mode_select.selectedIndex; - const simplex_mode = mode_select.options[i].text; - - data.simplex = {'frequency': simplex_freq_MHz * 1e6, 'mode': simplex_mode}; - } - */ - - const destinations = document.getElementById('destinations'); - const destList = destinations.querySelectorAll("p.destination"); - for (let i = 0; i < destList.length; i++) { - const dest_callsign = destList[i].querySelector("input.dest_callsign").value; - const dest_ssid_str = destList[i].querySelector("input.dest_ssid").value; - const dest_ssid = parseInt(dest_ssid_str, 10); - if (dest_ssid < 0 || dest_ssid > 255) { - alert("SSID must be between 0 and 255"); - return; - } - data.destinations.push({'callsign': dest_callsign, 'ssid': dest_ssid}); - } - - await post('/api/send_packet', data); -} async function post(url, data) { const params = { diff --git a/static/style.css b/static/style.css index 1023b38..eda120e 100644 --- a/static/style.css +++ b/static/style.css @@ -1 +1 @@ -/*! tailwindcss v3.3.5 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }html{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity));font-family:sans-serif}.mt-1{margin-top:.25rem}.flex{display:flex}.h-full{height:100%}.min-h-screen{min-height:100vh}.w-60{width:15rem}.w-8{width:2rem}.flex-auto{flex:1 1 auto}.flex-none{flex:none}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.25rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.25rem*var(--tw-space-y-reverse))}.space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.5rem*var(--tw-space-y-reverse))}.divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse))}.divide-sky-300>:not([hidden])~:not([hidden]){--tw-divide-opacity:1;border-color:rgb(125 211 252/var(--tw-divide-opacity))}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.bg-sky-100{--tw-bg-opacity:1;background-color:rgb(224 242 254/var(--tw-bg-opacity))}.bg-sky-200{--tw-bg-opacity:1;background-color:rgb(186 230 253/var(--tw-bg-opacity))}.bg-sky-300{--tw-bg-opacity:1;background-color:rgb(125 211 252/var(--tw-bg-opacity))}.p-3{padding:.75rem}.p-4{padding:1rem}.pb-4{padding-bottom:1rem}.pt-2{padding-top:.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.font-semibold{font-weight:600}.text-sky-800{--tw-text-opacity:1;color:rgb(7 89 133/var(--tw-text-opacity))}.text-sky-900{--tw-text-opacity:1;color:rgb(12 74 110/var(--tw-text-opacity))}h1{font-size:1.125rem;line-height:1.75rem}h1,h2{font-weight:700}fieldset{margin:.5rem;border-radius:.375rem;padding:.5rem;font-weight:400;--tw-text-opacity:1;color:rgb(3 105 161/var(--tw-text-opacity));outline-style:solid;outline-color:#3b82f61a}fieldset:hover{outline-color:#3b82f64d}legend{padding:.25rem;font-variant:small-caps}label{padding:.5rem}input,label{margin:.25rem}div.content{padding:.25rem .5rem}div.content,div.section{margin-top:.25rem;margin-bottom:.25rem}div.section{padding-top:.25rem;padding-bottom:.25rem;border-top-width:2px;--tw-border-opacity:1;border-color:rgb(125 211 252/var(--tw-border-opacity))}.btn{margin-top:.25rem;margin-bottom:.25rem;border-radius:.25rem;padding:.25rem .5rem;font-weight:700;--tw-bg-opacity:1;background-color:rgb(14 165 233/var(--tw-bg-opacity));--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.btn:hover{--tw-bg-opacity:1;background-color:rgb(2 132 199/var(--tw-bg-opacity))}.textinput{border-radius:.375rem;border-width:2px;--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity));padding:.25rem;font-size:.875rem;line-height:1.25rem;font-weight:400;--tw-text-opacity:1;color:rgb(3 105 161/var(--tw-text-opacity));outline-style:solid;outline-width:0}.textinput:focus{border-width:2px;--tw-border-opacity:1;border-color:rgb(113 113 122/var(--tw-border-opacity));outline-width:0}.textinput:disabled{border-width:0;--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity))}.hover\:bg-sky-300:hover{--tw-bg-opacity:1;background-color:rgb(125 211 252/var(--tw-bg-opacity))}
\ No newline at end of file +/*! tailwindcss v3.3.5 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }html{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity));font-family:sans-serif}.m-2{margin:.5rem}.mt-1{margin-top:.25rem}.flex{display:flex}.h-12{height:3rem}.h-\[96\%\]{height:96%}.h-full{height:100%}.min-h-screen{min-height:100vh}.w-60{width:15rem}.w-8{width:2rem}.w-full{width:100%}.flex-1{flex:1 1 0%}.flex-auto{flex:1 1 auto}.flex-none{flex:none}.grow{flex-grow:1}.grow-0{flex-grow:0}.flex-col{flex-direction:column}.gap-4{gap:1rem}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.25rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.25rem*var(--tw-space-y-reverse))}.space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.5rem*var(--tw-space-y-reverse))}.divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse))}.divide-sky-300>:not([hidden])~:not([hidden]){--tw-divide-opacity:1;border-color:rgb(125 211 252/var(--tw-divide-opacity))}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.border-l-2{border-left-width:2px}.border-sky-100{--tw-border-opacity:1;border-color:rgb(224 242 254/var(--tw-border-opacity))}.bg-sky-100{--tw-bg-opacity:1;background-color:rgb(224 242 254/var(--tw-bg-opacity))}.bg-sky-200{--tw-bg-opacity:1;background-color:rgb(186 230 253/var(--tw-bg-opacity))}.bg-sky-300{--tw-bg-opacity:1;background-color:rgb(125 211 252/var(--tw-bg-opacity))}.p-2{padding:.5rem}.p-3{padding:.75rem}.p-4{padding:1rem}.pb-4{padding-bottom:1rem}.pt-2{padding-top:.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.font-bold{font-weight:700}.font-semibold{font-weight:600}.font-thin{font-weight:100}.text-sky-400{--tw-text-opacity:1;color:rgb(56 189 248/var(--tw-text-opacity))}.text-sky-800{--tw-text-opacity:1;color:rgb(7 89 133/var(--tw-text-opacity))}.text-sky-900{--tw-text-opacity:1;color:rgb(12 74 110/var(--tw-text-opacity))}h1{font-size:1.125rem;line-height:1.75rem}h1,h2{font-weight:700}fieldset{margin:.5rem;border-radius:.375rem;padding:.5rem;font-weight:400;--tw-text-opacity:1;color:rgb(3 105 161/var(--tw-text-opacity));outline-style:solid;outline-color:#3b82f61a}fieldset:hover{outline-color:#3b82f64d}legend{padding:.25rem;font-variant:small-caps}label{padding:.5rem}input,label{margin:.25rem}div.content{padding:.25rem .5rem}div.content,div.section{margin-top:.25rem;margin-bottom:.25rem}div.section{padding-top:.25rem;padding-bottom:.25rem;border-top-width:2px;--tw-border-opacity:1;border-color:rgb(125 211 252/var(--tw-border-opacity))}.btn{margin-top:.25rem;margin-bottom:.25rem;border-radius:.25rem;padding:.25rem .5rem;font-weight:700;--tw-bg-opacity:1;background-color:rgb(14 165 233/var(--tw-bg-opacity));--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.btn:hover{--tw-bg-opacity:1;background-color:rgb(2 132 199/var(--tw-bg-opacity))}.textinput{border-radius:.375rem;border-width:2px;--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity));padding:.25rem;font-size:.875rem;line-height:1.25rem;font-weight:400;--tw-text-opacity:1;color:rgb(3 105 161/var(--tw-text-opacity));outline-style:solid;outline-width:0}.textinput:focus{border-width:2px;--tw-border-opacity:1;border-color:rgb(113 113 122/var(--tw-border-opacity));outline-width:0}.textinput:disabled{border-width:0;--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity))}.hover\:bg-sky-300:hover{--tw-bg-opacity:1;background-color:rgb(125 211 252/var(--tw-bg-opacity))}
\ No newline at end of file diff --git a/templates/chat.html b/templates/chat.html index 584bde5..8411b01 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -1,6 +1,42 @@ {% include "head.html" %} -<div class="content"> +<div class="content h-full"> <h1>Chat</h1> + <div class="section h-[96%]"> + <div class="m-2 h-full flex flex-col"> + <div class="flex-1 grow"> + <template id="message_template"> + <div class="p-2 m-2 border-l-1 border-sky-100"> + <div class="font-thin text-sky-400">Timestamp</div> + <div class="font-bold text-sky-900">FROM</div> + <div class="text-sky-800">Message</div> + </div> + </template> + {% for packet in packets %} + {% match packet.comment %}{% when Some with (comment) %} + <div class="p-2 border-l-2 border-sky-100 flex gap-4"> + <div class="flex-none font-thin text-sky-400">{{ packet.received_at_iso()|e }}</div> + <div class="flex-none font-bold text-sky-900">{{ packet.from_callsign|e }}-{{ packet.from_ssid|e }}</div> + <div class="flex-1 text-sky-800">{{ comment|e }} + </div> + </div> + {% when None %}{% endmatch %} + {% endfor %} + </div> + <div class="flex-none grow-0 h-12"> + <div class="flex"> + <div class="flex-none"> + <label for="dest">Message for:</label><input class="textinput" type="text" name="dest" value="" placeholder="callsign-ssid"> + </div> + <div class="flex-1"> + <input class="textinput w-full" type="text" name="message" value="" placeholder="Type your message here"> + </div> + <div class="flex-none"> + <button class="btn" type="button" onclick="btn_chat_send_message()">Send</button> + </div> + </div> + </div> + </div> + </div> </div> {% include "foot.html" %} {# vi:set et sw=2 ts=2: #} diff --git a/templates/dashboard.html b/templates/dashboard.html index a58bec6..029993b 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -10,7 +10,7 @@ <h2>Ten most recent packets</h2> <ul> {% for packet in packets %} - <li>{{ packet.received_at|e }} <b>{{ packet.from_callsign|e }}-{{ packet.from_ssid|e }}</b> + <li>{{ packet.received_at_iso()|e }} <b>{{ packet.from_callsign|e }}-{{ packet.from_ssid|e }}</b> {% match packet.comment %}{% when Some with (val) %}{{ val|e }}{% when None %}N/A{% endmatch %} </li> {% endfor %} diff --git a/templates/head.html b/templates/head.html index 3c611ed..fd0afe4 100644 --- a/templates/head.html +++ b/templates/head.html @@ -6,7 +6,9 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="/static/style.css" type="text/css"> <link rel="stylesheet" href="/static/font-awesome/css/font-awesome.min.css"> - <script src="/static/main.js" defer></script> + {% for js in page.styles() %} + <script src="/static/{{ js }}.js" defer></script> + {% endfor %} </head> <body> <div class="flex"> diff --git a/templates/send.html b/templates/send.html index b3bccab..f90d447 100644 --- a/templates/send.html +++ b/templates/send.html @@ -1,9 +1,11 @@ {% include "head.html" %} <div class="content"> <h1>Send a frame</h1> - <p>One main feature of CATS is that packets are constructed from Whiskers. - Each Whisker represents one possible attribute of data.</p> - <p>On this page you can select which whiskers to include in your packet.</p> + <div class="section"> + <p>One main feature of CATS is that packets are constructed from Whiskers. + Each Whisker represents one possible attribute of data.</p> + <p>On this page you can select which whiskers to include in your packet.</p> + </div> <div class="section"> <h2>Identification</h2> @@ -19,11 +21,11 @@ <p class="destination"> <input class="textinput dest_callsign" type="text" placeholder="Type callsign here"> <input class="textinput dest_ssid" type="text" placeholder="Type SSID here"> - <button class="btn" type="button" onclick="btn_remove_destination(this)">Remove</button> + <button class="btn" type="button" onclick="btn_send_remove_destination(this)">Remove</button> </p> </template> <div id="destinations"></div> - <button class="btn" type="button" onclick="btn_add_destination()">Add destination</button> + <button class="btn" type="button" onclick="btn_send_add_destination()">Add destination</button> </div> <div class="section"> <h2>Comment Whisker</h2> @@ -58,7 +60,7 @@ </div>--> <div class="section"> - <button class="btn" type="button" onclick="btn_send_packet()">Send</button> + <button class="btn" type="button" onclick="btn_send_send()">Send</button> </div> </div> {% include "foot.html" %} |