diff --git a/web/src/endpoints/availability/get_overview.rs b/web/src/endpoints/availability/get_overview.rs index f6ff33f2..800b5ea9 100644 --- a/web/src/endpoints/availability/get_overview.rs +++ b/web/src/endpoints/availability/get_overview.rs @@ -1,18 +1,19 @@ -use crate::{ - filters, - models::{find_free_date_time_slots, Assignment, Function, Vehicle}, - utils::{ - event_planning_template::generate_vehicles_assigned_and_available, ApplicationError, - TemplateResponse, - }, -}; use actix_web::{web, HttpResponse, Responder}; use askama::Template; use chrono::{NaiveDate, Utc}; use serde::Deserialize; use sqlx::PgPool; -use crate::models::{Area, Availability, Event, Role, User}; +use crate::filters; +use crate::models::{ + find_free_date_time_slots, Area, Assignment, Availability, Event, Function, Role, User, Vehicle, +}; +use crate::utils::{ + event_planning_template::generate_vehicles_assigned_and_available, + ApplicationError, + DateTimeFormat::{DayMonthYear, DayMonthYearHourMinute, HourMinute}, + TemplateResponse, +}; #[derive(Deserialize)] pub struct CalendarQuery { diff --git a/web/src/endpoints/availability/mod.rs b/web/src/endpoints/availability/mod.rs index 224b3e9c..155ee7d6 100644 --- a/web/src/endpoints/availability/mod.rs +++ b/web/src/endpoints/availability/mod.rs @@ -1,9 +1,10 @@ -use crate::filters; use askama::Template; use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use serde::Deserialize; +use crate::filters; use crate::models::{Availability, AvailabilityChangeset, Role, User}; +use crate::utils::DateTimeFormat::{DayMonth, DayMonthYear, DayMonthYearHourMinute}; pub mod delete; pub mod get_new; @@ -23,7 +24,7 @@ struct NewOrEditAvailabilityTemplate<'a> { end: Option, comment: Option<&'a str>, slot_suggestions: Vec<(NaiveDateTime, NaiveDateTime)>, - datetomorrow: NaiveDate + datetomorrow: NaiveDate, } #[derive(Deserialize)] diff --git a/web/src/endpoints/events/mod.rs b/web/src/endpoints/events/mod.rs index 0eb2a67c..aa39db3a 100644 --- a/web/src/endpoints/events/mod.rs +++ b/web/src/endpoints/events/mod.rs @@ -1,10 +1,11 @@ -use crate::filters; use askama::Template; use chrono::{Days, NaiveDateTime}; use chrono::{NaiveDate, NaiveTime}; use serde::Deserialize; +use crate::filters; use crate::models::{Location, Role, User}; +use crate::utils::DateTimeFormat::{DayMonthYear, HourMinute, YearMonthDayTHourMinute}; pub mod delete; pub mod get_edit; diff --git a/web/src/filters.rs b/web/src/filters.rs index 7bb8bfbe..c573273a 100644 --- a/web/src/filters.rs +++ b/web/src/filters.rs @@ -3,7 +3,7 @@ use std::fmt::Display; use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use maud::html; -use crate::models::UserFunction; +use crate::{models::UserFunction, utils::DateTimeFormat}; pub fn show_area_query(a: &Option, first: bool) -> askama::Result { let char = if first { '?' } else { '&' }; @@ -73,38 +73,14 @@ pub fn show_tree(f: &UserFunction) -> askama::Result { Ok(html.into_string()) } -pub fn dt_f(v: &NaiveDateTime) -> askama::Result { - Ok(v.format("%Y-%m-%dT%H:%M").to_string()) +pub fn fmt_date(v: &NaiveDate, format: DateTimeFormat) -> askama::Result { + Ok(v.format(format.into()).to_string()) } -pub fn dt_ff(v: &NaiveDateTime) -> askama::Result { - Ok(v.format("%d.%m.%Y %H:%M").to_string()) +pub fn fmt_datetime(v: &NaiveDateTime, format: DateTimeFormat) -> askama::Result { + Ok(v.format(format.into()).to_string()) } -pub fn date_d(v: &NaiveDate) -> askama::Result { - Ok(v.format("%d.%m.%Y").to_string()) -} - -pub fn date_c(v: &NaiveDate) -> askama::Result { - Ok(v.format("%d.%m").to_string()) -} - -pub fn date_c_and_time(v: &NaiveDateTime) -> askama::Result { - Ok(v.format("%d.%m. %H:%M").to_string()) -} - -pub fn time(v: &NaiveTime) -> askama::Result { - Ok(v.format("%H:%M").to_string()) -} - -pub fn time_opt(v: &Option, default: &str) -> askama::Result { - if let Some(t) = v { - return time(t); - } - - Ok(default.to_string()) -} - -pub fn dt_t(v: &NaiveDateTime) -> askama::Result { - Ok(v.format("%R").to_string()) +pub fn fmt_time(v: &NaiveTime, format: DateTimeFormat) -> askama::Result { + Ok(v.format(format.into()).to_string()) } diff --git a/web/src/utils/date_time_format.rs b/web/src/utils/date_time_format.rs new file mode 100644 index 00000000..6b7b7c88 --- /dev/null +++ b/web/src/utils/date_time_format.rs @@ -0,0 +1,21 @@ +pub enum DateTimeFormat { + DayMonth, + DayMonthHourMinute, + DayMonthYear, + DayMonthYearHourMinute, + YearMonthDayTHourMinute, + HourMinute +} + +impl From for &'static str { + fn from(value: DateTimeFormat) -> Self { + match value { + DateTimeFormat::DayMonth => "%d.%m.", + DateTimeFormat::DayMonthHourMinute => "%d.%m. %H:%M", + DateTimeFormat::DayMonthYear => "%d.%m.%Y", + DateTimeFormat::DayMonthYearHourMinute => "%d.%m.%Y %H:%M", + DateTimeFormat::YearMonthDayTHourMinute => "%Y-%m-%dT%H:%M", + DateTimeFormat::HourMinute => "%H:%M" // equivalent to %R, + } + } +} diff --git a/web/src/utils/mod.rs b/web/src/utils/mod.rs index 9d28b76f..f848a788 100644 --- a/web/src/utils/mod.rs +++ b/web/src/utils/mod.rs @@ -1,5 +1,6 @@ mod application_error; pub mod auth; +mod date_time_format; pub mod event_planning_template; pub mod manage_commands; pub mod password_change; @@ -10,10 +11,11 @@ pub mod token_generation; pub mod test_helper; pub use application_error::ApplicationError; -use chrono::{NaiveDate, Utc}; - +pub use date_time_format::DateTimeFormat; pub use template_response_trait::TemplateResponse; +use chrono::{NaiveDate, Utc}; + pub fn get_return_url_for_date(date: &NaiveDate) -> String { let today = Utc::now().date_naive(); if date == &today { diff --git a/web/templates/availability/new_or_edit.html b/web/templates/availability/new_or_edit.html index c137b672..90cdea46 100644 --- a/web/templates/availability/new_or_edit.html +++ b/web/templates/availability/new_or_edit.html @@ -5,7 +5,8 @@
{% let is_edit = id.is_some() %}
-

