diff --git a/unshell-gui/src/interface/interface.rs b/unshell-gui/src/interface/interface.rs index f1d32e4..d79e648 100644 --- a/unshell-gui/src/interface/interface.rs +++ b/unshell-gui/src/interface/interface.rs @@ -36,17 +36,31 @@ fn render_config_struct( }, serde_json::Value::String(value), ) => { - let mut widget = TextEdit::singleline(value); + ui.horizontal(|ui| { + let mut widget = TextEdit::singleline(value); - if let Some(limit) = &max_length { - widget = widget.char_limit(*limit); - } + if let Some(limit) = &max_length { + widget = widget.char_limit(*limit); + } - if let Some(protected) = &protected { - widget = widget.password(*protected); - } + let password = *protected && !ui.button("👁").is_pointer_button_down_on(); - ui.add(widget); + widget = widget.password(password); + + // if protected + // ui.selectable_label(show_plaintext, "👁") + // .on_hover_text("Show/hide password") + // .clicked(); + // { + // widget = widget.password(true); + // } + + ui.add(widget); + + if let Some(limit) = max_length { + ui.label(format!("{}/{}", value.len(), limit)); + } + }); } ( config_struct::ConfigStructField::Integer { default, min, max }, diff --git a/unshell-gui/src/interface/mod.rs b/unshell-gui/src/interface/mod.rs index ad4319a..5b84569 100644 --- a/unshell-gui/src/interface/mod.rs +++ b/unshell-gui/src/interface/mod.rs @@ -5,10 +5,8 @@ use std::{ sync::{Arc, Mutex}, }; -use egui_async::Bind; use log::debug; -use unshell_lib::config::TreeMessage; -use unshell_lib::{ModuleError, Result}; +use unshell_lib::{Result, config::TreeMessage}; use crate::auth::Auth; @@ -137,56 +135,6 @@ impl InterfaceWindow { drop(state_lock) } } - - // if ui.button("Go Up").clicked() { - // self.go_up(); - // // self.data_bind.clear(); - // } - - // match self.promise.as_mut() { - // Some(promise) => { - // if let Some(result) = promise.poll() { - // crate::log(&format!("{result:?}")); - // } else { - // crate::log("Poll failed"); - // } - // } - // None => { - // self.promise = - // Some(auth.get_async(&format!("/api/interface{}", self.path.to_str().unwrap()))); - // } - // } - - // let future = Auth::get_async::("/api/test").await; - // future.; - - // if let Some(res) = self.data_bind.read_or_request(async || { - // // self.go_up(); - // // auth.get("", |e: String| {}); - - // reqwest::get("https://icanhazip.com/") - // .await - // .map_err(|e| ModuleError::Error(e.to_string()))? - // .text() - // .await - // .map_err(|e| ModuleError::Error(e.to_string())) - // }) { - // match res { - // Ok(ip) => { - // ui.label(format!("OK {ip}")); - // } - // Err(err) => { - // ui.label(format!("ERR {err}")); - // } - // } - // } else { - // ui.spinner(); - // }; - - // if ui.button("Refresh").clicked() { - // Auth::get_async_callback::("/api/interface"); - // // self.data_bind.clear(); - // } } fn reset_path(&mut self) { @@ -202,8 +150,6 @@ impl InterfaceWindow { fn go_down(&mut self, path: String) { self.path = self.path.join(path); } - - async fn get() {} } impl Default for InterfaceWindow { diff --git a/unshell-lib/src/config/config_struct.rs b/unshell-lib/src/config/config_struct.rs index 713411a..068bd12 100644 --- a/unshell-lib/src/config/config_struct.rs +++ b/unshell-lib/src/config/config_struct.rs @@ -1,9 +1,8 @@ -use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; use crate::{ ModuleError, Result, - config::{InterfaceData, InterfaceStruct, TreeMessage}, + config::{ConfigStructField, InterfaceData, InterfaceStruct, TreeMessage}, warn, }; @@ -55,30 +54,3 @@ impl Config { } } } - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub enum ConfigStructField { - Header(String), - Text(String), - String { - // Default value of string edit in struct - #[serde(default)] - default: String, - max_length: Option, - // Display string edit as password - #[serde(default)] - protected: Option, - }, - Integer { - // Default value of integer in struct - #[serde(default)] - default: i32, - min: Option, - max: Option, - }, - // Checkbox - // Dropdown - // Collapsing header - // Slider - // ... -} diff --git a/unshell-lib/src/config/config_struct_list.rs b/unshell-lib/src/config/config_struct_list.rs new file mode 100644 index 0000000..38bb3fd --- /dev/null +++ b/unshell-lib/src/config/config_struct_list.rs @@ -0,0 +1,37 @@ +use serde::{Deserialize, Serialize}; +use serde_json::{Value, json}; + +use crate::{ + ModuleError, Result, + config::{ConfigStructField, InterfaceData, InterfaceStruct, Tree, TreeMessage}, + warn, +}; + +pub type ConfigStructListKeys = Vec; +pub type ConfigStructListValues = Vec>; + +pub struct ConfigStructList { + keys: ConfigStructListKeys, + values: ConfigStructListValues, +} + +impl ConfigStructList { + pub fn new(keys: ConfigStructListKeys) -> Self { + // let values = keys + // .iter() + // .map(|key| match key { + // ConfigStructField::Header(_) => Value::Null, + // ConfigStructField::Text(_) => Value::Null, + // ConfigStructField::String { default, .. } => json!(default), + // ConfigStructField::Integer { default, .. } => json!(default), + // }) + // .collect(); + + Self { + keys, + values: Vec::new(), + } + } +} + +// impl Tree for ConfigStructList {} diff --git a/unshell-lib/src/config/mod.rs b/unshell-lib/src/config/mod.rs index d0dc1c3..ac36916 100644 --- a/unshell-lib/src/config/mod.rs +++ b/unshell-lib/src/config/mod.rs @@ -1,4 +1,5 @@ pub mod config_struct; +pub mod config_struct_list; mod tree; pub use tree::{InterfaceData, InterfaceStruct, Tree, TreeMessage}; @@ -11,3 +12,30 @@ pub struct RuntimeConfig { pub name: String, pub config: HashMap, } + +#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] +pub enum ConfigStructField { + Header(String), + Text(String), + String { + // Default value of string edit in struct + #[serde(default)] + default: String, + max_length: Option, + // Display string edit as password + #[serde(default)] + protected: bool, + }, + Integer { + // Default value of integer in struct + #[serde(default)] + default: i32, + min: Option, + max: Option, + }, + // Checkbox + // Dropdown + // Collapsing header + // Slider + // ... +} diff --git a/unshell-server/src/config/blob.rs b/unshell-server/src/config/blob.rs index b5f62a7..09dd0fe 100644 --- a/unshell-server/src/config/blob.rs +++ b/unshell-server/src/config/blob.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use unshell_lib::config::config_struct::ConfigStructField; +use unshell_lib::config::ConfigStructField; // use crate::config::ConfigStructField; diff --git a/unshell-server/src/config/mod.rs b/unshell-server/src/config/mod.rs index 264df87..18bd78f 100644 --- a/unshell-server/src/config/mod.rs +++ b/unshell-server/src/config/mod.rs @@ -2,7 +2,6 @@ mod blob; use std::{ collections::HashMap, - error::Error, fs, path::{Path, PathBuf}, }; diff --git a/unshell-server/src/server/mod.rs b/unshell-server/src/server/mod.rs index bd306bf..d1c7dbf 100644 --- a/unshell-server/src/server/mod.rs +++ b/unshell-server/src/server/mod.rs @@ -5,10 +5,7 @@ use std::{ use unshell_lib::{ ModuleError, Result, - config::{ - Tree, TreeMessage, - config_struct::{Config, ConfigStructField}, - }, + config::{ConfigStructField, Tree, TreeMessage, config_struct::Config}, }; use unshell_manager::Manager; @@ -28,7 +25,7 @@ pub struct Server { impl Server { pub fn new(_config_paths: Vec, database: String) -> Result { - // let mut component_configs: Vec = Vec::new(); + // let mut component_configs: Vec = Vec::new(1); // for config in &config_paths { // component_configs.extend(crate::config::load_config(config)?); @@ -45,12 +42,12 @@ impl Server { ConfigStructField::String { default: "Test Texttttttttttttttt".into(), max_length: None, - protected: None, + protected: true, }, ConfigStructField::String { default: "Test ".into(), - max_length: None, - protected: None, + max_length: Some(15), + protected: false, }, ]))), // tree: Tree2::default(), diff --git a/unshell-server/src/server/tree2.rs b/unshell-server/src/server/tree2.rs index e1c7445..d58060c 100644 --- a/unshell-server/src/server/tree2.rs +++ b/unshell-server/src/server/tree2.rs @@ -1,5 +1,5 @@ use axum::{ - Extension, Json, + Json, extract::{Path, State}, }; @@ -10,7 +10,7 @@ use unshell_lib::{ debug, }; -use crate::{Server, auth::structs::CurrentUser}; +use crate::Server; impl Server { pub async fn get_tree2_root(