~homeworkprod/orgatalk-discord-orgateams

aeff5e66bf7fba3e58b109a2ee9c3f7bd65b0633 — Jochen Kupperschmidt a month ago 234a147
Show user count
5 files changed, 21 insertions(+), 5 deletions(-)

M CHANGELOG.md
M src/main.rs
M src/model.rs
M src/templates/index.html
M src/templating.rs
M CHANGELOG.md => CHANGELOG.md +2 -0
@@ 7,6 7,8 @@

- Fully switched to English.

- Added user count.

- Added generator and timestamp to page footer.

- Raised minimum supported Rust version to 1.76.0.

M src/main.rs => src/main.rs +13 -1
@@ 5,6 5,7 @@

use anyhow::Result;
use chrono::Utc;
use std::collections::HashSet;
use std::io::Write;
mod assembly;
mod cli;


@@ 52,7 53,18 @@ fn assemble_data(config: Config, roles: Vec<model::Role>) -> Data {
    Data {
        title: config.title,
        subtitle: config.subtitle,
        roles,
        roles: roles.clone(),
        user_count: count_users(roles),
        generated_at: Utc::now(),
    }
}

fn count_users(roles: Vec<model::Role>) -> u16 {
    let mut names = HashSet::new();
    for role in &roles {
        for name in &role.member_names {
            names.insert(name);
        }
    }
    names.len() as u16
}

M src/model.rs => src/model.rs +2 -1
@@ 16,10 16,11 @@ pub(crate) struct Data {
    pub title: String,
    pub subtitle: Option<String>,
    pub roles: Vec<Role>,
    pub user_count: u16,
    pub generated_at: DateTime<Utc>,
}

#[derive(Deserialize, Serialize, Debug)]
#[derive(Clone, Deserialize, Serialize, Debug)]
pub(crate) struct Role {
    pub name: String,
    pub member_names: Vec<String>,

M src/templates/index.html => src/templates/index.html +2 -2
@@ 41,7 41,7 @@
        margin-top: 0.25rem;
      }

      .roles-count {
      .counts {
        color: var(--dimmed);
        display: block;
        margin: 1.5rem 0 1.75rem 0;


@@ 100,7 100,7 @@
      <div class="subtitle">{{ subtitle }}</div>
      {%- endif %}

      <div class="roles-count">{{ roles|length }} {% if roles|length == 1 %}team{% else %}teams{% endif %}</div>
      <div class="counts">{{ user_count }} {% if user_count == 1 %}user{% else %}users{% endif %} in {{ roles|length }} {% if roles|length == 1 %}team{% else %}teams{% endif %}</div>

      <div class="roles">
        {%- for role in roles %}

M src/templating.rs => src/templating.rs +2 -1
@@ 25,9 25,10 @@ fn get_tera() -> &'static Tera {
/// Render roles as HTML representation.
pub(crate) fn render_html(data: Data, writer: impl Write) -> Result<()> {
    let mut context = Context::new();
    context.insert("roles", &data.roles);
    context.insert("title", &data.title);
    context.insert("subtitle", &data.subtitle);
    context.insert("roles", &data.roles);
    context.insert("user_count", &data.user_count);
    context.insert("generated_at", &data.generated_at);

    render("index.html", &context, writer)?;