rumtk_web/components/
info_card.rs1use crate::utils::defaults::{
22 DEFAULT_NO_TEXT, DEFAULT_TEXT_ITEM, OPT_INVERTED_DIRECTION, PARAMS_CSS_CLASS, PARAMS_INVERTED,
23 PARAMS_ITEM, SECTION_TEXT,
24};
25use crate::utils::types::{SharedAppState, URLParams, URLPath};
26use crate::utils::DEFAULT_TEXTMAP;
27use crate::{rumtk_web_get_config, rumtk_web_get_config_string, rumtk_web_get_param_eq, rumtk_web_get_text_item, ComponentResult, RUMWebTemplate};
28use rumtk_core::strings::RUMString;
29
30#[derive(RUMWebTemplate, Debug, Clone)]
31#[template(
32 source = "
33 {% if custom_css_enabled %}
34 <link href='/static/components/info_card.css' rel='stylesheet'>
35 {% endif %}
36 <div class='info-card-{{ css_class }}-container'>
37 {% if inverted %}
38 <pre class='f18 info-card-{{ css_class }}-descbox'>{{ description }}</pre>
39 <div class='f22 info-card-{{ css_class }}-titlebox'>{{ title }}</div>
40 {% else %}
41 <div class='f22 info-card-{{ css_class }}-titlebox'>{{ title }}</div>
42 <pre class='f18 info-card-{{ css_class }}-descbox'>{{ description }}</pre>
43 {% endif %}
44 </div>
45 ",
46 ext = "html"
47)]
48pub struct InfoCard {
49 title: RUMString,
50 description: RUMString,
51 inverted: bool,
52 css_class: RUMString,
53 custom_css_enabled: bool,
54}
55
56pub fn info_card<'a>(
57 _path_components: URLPath<'a, 'a>,
58 params: URLParams<'a>,
59 state: SharedAppState,
60) -> ComponentResult<InfoCard> {
61 let card_text_item = rumtk_web_get_text_item!(params, PARAMS_ITEM, DEFAULT_TEXT_ITEM);
62 let inverted = rumtk_web_get_param_eq!(params, PARAMS_INVERTED, OPT_INVERTED_DIRECTION, false);
63 let css_class = rumtk_web_get_text_item!(params, PARAMS_CSS_CLASS, DEFAULT_TEXT_ITEM).to_string();
64
65 let custom_css_enabled = rumtk_web_get_config!(state).flags.custom_css;
66
67 let text_store = rumtk_web_get_config_string!(state, SECTION_TEXT);
68 let itm = rumtk_web_get_text_item!(&text_store, card_text_item, &DEFAULT_TEXTMAP);
69 let title = rumtk_web_get_text_item!(&itm, "title", DEFAULT_NO_TEXT).to_string();
70 let desc = rumtk_web_get_text_item!(&itm, "description", DEFAULT_NO_TEXT).to_string();
71
72 Ok(InfoCard {
73 title,
74 description: desc,
75 inverted,
76 css_class,
77 custom_css_enabled
78 })
79}