refactor: bugfixes and code cleanup
This commit is contained in:
parent
cd20457f67
commit
f06d907b25
137
.sqlx/query-e5c0fdebea352e78f5d34fd0774f8802090ce15f811d1b2506ff8bc12fe8fad9.json
generated
Normal file
137
.sqlx/query-e5c0fdebea352e78f5d34fd0774f8802090ce15f811d1b2506ff8bc12fe8fad9.json
generated
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n SELECT\n availabillity.id,\n availabillity.userId,\n availabillity.date,\n availabillity.startTime,\n availabillity.endTime,\n availabillity.comment,\n user_.name,\n user_.email,\n user_.password,\n user_.salt,\n user_.role AS \"role: Role\",\n user_.function AS \"function: Function\",\n user_.areaId,\n user_.locked,\n user_.lastLogin,\n user_.receiveNotifications\n FROM availabillity\n JOIN user_ ON availabillity.userId = user_.id\n WHERE availabillity.date = $1\n AND user_.areaId = $2\n AND ((availabillity.startTime IS NULL AND availabillity.endTime IS NULL)\n OR (availabillity.startTime <= $3 AND availabillity.endTime >= $4));\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "id",
|
||||||
|
"type_info": "Int4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 1,
|
||||||
|
"name": "userid",
|
||||||
|
"type_info": "Int4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 2,
|
||||||
|
"name": "date",
|
||||||
|
"type_info": "Date"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 3,
|
||||||
|
"name": "starttime",
|
||||||
|
"type_info": "Time"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 4,
|
||||||
|
"name": "endtime",
|
||||||
|
"type_info": "Time"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 5,
|
||||||
|
"name": "comment",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 6,
|
||||||
|
"name": "name",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 7,
|
||||||
|
"name": "email",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 8,
|
||||||
|
"name": "password",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 9,
|
||||||
|
"name": "salt",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 10,
|
||||||
|
"name": "role: Role",
|
||||||
|
"type_info": {
|
||||||
|
"Custom": {
|
||||||
|
"name": "role",
|
||||||
|
"kind": {
|
||||||
|
"Enum": [
|
||||||
|
"staff",
|
||||||
|
"areamanager",
|
||||||
|
"admin"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 11,
|
||||||
|
"name": "function: Function",
|
||||||
|
"type_info": {
|
||||||
|
"Custom": {
|
||||||
|
"name": "function",
|
||||||
|
"kind": {
|
||||||
|
"Enum": [
|
||||||
|
"posten",
|
||||||
|
"fuehrungsassistent",
|
||||||
|
"wachhabender"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 12,
|
||||||
|
"name": "areaid",
|
||||||
|
"type_info": "Int4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 13,
|
||||||
|
"name": "locked",
|
||||||
|
"type_info": "Bool"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 14,
|
||||||
|
"name": "lastlogin",
|
||||||
|
"type_info": "Timestamptz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 15,
|
||||||
|
"name": "receivenotifications",
|
||||||
|
"type_info": "Bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Date",
|
||||||
|
"Int4",
|
||||||
|
"Time",
|
||||||
|
"Time"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "e5c0fdebea352e78f5d34fd0774f8802090ce15f811d1b2506ff8bc12fe8fad9"
|
||||||
|
}
|
@ -16,7 +16,7 @@ pub async fn delete(
|
|||||||
return Ok(HttpResponse::NotFound().finish());
|
return Ok(HttpResponse::NotFound().finish());
|
||||||
};
|
};
|
||||||
|
|
||||||
if availabillity.user_id == user.id {
|
if availabillity.user_id != user.id {
|
||||||
return Err(ApplicationError::Unauthorized);
|
return Err(ApplicationError::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,12 +4,10 @@ use serde::Deserialize;
|
|||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
endpoints::{
|
endpoints::{availability::NewOrEditAvailabilityTemplate, IdPath},
|
||||||
availability::NewOrEditAvailabilityTemplate,
|
|
||||||
IdPath,
|
|
||||||
},
|
|
||||||
models::{find_free_time_slots, Availability, AvailabilityTime, User},
|
models::{find_free_time_slots, Availability, AvailabilityTime, User},
|
||||||
utils::ApplicationError,
|
utils::ApplicationError,
|
||||||
|
END_OF_DAY, START_OF_DAY,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@ -34,12 +32,9 @@ pub async fn get(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let suggestions = if let AvailabilityTime::Temporarily(start, end) = availability.time {
|
let suggestions = if let AvailabilityTime::Temporarily(start, end) = availability.time {
|
||||||
let availabilities = Availability::read_by_user_and_date(
|
let availabilities =
|
||||||
pool.get_ref(),
|
Availability::read_by_user_and_date(pool.get_ref(), user.id, &availability.date)
|
||||||
user.id,
|
.await?;
|
||||||
&availability.date,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
find_free_time_slots(&availabilities)
|
find_free_time_slots(&availabilities)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -49,8 +44,12 @@ pub async fn get(
|
|||||||
Vec::new()
|
Vec::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
let time_selection = if query.whole_day.unwrap_or(availability.time == AvailabilityTime::WholeDay) {
|
let time_selection = if let Some(whole_day) = query.whole_day {
|
||||||
AvailabilityTime::WholeDay
|
if whole_day {
|
||||||
|
AvailabilityTime::WholeDay
|
||||||
|
} else {
|
||||||
|
AvailabilityTime::Temporarily(START_OF_DAY, END_OF_DAY)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
availability.time.clone()
|
availability.time.clone()
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
use actix_web::{http::header::LOCATION, web, HttpResponse, Responder};
|
use actix_web::{http::header::LOCATION, web, HttpResponse, Responder};
|
||||||
|
use chrono::NaiveTime;
|
||||||
use garde::Validate;
|
use garde::Validate;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
endpoints::{availability::{find_adjacend_availability, post_new::AvailabillityForm}, IdPath},
|
endpoints::{
|
||||||
|
availability::{find_adjacend_availability, post_new::AvailabillityForm},
|
||||||
|
IdPath,
|
||||||
|
},
|
||||||
models::{Availability, AvailabilityChangeset, AvailabilityContext, AvailabilityTime, User},
|
models::{Availability, AvailabilityChangeset, AvailabilityContext, AvailabilityTime, User},
|
||||||
utils::{self, ApplicationError},
|
utils::{self, ApplicationError},
|
||||||
|
END_OF_DAY,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[actix_web::post("/availabillity/edit/{id}")]
|
#[actix_web::post("/availabillity/edit/{id}")]
|
||||||
@ -23,14 +28,24 @@ pub async fn post(
|
|||||||
return Err(ApplicationError::Unauthorized);
|
return Err(ApplicationError::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
let existing_availabilities =
|
let existing_availabilities: Vec<Availability> =
|
||||||
Availability::read_by_user_and_date(pool.get_ref(), user.id, &availability.date).await?;
|
Availability::read_by_user_and_date(pool.get_ref(), user.id, &availability.date)
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.filter(|a| a.id != availability.id)
|
||||||
|
.collect();
|
||||||
|
|
||||||
let context = AvailabilityContext {
|
let context = AvailabilityContext {
|
||||||
existing_availabilities: existing_availabilities.clone(),
|
existing_availabilities: existing_availabilities.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let time = if form.from.is_some() && form.till.is_some() {
|
let time = if form.from.is_some() && form.till.is_some() {
|
||||||
AvailabilityTime::Temporarily(form.from.unwrap(), form.till.unwrap())
|
let end_time = if form.till.unwrap() == NaiveTime::from_hms_opt(23, 59, 0).unwrap() {
|
||||||
|
END_OF_DAY
|
||||||
|
} else {
|
||||||
|
form.till.unwrap()
|
||||||
|
};
|
||||||
|
AvailabilityTime::Temporarily(form.from.unwrap(), end_time)
|
||||||
} else {
|
} else {
|
||||||
AvailabilityTime::WholeDay
|
AvailabilityTime::WholeDay
|
||||||
};
|
};
|
||||||
@ -44,7 +59,9 @@ pub async fn post(
|
|||||||
return Ok(HttpResponse::BadRequest().body(e.to_string()));
|
return Ok(HttpResponse::BadRequest().body(e.to_string()));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(a) = find_adjacend_availability(&changeset, Some(availability.id), &existing_availabilities) {
|
if let Some(a) =
|
||||||
|
find_adjacend_availability(&changeset, Some(availability.id), &existing_availabilities)
|
||||||
|
{
|
||||||
let (changeset_start, changeset_end) = changeset.time.time_tuple_opt().unwrap();
|
let (changeset_start, changeset_end) = changeset.time.time_tuple_opt().unwrap();
|
||||||
let (adjacent_start, adjacent_end) = changeset.time.time_tuple_opt().unwrap();
|
let (adjacent_start, adjacent_end) = changeset.time.time_tuple_opt().unwrap();
|
||||||
|
|
||||||
|
@ -1,20 +1,25 @@
|
|||||||
use actix_web::{web, HttpResponse, Responder};
|
use actix_web::{web, HttpResponse, Responder};
|
||||||
|
use chrono::{NaiveDate, Utc};
|
||||||
use rinja::Template;
|
use rinja::Template;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
use crate::{models::{Area, Role, User}, utils::ApplicationError};
|
use crate::{
|
||||||
|
models::{Area, Role, User},
|
||||||
|
utils::ApplicationError,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "export/availability.html")]
|
#[template(path = "export/availability.html")]
|
||||||
struct AvailabilityExportTemplate {
|
struct AvailabilityExportTemplate {
|
||||||
user: User,
|
user: User,
|
||||||
areas: Option<Vec<Area>>
|
areas: Option<Vec<Area>>,
|
||||||
|
today: NaiveDate,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::get("/export/availability")]
|
#[actix_web::get("/export/availability")]
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
user: web::ReqData<User>,
|
user: web::ReqData<User>,
|
||||||
pool: web::Data<PgPool>
|
pool: web::Data<PgPool>,
|
||||||
) -> Result<impl Responder, ApplicationError> {
|
) -> Result<impl Responder, ApplicationError> {
|
||||||
if user.role != Role::Admin && user.role != Role::AreaManager {
|
if user.role != Role::Admin && user.role != Role::AreaManager {
|
||||||
return Err(ApplicationError::Unauthorized);
|
return Err(ApplicationError::Unauthorized);
|
||||||
@ -28,7 +33,8 @@ pub async fn get(
|
|||||||
|
|
||||||
let template = AvailabilityExportTemplate {
|
let template = AvailabilityExportTemplate {
|
||||||
user: user.into_inner(),
|
user: user.into_inner(),
|
||||||
areas
|
areas,
|
||||||
|
today: Utc::now().date_naive(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().body(template.render()?))
|
Ok(HttpResponse::Ok().body(template.render()?))
|
||||||
|
@ -4,11 +4,12 @@ use actix_web::{
|
|||||||
web, HttpResponse, Responder,
|
web, HttpResponse, Responder,
|
||||||
};
|
};
|
||||||
use chrono::{Months, NaiveDate, NaiveTime, Utc};
|
use chrono::{Months, NaiveDate, NaiveTime, Utc};
|
||||||
|
use quick_xml::se::Serializer;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
models::{Availability, AvailabilityTime, Function, Role, User},
|
models::{Area, Availability, AvailabilityTime, Function, Role, User},
|
||||||
END_OF_DAY, START_OF_DAY,
|
END_OF_DAY, START_OF_DAY,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,16 +98,30 @@ pub async fn get(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let area = Area::read_by_id(pool.get_ref(), area_id)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap()
|
||||||
|
.name;
|
||||||
|
|
||||||
let export = Export {
|
let export = Export {
|
||||||
year: query.year,
|
year: query.year,
|
||||||
month: query.month,
|
month: query.month,
|
||||||
area: area_id.to_string(),
|
area,
|
||||||
availabillities: export_availabillities,
|
availabillities: export_availabillities,
|
||||||
};
|
};
|
||||||
|
|
||||||
let out = match query.format.as_str() {
|
let out = match query.format.as_str() {
|
||||||
"xml" => quick_xml::se::to_string(&export).unwrap_or_default(),
|
"xml" => {
|
||||||
"json" => serde_json::to_string(&export).unwrap_or_default(),
|
let mut buffer = String::new();
|
||||||
|
let mut ser = Serializer::new(&mut buffer);
|
||||||
|
ser.indent(' ', 2);
|
||||||
|
|
||||||
|
export.serialize(ser).unwrap();
|
||||||
|
|
||||||
|
buffer
|
||||||
|
}
|
||||||
|
"json" => serde_json::to_string_pretty(&export).unwrap_or_default(),
|
||||||
_ => return HttpResponse::BadRequest().finish(),
|
_ => return HttpResponse::BadRequest().finish(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use maud::html;
|
||||||
|
|
||||||
use crate::models::Function;
|
use crate::models::Function;
|
||||||
|
|
||||||
pub fn show_area_query(a: &Option<i32>, first: bool) -> rinja::Result<String> {
|
pub fn show_area_query(a: &Option<i32>, first: bool) -> rinja::Result<String> {
|
||||||
@ -39,15 +41,17 @@ pub fn invert(b: &bool) -> rinja::Result<bool> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_tree(f: &Function) -> rinja::Result<String> {
|
pub fn show_tree(f: &Function) -> rinja::Result<String> {
|
||||||
let mut tags = String::from(r#"<span class="tag is-info is-light">Posten</span>"#);
|
let html = html! {
|
||||||
|
div class="tags" {
|
||||||
|
span class="tag is-primary is-light" { "Posten"}
|
||||||
|
@if *f == Function::Fuehrungsassistent || *f == Function::Wachhabender {
|
||||||
|
span class="tag is-primary has-background-primary-85 has-text-primary-85-invert" { "Führungsassistent"}
|
||||||
|
}
|
||||||
|
@if *f == Function::Wachhabender {
|
||||||
|
span class="tag is-primary" { "Wachhabender"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if f == &Function::Fuehrungsassistent || f == &Function::Wachhabender {
|
Ok(html.into_string())
|
||||||
tags.push_str(r#"<span class="tag is-info is-light">Führungsassistent</span>"#);
|
|
||||||
}
|
|
||||||
|
|
||||||
if f == &Function::Wachhabender {
|
|
||||||
tags.push_str(r#"<span class="tag is-info">Wachhabender</span>"#);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(format!(r#"<div class="tags">{tags}</div>"#))
|
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,77 @@ impl Availability {
|
|||||||
Ok(availabillities)
|
Ok(availabillities)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn read_by_date_time_area_including_user(
|
||||||
|
pool: &PgPool,
|
||||||
|
date: NaiveDate,
|
||||||
|
time: (NaiveTime, NaiveTime),
|
||||||
|
area_id: i32,
|
||||||
|
) -> Result<Vec<Availability>> {
|
||||||
|
let records = query!(
|
||||||
|
r##"
|
||||||
|
SELECT
|
||||||
|
availabillity.id,
|
||||||
|
availabillity.userId,
|
||||||
|
availabillity.date,
|
||||||
|
availabillity.startTime,
|
||||||
|
availabillity.endTime,
|
||||||
|
availabillity.comment,
|
||||||
|
user_.name,
|
||||||
|
user_.email,
|
||||||
|
user_.password,
|
||||||
|
user_.salt,
|
||||||
|
user_.role AS "role: Role",
|
||||||
|
user_.function AS "function: Function",
|
||||||
|
user_.areaId,
|
||||||
|
user_.locked,
|
||||||
|
user_.lastLogin,
|
||||||
|
user_.receiveNotifications
|
||||||
|
FROM availabillity
|
||||||
|
JOIN user_ ON availabillity.userId = user_.id
|
||||||
|
WHERE availabillity.date = $1
|
||||||
|
AND user_.areaId = $2
|
||||||
|
AND ((availabillity.startTime IS NULL AND availabillity.endTime IS NULL)
|
||||||
|
OR (availabillity.startTime <= $3 AND availabillity.endTime >= $4));
|
||||||
|
"##,
|
||||||
|
date,
|
||||||
|
area_id,
|
||||||
|
time.0,
|
||||||
|
time.1
|
||||||
|
)
|
||||||
|
.fetch_all(pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let availabillities = records
|
||||||
|
.iter()
|
||||||
|
.map(|r| Availability {
|
||||||
|
id: r.id,
|
||||||
|
user_id: r.userid,
|
||||||
|
user: Some(User {
|
||||||
|
id: r.userid,
|
||||||
|
name: r.name.clone(),
|
||||||
|
email: r.email.clone(),
|
||||||
|
password: r.password.clone(),
|
||||||
|
salt: r.salt.clone(),
|
||||||
|
role: r.role,
|
||||||
|
function: r.function,
|
||||||
|
area_id: r.areaid,
|
||||||
|
area: None,
|
||||||
|
locked: r.locked,
|
||||||
|
last_login: r.lastlogin,
|
||||||
|
receive_notifications: r.receivenotifications,
|
||||||
|
}),
|
||||||
|
date: r.date,
|
||||||
|
time: match (r.starttime, r.endtime) {
|
||||||
|
(Some(start), Some(end)) => AvailabilityTime::Temporarily(start, end),
|
||||||
|
(_, _) => AvailabilityTime::WholeDay,
|
||||||
|
},
|
||||||
|
comment: r.comment.clone(),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(availabillities)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn read_by_id_including_user(pool: &PgPool, id: i32) -> Result<Option<Availability>> {
|
pub async fn read_by_id_including_user(pool: &PgPool, id: i32) -> Result<Option<Availability>> {
|
||||||
let record = query!(
|
let record = query!(
|
||||||
r##"
|
r##"
|
||||||
@ -165,29 +236,29 @@ impl Availability {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let availabillity = record.map(|r| Availability {
|
let availabillity = record.map(|r| Availability {
|
||||||
id: r.id,
|
id: r.id,
|
||||||
user_id: r.userid,
|
user_id: r.userid,
|
||||||
user: Some(User {
|
user: Some(User {
|
||||||
id: r.userid,
|
id: r.userid,
|
||||||
name: r.name.clone(),
|
name: r.name.clone(),
|
||||||
email: r.email.clone(),
|
email: r.email.clone(),
|
||||||
password: r.password.clone(),
|
password: r.password.clone(),
|
||||||
salt: r.salt.clone(),
|
salt: r.salt.clone(),
|
||||||
role: r.role,
|
role: r.role,
|
||||||
function: r.function,
|
function: r.function,
|
||||||
area_id: r.areaid,
|
area_id: r.areaid,
|
||||||
area: None,
|
area: None,
|
||||||
locked: r.locked,
|
locked: r.locked,
|
||||||
last_login: r.lastlogin,
|
last_login: r.lastlogin,
|
||||||
receive_notifications: r.receivenotifications,
|
receive_notifications: r.receivenotifications,
|
||||||
}),
|
}),
|
||||||
date: r.date,
|
date: r.date,
|
||||||
time: match (r.starttime, r.endtime) {
|
time: match (r.starttime, r.endtime) {
|
||||||
(Some(start), Some(end)) => AvailabilityTime::Temporarily(start, end),
|
(Some(start), Some(end)) => AvailabilityTime::Temporarily(start, end),
|
||||||
(_, _) => AvailabilityTime::WholeDay,
|
(_, _) => AvailabilityTime::WholeDay,
|
||||||
},
|
},
|
||||||
comment: r.comment.clone(),
|
comment: r.comment.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(availabillity)
|
Ok(availabillity)
|
||||||
}
|
}
|
||||||
@ -198,16 +269,16 @@ impl Availability {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let availabillity = record.map(|record| Availability {
|
let availabillity = record.map(|record| Availability {
|
||||||
id: record.id,
|
id: record.id,
|
||||||
user_id: record.userid,
|
user_id: record.userid,
|
||||||
user: None,
|
user: None,
|
||||||
date: record.date,
|
date: record.date,
|
||||||
time: match (record.starttime, record.endtime) {
|
time: match (record.starttime, record.endtime) {
|
||||||
(Some(start), Some(end)) => AvailabilityTime::Temporarily(start, end),
|
(Some(start), Some(end)) => AvailabilityTime::Temporarily(start, end),
|
||||||
(_, _) => AvailabilityTime::WholeDay,
|
(_, _) => AvailabilityTime::WholeDay,
|
||||||
},
|
},
|
||||||
comment: record.comment.clone(),
|
comment: record.comment.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(availabillity)
|
Ok(availabillity)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
Assignment, Availability, AvailabillityAssignmentState, Event, Function, Vehicle, VehicleAssignement,
|
Assignment, Availability, AvailabillityAssignmentState, Event, Function, Vehicle,
|
||||||
|
VehicleAssignement,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::ApplicationError;
|
use super::ApplicationError;
|
||||||
@ -10,9 +11,10 @@ pub async fn generate_availabillity_assignment_list(
|
|||||||
pool: &PgPool,
|
pool: &PgPool,
|
||||||
event: &Event,
|
event: &Event,
|
||||||
) -> Result<Vec<(Availability, AvailabillityAssignmentState)>, ApplicationError> {
|
) -> Result<Vec<(Availability, AvailabillityAssignmentState)>, ApplicationError> {
|
||||||
let availabillities_in_db = Availability::read_by_date_and_area_including_user(
|
let availabillities_in_db = Availability::read_by_date_time_area_including_user(
|
||||||
pool,
|
pool,
|
||||||
event.date,
|
event.date,
|
||||||
|
(event.start_time, event.end_time),
|
||||||
event.location.as_ref().unwrap().area_id,
|
event.location.as_ref().unwrap().area_id,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
<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 }} - {{ e }}</span>
|
<span class="tag">{{ s.format("%R") }} - {{ e.format("%R") }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -6,49 +6,49 @@
|
|||||||
<h3 class="title is-3">
|
<h3 class="title is-3">
|
||||||
Verfügbarkeiten nach XML exportieren
|
Verfügbarkeiten nach XML exportieren
|
||||||
</h3>
|
</h3>
|
||||||
<form action="/export/availabilitydata" target="_blank">
|
<form action="/export/availabilitydata" target="_blank">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">Jahr</label>
|
<label class="label">Jahr</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input class="input" type="number" name="year" min="2024" max="9999" value="2024" />
|
<input class="input" type="number" name="year" min="2024" max="9999" value='{{ today.format("%Y") }}' />
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">Monat</label>
|
<label class="label">Monat</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input class="input" type="number" name="month" min="1" max="12" value="1" />
|
<input class="input" type="number" name="month" min="1" max="12" value='{{ today.format("%m") }}' />
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">Format</label>
|
<label class="label">Format</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<div class="select is-fullwidth">
|
<div class="select is-fullwidth">
|
||||||
<select name="format">
|
<select name="format">
|
||||||
<option value="xml">XML</option>
|
<option value="xml">XML</option>
|
||||||
<option value="json">JSON</option>
|
<option value="json">JSON</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% if user.role == Role::Admin %}
|
{% if user.role == Role::Admin %}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">Bereich</label>
|
<label class="label">Bereich</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<div class="select is-fullwidth">
|
<div class="select is-fullwidth">
|
||||||
<select name="area">
|
<select name="area">
|
||||||
{% for area in areas.as_ref().unwrap() %}
|
{% for area in areas.as_ref().unwrap() %}
|
||||||
<option value="{{ area.id }}">{{ area.name }}</option>
|
<option value="{{ area.id }}">{{ area.name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
</div>
|
||||||
<input class="button is-primary" type="submit" value="Exportieren" />
|
{% endif %}
|
||||||
</form>
|
<input class="button is-primary" type="submit" value="Exportieren" />
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user