mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Work on tree
This commit is contained in:
@@ -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 },
|
||||
|
||||
@@ -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::<String>("/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::<String>("/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 {
|
||||
|
||||
@@ -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<usize>,
|
||||
// Display string edit as password
|
||||
#[serde(default)]
|
||||
protected: Option<bool>,
|
||||
},
|
||||
Integer {
|
||||
// Default value of integer in struct
|
||||
#[serde(default)]
|
||||
default: i32,
|
||||
min: Option<i32>,
|
||||
max: Option<i32>,
|
||||
},
|
||||
// Checkbox
|
||||
// Dropdown
|
||||
// Collapsing header
|
||||
// Slider
|
||||
// ...
|
||||
}
|
||||
|
||||
@@ -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<ConfigStructField>;
|
||||
pub type ConfigStructListValues = Vec<Vec<Value>>;
|
||||
|
||||
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 {}
|
||||
@@ -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<String, String>,
|
||||
}
|
||||
|
||||
#[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<usize>,
|
||||
// Display string edit as password
|
||||
#[serde(default)]
|
||||
protected: bool,
|
||||
},
|
||||
Integer {
|
||||
// Default value of integer in struct
|
||||
#[serde(default)]
|
||||
default: i32,
|
||||
min: Option<i32>,
|
||||
max: Option<i32>,
|
||||
},
|
||||
// Checkbox
|
||||
// Dropdown
|
||||
// Collapsing header
|
||||
// Slider
|
||||
// ...
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use unshell_lib::config::config_struct::ConfigStructField;
|
||||
use unshell_lib::config::ConfigStructField;
|
||||
|
||||
// use crate::config::ConfigStructField;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ mod blob;
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
error::Error,
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
@@ -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<PathBuf>, database: String) -> Result<Self> {
|
||||
// let mut component_configs: Vec<crate::config::ComponentState> = Vec::new();
|
||||
// let mut component_configs: Vec<crate::config::ComponentState> = 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(),
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user