rumtk_web/components/
portrait_card.rs1use crate::components::contact_card::{contact_card, ContactCard};
22use crate::utils::defaults::{DEFAULT_TEXT_ITEM, PARAMS_CSS_CLASS, PARAMS_SECTION, PARAMS_TYPE};
23use crate::utils::types::{SharedAppState, URLParams, URLPath};
24use crate::{rumtk_web_get_config, rumtk_web_get_config_string, rumtk_web_get_text_item, rumtk_web_params_map, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe};
25use rumtk_core::base::RUMResult;
26use rumtk_core::strings::RUMString;
27
28type PortraitGrid = Vec<Vec<ContactCard>>;
29
30#[derive(RUMWebTemplate, Debug)]
31#[template(
32 source = "
33 {% if custom_css_enabled %}
34 <link href='/static/components/portrait_card.css' rel='stylesheet'>
35 {% endif %}
36 <div class='centered twothird-width portrait-card-{{ css_class }}-container'>
37 <table>
38 <thead></thead>
39 <tbody>
40 {% for row in icon_data %}
41 <tr class='portrait-card-{{ css_class }}-row'>
42 {% for item in row %}
43 <td class='portrait-card-{{ css_class }}-item'>
44 {{item | safe}}
45 </td>
46 {% endfor %}
47 </tr>
48 {% endfor %}
49 </tbody>
50 </table>
51 </div>
52 ",
53 ext = "html"
54)]
55pub struct PortraitCard {
56 icon_data: PortraitGrid,
57 css_class: RUMString,
58 custom_css_enabled: bool,
59}
60
61impl RUMWebTemplateSafe for PortraitCard {}
62
63fn get_portrait_grid<'a>(section: &'a str, typ: &'a str, app_state: &'a SharedAppState) -> RUMResult<PortraitGrid> {
64 let text_conf = rumtk_web_get_config_string!(app_state, typ);
65
66 let mut grid = Vec::with_capacity(text_conf.len());
67 for (_r_name, r_list) in text_conf {
68 let mut grid_row = Vec::with_capacity(r_list.len());
69 for (i_name, _i_item) in r_list {
70 let item_params = rumtk_web_params_map!([
71 (PARAMS_SECTION, section),
72 (PARAMS_TYPE, i_name.as_str()),
73 ]);
74 let item = contact_card(
75 &[],
76 item_params.get_inner(),
77 app_state.clone()
78 )?;
79 grid_row.push(item);
80 }
81 grid.push(grid_row);
82 }
83 Ok(grid)
84}
85
86pub fn portrait_card<'a>(
87 _path_components: URLPath<'a, 'a>,
88 params: URLParams<'a>,
89 state: SharedAppState,
90) -> ComponentResult<PortraitCard> {
91 let section = rumtk_web_get_text_item!(params, PARAMS_SECTION, DEFAULT_TEXT_ITEM);
92 let typ = rumtk_web_get_text_item!(params, PARAMS_TYPE, DEFAULT_TEXT_ITEM);
93 let css_class = rumtk_web_get_text_item!(params, PARAMS_CSS_CLASS, DEFAULT_TEXT_ITEM).to_string();
94 let icon_data = get_portrait_grid(section, typ, &state)?;
95
96 let custom_css_enabled = rumtk_web_get_config!(state).flags.custom_css;
97
98 Ok(PortraitCard {
99 icon_data,
100 css_class,
101 custom_css_enabled
102 })
103}