refactor: fomatting
This commit is contained in:
parent
01cf373b98
commit
075cdc713d
@ -17,6 +17,7 @@ struct ExportQuery {
|
|||||||
area: Option<i32>,
|
area: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
struct EventExportEntry {
|
struct EventExportEntry {
|
||||||
date: String,
|
date: String,
|
||||||
weekday: String,
|
weekday: String,
|
||||||
@ -30,10 +31,13 @@ struct EventExportEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn read(pool: &PgPool) -> Result<Vec<EventExportEntry>, ApplicationError> {
|
async fn read(pool: &PgPool) -> Result<Vec<EventExportEntry>, ApplicationError> {
|
||||||
let results = query!("select
|
let results = query!(
|
||||||
|
"select
|
||||||
event.starttimestamp,
|
event.starttimestamp,
|
||||||
event.endtimestamp,
|
event.endtimestamp,
|
||||||
(event.amountofposten + event.voluntaryfuehrungsassistent::int + event.voluntarywachhabender::int) as expectedPeople,
|
event.amountofposten,
|
||||||
|
event.voluntaryfuehrungsassistent,
|
||||||
|
event.voluntarywachhabender,
|
||||||
location.name as locationName,
|
location.name as locationName,
|
||||||
event.name as eventName,
|
event.name as eventName,
|
||||||
array (
|
array (
|
||||||
@ -59,7 +63,11 @@ async fn read(pool: &PgPool) -> Result<Vec<EventExportEntry>, ApplicationError>
|
|||||||
from
|
from
|
||||||
event
|
event
|
||||||
join location on
|
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();
|
let mut entries = Vec::new();
|
||||||
|
|
||||||
@ -83,13 +91,26 @@ join location on
|
|||||||
|
|
||||||
let mut event_new: Vec<EventExportEntry> = Vec::new();
|
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 {
|
if let Some(assignments) = r.assignments {
|
||||||
for a in assignments {
|
for a in assignments {
|
||||||
let (assigned_name, assigned_function) = a.split_once("---").unwrap();
|
let (assigned_name, assigned_function) = a.split_once("---").unwrap();
|
||||||
let assigned_function = match assigned_function.trim() {
|
let assigned_function = match assigned_function.trim() {
|
||||||
"posten" => "PO",
|
"posten" => {
|
||||||
"wachhabender" => "WH",
|
assigned_posten += 1;
|
||||||
"fuehrungsassistent" => "FüAss",
|
"PO"
|
||||||
|
}
|
||||||
|
"wachhabender" => {
|
||||||
|
assigned_wachhabender = true;
|
||||||
|
"WH"
|
||||||
|
}
|
||||||
|
"fuehrungsassistent" => {
|
||||||
|
assigned_fuehrungassistent = true;
|
||||||
|
"FüAss"
|
||||||
|
}
|
||||||
_ => assigned_function.trim(),
|
_ => assigned_function.trim(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -107,9 +128,13 @@ join location on
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let expected = r.expectedpeople.unwrap_or(0) as usize;
|
if !assigned_wachhabender {
|
||||||
if event_new.len() < expected {
|
let function = if r.voluntarywachhabender {
|
||||||
for _ in 0..(expected - event_new.len()) {
|
"WH"
|
||||||
|
} else {
|
||||||
|
"BF-WH"
|
||||||
|
};
|
||||||
|
|
||||||
event_new.push(EventExportEntry {
|
event_new.push(EventExportEntry {
|
||||||
date: date.to_string(),
|
date: date.to_string(),
|
||||||
weekday: weekday.to_string(),
|
weekday: weekday.to_string(),
|
||||||
@ -119,7 +144,36 @@ join location on
|
|||||||
location: location.to_string(),
|
location: location.to_string(),
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
assigned_name: None,
|
assigned_name: None,
|
||||||
assigned_function: 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(),
|
||||||
|
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("PO".to_string()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,6 +217,20 @@ pub async fn get(
|
|||||||
// let time_format = Format::new();
|
// let time_format = Format::new();
|
||||||
// time_format.set_num_format(num_format)
|
// 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() {
|
for (i, entry) in entries.iter().enumerate() {
|
||||||
let i = (i + 3) as u32;
|
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, 2, &entry.start_time).unwrap();
|
||||||
worksheet.write(i, 3, &entry.end_time).unwrap();
|
worksheet.write(i, 3, &entry.end_time).unwrap();
|
||||||
worksheet.write(i, 4, entry.hours).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, 5, &entry.location).unwrap();
|
||||||
worksheet.write(i, 6, &entry.name).unwrap();
|
worksheet.write(i, 6, &entry.name).unwrap();
|
||||||
worksheet.write(i, 7, entry.assigned_name.as_ref()).unwrap();
|
worksheet.write(i, 7, entry.assigned_name.as_ref()).unwrap();
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<section class="section">
|
<section class="section">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h3 class="title is-3">
|
<h3 class="title is-3">
|
||||||
Veranstaltungen nach Excel (.xslx) exportieren
|
Veranstaltungen nach Excel (.xlsx) exportieren
|
||||||
</h3>
|
</h3>
|
||||||
<form action="/export/eventsdata" target="_blank">
|
<form action="/export/eventsdata" target="_blank">
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user