remove unnecessary serde derivations, state-based remplate rendering, styling improvements
This commit is contained in:
parent
3572fd4e7b
commit
6cdd6dc41b
|
@ -3,11 +3,7 @@
|
|||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use rocket::{
|
||||
form::FromForm,
|
||||
serde::{Deserialize, Serialize},
|
||||
UriDisplayQuery,
|
||||
};
|
||||
use rocket::{form::FromForm, serde::Serialize, UriDisplayQuery};
|
||||
|
||||
use peach_network::{
|
||||
network,
|
||||
|
@ -36,12 +32,12 @@ pub fn ap_state() -> String {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, FromForm, UriDisplayQuery)]
|
||||
#[derive(Debug, FromForm, UriDisplayQuery)]
|
||||
pub struct Ssid {
|
||||
pub ssid: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, FromForm)]
|
||||
#[derive(Debug, FromForm)]
|
||||
pub struct WiFi {
|
||||
pub ssid: String,
|
||||
pub pass: String,
|
||||
|
|
|
@ -62,11 +62,11 @@ impl StatusContext {
|
|||
// retrieve go-sbot systemd process status
|
||||
let sbot_status = SbotStatus::read()?;
|
||||
|
||||
// retrieve latest go-sbot configuration parameters
|
||||
let sbot_config = SbotConfig::read().ok();
|
||||
|
||||
// we only want to try and interact with the sbot if it's active
|
||||
if sbot_status.state == Some("active".to_string()) {
|
||||
// retrieve latest go-sbot configuration parameters
|
||||
let sbot_config = SbotConfig::read().ok();
|
||||
|
||||
let mut sbot_client = init_sbot_with_config(&sbot_config).await?;
|
||||
|
||||
// retrieve the local id
|
||||
|
@ -80,14 +80,13 @@ impl StatusContext {
|
|||
|
||||
// assign the sequence number of the latest msg
|
||||
context.latest_seq = Some(msgs[0].sequence);
|
||||
|
||||
context.sbot_config = sbot_config;
|
||||
} else {
|
||||
// the sbot is not currently active; return a helpful message
|
||||
context.flash_name = Some("warning".to_string());
|
||||
context.flash_msg = Some("The Sbot is currently inactive. As a result, status data cannot be retrieved. Visit the Scuttlebutt settings menu to start the Sbot and then try again".to_string());
|
||||
}
|
||||
|
||||
context.sbot_config = sbot_config;
|
||||
context.sbot_status = Some(sbot_status);
|
||||
|
||||
Ok(context)
|
||||
|
|
|
@ -156,7 +156,7 @@ pub async fn create_invite(invite: Form<Invite>, _auth: Authenticated) -> Flash<
|
|||
Ok(false) => {
|
||||
return Flash::warning(
|
||||
Redirect::to(url),
|
||||
"The Sbot is currently inactive. As a result, new posts cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
||||
"The Sbot is currently inactive. As a result, new invite codes cannot be generated. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
||||
)
|
||||
}
|
||||
// failed to retrieve go-sbot systemd process status
|
||||
|
@ -335,12 +335,20 @@ pub fn peers(flash: Option<FlashMessage>, _auth: Authenticated) -> Template {
|
|||
context.insert("title", &Some("Scuttlebutt Peers"));
|
||||
context.insert("back", &Some("/"));
|
||||
|
||||
// check to see if there is a flash message to display
|
||||
if let Some(flash) = flash {
|
||||
// add flash message contents to the context object
|
||||
context.insert("flash_name", &Some(flash.kind().to_string()));
|
||||
context.insert("flash_msg", &Some(flash.message().to_string()));
|
||||
};
|
||||
// display a helpful message if the sbot is inactive
|
||||
if let Ok(false) = is_sbot_active() {
|
||||
context.insert("sbot_state", &Some("inactive".to_string()));
|
||||
context.insert("flash_name", &Some("warning".to_string()));
|
||||
context.insert("flash_msg", &Some("The Sbot is currently inactive. As a result, social lists and interactions are unavailable. Visit the Scuttlebutt settings menu to start the Sbot and then try again".to_string()));
|
||||
} else {
|
||||
context.insert("sbot_state", &Some("active".to_string()));
|
||||
// check to see if there is a flash message to display
|
||||
if let Some(flash) = flash {
|
||||
// add flash message contents to the context object
|
||||
context.insert("flash_name", &Some(flash.kind().to_string()));
|
||||
context.insert("flash_msg", &Some(flash.message().to_string()));
|
||||
};
|
||||
}
|
||||
|
||||
Template::render("scuttlebutt/peers", &context.into_json())
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ use rocket::{
|
|||
form::{Form, FromForm},
|
||||
get, post,
|
||||
request::FlashMessage,
|
||||
serde::Deserialize,
|
||||
};
|
||||
use rocket_dyn_templates::Template;
|
||||
|
||||
|
@ -19,7 +18,7 @@ use crate::{
|
|||
utils,
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize, FromForm)]
|
||||
#[derive(Debug, FromForm)]
|
||||
pub struct DnsForm {
|
||||
pub external_domain: String,
|
||||
pub enable_dyndns: bool,
|
||||
|
|
|
@ -4,7 +4,6 @@ use rocket::{
|
|||
get, post,
|
||||
request::FlashMessage,
|
||||
response::{Flash, Redirect},
|
||||
serde::Deserialize,
|
||||
uri, UriDisplayQuery,
|
||||
};
|
||||
use rocket_dyn_templates::{tera::Context, Template};
|
||||
|
@ -21,12 +20,12 @@ use crate::{
|
|||
|
||||
// STRUCTS USED BY NETWORK ROUTES
|
||||
|
||||
#[derive(Debug, Deserialize, FromForm, UriDisplayQuery)]
|
||||
#[derive(Debug, FromForm, UriDisplayQuery)]
|
||||
pub struct Ssid {
|
||||
pub ssid: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, FromForm)]
|
||||
#[derive(Debug, FromForm)]
|
||||
pub struct WiFi {
|
||||
pub ssid: String,
|
||||
pub pass: String,
|
||||
|
|
|
@ -10,14 +10,13 @@ use rocket::{
|
|||
get, post,
|
||||
request::FlashMessage,
|
||||
response::{Flash, Redirect},
|
||||
serde::Deserialize,
|
||||
};
|
||||
use rocket_dyn_templates::{tera::Context, Template};
|
||||
|
||||
use crate::routes::authentication::Authenticated;
|
||||
use crate::utils;
|
||||
|
||||
#[derive(Debug, Deserialize, FromForm)]
|
||||
#[derive(Debug, FromForm)]
|
||||
pub struct SbotConfigForm {
|
||||
/// Directory path for the log and indexes.
|
||||
repo: String,
|
||||
|
|
|
@ -720,7 +720,7 @@ form {
|
|||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
margin-top: 0.5rem;
|
||||
/* margin-top: 0.5rem; */
|
||||
margin-bottom: 1rem;
|
||||
padding-left: 5px;
|
||||
line-height: 1.5rem;
|
||||
|
@ -738,6 +738,7 @@ form {
|
|||
|
||||
.message-input {
|
||||
height: 7rem;
|
||||
margin-top: 0.5rem;
|
||||
overflow: auto;
|
||||
resize: vertical;
|
||||
width: 100%;
|
||||
|
@ -770,7 +771,6 @@ form {
|
|||
}
|
||||
|
||||
.label-medium {
|
||||
color: var(--text-color);
|
||||
font-size: var(--font-size-3);
|
||||
display: block;
|
||||
}
|
||||
|
@ -799,6 +799,10 @@ form {
|
|||
/* color: var(--font-near-black); */
|
||||
}
|
||||
|
||||
.link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/*
|
||||
* LISTS
|
||||
*/
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
{%- block card %}
|
||||
<!-- SCUTTLEBUTT PEERS -->
|
||||
<div class="card center">
|
||||
{# only render the peer menu elements if the sbot is active #}
|
||||
{%- if sbot_state == "active" %}
|
||||
<div class="card-container">
|
||||
<!-- BUTTONS -->
|
||||
<div id="buttons">
|
||||
|
@ -12,5 +14,8 @@
|
|||
<a id="invites" class="button button-primary center" href="/scuttlebutt/invites" title="Create invites">Invites</a>
|
||||
</div>
|
||||
</div>
|
||||
{%- endif %}
|
||||
<!-- FLASH MESSAGE -->
|
||||
{% include "snippets/flash_message" %}
|
||||
</div>
|
||||
{%- endblock card -%}
|
||||
|
|
|
@ -1,24 +1,30 @@
|
|||
{%- extends "nav" -%}
|
||||
{%- block card %}
|
||||
<div class="card center">
|
||||
{%- if peers %}
|
||||
{%- if peers %}
|
||||
<ul class="list">
|
||||
{%- for peer in peers %}
|
||||
{%- for peer in peers %}
|
||||
{# set a fall-back value for name in case the data is unavailable #}
|
||||
{%- if not peer['name'] %}
|
||||
{%- set name = "name unavailable" %}
|
||||
{%- else %}
|
||||
{%- set name = peer['name'] %}
|
||||
{%- endif %}
|
||||
<li>
|
||||
<a class="list-item link light-bg" href="/scuttlebutt/profile?public_key={{ peer['id'] }}">
|
||||
{%- if peer['blob_path'] and peer['blob_exists'] == "true" %}
|
||||
<img id="peerImage" class="icon list-icon" src="/blob/{{ peer['blob_path'] }}" alt="{{ peer['name'] }}'s profile image">
|
||||
<img id="peerImage" class="icon list-icon" src="/blob/{{ peer['blob_path'] }}" alt="{{ name }}'s profile image">
|
||||
{%- else %}
|
||||
<img id="peerImage" class="icon list-icon" src="/icons/user.svg" alt="Placeholder profile image">
|
||||
{%- endif %}
|
||||
<p id="peerName" class="font-normal list-text">{{ peer['name'] }}</p>
|
||||
<label class="label-small label-ellipsis list-label font-gray" for="peerName" title="{{ peer['name'] }}'s Public Key">{{ peer['id'] }}</label>
|
||||
<p id="peerName" class="font-normal list-text">{{ name }}</p>
|
||||
<label class="label-small label-ellipsis list-label font-gray" for="peerName" title="{{ name }}'s Public Key">{{ peer['id'] }}</label>
|
||||
</a>
|
||||
</li>
|
||||
{%- endfor %}
|
||||
</ul>
|
||||
{%- else %}
|
||||
<p>No follows found</p>
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
</div>
|
||||
{%- endblock card -%}
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
</div>
|
||||
<!-- BUTTONS -->
|
||||
<input id="search" class="button button-primary center" type="submit" title="Search for peer" value="Search">
|
||||
<!-- FLASH MESSAGE -->
|
||||
{% include "snippets/flash_message" %}
|
||||
</form>
|
||||
<!-- FLASH MESSAGE -->
|
||||
{% include "snippets/flash_message" %}
|
||||
</div>
|
||||
{%- endblock card -%}
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
{% else %}
|
||||
<a id="start" class="button button-primary center" href="/settings/scuttlebutt/start" title="Start Sbot">Start Sbot</a>
|
||||
{% endif %}
|
||||
<a id="checkFilesystem" class="button button-primary center" href="/settings/scuttlebutt/check_fs" title="Check Filesystem">Check Filesystem</a>
|
||||
<a id="removeFeeds" class="button button-primary center" href="/settings/scuttlebutt/remove_feeds" title="Remove Blocked Feeds">Remove Blocked Feeds</a>
|
||||
</div>
|
||||
<!-- FLASH MESSAGE -->
|
||||
{% include "snippets/flash_message" %}
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
{%- if sbot_status.memory -%}
|
||||
{% set mem = sbot_status.memory / 1024 / 1024 | round | int -%}
|
||||
{%- else -%}
|
||||
{% set mem = "X" -%}
|
||||
{% set mem = "0" -%}
|
||||
{%- endif -%}
|
||||
{%- if sbot_status.blobstore -%}
|
||||
{% set blobs = sbot_status.blobstore / 1024 / 1024 | round | int -%}
|
||||
{%- else -%}
|
||||
{% set blobs = "X" -%}
|
||||
{% set blobs = "0" -%}
|
||||
{%- endif -%}
|
||||
<!-- SCUTTLEBUTT STATUS -->
|
||||
<div class="card center">
|
||||
|
@ -54,8 +54,12 @@
|
|||
<div id="middleSection" style="margin-top: 1rem;">
|
||||
<div id="sbotInfo" class="center" style="display: flex; justify-content: space-between; width: 90%;">
|
||||
<div class="center" style="display: flex; align-items: last baseline;">
|
||||
{% if sbot_status.state == "active" %}
|
||||
<label class="card-text" style="margin-right: 5px;">{{ latest_seq }}</label>
|
||||
<label class="label-small font-gray">MESSAGES IN LOCAL DATABASE</label>
|
||||
{% else %}
|
||||
<label class="label-small font-gray">DATABASE UNAVAILABLE</label>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -65,22 +69,22 @@
|
|||
<div class="stack">
|
||||
<img class="icon icon-active" title="Hops" src="/icons/orbits.png">
|
||||
<div class="flex-grid" style="padding-top: 0.5rem;">
|
||||
<label class="label-medium" style="padding-right: 3px;" title="Replication hops">{{ sbot_config.hops }}</label>
|
||||
<label class="label-medium font-normal" style="padding-right: 3px;" title="Replication hops">{{ sbot_config.hops }}</label>
|
||||
</div>
|
||||
<label class="label-small font-gray">HOPS</label>
|
||||
</div>
|
||||
<div class="stack">
|
||||
<img class="icon icon-active" title="Blobs" src="/icons/image-file.png">
|
||||
<div class="flex-grid" style="padding-top: 0.5rem;">
|
||||
<label class="label-medium{% if sbot_status.state == "inactive" %} font-gray{% endif %}" style="padding-right: 3px;" title="Blobstore size in MB">{{ blobs }}</label>
|
||||
<label class="label-small{% if sbot_status.state == "inactive" %} font-gray{% else %} font-normal{% endif %}">MB</label>
|
||||
<label class="label-medium font-normal" style="padding-right: 3px;" title="Blobstore size in MB">{{ blobs }}</label>
|
||||
<label class="label-small font-normal">MB</label>
|
||||
</div>
|
||||
<label class="label-small font-gray">BLOBSTORE</label>
|
||||
</div>
|
||||
<div class="stack">
|
||||
<img class="icon{% if sbot_status.memory %} icon-active{% else %} icon-inactive{% endif %}" title="Memory" src="/icons/ram.png">
|
||||
<div class="flex-grid" style="padding-top: 0.5rem;">
|
||||
<label class="label-medium{% if sbot_status.state == "inactive" %} font-gray{% endif %}" style="padding-right: 3px;" title="Memory usage of the go-sbot process in MB">{{ mem }}</label>
|
||||
<label class="label-medium{% if sbot_status.state == "inactive" %} font-gray{% else %} font-normal{% endif %}" style="padding-right: 3px;" title="Memory usage of the go-sbot process in MB">{{ mem }}</label>
|
||||
<label class="label-small{% if sbot_status.state == "inactive" %} font-gray{% else %} font-normal{% endif %}">MB</label>
|
||||
</div>
|
||||
<label class="label-small font-gray">MEMORY</label>
|
||||
|
|
Loading…
Reference in New Issue