changed the date format, it's now almost the same as used by calutil
This commit is contained in:
parent
6cf7d27115
commit
3af4f2fde9
4 changed files with 100 additions and 53 deletions
77
source/app.d
77
source/app.d
|
@ -1,4 +1,5 @@
|
||||||
import std.datetime.date;
|
import std.datetime.date;
|
||||||
|
import std.typecons : Nullable;
|
||||||
|
|
||||||
import vibe.vibe;
|
import vibe.vibe;
|
||||||
|
|
||||||
|
@ -7,47 +8,69 @@ class CalendarWebapp
|
||||||
private:
|
private:
|
||||||
immutable fileName = Path("events.json");
|
immutable fileName = Path("events.json");
|
||||||
|
|
||||||
struct Event
|
enum EventType
|
||||||
{
|
{
|
||||||
string name, place;
|
Holiday,
|
||||||
DateTime begin, end;
|
Birthday,
|
||||||
|
FSI_Event,
|
||||||
|
General_University_Event,
|
||||||
|
Any
|
||||||
}
|
}
|
||||||
|
|
||||||
Event[] getEventsFromFile(in Path fileName)
|
struct Entry
|
||||||
{
|
{
|
||||||
Event[] events;
|
@name("date") Date begin;
|
||||||
auto eventsString = readFileUTF8(fileName);
|
@name("end_date") Nullable!Date end;
|
||||||
|
Event event;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Event
|
||||||
|
{
|
||||||
|
@(vibe.data.serialization.name("eid")) string id;
|
||||||
|
string name;
|
||||||
|
@(vibe.data.serialization.name("desc")) string[] description;
|
||||||
|
@(vibe.data.serialization.name("etype")) EventType type;
|
||||||
|
bool shout;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entry[] getEventsFromFile(in Path fileName)
|
||||||
|
{
|
||||||
|
Entry[] entries;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
deserializeJson(events, eventsString.parseJsonString);
|
auto entriesString = readFileUTF8(fileName);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
deserializeJson(entries, entriesString.parseJsonString);
|
||||||
|
}
|
||||||
|
catch (std.json.JSONException)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (std.json.JSONException)
|
catch(Exception)
|
||||||
{
|
{}
|
||||||
}
|
return entries;
|
||||||
return events;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@method(HTTPMethod.POST) @path("/event/create")
|
@method(HTTPMethod.POST) @path("/event/create")
|
||||||
void createEvent(string Ereignisname, string Ereignisort, string Von, string Bis)
|
void createEvent(Date begin, Nullable!Date end, string description,
|
||||||
|
string name, EventType type, bool shout)
|
||||||
{
|
{
|
||||||
Event event;
|
import std.array : split, replace;
|
||||||
|
|
||||||
event.name = Ereignisname;
|
if (!end.isNull)
|
||||||
event.place = Ereignisort;
|
enforce(end - begin >= 1.days);
|
||||||
|
|
||||||
event.begin = DateTime.fromISOExtString(Von ~ ":00");
|
auto entry = Entry(begin, end, Event("", name,
|
||||||
event.end = DateTime.fromISOExtString(Bis ~ ":00");
|
description.replace("\r", "").split('\n'), type, shout));
|
||||||
enforce(event.end - event.begin > 0.seconds);
|
|
||||||
|
|
||||||
auto events = getEventsFromFile(fileName);
|
auto entries = getEventsFromFile(fileName);
|
||||||
|
entries ~= entry;
|
||||||
events ~= event;
|
writeFileUTF8(fileName, serializeToPrettyJson(entries));
|
||||||
|
render!("showevents.dt", entries);
|
||||||
writeFileUTF8(fileName, events.serializeToJsonString());
|
|
||||||
|
|
||||||
render!("listevents.dt", events);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@method(HTTPMethod.GET) @path("create")
|
@method(HTTPMethod.GET) @path("create")
|
||||||
|
@ -58,8 +81,8 @@ public:
|
||||||
|
|
||||||
void index()
|
void index()
|
||||||
{
|
{
|
||||||
auto events = getEventsFromFile(fileName);
|
auto entries = getEventsFromFile(fileName);
|
||||||
render!("listevents.dt", events);
|
render!("showevents.dt", entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,24 +6,39 @@ block content
|
||||||
tbody#fieldTable
|
tbody#fieldTable
|
||||||
tr
|
tr
|
||||||
td
|
td
|
||||||
label(for="Ereignisname") Ereignisname
|
label(for="name") Ereignisname
|
||||||
td
|
td
|
||||||
input#Ereignisname(value="", name="Ereignisname", type="text")
|
input#name(value="", name="name", type="text")
|
||||||
tr
|
tr
|
||||||
td
|
td
|
||||||
label(for="Ereignisort") Ereignisort
|
label(for="description") Beschreibung
|
||||||
td
|
td
|
||||||
input#Ereignisort(value="", name="Ereignisort", type="text")
|
textarea#description(value="", name="description", cols="40", rows="5")
|
||||||
tr
|
tr
|
||||||
td
|
td
|
||||||
label(for="Von") Von
|
label(for="begin") Von
|
||||||
td
|
td
|
||||||
input#Von(value="", name="Von", type="datetime-local")
|
input#begin(value="", name="begin", type="date")
|
||||||
tr
|
tr
|
||||||
td
|
td
|
||||||
label(for="Bis") Bis
|
label(for="end") Bis
|
||||||
td
|
td
|
||||||
input#Bis(value="", name="Bis", type="datetime-local")
|
input#end(value="", name="end", type="date")
|
||||||
|
tr
|
||||||
|
td
|
||||||
|
label(for="type") Typ
|
||||||
|
td
|
||||||
|
select#type(name="type")
|
||||||
|
option(value="Holiday") Feiertag
|
||||||
|
option(value="Birthday") Geburtstag
|
||||||
|
option(value="FSI_Event") FSI Ereignis
|
||||||
|
option(value="General_University_Event") Allgemeines Universitäts Ereignis
|
||||||
|
option(value="Any") Sonstiges
|
||||||
|
tr
|
||||||
|
td
|
||||||
|
label(for="shout") Shout
|
||||||
|
td
|
||||||
|
input#shout(name="shout", type="checkbox")
|
||||||
|
|
||||||
tfoot
|
tfoot
|
||||||
tr
|
tr
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
extends layout.dt
|
|
||||||
block content
|
|
||||||
h1 Events
|
|
||||||
- foreach(event; events)
|
|
||||||
table
|
|
||||||
tr
|
|
||||||
td Ereignisname
|
|
||||||
td #{event.name}
|
|
||||||
tr
|
|
||||||
td Ereignisort
|
|
||||||
td #{event.place}
|
|
||||||
tr
|
|
||||||
td Von
|
|
||||||
td #{event.begin}
|
|
||||||
tr
|
|
||||||
td Bis
|
|
||||||
td #{event.end}
|
|
||||||
hr
|
|
27
views/showevents.dt
Normal file
27
views/showevents.dt
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
extends layout.dt
|
||||||
|
block content
|
||||||
|
h1 Events
|
||||||
|
- foreach (entry; entries)
|
||||||
|
table
|
||||||
|
tr
|
||||||
|
td begin
|
||||||
|
td #{entry.begin}
|
||||||
|
tr
|
||||||
|
td end
|
||||||
|
td #{entry.end}
|
||||||
|
tr
|
||||||
|
td eid
|
||||||
|
td #{entry.event.id}
|
||||||
|
tr
|
||||||
|
td name
|
||||||
|
td #{entry.event.name}
|
||||||
|
tr
|
||||||
|
td desc
|
||||||
|
td #{entry.event.description}
|
||||||
|
tr
|
||||||
|
td etype
|
||||||
|
td #{entry.event.type}
|
||||||
|
tr
|
||||||
|
td shout
|
||||||
|
td #{entry.event.shout}
|
||||||
|
hr
|
Loading…
Reference in a new issue