feat: styling of availability input

This commit is contained in:
Max Hohlfeld 2025-05-11 20:07:05 +02:00
parent a6b12d9bf2
commit 5047530a3d
3 changed files with 29 additions and 23 deletions

View File

@ -89,6 +89,10 @@ pub fn date_c(v: &NaiveDate) -> askama::Result<String> {
Ok(v.format("%d.%m").to_string()) Ok(v.format("%d.%m").to_string())
} }
pub fn date_c_and_time(v: &NaiveDateTime) -> askama::Result<String> {
Ok(v.format("%d.%m. %H:%M").to_string())
}
pub fn time(v: &NaiveTime) -> askama::Result<String> { pub fn time(v: &NaiveTime) -> askama::Result<String> {
Ok(v.format("%H:%M").to_string()) Ok(v.format("%H:%M").to_string())
} }

View File

@ -1,4 +1,4 @@
use chrono::NaiveDateTime; use chrono::{Days, NaiveDateTime};
use garde::Validate; use garde::Validate;
use crate::{END_OF_DAY, START_OF_DAY}; use crate::{END_OF_DAY, START_OF_DAY};
@ -80,9 +80,9 @@ pub fn find_free_date_time_slots(
//println!("zeiten unified {times:?}"); //println!("zeiten unified {times:?}");
let date = times.first().unwrap().0.date(); let date = times.first().unwrap().0.date();
let date_next_day = date.checked_add_days(Days::new(1)).unwrap();
let start_of_day = date.and_time(START_OF_DAY); let start_of_day = date.and_time(START_OF_DAY);
// for now only calculate suggestions for the same day (if not add one day for end_of_Day:) let end_of_day = date_next_day.and_time(END_OF_DAY);
let end_of_day = date.and_time(END_OF_DAY);
// now times contains unified list of existing availabilities -> now calculate the "inverse" // now times contains unified list of existing availabilities -> now calculate the "inverse"

View File

@ -22,14 +22,18 @@
<p class="help">noch mögliche Zeiträume:</p> <p class="help">noch mögliche Zeiträume:</p>
<div class="tags help"> <div class="tags help">
{% for (s, e) in slot_suggestions %} {% for (s, e) in slot_suggestions %}
<span class="tag">{{ *s|dt_t }} - {{ *e|dt_t }}</span> <span class="tag">{{ *s|date_c_and_time }} - {{ *e|date_c_and_time }}</span>
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
</div> </div>
<div class="field"> <div class="field">
<input class="input" type="time" name="endtime" required {{ end|insert_time_value|safe }} <input class="input" type="time" name="endtime" required {{ end|insert_time_value|safe }}
_='on change put the value of me into #et then if (value of the previous <input/>) is greater than (value of me) then set the value of #enddate to "{{ datetomorrow }}" then add @disabled to #nextbtn then remove @disabled from #samebtn then put "{{ datetomorrow|date_c }}" into #ed end' /> _='on change put the value of me into #et
then if (value of the previous <input/>) is greater than (value of me)
then set the value of #enddate to "{{ datetomorrow }}"
then put "{{ datetomorrow|date_c }}" into #ed
end' />
</div> </div>
</div> </div>
</div> </div>
@ -41,20 +45,21 @@
<div class="field-body"> <div class="field-body">
<div class="field is-narrow"> <div class="field is-narrow">
{% let is_overnight = enddate.is_some() && enddate.as_ref().unwrap() == datetomorrow|ref %} {% let is_overnight = enddate.is_some() && enddate.as_ref().unwrap() == datetomorrow|ref %}
<button id="samebtn" class="button is-small is-success is-light" type="button" <div class="control">
{{ is_overnight|invert|ref|cond_show("disabled")|safe }} <label class="radio">
_='on click set the value of #enddate to "{{ date }}" then toggle @disabled on me then toggle @disabled on #nextbtn then put "{{ date|date_c }}" into #ed'>am <input type="radio" name="isovernight" {{ is_overnight|invert|ref|cond_show("checked")|safe }}
selben Tag</button> _='on click set the value of #enddate to "{{ date }}" then put "{{ date|date_c }}" into #ed'>
</div> am selben Tag
<div class="field is-narrow"> </label>
<button id="nextbtn" class="button is-small is-info is-light" type="button" <label class="radio ml-3">
{{ is_overnight|cond_show("disabled")|safe }} <input type="radio" name="isovernight" {{ is_overnight|cond_show("checked")|safe }}
_='on click set the value of #enddate to "{{ datetomorrow }}" then toggle @disabled on me then toggle @disabled on #samebtn then put "{{ datetomorrow|date_c }}" into #ed'>am _='on click set the value of #enddate to "{{ datetomorrow }}" then put "{{ datetomorrow|date_c }}" into #ed'>
Tag darauf</button> am Tag darauf
</label>
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="field is-horizontal"> <div class="field is-horizontal">
<div class="field-label"> <div class="field-label">
@ -67,6 +72,9 @@
comment.unwrap_or("") }}</textarea> comment.unwrap_or("") }}</textarea>
</div> </div>
<p class="help is-info"> <p class="help is-info">
<svg class="icon is-small">
<use href="/static/feather-sprite.svg#info" />
</svg>
verfügbar von {{ date|date_c }} <span id="st">{{ start|time_opt("10:00")|safe }}</span> Uhr verfügbar von {{ date|date_c }} <span id="st">{{ start|time_opt("10:00")|safe }}</span> Uhr
bis <span id="ed">{{ enddate.as_ref().unwrap_or(date)|date_c }}</span> bis <span id="ed">{{ enddate.as_ref().unwrap_or(date)|date_c }}</span>
<span id="et">{{ end|time_opt("20:00")|safe }}</span> Uhr <span id="et">{{ end|time_opt("20:00")|safe }}</span> Uhr
@ -84,13 +92,7 @@
<svg class="icon"> <svg class="icon">
<use href="/static/feather-sprite.svg#check-circle" /> <use href="/static/feather-sprite.svg#check-circle" />
</svg> </svg>
<span> <span>{% if is_edit %}Speichern{% else %}Erstellen{% endif %}</span>
{% if id.is_some() %}
Speichern
{% else %}
Erstellen
{% endif %}
</span>
</button> </button>
</div> </div>
<div class="control"> <div class="control">