Skip to main content

rumtk_web/components/app/
navlink.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::{DEFAULT_HOME_PAGE, DEFAULT_HOME_PAGE_URL, PARAMS_TITLE};
22use crate::utils::defaults::{DEFAULT_TEXT_ITEM, PARAMS_CSS_CLASS, PARAMS_TARGET};
23use crate::utils::types::{RUMString, SharedAppState, URLParams, URLPath};
24use crate::{rumtk_web_get_config, rumtk_web_get_text_item, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe};
25
26#[derive(Debug, Clone)]
27struct NavItem {
28    title: RUMString,
29    url: RUMString,
30}
31
32#[derive(RUMWebTemplate, Debug, Clone)]
33#[template(
34    source = "
35        {% if custom_css_enabled %}
36            <link href='/static/components/navlink.css' rel='stylesheet'>
37        {% endif %}
38        <a class='undecorated navlink f16 navlink-{{css_class}}' href='{{target.url}}'>{{target.title|capitalize}}</a>
39    ",
40    ext = "html"
41)]
42pub struct NavLink {
43    target: NavItem,
44    css_class: RUMString,
45    custom_css_enabled: bool,
46}
47
48impl RUMWebTemplateSafe for NavLink {}
49
50pub fn navlink<'a>(_path_components: URLPath<'a, 'a>, params: URLParams<'a>, state: SharedAppState) -> ComponentResult<NavLink> {
51    let title = rumtk_web_get_text_item!(params, PARAMS_TITLE, DEFAULT_HOME_PAGE).to_string();
52    let url = rumtk_web_get_text_item!(params, PARAMS_TARGET, DEFAULT_HOME_PAGE_URL).to_string();
53    let css_class = rumtk_web_get_text_item!(params, PARAMS_CSS_CLASS, DEFAULT_TEXT_ITEM).to_string();
54
55    let custom_css_enabled = rumtk_web_get_config!(state).flags.custom_css;
56
57    Ok(NavLink {
58        target: NavItem { title, url },
59        css_class: RUMString::from(css_class),
60        custom_css_enabled
61    })
62}