changed the date format, it's now almost the same as used by calutil

This commit is contained in:
Johannes Loher 2017-08-06 21:52:27 +02:00
parent 6cf7d27115
commit 3af4f2fde9
4 changed files with 100 additions and 53 deletions

View file

@ -1,4 +1,5 @@
import std.datetime.date;
import std.typecons : Nullable;
import vibe.vibe;
@ -7,47 +8,69 @@ class CalendarWebapp
private:
immutable fileName = Path("events.json");
struct Event
enum EventType
{
string name, place;
DateTime begin, end;
Holiday,
Birthday,
FSI_Event,
General_University_Event,
Any
}
Event[] getEventsFromFile(in Path fileName)
struct Entry
{
Event[] events;
auto eventsString = readFileUTF8(fileName);
@name("date") Date begin;
@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
{
deserializeJson(events, eventsString.parseJsonString);
auto entriesString = readFileUTF8(fileName);
try
{
deserializeJson(entries, entriesString.parseJsonString);
}
catch (std.json.JSONException)
{
}
}
catch (std.json.JSONException)
{
}
return events;
catch(Exception)
{}
return entries;
}
public:
@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;
event.place = Ereignisort;
if (!end.isNull)
enforce(end - begin >= 1.days);
event.begin = DateTime.fromISOExtString(Von ~ ":00");
event.end = DateTime.fromISOExtString(Bis ~ ":00");
enforce(event.end - event.begin > 0.seconds);
auto entry = Entry(begin, end, Event("", name,
description.replace("\r", "").split('\n'), type, shout));
auto events = getEventsFromFile(fileName);
events ~= event;
writeFileUTF8(fileName, events.serializeToJsonString());
render!("listevents.dt", events);
auto entries = getEventsFromFile(fileName);
entries ~= entry;
writeFileUTF8(fileName, serializeToPrettyJson(entries));
render!("showevents.dt", entries);
}
@method(HTTPMethod.GET) @path("create")
@ -58,8 +81,8 @@ public:
void index()
{
auto events = getEventsFromFile(fileName);
render!("listevents.dt", events);
auto entries = getEventsFromFile(fileName);
render!("showevents.dt", entries);
}
}

View file

@ -6,24 +6,39 @@ block content
tbody#fieldTable
tr
td
label(for="Ereignisname") Ereignisname
label(for="name") Ereignisname
td
input#Ereignisname(value="", name="Ereignisname", type="text")
input#name(value="", name="name", type="text")
tr
td
label(for="Ereignisort") Ereignisort
label(for="description") Beschreibung
td
input#Ereignisort(value="", name="Ereignisort", type="text")
textarea#description(value="", name="description", cols="40", rows="5")
tr
td
label(for="Von") Von
label(for="begin") Von
td
input#Von(value="", name="Von", type="datetime-local")
input#begin(value="", name="begin", type="date")
tr
td
label(for="Bis") Bis
label(for="end") Bis
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
tr

View file

@ -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
View 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