diff --git a/controllers/templates.go b/controllers/templates.go index 4659e26..6648603 100644 --- a/controllers/templates.go +++ b/controllers/templates.go @@ -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")). diff --git a/main.go b/main.go index 83e3065..6499bcc 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/repositories/officeHour.go b/repositories/officeHour.go index ff04b82..5dff4a0 100644 --- a/repositories/officeHour.go +++ b/repositories/officeHour.go @@ -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 - for _, officeHour := range officeHours { - if models.DateLess(models.GetEndDate(officeHour.Date, officeHour.Duration, false), date) || models.GetEndDate(officeHour.Date, officeHour.Duration, false) == date { - continue + // 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 { + // 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 + if minuteCount > count { + count = minuteCount } - count += 1 } return count, nil } diff --git a/templates/addFailure.html b/templates/addFailure.html index e032c42..f160553 100644 --- a/templates/addFailure.html +++ b/templates/addFailure.html @@ -1,6 +1,8 @@ - + + Sprechstunde anlegen + {{template "head.html" .}} Irgendetwas ist schief gegangen. Bitte sende folgende Daten an sprechstundentool@mathebau.de mit einer Beschreibung, was du tun wolltest. diff --git a/templates/addMask.html b/templates/addMask.html index e4e4e2b..8fbca62 100644 --- a/templates/addMask.html +++ b/templates/addMask.html @@ -1,49 +1,49 @@ - + + Sprechstunde anlegen + {{template "head.html" .}}

{{range .Errors}}{{.}}
{{end}}

-

-

- : -
- : -
- :
- :
- :
- : -
- :
- :
- : -
- :
- -
-

+
+ : +
+ : +
+ :
+ :
+ :
+ : +
+ :
+ :
+ : +
+ :
+ +
{{if ne .Config.Tutor.MailSuffix ""}}Du musst hier eine Email-Adresse angeben, die auf „{{.Config.Tutor.MailSuffix}}“ endet.
{{end}} Außerdem dürfen in Räumen nur begrenzt viele Sprechstunden gleichzeitig stattfinden, nämlich
{{range $room := .Rooms}} -
{{$room.Name}}
{{$room.MaxOccupy}} Sprechstunde{{if gt $room.MaxOccupy 1}}n{{end}}

{{end}} +
{{$room.Name}}
{{$room.MaxOccupy}} Sprechstunde{{if gt $room.MaxOccupy 1}}n{{end}}
{{end}}
{{template "footer.html" .}} diff --git a/templates/addSuccess.html b/templates/addSuccess.html index b253965..272e500 100644 --- a/templates/addSuccess.html +++ b/templates/addSuccess.html @@ -1,6 +1,8 @@ - + + Sprechstunde anlegen + {{template "head.html" .}} Die Sprechstunde wurde angelegt. Du solltest eine Mail mit einem Aktivierungslink erhalten haben. diff --git a/templates/deleteSuccess.html b/templates/deleteSuccess.html index 43502ac..01162c6 100644 --- a/templates/deleteSuccess.html +++ b/templates/deleteSuccess.html @@ -1,6 +1,8 @@ - + + Sprechstunde löschen + {{template "head.html" .}} Du solltest eine Mail mit einem Bestätigungslink erhalten haben. diff --git a/templates/executeFailure.html b/templates/executeFailure.html index c1d86ca..df27062 100644 --- a/templates/executeFailure.html +++ b/templates/executeFailure.html @@ -1,6 +1,8 @@ - + + Anfrage ausführen fehlgeschlagen + {{template "head.html" .}} Irgendetwas ist schief gegangen. Bitte sende folgende Daten an sprechstundentool@mathebau.de mit einer Beschreibung, was du tun wolltest. diff --git a/templates/executeSuccess.html b/templates/executeSuccess.html index a99efbb..1d4cdca 100644 --- a/templates/executeSuccess.html +++ b/templates/executeSuccess.html @@ -1,9 +1,11 @@ - + + Anfrage ausgeführt + {{template "head.html" .}} - Deine Anfrage wurde ausgeführt. + Deine Anfrage wurde ausgeführt.
{{template "footer.html" .}} \ No newline at end of file diff --git a/templates/footer.html b/templates/footer.html index 8b85b85..0736807 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -1,4 +1,5 @@