From bdd3b7ab9b2dd7380760a4fd0540e663ba2e5a58 Mon Sep 17 00:00:00 2001 From: glyph Date: Mon, 3 Oct 2022 10:48:56 +0100 Subject: [PATCH] add wip refactored template for ap detail --- .../src/routes/settings/network/ap_details.rs | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/peach-web/src/routes/settings/network/ap_details.rs b/peach-web/src/routes/settings/network/ap_details.rs index e69de29..d6e5c82 100644 --- a/peach-web/src/routes/settings/network/ap_details.rs +++ b/peach-web/src/routes/settings/network/ap_details.rs @@ -0,0 +1,120 @@ +use maud::{html, PreEscaped}; +use peach_network::{network, network::Scan}; +use rouille::Request; + +use crate::{ + templates, + utils::{flash::FlashRequest, theme}, +}; + +// ROUTE: /settings/network/wifi? + +fn render_status_elements<'a>() -> () { + let wlan_ssid = match network::ssid("wlan0") { + Ok(Some(ssid)) => ssid, + _ => String::from("Not connected") + }; + + if + div class="two-grid capsule{% if ssid == wlan_ssid %} success-border{% endif %}" title="PeachCloud network mode and status" { + +} + +fn render_network_status_icon() { + + + (PreEscaped("")) + + div class="grid-column-1" { + img id="wifiIcon" class="center icon" src="/icons/wifi.svg" alt="WiFi icon"; + label class="center label-small font-gray" for="wifiIcon" title="Access Point Status">{% if ssid == wlan_ssid %}CONNECTED{% elif ap.state == "Available" %}AVAILABLE{% else %}NOT IN RANGE{% endif %}; + } +} + +fn render_network_detailed_info() -> Markup { + html! { + (PreEscaped("")) + div class="grid-column-2" { + label class="label-small font-gray" for="netSsid" title="WiFi network SSID" { "SSID" }; + p id="netSsid" class="card-text" title="SSID" { (ssid) } + label class="label-small font-gray" for="netSec" title="Security protocol" { "SECURITY" }; + p id="netSec" class="card-text" title="Security protocol in use by {{ ssid }}" { "{% if ap.detail %}{% if ap.detail.protocol != "" %}{{ ap.detail.protocol }}{% else %}None{% endif %}{% else %}Unknown{% endif %}" } + label class="label-small font-gray" for="netSig" title="Signal Strength" { "SIGNAL" }; + p id="netSig" class="card-text" title="Signal strength of WiFi access point" { "{% if ap.signal %}{{ ap.signal }}%{% else %}Unknown{% endif %}" } + } + } +} + +// fn render_network_card +// +fn render_buttons() -> Markup { + html! { + (PreEscaped("")) + div class="card-container" style="padding-top: 0;" { + div id="buttonDiv" { + {%- if wlan_ssid == selected -%} + form id="wifiDisconnect" action="/settings/network/wifi/disconnect" method="post" { + (PreEscaped("")) + input id="disconnectSsid" name="ssid" type="text" value="{{ ssid }}" style="display: none;"; + input id="disconnectWifi" class="button button-warning center" title="Disconnect from Network" type="submit" value="Disconnect"; + } + {%- endif -%} + {%- if saved_aps -%} + {# Loop through the list of AP's with saved credentials #} + {%- for ap in saved_aps -%} + {# If the selected access point appears in the list, #} + {# display the Modify and Forget buttons. #} + {%- if ap.ssid == selected -%} + {# Set 'in_list' to true to allow correct Add button display #} + {% set_global in_list = true %} + {%- if wlan_ssid != selected and ap.state == "Available" -%} + form id="wifiConnect" action="/settings/network/wifi/connect" method="post" { + (PreEscaped("")) + input id="connectSsid" name="ssid" type="text" value="{{ ap.ssid }}" style="display: none;"; + input id="connectWifi" class="button button-primary center" title="Connect to Network" type="submit" value="Connect"; + } + {%- endif -%} + a class="button button-primary center" href="/settings/network/wifi/modify?ssid={{ ssid }}" { "Modify" } + form id="wifiForget" action="/settings/network/wifi/forget" method="post" { + (PreEscaped("")) + input id="forgetSsid" name="ssid" type="text" value="{{ ap.ssid }}" style="display: none;"; + input id="forgetWifi" class="button button-warning center" title="Forget Network" type="submit" value="Forget"; + } + {%- endif -%} + {%- endfor -%} + {%- endif -%} + {%- if in_list == false -%} + {# Display the Add button if AP creds not already in saved networks list #} + a class="button button-primary center" href="/settings/network/wifi/add?ssid={{ ssid }}" { "Add" } + {%- endif -%} + a class="button button-secondary center" href="/settings/network/wifi" title="Cancel" { "Cancel" }/ + +/// WiFi access point (AP) details. +pub fn build_template(request: &Request, selected_ap: String) -> PreEscaped { + let network_list_template = html! { + @if let Ok(Some(wlan_networks)) = network::all_networks("wlan0") { + @for ssid, ap in wlan_networks { + // select only the access point we are interested in displaying + @if ssid == selected_ap { + (PreEscaped("")) + div class="card center" { + (PreEscaped("")) + div class="two-grid capsule{% if ssid == wlan_ssid %} success-border{% endif %}" title="PeachCloud network mode and status" { + (PreEscaped("")) + // network status icon goes here + // ... + // network detailed info goes here + // ... + } + // buttons go here + // ... + + } + // flash + } + } + } + } + } + } +}