admin functionality

This commit is contained in:
Priec
2026-05-16 17:21:14 +02:00
parent 7220ec87bc
commit 70920ede87
5 changed files with 48 additions and 2 deletions

View File

@@ -86,6 +86,9 @@ pub struct CalendarPage {
pub prev_week: String,
pub this_week: String,
pub next_week: String,
/// `false` on the public calendar once it reaches the two-week look-back
/// limit, which disables the "previous week" button. Always `true` for admin.
pub can_prev: bool,
pub days: Vec<DayHead>,
pub rows: Vec<Row>,
}
@@ -185,6 +188,10 @@ pub async fn build_calendar(
.unwrap_or_default();
let monday = week_monday(q_week.as_deref());
// The public calendar may look back at most two weeks; the admin has no limit.
let min_monday = monday_of(Utc::now().date_naive()) - Duration::weeks(2);
let monday = if is_admin { monday } else { monday.max(min_monday) };
let can_prev = is_admin || monday > min_monday;
let sunday = monday + Duration::days(6);
let days: Vec<DayHead> = (0..7i64)
@@ -269,6 +276,7 @@ pub async fn build_calendar(
.format("%Y-%m-%d")
.to_string(),
next_week: (monday + Duration::days(7)).format("%Y-%m-%d").to_string(),
can_prev,
days,
rows,
})