//! Markup of the structure and people pages: projects (`/tags`), columns (`/columns`), the members, limits //! and server sections of `/settings`, and the person card (`/people/{sub}`). Plain data in, markup out. //! Every value is escaped by `view!`; no script or inline style is emitted. use topcoat::Result; use topcoat::view::{View, component, view}; use crate::i18n::Lang; use crate::i18n::admin::fill; use crate::i18n::structure::{K, t}; use crate::views::admin::admin_tabs; use crate::views::board::flag; use crate::views::{alert, notice}; /// One project as the tags page shows it. #[derive(Debug, Clone)] pub struct TagRow { /// Project id. pub id: String, /// Project name. pub name: String, /// Palette colour name (`c0` to `c7`), if set. pub colour: Option, /// Whether this is the default project. pub is_default: bool, /// Live cards in the project. pub uses: i64, } /// The tags page: the list, the add form, and the palette. #[derive(Debug, Clone)] pub struct TagsView { /// The language. pub lang: Lang, /// Projects in board order. pub tags: Vec, /// The palette colour names, in order. pub palette: Vec, /// A confirmation, already translated. pub notice: Option, /// A refusal, already translated or a store message. pub alert: Option, } /// One column as the columns page shows it. #[derive(Debug, Clone)] pub struct ColumnRow { /// Column id. pub id: String, /// Column name. pub name: String, /// Whether this is the done column. pub is_done: bool, /// Live cards in the column. pub cards: i64, } /// The columns page: the list in board order and the add form. #[derive(Debug, Clone)] pub struct ColumnsView { /// The language. pub lang: Lang, /// Live columns in board order. pub columns: Vec, /// A confirmation, already translated. pub notice: Option, /// A refusal, already translated or a store message. pub alert: Option, } /// One member as the settings page shows them. #[derive(Debug, Clone)] pub struct MemberRow { /// Member id (the OIDC `sub`). pub sub: String, /// Display name. pub name: String, /// Address. pub email: String, /// Stored role: `admin`, `member`, `viewer` or `none`. pub role: String, /// The directory marks this person as an administrator. pub im_admin: bool, /// The directory has disabled this person. pub disabled: bool, } /// Read-only facts about the running server. #[derive(Debug, Clone, Default)] pub struct ServerInfo { /// The public base address. pub base_url: String, /// The listen address. pub listen: String, /// The data directory. pub data_dir: String, /// The database file. pub database: String, /// The highest applied migration. pub schema: i64, /// The build id. pub build: String, /// Whether sign-in through im is configured. pub sign_in: bool, /// Whether attachments go to the Files service. pub storage_in: bool, } /// Where attachments are kept, and how far a move between the two places has got. Read from the store for the /// settings page; `in_available` says whether the Files service can be chosen at all. #[derive(Debug, Clone, Default)] pub struct StorageInfo { /// The chosen place: `local` or `in`. pub target: String, /// Whether the Files service is set up (configured, and a token can be had). pub in_available: bool, /// Rows whose bytes are on this server. pub local: i64, /// Rows whose bytes are in the Files service. pub in_files: i64, /// Rows being moved right now. pub moving: i64, } /// The attachment storage section of `/settings`: the chosen place, the counts, and the migration still to do. #[component] pub async fn storage_section(lang: Lang, info: &StorageInfo, csrf: &str) -> Result { let in_chosen = info.target == "in"; let counts = fill( t(lang, K::StorageCounts), &[ &info.local.to_string(), &info.in_files.to_string(), &info.moving.to_string(), ], ); // Rows not yet where the setting says: the ones the mover still has to bring over, plus any mid-move. let waiting = if in_chosen { info.local + info.moving } else { info.in_files + info.moving }; let target_word = if in_chosen { t(lang, K::StorageIn) } else { t(lang, K::StorageLocal) }; let migrating = (waiting > 0).then(|| { fill( t(lang, K::StorageMigrating), &[&waiting.to_string(), target_word], ) }); Ok(view! {

(t(lang, K::StorageHeading))

(t(lang, K::StorageHelp))

(counts.as_str())

if let Some(line) = &migrating {

(line.as_str())

}
if !info.in_available {

(t(lang, K::StorageInUnavailable))

}
}) } /// The projects page body. #[component] pub async fn tags_content(page: &TagsView, csrf: &str) -> Result { let lang = page.lang; Ok(view! {

