peach-workspace/peach-web/src/routes/settings/scuttlebutt/menu.rs

52 lines
2.2 KiB
Rust

use maud::{html, PreEscaped};
use peach_lib::sbot::SbotStatus;
use crate::templates;
// TODO: flash message implementation for rouille
//
/// Read the status of the go-sbot service and render buttons accordingly.
fn render_process_buttons() -> PreEscaped<String> {
// retrieve go-sbot systemd process status
let sbot_status = SbotStatus::read();
html! {
// render the stop and restart buttons if sbot process is currently active
@if let Ok(status) = sbot_status {
@if status.state == Some("active".to_string()) {
a id="stop" class="button button-primary center" href="/settings/scuttlebutt/stop" title="Stop Sbot" { "Stop Sbot" }
a id="restart" class="button button-primary center" href="/settings/scuttlebutt/restart" title="Restart Sbot" { "Restart Sbot" }
// render the start button if sbot process is currently inactive
} @else {
a id="start" class="button button-primary center" href="/settings/scuttlebutt/start" title="Start Sbot" { "Start Sbot" }
}
// render the start button if an error was returned by the status query
} @else {
a id="start" class="button button-primary center" href="/settings/scuttlebutt/start" title="Start Sbot" { "Start Sbot" }
}
}
}
/// Scuttlebutt settings menu template builder.
pub fn build() -> PreEscaped<String> {
let menu_template = html! {
(PreEscaped("<!-- SCUTTLEBUTT SETTINGS MENU -->"))
div class="card center" {
(PreEscaped("<!-- BUTTONS -->"))
div id="settingsButtons" {
a id="configureSbot" class="button button-primary center" href="/settings/scuttlebutt/configure" title="Configure Sbot" { "Configure Sbot" }
// conditionally render the start / stop / restart buttons
(render_process_buttons())
}
}
};
// wrap the nav bars around the settings menu template content
// parameters are template, title and back url
let body = templates::nav::build(menu_template, "Scuttlebutt Settings", Some("/settings"));
// render the base template with the provided body
templates::base::build(body)
}