feat: view of new event
This commit is contained in:
parent
28c562d82f
commit
fedfc87259
38
src/endpoints/events/get_new.rs
Normal file
38
src/endpoints/events/get_new.rs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
use actix_identity::Identity;
|
||||||
|
use actix_web::{web, HttpResponse, Responder};
|
||||||
|
use askama::Template;
|
||||||
|
use askama_actix::TemplateToResponse;
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
use crate::{endpoints::NaiveDateQuery, models::{Role, User, Location}};
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "events/new.html")]
|
||||||
|
pub struct NewEventTemplate {
|
||||||
|
user: User,
|
||||||
|
date: NaiveDate,
|
||||||
|
locations: Vec<Location>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::get("/events/new")]
|
||||||
|
pub async fn get(user: Identity, pool: web::Data<PgPool>, query: web::Query<NaiveDateQuery>) -> impl Responder {
|
||||||
|
let current_user = User::read_by_id(pool.get_ref(), user.id().unwrap().parse().unwrap())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if current_user.role != Role::Admin && current_user.role != Role::AreaManager {
|
||||||
|
return HttpResponse::Unauthorized().finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
let locations;
|
||||||
|
if current_user.role == Role::Admin {
|
||||||
|
locations = Location::read_all_including_area(pool.get_ref()).await.unwrap();
|
||||||
|
} else {
|
||||||
|
locations = Location::read_by_area(pool.get_ref(), current_user.area_id).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let template = NewEventTemplate { user: current_user, date: query.date, locations };
|
||||||
|
|
||||||
|
return template.to_response();
|
||||||
|
}
|
2
src/endpoints/events/mod.rs
Normal file
2
src/endpoints/events/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod get_new;
|
||||||
|
pub mod post_new;
|
11
src/endpoints/events/post_new.rs
Normal file
11
src/endpoints/events/post_new.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
use actix_identity::Identity;
|
||||||
|
use actix_web::{web, HttpResponse, Responder};
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[actix_web::post("/events/new")]
|
||||||
|
pub async fn post(user: Identity, pool: web::Data<PgPool>) -> impl Responder {
|
||||||
|
|
||||||
|
return HttpResponse::BadRequest().finish();
|
||||||
|
}
|
@ -1,14 +1,21 @@
|
|||||||
use actix_web::web::ServiceConfig;
|
use actix_web::web::ServiceConfig;
|
||||||
|
use chrono::NaiveDate;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
mod location;
|
mod location;
|
||||||
mod user;
|
mod user;
|
||||||
|
mod events;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct IdPath {
|
pub struct IdPath {
|
||||||
pub id: i32
|
pub id: i32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct NaiveDateQuery {
|
||||||
|
pub date: NaiveDate
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init(cfg: &mut ServiceConfig) {
|
pub fn init(cfg: &mut ServiceConfig) {
|
||||||
cfg.service(location::get_overview::get);
|
cfg.service(location::get_overview::get);
|
||||||
cfg.service(location::get_new::get);
|
cfg.service(location::get_new::get);
|
||||||
@ -21,4 +28,7 @@ pub fn init(cfg: &mut ServiceConfig) {
|
|||||||
cfg.service(user::post_edit::post_edit);
|
cfg.service(user::post_edit::post_edit);
|
||||||
cfg.service(user::patch::patch);
|
cfg.service(user::patch::patch);
|
||||||
cfg.service(user::delete::delete);
|
cfg.service(user::delete::delete);
|
||||||
|
|
||||||
|
cfg.service(events::get_new::get);
|
||||||
|
// cfg.service(events::post_new::);
|
||||||
}
|
}
|
||||||
|
118
templates/events/new.html
Normal file
118
templates/events/new.html
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
{% extends "nav.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<section class="section">
|
||||||
|
<div class="container">
|
||||||
|
<form method="post" action="/events/new">
|
||||||
|
<h1 class="title">Neues Event anlegen für den {{ date.format("%d.%m.%Y") }}</h1>
|
||||||
|
|
||||||
|
<input type="hidden" name="date" value="{{ date }}">
|
||||||
|
|
||||||
|
<div class="field is-horizontal">
|
||||||
|
<div class="field-label">
|
||||||
|
<label class="label">Veranstaltungsname</label>
|
||||||
|
</div>
|
||||||
|
<div class="field-body">
|
||||||
|
<div class="field">
|
||||||
|
<div class="control">
|
||||||
|
<input class="input" name="name" placeholder="Wave Gotik Treffen" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field is-horizontal">
|
||||||
|
<div class="field-label">
|
||||||
|
<label class="label">Startzeit - Endzeit</label>
|
||||||
|
</div>
|
||||||
|
<div class="field-body">
|
||||||
|
<div class="field">
|
||||||
|
<input class="input" type="time" id="from" name="from" value="00:00">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<input class="input" type="time" id="till" name="till" value="23:59">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field is-horizontal">
|
||||||
|
<div class="field-label">
|
||||||
|
<label class="label">Veranstaltungsort</label>
|
||||||
|
</div>
|
||||||
|
<div class="field-body">
|
||||||
|
<div class="field is-narrow">
|
||||||
|
<div class="control">
|
||||||
|
<div class="select is-fullwidth">
|
||||||
|
<select name="location">
|
||||||
|
{% for location in locations %}
|
||||||
|
<option value="{{ location.id }}">{{ location.name }}{% if user.role == Role::Admin %} - ({{ location.area.as_ref().unwrap().name }}){% endif %}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field is-horizontal">
|
||||||
|
<div class="field-label">
|
||||||
|
<label class="label">Wachhabender durch FF gestellt?</label>
|
||||||
|
</div>
|
||||||
|
<div class="field-body">
|
||||||
|
<div class="field is-narrow">
|
||||||
|
<div class="control">
|
||||||
|
<label class="checkbox">
|
||||||
|
<input class="checkbox" type="checkbox" name="voluntaryWachhabender">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field is-horizontal">
|
||||||
|
<div class="field-label">
|
||||||
|
<label class="label">Anzahl der Posten</label>
|
||||||
|
</div>
|
||||||
|
<div class="field-body">
|
||||||
|
<div class="field">
|
||||||
|
<div class="control">
|
||||||
|
<input class="input" type="number" name="name" min="1" max="100"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field is-horizontal">
|
||||||
|
<div class="field-label">
|
||||||
|
<label class="label">Anzugsordnung</label>
|
||||||
|
</div>
|
||||||
|
<div class="field-body">
|
||||||
|
<div class="field">
|
||||||
|
<div class="control">
|
||||||
|
<input class="input" name="clothing" placeholder="Tuchuniform" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field is-horizontal">
|
||||||
|
<div class="field-label"></div>
|
||||||
|
<div class="field-body">
|
||||||
|
<div class="field is-grouped">
|
||||||
|
<div class="control">
|
||||||
|
<input class="button is-link" type="submit" value="Erstellen">
|
||||||
|
</div>
|
||||||
|
<div class="control">
|
||||||
|
<a class="button is-link is-light" href="/locations">Zurück</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
@ -26,7 +26,7 @@
|
|||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="level-right">
|
<div class="level-right">
|
||||||
<a class="button" href="/event/new">Neues Event für diesen Tag</a>
|
<a class="button" href="/events/new?date={{ date }}">Neues Event für diesen Tag</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user