(t(lang, K::TagsTitle))

admin_tabs(lang: lang, current: "tags") if let Some(message) = &page.alert { alert(message: message.as_str()) } if let Some(message) = &page.notice { notice(message: message.as_str()) }

(t(lang, K::TagsHelp))

for tag in page.tags.iter() { }
" " (tag.name.as_str()) if tag.is_default { " " (t(lang, K::TagDefault)) } " " (fill(t(lang, K::TagUsedBy), &[&tag.uses.to_string()]))
if !tag.is_default {
}

(t(lang, K::TagsNew))

}) } /// The columns page body. #[component] pub async fn columns_content(page: &ColumnsView, csrf: &str) -> Result { let lang = page.lang; Ok(view! {

(t(lang, K::ColumnsTitle))

admin_tabs(lang: lang, current: "columns") if let Some(message) = &page.alert { alert(message: message.as_str()) } if let Some(message) = &page.notice { notice(message: message.as_str()) }

(t(lang, K::ColumnsHelp))

for column in page.columns.iter() { }
(column.name.as_str()) if column.is_done { " " (t(lang, K::ColumnDone)) } " " (fill(t(lang, K::ColumnCards), &[&column.cards.to_string()]))
if !column.is_done {
}

(t(lang, K::ColumnsNew))

}) } /// The members and roles section of `/settings`. One row per member, each with its own role form. #[component] pub async fn members_section(lang: Lang, members: &[MemberRow], csrf: &str) -> Result { Ok(view! {

(t(lang, K::MembersHeading))

(t(lang, K::MembersHelp))

for member in members.iter() { }
(t(lang, K::MemberName)) (t(lang, K::MemberEmail)) (t(lang, K::MemberFlags)) (t(lang, K::MemberRole))
(member.name.as_str()) (member.email.as_str()) if member.im_admin { (t(lang, K::MemberImAdmin)) } if member.disabled { (t(lang, K::MemberDisabled)) } if member.im_admin { (t(lang, K::RoleAdmin)) } else {
}
}) } /// The limits section of `/settings`: attachment size and allowed extensions. #[component] pub async fn limits_section( lang: Lang, limit_mib: &str, extensions: &str, csrf: &str, ) -> Result { Ok(view! {

(t(lang, K::LimitsHeading))

(t(lang, K::LimitsHelp))

}) } /// The server section of `/settings`: read-only facts. #[component] pub async fn server_section(lang: Lang, info: &ServerInfo) -> Result { let (on_text, off_text) = (t(lang, K::On), t(lang, K::Off)); let storage = if info.storage_in { t(lang, K::StorageIn) } else { t(lang, K::StorageLocal) }; let schema = info.schema.to_string(); Ok(view! {

(t(lang, K::ServerHeading))

(t(lang, K::ServerHelp))

(t(lang, K::ServerBase))
(info.base_url.as_str())
(t(lang, K::ServerListen))
(info.listen.as_str())
(t(lang, K::ServerData))
(info.data_dir.as_str())
(t(lang, K::ServerDatabase))
(info.database.as_str())
(t(lang, K::ServerSchema))
(schema.as_str())
(t(lang, K::ServerBuild))
(info.build.as_str())
(t(lang, K::ServerSignIn))
(if info.sign_in { on_text } else { off_text })
(t(lang, K::ServerStorage))
(storage)
}) } /// The person card body: name, role and zone, counts, and the recent activity of this member on the board. #[component] pub async fn person_content( lang: Lang, name: &str, role: &str, zone: &str, last_sign_in: &str, counts: &[(&'static str, String)], recent: &[(String, String, String)], ) -> Result { let role_line = fill(t(lang, K::PersonRole), &[role]); Ok(view! {

(name)

(role_line.as_str())

for (label, value) in counts.iter() {
(*label)
(value.as_str())
}
(t(lang, K::PersonZone))
(zone)
(t(lang, K::PersonLastSignIn))
(last_sign_in)

(t(lang, K::PersonRecent))

if recent.is_empty() {

(t(lang, K::PersonNoActivity))

}
    for (when, sentence, task) in recent.iter() {
  • " " (sentence.as_str()) " " (task.as_str())
  • }

(t(lang, K::PersonBack))

}) }