refactor: fomatting

This commit is contained in:
Max Hohlfeld 2025-05-31 22:41:39 +02:00
parent 01cf373b98
commit 075cdc713d
2 changed files with 82 additions and 11 deletions

View File

@ -17,6 +17,7 @@ struct ExportQuery {
area: Option<i32>,
}
#[derive(PartialEq)]
struct EventExportEntry {
date: String,
weekday: String,
@ -30,10 +31,13 @@ struct EventExportEntry {
}
async fn read(pool: &PgPool) -> Result<Vec<EventExportEntry>, ApplicationError> {
let results = query!("select
let results = query!(
"select
event.starttimestamp,
event.endtimestamp,
(event.amountofposten + event.voluntaryfuehrungsassistent::int + event.voluntarywachhabender::int) as expectedPeople,
event.amountofposten,
event.voluntaryfuehrungsassistent,
event.voluntarywachhabender,
location.name as locationName,
event.name as eventName,
array (
@ -59,7 +63,11 @@ async fn read(pool: &PgPool) -> Result<Vec<EventExportEntry>, ApplicationError>
from
event
join location on
event.locationId = location.id").fetch_all(pool).await?;
event.locationId = location.id
order by event.starttimestamp"
)
.fetch_all(pool)
.await?;
let mut entries = Vec::new();
@ -83,13 +91,26 @@ join location on
let mut event_new: Vec<EventExportEntry> = Vec::new();
let mut assigned_posten: i16 = 0;
let mut assigned_wachhabender = false;
let mut assigned_fuehrungassistent = false;
if let Some(assignments) = r.assignments {
for a in assignments {
let (assigned_name, assigned_function) = a.split_once("---").unwrap();
let assigned_function = match assigned_function.trim() {
"posten" => "PO",
"wachhabender" => "WH",
"fuehrungsassistent" => "FüAss",
"posten" => {
assigned_posten += 1;
"PO"
}
"wachhabender" => {
assigned_wachhabender = true;
"WH"
}
"fuehrungsassistent" => {
assigned_fuehrungassistent = true;
"FüAss"
}
_ => assigned_function.trim(),
};
@ -107,9 +128,42 @@ join location on
}
}
let expected = r.expectedpeople.unwrap_or(0) as usize;
if event_new.len() < expected {
for _ in 0..(expected - event_new.len()) {
if !assigned_wachhabender {
let function = if r.voluntarywachhabender {
"WH"
} else {
"BF-WH"
};
event_new.push(EventExportEntry {
date: date.to_string(),
weekday: weekday.to_string(),
start_time: start_time.to_string(),
end_time: end_time.to_string(),
hours,
location: location.to_string(),
name: name.to_string(),
assigned_name: None,
assigned_function: Some(function.to_string()),
});
}
if !assigned_fuehrungassistent && r.voluntaryfuehrungsassistent {
event_new.push(EventExportEntry {
date: date.to_string(),
weekday: weekday.to_string(),
start_time: start_time.to_string(),
end_time: end_time.to_string(),
hours,
location: location.to_string(),
name: name.to_string(),
assigned_name: None,
assigned_function: Some("FüAss".to_string()),
});
}
if assigned_posten < r.amountofposten {
for _ in 0..(r.amountofposten - assigned_posten) {
event_new.push(EventExportEntry {
date: date.to_string(),
weekday: weekday.to_string(),
@ -119,7 +173,7 @@ join location on
location: location.to_string(),
name: name.to_string(),
assigned_name: None,
assigned_function: None,
assigned_function: Some("PO".to_string()),
});
}
}
@ -163,6 +217,20 @@ pub async fn get(
// let time_format = Format::new();
// time_format.set_num_format(num_format)
const HEADER: [&str; 10] = [
"Datum",
"Wochentag",
"Beginn",
"Ende",
"Stunden",
"Ort",
"VA",
"Namen",
"Fkt",
"Reserve",
];
worksheet.write_row(2, 0, HEADER).unwrap();
for (i, entry) in entries.iter().enumerate() {
let i = (i + 3) as u32;
@ -171,6 +239,9 @@ pub async fn get(
worksheet.write(i, 2, &entry.start_time).unwrap();
worksheet.write(i, 3, &entry.end_time).unwrap();
worksheet.write(i, 4, entry.hours).unwrap();
worksheet
.write(i, 4, format!("{:.1}", entry.hours))
.unwrap();
worksheet.write(i, 5, &entry.location).unwrap();
worksheet.write(i, 6, &entry.name).unwrap();
worksheet.write(i, 7, entry.assigned_name.as_ref()).unwrap();

View File

@ -4,7 +4,7 @@
<section class="section">
<div class="container">
<h3 class="title is-3">
Veranstaltungen nach Excel (.xslx) exportieren
Veranstaltungen nach Excel (.xlsx) exportieren
</h3>
<form action="/export/eventsdata" target="_blank">