Add admin_header template to organize tabs #1156

This commit is contained in:
GrO2Bl 2024-06-12 20:24:59 +03:30
parent d004a7047b
commit d950a34b6b
6 changed files with 34 additions and 45 deletions

View file

@ -1,6 +1,6 @@
@use plume_models::instance::Instance; @use plume_models::instance::Instance;
@use validator::ValidationErrors; @use validator::ValidationErrors;
@use crate::templates::base; @use crate::templates::{base, instance::admin_header};
@use crate::template_utils::*; @use crate::template_utils::*;
@use crate::routes::instance::InstanceSettingsForm; @use crate::routes::instance::InstanceSettingsForm;
@use crate::routes::*; @use crate::routes::*;
@ -8,14 +8,7 @@
@(ctx: BaseContext, instance: Instance, form: InstanceSettingsForm, errors: ValidationErrors) @(ctx: BaseContext, instance: Instance, form: InstanceSettingsForm, errors: ValidationErrors)
@:base(ctx, i18n!(ctx.1, "Administration of {0}"; instance.name.clone()), {}, {}, { @:base(ctx, i18n!(ctx.1, "Administration of {0}"; instance.name.clone()), {}, {}, {
<h1>@i18n!(ctx.1, "Administration")</h1> @:admin_header(ctx, "Administration", 1)
@tabs(&[
(&uri!(instance::admin).to_string(), i18n!(ctx.1, "Configuration"), true),
(&uri!(instance::admin_instances: page = _).to_string(), i18n!(ctx.1, "Instances"), false),
(&uri!(instance::admin_users: page = _).to_string(), i18n!(ctx.1, "Users"), false),
(&uri!(instance::admin_email_blocklist: page=_).to_string(), i18n!(ctx.1, "Email blocklist"), false)
])
<form method="post" action="@uri!(instance::update_settings)"> <form method="post" action="@uri!(instance::update_settings)">
@(Input::new("name", i18n!(ctx.1, "Name")) @(Input::new("name", i18n!(ctx.1, "Name"))

View file

@ -0,0 +1,23 @@
@use crate::template_utils::*;
@use crate::routes::*;
@(ctx: BaseContext, title: &str, selectedTab: u8)
@if ctx.2.clone().map(|u| u.is_admin()).unwrap_or(false) {
<h1>@i18n!(ctx.1, title)</h1>
@tabs(&[
(&uri!(instance::admin).to_string(), i18n!(ctx.1, "Configuration"), if selectedTab == 1 {true} else {false}),
(&uri!(instance::admin_instances: page = _).to_string(), i18n!(ctx.1, "Instances"), if selectedTab == 2 {true} else {false}),
(&uri!(instance::admin_users: page = _).to_string(), i18n!(ctx.1, "Users"), if selectedTab == 3 {true} else {false}),
(&uri!(instance::admin_email_blocklist: page=_).to_string(), i18n!(ctx.1, "Email blocklist"), if selectedTab == 4 {true} else {false})
])
} else {
<h1>@i18n!(ctx.1, "Moderation")</h1>
@tabs(&[
(&uri!(instance::admin_instances: page = _).to_string(), i18n!(ctx.1, "Instances"), if selectedTab == 1 {true} else {false}),
(&uri!(instance::admin_users: page = _).to_string(), i18n!(ctx.1, "Users"), if selectedTab == 2 {true} else {false}),
(&uri!(instance::admin_email_blocklist: page=_).to_string(), i18n!(ctx.1, "Email blocklist"), if selectedTab == 3 {true} else {false})
])
}

View file

@ -1,15 +1,8 @@
@use crate::templates::base; @use crate::templates::{base, instance::admin_header};
@use crate::template_utils::*; @use crate::template_utils::*;
@use crate::routes::*;
@(ctx: BaseContext) @(ctx: BaseContext)
@:base(ctx, i18n!(ctx.1, "Moderation"), {}, {}, { @:base(ctx, i18n!(ctx.1, "Moderation"), {}, {}, {
<h1>@i18n!(ctx.1, "Moderation")</h1> @:admin_header(ctx, "Moderation", 0)
@tabs(&[
(&uri!(instance::admin).to_string(), i18n!(ctx.1, "Home"), true),
(&uri!(instance::admin_instances: page = _).to_string(), i18n!(ctx.1, "Instances"), false),
(&uri!(instance::admin_users: page = _).to_string(), i18n!(ctx.1, "Users"), false),
])
}) })

View file

@ -1,17 +1,11 @@
@use plume_models::blocklisted_emails::BlocklistedEmail; @use plume_models::blocklisted_emails::BlocklistedEmail;
@use crate::templates::base; @use crate::templates::{base, instance::admin_header};
@use crate::template_utils::*; @use crate::template_utils::*;
@use crate::routes::*; @use crate::routes::*;
@(ctx:BaseContext, emails: Vec<BlocklistedEmail>, page:i32, n_pages:i32) @(ctx:BaseContext, emails: Vec<BlocklistedEmail>, page:i32, n_pages:i32)
@:base(ctx, i18n!(ctx.1, "Blocklisted Emails"), {}, {}, { @:base(ctx, i18n!(ctx.1, "Blocklisted Emails"), {}, {}, {
<h1>@i18n!(ctx.1,"Blocklisted Emails")</h1> @:admin_header(ctx, "Blocklisted Emails", (if ctx.2.clone().map(|u| u.is_admin()).unwrap() {4} else {3}))
@tabs(&[
(&uri!(instance::admin).to_string(), i18n!(ctx.1, "Configuration"), false),
(&uri!(instance::admin_instances: page = _).to_string(), i18n!(ctx.1, "Instances"), false),
(&uri!(instance::admin_users: page = _).to_string(), i18n!(ctx.1, "Users"), false),
(&uri!(instance::admin_email_blocklist:page=_).to_string(), i18n!(ctx.1, "Email blocklist"), true),
])
<form method="post" action="@uri!(instance::add_email_blocklist)"> <form method="post" action="@uri!(instance::add_email_blocklist)">
@(Input::new("email_address", i18n!(ctx.1, "Email address")) @(Input::new("email_address", i18n!(ctx.1, "Email address"))
.details(i18n!(ctx.1, "The email address you wish to block. In order to block domains, you can use globbing syntax, for example '*@example.com' blocks all addresses from example.com")) .details(i18n!(ctx.1, "The email address you wish to block. In order to block domains, you can use globbing syntax, for example '*@example.com' blocks all addresses from example.com"))

View file

@ -1,19 +1,12 @@
@use plume_models::instance::Instance; @use plume_models::instance::Instance;
@use crate::templates::base; @use crate::templates::{base, instance::admin_header};
@use crate::template_utils::*; @use crate::template_utils::*;
@use crate::routes::*; @use crate::routes::*;
@(ctx: BaseContext, instance: Instance, instances: Vec<Instance>, page: i32, n_pages: i32) @(ctx: BaseContext, instance: Instance, instances: Vec<Instance>, page: i32, n_pages: i32)
@:base(ctx, i18n!(ctx.1, "Administration of {0}"; instance.name), {}, {}, { @:base(ctx, i18n!(ctx.1, "Administration of {0}"; instance.name), {}, {}, {
<h1>@i18n!(ctx.1, "Instances")</h1> @:admin_header(ctx, "Instances", (if ctx.2.clone().map(|u| u.is_admin()).unwrap() {2} else {1}))
@tabs(&[
(&uri!(instance::admin).to_string(), i18n!(ctx.1, "Configuration"), false),
(&uri!(instance::admin_instances: page = _).to_string(), i18n!(ctx.1, "Instances"), true),
(&uri!(instance::admin_users: page = _).to_string(), i18n!(ctx.1, "Users"), false),
(&uri!(instance::admin_email_blocklist:page=_).to_string(), i18n!(ctx.1, "Email blocklist"), false),
])
<div class="list"> <div class="list">
@for instance in instances { @for instance in instances {

View file

@ -1,19 +1,12 @@
@use plume_models::users::User; @use plume_models::users::User;
@use crate::templates::base; @use crate::templates::{base, instance::admin_header};
@use crate::template_utils::*; @use crate::template_utils::*;
@use crate::routes::*; @use crate::routes::*;
@(ctx: BaseContext, users: Vec<User>, user: Option<&str>, page: i32, n_pages: i32) @(ctx: BaseContext, users: Vec<User>, user: Option<&str>, page: i32, n_pages: i32)
@:base(ctx, i18n!(ctx.1, "Users"), {}, {}, { @:base(ctx, i18n!(ctx.1, "Users"), {}, {}, {
<h1>@i18n!(ctx.1, "Users")</h1> @:admin_header(ctx, "Users", (if ctx.2.clone().map(|u| u.is_admin()).unwrap() {3} else {2}))
@tabs(&[
(&uri!(instance::admin).to_string(), i18n!(ctx.1, "Configuration"), false),
(&uri!(instance::admin_instances: page = _).to_string(), i18n!(ctx.1, "Instances"), false),
(&uri!(instance::admin_users: page = _).to_string(), i18n!(ctx.1, "Users"), true),
(&uri!(instance::admin_email_blocklist: page=_).to_string(), i18n!(ctx.1, "Email blocklist"), false)
])
<form method="get" action="@uri!(instance::admin_search_users: page = _, user = user.unwrap_or_default())"> <form method="get" action="@uri!(instance::admin_search_users: page = _, user = user.unwrap_or_default())">
<header> <header>