Compare commits

...

2 commits

Author SHA1 Message Date
d91de014e9 Korrigiere Zählung paralleler Sprechstunden 2022-09-19 18:32:15 +02:00
e1c5ccab3a HTML in Templates verbessert 2022-09-19 18:04:59 +02:00
14 changed files with 86 additions and 56 deletions

View file

@ -13,6 +13,7 @@ var Templates, _ = template.Must(template.ParseFiles(
"templates/executeFailure.html",
"templates/executeSuccess.html",
"templates/footer.html",
"templates/head.html",
"templates/index.html",
"templates/officeHourTable.html",
"templates/requestNotFound.html")).

View file

@ -40,7 +40,7 @@ func main() {
roomRepo := repositories.NewRoomRepo(db)
courseRepo := repositories.NewCourseRepo(db)
tutorRepo := repositories.NewTutorRepo(db)
officeHourRepo := repositories.NewOfficeHourRepo(db, roomRepo, tutorRepo, courseRepo)
officeHourRepo := repositories.NewOfficeHourRepo(db, roomRepo, tutorRepo, courseRepo, conf)
requestRepo := repositories.NewRequestRepo(db, officeHourRepo, conf)
h := controllers.NewBaseHandler(roomRepo, officeHourRepo, courseRepo, tutorRepo, requestRepo, conf)

View file

@ -4,6 +4,8 @@ package repositories
import (
"database/sql"
"fmt"
"log"
"sprechstundentool/config"
"sprechstundentool/models"
)
@ -12,14 +14,16 @@ type OfficeHourRepo struct {
roomRepo *RoomRepo
tutorRepo *TutorRepo
courseRepo *CourseRepo
config config.Config
}
func NewOfficeHourRepo(db *sql.DB, roomRepo *RoomRepo, tutorRepo *TutorRepo, courseRepo *CourseRepo) *OfficeHourRepo {
func NewOfficeHourRepo(db *sql.DB, roomRepo *RoomRepo, tutorRepo *TutorRepo, courseRepo *CourseRepo, conf config.Config) *OfficeHourRepo {
return &OfficeHourRepo{
db: db,
roomRepo: roomRepo,
tutorRepo: tutorRepo,
courseRepo: courseRepo,
config: conf,
}
}
@ -168,14 +172,18 @@ func (r *OfficeHourRepo) NumberByTimeSpanAndRoom(date models.Date, duration int,
return 0, err
}
var count int
// iterate over all points in the new officehour to get the maximum parallel officehours
for minute := 0; minute < duration; minute += r.config.Date.MinuteGranularity {
var minuteCount int = 0
for _, officeHour := range officeHours {
if models.DateLess(models.GetEndDate(officeHour.Date, officeHour.Duration, false), date) || models.GetEndDate(officeHour.Date, officeHour.Duration, false) == date {
continue
// increase count if officehour starts before this point in time and ends later
if models.DateLess(officeHour.Date, models.GetEndDate(date, minute, false)) && models.DateLess(models.GetEndDate(date, minute, false), models.GetEndDate(officeHour.Date, officeHour.Duration, false)) {
minuteCount += 1
}
if models.DateLess(models.GetEndDate(date, duration, false), officeHour.Date) || models.GetEndDate(date, duration, false) == officeHour.Date {
continue
}
count += 1
if minuteCount > count {
count = minuteCount
}
}
return count, nil
}

View file

@ -1,6 +1,8 @@
<html>
<!DOCTYPE html>
<html lang="de">
<head>
<title>Sprechstunde anlegen</title>
{{template "head.html" .}}
</head>
<body>
Irgendetwas ist schief gegangen. Bitte sende folgende Daten an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a> mit einer Beschreibung, was du tun wolltest.

View file

@ -1,49 +1,49 @@
<html>
<!DOCTYPE html>
<html lang="de">
<head>
<title>Sprechstunde anlegen</title>
{{template "head.html" .}}
</head>
<body>
<p>
{{range .Errors}}{{.}}<br />{{end}}
</p>
<p>
<form method="POST" action="addOfficeHour">
<label for="veranstaltung">Veranstaltung</label>:
<select name="veranstaltung">{{range $course := .Courses}}
<select name="veranstaltung" id="veranstaltung">{{range $course := .Courses}}
<option value="{{$course.Id}}"{{if eq $course.Id $.SelectedCourse}} selected{{end}}>{{$course.Name}}</option>{{end}}
</select><br />
<label for="woche">Woche</label>:
<select name="woche">
<select name="woche" id="woche">
<option value="0"{{if eq 0 $.Date.Week}} selected{{end}}>Jede</option>
<option value="1"{{if eq 1 $.Date.Week}} selected{{end}}>Gerade</option>
<option value="2"{{if eq 2 $.Date.Week}} selected{{end}}>Ungerade</option>
<option value="1"{{if eq 1 $.Date.Week}} selected{{end}}>Ungerade</option>
<option value="2"{{if eq 2 $.Date.Week}} selected{{end}}>Gerade</option>
</select><br />
<label for="tag">Tag</label>: <select name="tag">
<label for="tag">Tag</label>: <select name="tag" id="tag">
<option value="0"{{if eq 0 $.Date.Day}} selected{{end}}>Montag</option>
<option value="1"{{if eq 1 $.Date.Day}} selected{{end}}>Dienstag</option>
<option value="2"{{if eq 2 $.Date.Day}} selected{{end}}>Mittwoch</option>
<option value="3"{{if eq 3 $.Date.Day}} selected{{end}}>Donnerstag</option>
<option value="4"{{if eq 4 $.Date.Day}} selected{{end}}>Freitag</option>
</select><br />
<label for="startzeit">Startzeit</label>: <input type="time" name="startzeit" min="08:00" max="17:30" {{if gt $.Date.Hour 7}}value="{{printf "%02d" $.Date.Hour}}:{{printf "%02d" $.Date.Minute}}"{{end}} required/><br />
<label for="dauer">Dauer in Minuten</label>: <input name="dauer" type="number" min="{{.MinuteGranularity}}" max="120" step="{{.MinuteGranularity}}" value="{{.Duration}}" required/><br />
<label for="startzeit">Startzeit</label>: <input type="time" name="startzeit" id="startzeit" min="08:00" max="17:30" {{if gt $.Date.Hour 7}}value="{{printf "%02d" $.Date.Hour}}:{{printf "%02d" $.Date.Minute}}"{{end}} required/><br />
<label for="dauer">Dauer in Minuten</label>: <input name="dauer" id="dauer" type="number" min="{{.MinuteGranularity}}" max="120" step="{{.MinuteGranularity}}" value="{{.Duration}}" required/><br />
<label for="raum">Raum</label>:
<select name="raum">{{range $room := .Rooms}}
<select name="raum" id="raum">{{range $room := .Rooms}}
<option value="{{$room.Id}}"{{if eq $room.Id $.SelectedRoom}} selected{{end}}>{{$room.Name}}</option>{{end}}
</select><br />
<label for="raumname">Raumname (für Sonderräume)</label>: <input type="text" name="raumname" value="{{.Roomname}}"/><br />
<label for="name">Name</label>: <input name="name" type="text" size="50" value="{{.Name}}" required/><br />
<label for="raumname">Raumname (für Sonderräume)</label>: <input type="text" name="raumname" id="raumname" value="{{.Roomname}}"/><br />
<label for="name">Name</label>: <input name="name" id="name" type="text" size="50" value="{{.Name}}" required/><br />
<label for="email">Email-Adresse</label>:
<input name="email" type="email" size="50" value="{{.Email}}" required/><br />
<label for="info">Info</label>: <input name="info" type="text" size="50" value="{{.Info}}"/><br />
<input name="email" id="email" type="email" size="50" value="{{.Email}}" required/><br />
<label for="info">Info</label>: <input name="info" id="info" type="text" size="50" value="{{.Info}}"/><br />
<input type="submit">
</form>
</p>
{{if ne .Config.Tutor.MailSuffix ""}}Du musst hier eine Email-Adresse angeben, die auf „{{.Config.Tutor.MailSuffix}}“ endet.<br />{{end}}
Außerdem dürfen in Räumen nur begrenzt viele Sprechstunden gleichzeitig stattfinden, nämlich
<dl>
{{range $room := .Rooms}}
<dt>{{$room.Name}}</dt><dl>{{$room.MaxOccupy}} Sprechstunde{{if gt $room.MaxOccupy 1}}n{{end}}</dl><br />{{end}}
<dt>{{$room.Name}}</dt><dd>{{$room.MaxOccupy}} Sprechstunde{{if gt $room.MaxOccupy 1}}n{{end}}</dd>{{end}}
</dl>
{{template "footer.html" .}}
</body>

View file

@ -1,6 +1,8 @@
<html>
<!DOCTYPE html>
<html lang="de">
<head>
<title>Sprechstunde anlegen</title>
{{template "head.html" .}}
</head>
<body>
Die Sprechstunde wurde angelegt. Du solltest eine Mail mit einem Aktivierungslink erhalten haben.

View file

@ -1,6 +1,8 @@
<html>
<!DOCTYPE html>
<html lang="de">
<head>
<title>Sprechstunde löschen</title>
{{template "head.html" .}}
</head>
<body>
Du solltest eine Mail mit einem Bestätigungslink erhalten haben.

View file

@ -1,6 +1,8 @@
<html>
<!DOCTYPE html>
<html lang="de">
<head>
<title>Anfrage ausführen fehlgeschlagen</title>
{{template "head.html" .}}
</head>
<body>
Irgendetwas ist schief gegangen. Bitte sende folgende Daten an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a> mit einer Beschreibung, was du tun wolltest.

View file

@ -1,9 +1,11 @@
<html>
<!DOCTYPE html>
<html lang="de">
<head>
<title>Anfrage ausgeführt</title>
{{template "head.html" .}}
</head>
<body>
Deine Anfrage wurde ausgeführt.
Deine Anfrage wurde ausgeführt. <br />
{{template "footer.html" .}}
</body>
</html>

View file

@ -1,4 +1,5 @@
<footer>
<a href="/">Startseite</a><br />
<a href="/addOfficeHour">Sprechstunde anlegen</a><br />
<a href="/deleteOfficeHour">Sprechstunde löschen</a><br />
Technische Fragen an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a>

4
templates/head.html Normal file
View file

@ -0,0 +1,4 @@
<meta charset="UTF-8">
<meta name="keywords" content="Mathebau, Sprechstunde, Sprechstunden, Mathe, Mathematik, technische, Universität, Darmstadt, TU, Fachschaft">
<meta name="description" content="Eine Übersicht der Sprechstunden, die in den offenen Arbeitsräumen der Fachschaft Mathematik, TU Darmstadt, angeboten werden">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

View file

@ -1,11 +1,13 @@
<html>
<!DOCTYPE html>
<html lang="de">
<head>
<title>Sprechstunden</title>
{{template "head.html" .}}
</head>
<body>
<form method="GET" action="/getByCourse">
<label for="veranstaltung">Veranstaltung: </label>
<select name="veranstaltung" size="1" onchange="document.forms[0].submit()">
<select name="veranstaltung" id="veranstaltung" size="1" onchange="document.forms[0].submit()">
<option value="">Alle</option>
{{range $course := .Courses}}
<option value="{{$course.Id}}"{{if eq $course.Id $.SelectedCourse}} selected{{end}}>{{$course.Name}}</option>{{end}}
@ -14,7 +16,7 @@
</form>
<form method="GET" action="/getByRoom">
<label for="raum">Raum: </label>
<select name="raum" size="1" onchange="document.forms[1].submit()">
<select name="raum" id="raum" size="1" onchange="document.forms[1].submit()">
<option value="">Alle</option>
{{range $room := .Rooms}}
<option value="{{$room.Id}}"{{if eq $room.Id $.SelectedRoom}} selected{{end}}>{{$room.Name}}</option>{{end}}

View file

@ -1,6 +1,8 @@
<html>
<!DOCTYPE html>
<html lang="de">
<head>
<title>Anfrage bestätigen fehlgeschlagen</title>
{{template "head.html" .}}
</head>
<body>
<p>
@ -8,7 +10,7 @@
Bitte gib deinen Bestätigungscode hier ein.
</p>
<form action="/confirmRequest">
<label for="code">Bestätigungscode</label>: <input type="text" name="code"/>
<label for="code">Bestätigungscode</label>: <input type="text" name="code" id="code"/>
<input type="submit" />
</form>
{{template "footer.html" .}}

View file

@ -1,7 +1,9 @@
<td rowspan="{{divide .OfficeHour.Duration .MinuteGranularity}}" style="border: 1px solid">
{{if .DeleteIcons}}<div style="text-align: right;"><a href="/deleteOfficeHour?id={{.OfficeHour.Id}}"></a></div>{{end}}
{{printf "%02d" .OfficeHour.Date.Hour}}:{{printf "%02d" .OfficeHour.Date.Minute}} - {{printf "%02d" .OfficeHour.EndDate.Hour}}:{{printf "%02d" .OfficeHour.EndDate.Minute}}<br />
{{if eq .OfficeHour.Date.Week 1}}in ungeraden Wochen<br />{{end}}{{if eq .OfficeHour.Date.Week 2}}in geraden Wochen<br />{{end}}
{{.OfficeHour.Course.Name}}<br />
{{.OfficeHour.Tutor.Name}}<br />
{{.OfficeHour.Room.Name}}
{{.OfficeHour.Room.Name}}<br />
{{if ne .OfficeHour.Info ""}}{{.OfficeHour.Info}}<br />{{end}}
</td>