feat: export events ui

This commit is contained in:
Max Hohlfeld 2025-05-25 19:31:16 +02:00
parent 1c4eb6ba83
commit 4af004456f
6 changed files with 134 additions and 0 deletions

View File

@ -0,0 +1,48 @@
use actix_web::{web, Responder};
use askama::Template;
use chrono::{Datelike, NaiveDate, Utc};
use sqlx::PgPool;
use crate::{
models::{Area, Role, User},
utils::{ApplicationError, TemplateResponse},
};
#[derive(Template)]
#[template(path = "export/events.html")]
struct EventExportTemplate {
user: User,
areas: Option<Vec<Area>>,
daterange: (NaiveDate, NaiveDate),
}
#[actix_web::get("/export/events")]
pub async fn get(
user: web::ReqData<User>,
pool: web::Data<PgPool>,
) -> Result<impl Responder, ApplicationError> {
if user.role != Role::Admin && user.role != Role::AreaManager {
return Err(ApplicationError::Unauthorized);
}
let areas = if user.role == Role::Admin {
Some(Area::read_all(pool.get_ref()).await?)
} else {
None
};
let today = Utc::now().date_naive();
let start = NaiveDate::from_ymd_opt(today.year(), today.month0() + 1, 1).unwrap();
let end = NaiveDate::from_ymd_opt(today.year(), today.month0() + 2, 1)
.unwrap()
.pred_opt()
.unwrap();
let template = EventExportTemplate {
user: user.into_inner(),
areas,
daterange: (start, end),
};
Ok(template.to_response()?)
}

View File

@ -0,0 +1,29 @@
use actix_web::{web, HttpResponse, Responder};
use chrono::NaiveDate;
use serde::Deserialize;
use sqlx::PgPool;
use crate::{
models::{Role, User},
utils::ApplicationError,
};
#[derive(Deserialize)]
struct ExportQuery {
start: NaiveDate,
end: NaiveDate,
area: Option<i32>,
}
#[actix_web::get("/export/eventsdata")]
pub async fn get(
pool: web::Data<PgPool>,
user: web::ReqData<User>,
query: web::Query<ExportQuery>,
) -> Result<impl Responder, ApplicationError> {
if user.role != Role::Admin && user.role != Role::AreaManager {
return Err(ApplicationError::Unauthorized);
}
Ok(HttpResponse::BadRequest().finish())
}

View File

@ -1,2 +1,4 @@
pub mod get_availability; pub mod get_availability;
pub mod get_availability_data; pub mod get_availability_data;
pub mod get_events;
pub mod get_events_data;

View File

@ -81,6 +81,8 @@ pub fn init(cfg: &mut ServiceConfig) {
cfg.service(export::get_availability::get); cfg.service(export::get_availability::get);
cfg.service(export::get_availability_data::get); cfg.service(export::get_availability_data::get);
cfg.service(export::get_events::get);
cfg.service(export::get_events_data::get);
cfg.service(imprint::get_imprint); cfg.service(imprint::get_imprint);

View File

@ -0,0 +1,49 @@
{% extends "nav.html" %}
{% block content %}
<section class="section">
<div class="container">
<h3 class="title is-3">
Veranstaltungen nach Excel (.xslx) exportieren
</h3>
<form action="/export/eventsdata" target="_blank">
<div class="field">
<label class="label">Zeitraum Start</label>
<div class="control">
<input class="input" type="date" name="start" required value="{{ daterange.0 }}" />
</div>
<div class="tags help">
<span class="tag">aktueller Monat</span>
<span class="tag">nächster Monat</span>
<span class="tag">aktuelles Quartal</span>
<span class="tag">nächstes Quartal</span>
</div>
</div>
<div class="field">
<label class="label">Zeitraum Ende</label>
<div class="control">
<input class="input" type="date" name="end" required value="{{ daterange.1 }}" />
</div>
</div>
{% if user.role == Role::Admin %}
<div class="field">
<label class="label">Bereich</label>
<div class="control">
<div class="select is-fullwidth">
<select name="area">
{% for area in areas.as_ref().unwrap() %}
<option value="{{ area.id }}">{{ area.name }}</option>
{% endfor %}
</select>
</div>
</div>
</div>
{% endif %}
<input class="button is-primary" type="submit" value="Exportieren" />
</form>
</div>
</section>
{% endblock %}

View File

@ -31,6 +31,10 @@
<a href="/export/availability" class="navbar-item"> <a href="/export/availability" class="navbar-item">
Verfügbarkeiten Verfügbarkeiten
</a> </a>
<a href="/export/events" class="navbar-item">
Veranstaltungen
</a>
</div> </div>
</div> </div>