Skip to main content

rumtk_web/components/
info_card.rs

1/*
2 * rumtk attempts to implement HL7 and medical protocols for interoperability in medicine.
3 * This toolkit aims to be reliable, simple, performant, and standards compliant.
4 * Copyright (C) 2025  Luis M. Santos, M.D. <lsantos@medicalmasses.com>
5 * Copyright (C) 2025  Ethan Dixon
6 * Copyright (C) 2025  MedicalMasses L.L.C. <contact@medicalmasses.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 */
21use 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}