add wip refactored template for ap detail

This commit is contained in:
glyph 2022-10-03 10:48:56 +01:00
parent 4f36f61128
commit bdd3b7ab9b
1 changed files with 120 additions and 0 deletions

View File

@ -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?<ssid>
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("<!-- NETWORK STATUS ICON -->"))
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("<!-- NETWORK DETAILED INFO -->"))
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("<!-- BUTTONS -->"))
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("<!-- hidden element: allows ssid to be sent in request -->"))
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("<!-- hidden element: allows ssid to be sent in request -->"))
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("<!-- hidden element: allows ssid to be sent in request -->"))
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<String> {
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("<!-- NETWORK CARD -->"))
div class="card center" {
(PreEscaped("<!-- NETWORK INFO BOX -->"))
div class="two-grid capsule{% if ssid == wlan_ssid %} success-border{% endif %}" title="PeachCloud network mode and status" {
(PreEscaped("<!-- left column -->"))
// network status icon goes here
// ...
// network detailed info goes here
// ...
}
// buttons go here
// ...
}
// flash
}
}
}
}
}
}
}