{% if is_edit %}Bearbeite{% else %}Neue{% endif %} Vefügbarkeit für den {{ date|date_d }}

+

{% if is_edit %}Bearbeite{% else %}Neue{% endif %} Vefügbarkeit für den {{ + date|fmt_date(DayMonthYear) }}

@@ -22,7 +23,8 @@

noch mögliche Zeiträume:

{% for (s, e) in slot_suggestions %} - {{ *s|date_c_and_time }} - {{ *e|date_c_and_time }} + {{ s|fmt_datetime(DayMonthYearHourMinute) }} - + {{ e|fmt_datetime(DayMonthYearHourMinute) }} {% endfor %}
{% endif %} @@ -32,7 +34,7 @@ _='on change put the value of me into #et then if (value of the previous ) is greater than (value of me) then set the value of #enddate to "{{ datetomorrow }}" - then put "{{ datetomorrow|date_c }}" into #ed + then put "{{ datetomorrow|fmt_date(DayMonth) }}" into #ed end' />
@@ -48,12 +50,14 @@
@@ -75,9 +79,11 @@ - verfügbar von {{ date|date_c }} {{ start|time_opt("10:00")|safe }} Uhr - bis {{ enddate.as_ref().unwrap_or(date)|date_c }} - {{ end|time_opt("20:00")|safe }} Uhr + {% let start_time = start.unwrap_or(NaiveTime::from_hms_opt(10, 0, 0).unwrap()) %} + {% let end_time = start.unwrap_or(NaiveTime::from_hms_opt(20, 0, 0).unwrap()) %} + verfügbar von {{ date|fmt_date(DayMonth) }} {{ start_time|fmt_time(DayMonth) }} Uhr + bis {{ enddate.as_ref().unwrap_or(date)|fmt_date(DayMonth) }} + {{ end_time|fmt_time(DayMonth) }} Uhr

diff --git a/web/templates/events/new_or_edit.html b/web/templates/events/new_or_edit.html index 37349b6b..40354fe3 100644 --- a/web/templates/events/new_or_edit.html +++ b/web/templates/events/new_or_edit.html @@ -7,7 +7,7 @@ {% if let Some(name) = name %}

Event '{{ name }}' bearbeiten

{% else %} -

Neues Event anlegen für den {{ date|date_d }}

+

Neues Event anlegen für den {{ date|fmt_date(DayMonthYear) }}

{% endif %} @@ -74,12 +74,12 @@
+ value="{{ start|fmt_time(HourMinute) }}" {{ canceled|cond_show("disabled") }} />
{% let tomorrow = date.checked_add_days(Days::new(1)).unwrap() %}
diff --git a/web/templates/index.html b/web/templates/index.html index 6278cd67..4a1e866b 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -7,7 +7,7 @@
+ href="/?date={{ date.pred() }}{{ selected_area|show_area_query(false) }}"> @@ -16,7 +16,7 @@