Merge pull request 'be able to auto populate people from planned trip' (#671) from quick-add-people-from-planned-trip into main
All checks were successful
CI/CD Pipeline / test (push) Successful in 8m54s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Successful in 6m30s

Reviewed-on: #671
This commit is contained in:
philipp 2024-08-13 23:11:00 +02:00
commit f687e18195
8 changed files with 59 additions and 8 deletions

View File

@ -773,3 +773,4 @@ function replaceStrings() {
weekday.innerHTML = weekday.innerHTML.replace("Freitag", "Markttag");
});
}

View File

@ -1,4 +1,4 @@
use chrono::NaiveDate;
use chrono::{Local, NaiveDate};
use serde::Serialize;
use sqlx::SqlitePool;
@ -164,6 +164,11 @@ WHERE trip.id=?
}
}
pub async fn get_for_today(db: &SqlitePool) -> Vec<TripWithUserAndType> {
let today = Local::now().date_naive();
Self::get_for_day(db, today).await
}
pub async fn get_for_day(db: &SqlitePool, day: NaiveDate) -> Vec<TripWithUserAndType> {
let day = format!("{day}");
let trips = sqlx::query_as!(

View File

@ -24,6 +24,7 @@ use crate::model::{
LogbookDeleteError, LogbookUpdateError,
},
logtype::LogType,
trip::Trip,
user::{AdminUser, DonauLinzUser, User, UserWithDetails, VorstandUser},
};
@ -84,6 +85,7 @@ async fn index(
}
context.insert("boats", &boats);
context.insert("planned_trips", &Trip::get_for_today(db).await);
context.insert(
"reservations",
&BoatReservation::all_future_with_groups(db).await,
@ -187,6 +189,7 @@ async fn kiosk(
context.insert("flash", &msg.into_inner());
}
context.insert("planned_trips", &Trip::get_for_today(db).await);
context.insert("boats", &boats);
context.insert(
"reservations",

View File

@ -61,7 +61,8 @@
<small class="block text-gray-600 dark:text-gray-100">
{% for role in user.roles -%}
{{ role }}
{%- if not loop.last %}, {% endif -%}
{%- if not loop.last %},
{% endif -%}
{% endfor %}
</small>
</span>

View File

@ -1,3 +1,42 @@
{% macro plannedtrips() %}
{% if planned_trips %}
<script>
function setChoiceByLabel(choicesInstance, label) {
const choices = choicesInstance.config.choices;
const normalizedLabel = label.trim().replace(/\n/g, '');
const choice = choices.find(c => {
const choiceLabel = c.label.trim().replace(/\n/g, '');
return choiceLabel === normalizedLabel;
});
if (choice) {
choicesInstance.setChoiceByValue(choice.value);
} else {
console.warn(`Choice with label "${normalizedLabel}" not found`);
}
}
</script>
<div class="bg-white dark:bg-primary-900 rounded-md shadow pb-2 mt-3">
<h2 class="h2">Heute geplante Ausfahrten</h2>
<div class="grid grid-cols-1 gap-3 mb-3 w-full">
{% for planned_trip in planned_trips | sort(attribute='planned_starting_time') %}
<div class="pt-2 px-3 border-t text-primary-900 dark:text-white">
<strong class="block">
{{ planned_trip.cox_name }} ({{ planned_trip.rower | length + 1 }} Personen)
<small>{{ planned_trip.planned_starting_time }}</small>
<button class="btn btn-primary"
onclick="choiceObjects['newrower'].removeActiveItems(-1);choiceObjects['newrower'].setChoiceByValue('{{ planned_trip.cox_id }}'); {% for rower in planned_trip.rower %}setChoiceByLabel(choiceObjects['newrower'], '{{ rower.name }}'){% endfor %} ">
👥
</button>
</strong>
</div>
{% endfor %}
</div>
</div>
{% endif %}
{% endmacro plannedtrips %}
{% macro boatreservation() %}
<div class="bg-white dark:bg-primary-900 rounded-md shadow pb-2 mt-3">
<h2 class="h2">Reservierungen ({{ reservations | length }})</h2>

View File

@ -53,6 +53,7 @@
</div>
</div>
{{ macros::boatreservation() }}
{{ macros::plannedtrips() }}
</div>
</div>
</div>

View File

@ -35,6 +35,7 @@
{% endif %}
</div>
{{ macros::boatreservation() }}
{{ macros::plannedtrips() }}
</div>
</div>
</div>