save a small step [refs #19]
This commit is contained in:
parent
cd606cd014
commit
1f983cd7ca
5 changed files with 58 additions and 78 deletions
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
pub struct Preset {
|
||||
|
||||
}
|
||||
|
||||
impl Preset {
|
||||
pub fn new() -> Self { Self {
|
||||
|
||||
}}
|
||||
|
||||
pub fn collection(&self) -> &Colle
|
||||
}
|
||||
|
|
@ -1,23 +1,27 @@
|
|||
use axum::extract::State;
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::Response;
|
||||
use sslo_lib::cds::collection::Collection;
|
||||
use sslo_lib::cds::param_int::ParamInt;
|
||||
use sslo_lib::cds::parameter::{Parameter, ParameterMetaData};
|
||||
use crate::app_state::AppState;
|
||||
use crate::http::HtmlTemplate;
|
||||
use crate::http::http_user::HttpUserExtractor;
|
||||
|
||||
|
||||
pub async fn handler(State(app_state): State<AppState>,
|
||||
HttpUserExtractor(http_user): HttpUserExtractor,
|
||||
) -> Result<Response, StatusCode> {
|
||||
let mut html = HtmlTemplate::new(http_user, app_state.clone());
|
||||
|
||||
let mut pc = Collection::new("Test Collection".to_string());
|
||||
let p = ParamInt::new(
|
||||
"Test Parameter".to_string(),
|
||||
"°C".to_string()
|
||||
"Temperature".to_string(),
|
||||
Some("°C".to_string()),
|
||||
);
|
||||
html.push_body(&p.html());
|
||||
pc.add_parameter(Box::new(p));
|
||||
|
||||
|
||||
html.push_body(&pc.html());
|
||||
Ok(html.into_response().await)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,45 +2,46 @@ use std::rc::Weak;
|
|||
use crate::cds::Access;
|
||||
use crate::cds::parameter::{Parameter, ParameterMetaData};
|
||||
|
||||
pub trait Collection {
|
||||
|
||||
/// The metadata that every type needs to contain
|
||||
/// Must be implemented by the actual type
|
||||
fn meta(&self) -> &CollectionMetaData;
|
||||
|
||||
/// Structured html as user interface
|
||||
/// Should not be implemented by types
|
||||
fn html(&self) -> String {
|
||||
let meta = self.meta();
|
||||
|
||||
// parameter table
|
||||
let html_param_tbl = format!("<table class=\"CdsCollectionParameters\">{}</table>",
|
||||
meta.child_parameters.iter().map(|p| {
|
||||
format!("<tr><th>{}</th><td>{}</td></tr>",
|
||||
p.label(), p.html_input())
|
||||
}).collect()
|
||||
);
|
||||
|
||||
format!("<div class=\"CdsCollectionContainer\">\
|
||||
<div clas=\"CdsCollectionLabel\">{0}</div>\
|
||||
{1}
|
||||
</div>",
|
||||
meta.label, html_param_tbl,
|
||||
)
|
||||
}
|
||||
|
||||
fn html_bottom_level(&self) -> String {}
|
||||
}
|
||||
|
||||
pub struct CollectionMetaData {
|
||||
|
||||
pub struct Collection {
|
||||
/// The UI label of the collection
|
||||
pub label: String,
|
||||
|
||||
collected_in: Option<Weak<Self>>,
|
||||
|
||||
// collected_in: Option<Weak<Self>>,
|
||||
//
|
||||
child_parameters: Vec<Box<dyn Parameter>>,
|
||||
child_collection: Vec<Box<dyn Collection>>,
|
||||
// child_collection: Vec<Box<Collection>>,
|
||||
// base: Option<Weak<Self>>,
|
||||
// access: Access,
|
||||
}
|
||||
|
||||
impl Collection {
|
||||
|
||||
pub fn new(label: String) -> Self { Self {
|
||||
label,
|
||||
// collected_in: None,
|
||||
child_parameters: Vec::new(),
|
||||
// child_collection: Vec::new(),
|
||||
}}
|
||||
|
||||
pub fn add_parameter(&mut self, parameter: Box<dyn Parameter>) {
|
||||
self.child_parameters.push(parameter);
|
||||
}
|
||||
|
||||
/// Structured html as user interface
|
||||
/// Should not be implemented by types
|
||||
pub fn html(&self) -> String {
|
||||
|
||||
// parameter table
|
||||
let html_param_trs: String = self.child_parameters.iter().map(|p| {
|
||||
format!("<tr><th>{}</th><td>{}</td></tr>",
|
||||
p.label(), p.html_input())
|
||||
}).collect();
|
||||
|
||||
format!("<div class=\"CdsCollectionContainer\">\
|
||||
<div clas=\"CdsCollectionLabel\">{0}</div>\
|
||||
<table class=\"CdsCollectionParameters\">{1}</table>\
|
||||
</div>",
|
||||
self.label, html_param_trs,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,21 +5,18 @@ pub struct ParamInt {
|
|||
}
|
||||
|
||||
impl ParamInt {
|
||||
|
||||
pub fn new(label: String, unit: String) -> Self { Self {
|
||||
meta: ParameterMetaData {
|
||||
label,
|
||||
unit,
|
||||
},
|
||||
} }
|
||||
|
||||
pub fn new(label: String, unit: Option<String>) -> Self { Self {
|
||||
meta: ParameterMetaData {
|
||||
label,
|
||||
unit,
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
impl Parameter for ParamInt {
|
||||
fn meta(&self) -> &ParameterMetaData { &self.meta }
|
||||
fn meta(&self) -> &ParameterMetaData {&self.meta}
|
||||
|
||||
fn html_input(&self, css_class: &str, id: &str) -> String {
|
||||
format!("<input type=\"number\" value=\"0\" id=\"{}\" class=\"{}\">",
|
||||
id, css_class)
|
||||
fn html_input(&self) -> String {
|
||||
"<input type=\"number\" />".to_string()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
pub trait Parameter {
|
||||
pub trait Parameter : Send {
|
||||
|
||||
/// The metadata that every type needs to contain
|
||||
/// Must be implemented by the actual type
|
||||
|
|
@ -11,29 +11,19 @@ pub trait Parameter {
|
|||
fn label(&self) -> String {
|
||||
self.meta().label.clone()
|
||||
}
|
||||
|
||||
/// Structured html as user interface
|
||||
/// Should not be implemented by types
|
||||
fn html(&self) -> String {
|
||||
format!("<div class=\"CdsParameter\">\
|
||||
<label class=\"CdsParameterLabel\">{}</label>\
|
||||
{}\
|
||||
<div class=\"CdsParameterUnit\">{}</div>\
|
||||
</div>",
|
||||
self.meta().label,
|
||||
self.meta().unit,
|
||||
self.html_input("CdsParameterInput", "FooBar"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct ParameterMetaData {
|
||||
|
||||
/// Unique Parameter ID
|
||||
/// All existing parameter types must be unique
|
||||
pub upid: String,
|
||||
|
||||
/// The UI label of the parameter
|
||||
pub label: String,
|
||||
|
||||
/// The UI unit of the parameter (eg. m, s, °C, ...)
|
||||
/// Should be a string with only very few characters, can be empty
|
||||
pub unit: String,
|
||||
pub unit: Option<String>,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue