Skip to main content

rumtk_web/components/
contact_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::defaults::SECTION_ALT;
22use crate::utils::defaults::{
23    DEFAULT_CONTACT_ITEM, DEFAULT_TEXT_ITEM, PARAMS_CSS_CLASS, PARAMS_TYPE, SECTION_CONTACT,
24};
25use crate::utils::types::{SharedAppState, TextMap, URLParams, URLPath};
26use crate::utils::DEFAULT_TEXTMAP;
27use crate::{rumtk_web_get_config, rumtk_web_get_config_string, rumtk_web_get_text_item, ComponentResult, RUMWebTemplate, DEFAULT_TEXT};
28use rumtk_core::strings::RUMString;
29
30#[derive(RUMWebTemplate, Debug)]
31#[template(
32    source = "
33        {% if custom_css_enabled %}
34            <link href='/static/components/contact_card.css' rel='stylesheet'>
35        {% endif %}
36        <div class='centered'>
37            <div class='f18 contact-card-{{ css_class }}-container'>
38                {% for (details_typ, details_data) in contact_lines %}
39                    {% if details_typ == &\"phrase\" && !details_data.is_empty() %}
40                    <p class='f14 italics' >
41                        '{{ details_data }}'
42                    </p>
43                    {% else if details_typ == &\"email\" && !details_data.is_empty() %}
44                    <p>
45                        <a href='mailto:{{ details_data }}'>{{ details_data }}</a>
46                    </p>
47                    {% else if details_typ == &\"phone\" && !details_data.is_empty() %}
48                    <p>
49                        <a href='tel:{{ details_data }}'>{{ details_data }}</a>
50                    </p>
51                    {% else if details_typ == &\"portrait\" && !details_data.is_empty() %}
52                    <img src='{{ details_data }}' alt='{{ alt }}' class='contact-card-{{ css_class }}-portrait' fetchpriority='low' loading='lazy'/>
53                    {% else if !details_data.is_empty() %}
54                    <p><strong>
55                        {{ details_data }}
56                    </strong></p>
57                    {% endif %}
58                {% endfor %}
59            </div>
60        </div>
61    ",
62    ext = "html"
63)]
64pub struct ContactCard {
65    alt: RUMString,
66    contact_lines: TextMap,
67    css_class: RUMString,
68    custom_css_enabled: bool,
69}
70
71pub fn contact_card<'a>(
72    _path_components: URLPath<'a, 'a>,
73    params: URLParams<'a>,
74    state: SharedAppState,
75) -> ComponentResult<ContactCard> {
76    let typ = rumtk_web_get_text_item!(params, PARAMS_TYPE, DEFAULT_CONTACT_ITEM);
77    let css_class = rumtk_web_get_text_item!(params, PARAMS_CSS_CLASS, DEFAULT_TEXT_ITEM).to_string();
78
79    let custom_css_enabled = rumtk_web_get_config!(state).flags.custom_css;
80
81    let text_conf = rumtk_web_get_config_string!(state, SECTION_CONTACT);
82    let contact_lines = rumtk_web_get_text_item!(&text_conf, typ, &DEFAULT_TEXTMAP).clone();
83    let alt_text = rumtk_web_get_text_item!(&contact_lines, SECTION_ALT, &*DEFAULT_TEXT).to_string();
84
85    Ok(ContactCard {
86        alt: alt_text,
87        contact_lines,
88        css_class,
89        custom_css_enabled
90    })
91}