diff --git a/config/config.go b/config/config.go index 812e00e..c284627 100644 --- a/config/config.go +++ b/config/config.go @@ -24,6 +24,7 @@ type Config struct { } Date struct { MinuteGranularity int // Restricts the minutes on which office hours can start and end to multiples of it. + MaxDuration int // Limits the length of office hours to minutes EarliestStartTime struct { Hour int Minute int @@ -103,6 +104,10 @@ func validateConfig(conf *Config) error { err = fmt.Errorf("Validating config: Earliest start time minute must be between 0 and 60, but is %d.", conf.Date.EarliestStartTime.Minute) log.Println(err.Error()) } + if !(conf.Date.MaxDuration >= conf.Date.MinuteGranularity && conf.Date.MaxDuration <= 4*60) { + err = fmt.Errorf("Validating config: Maximum duration must be between %d minute and 4 hours, but is %d.", conf.Date.MinuteGranularity, conf.Date.MaxDuration) + log.Println(err.Error()) + } if !(conf.Date.LatestStartTime.Hour >= 0 && conf.Date.LatestStartTime.Hour <= 23) { err = fmt.Errorf("Validating config: Latest start time hour must be between 0 and 23, but is %d.", conf.Date.LatestStartTime.Hour) log.Println(err.Error()) diff --git a/config/config.json b/config/config.json index 40b1bb3..2e78982 100644 --- a/config/config.json +++ b/config/config.json @@ -7,6 +7,7 @@ }, "date": { "minuteGranularity": 5, + "maxDuration": 120, "earliestStartTime": { "hour" : 8, "minute" : 0 diff --git a/controllers/addOfficeHourHandler.go b/controllers/addOfficeHourHandler.go index 56289e7..816a874 100644 --- a/controllers/addOfficeHourHandler.go +++ b/controllers/addOfficeHourHandler.go @@ -16,6 +16,7 @@ type maskData struct { Courses []models.Course Rooms []models.Room MinuteGranularity int + MaxDuration int EarliestStartTime struct { Hour int Minute int @@ -109,8 +110,8 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ if err != nil { errors = append(errors, "Die Dauer muss eine ganze Zahl sein.") } - if !(duration >= b.config.Date.MinuteGranularity && duration <= 120 && duration%b.config.Date.MinuteGranularity == 0) { - errors = append(errors, fmt.Sprintf("Sprechstunden müssen zwischen %d und 120 Minuten lang sein.", b.config.Date.MinuteGranularity)) + if !(duration >= b.config.Date.MinuteGranularity && duration <= b.config.Date.MaxDuration && duration%b.config.Date.MinuteGranularity == 0) { + errors = append(errors, fmt.Sprintf("Sprechstunden müssen zwischen %d und %d Minuten lang sein.", b.config.Date.MinuteGranularity, b.config.Date.MaxDuration)) } roomname := req.FormValue("raumname") @@ -144,6 +145,7 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ courses, rooms, b.config.Date.MinuteGranularity, + b.config.Date.MaxDuration, b.config.Date.EarliestStartTime, b.config.Date.LatestStartTime, courseid, diff --git a/controllers/timetable.go b/controllers/timetable.go index 0d7b379..1f9b413 100644 --- a/controllers/timetable.go +++ b/controllers/timetable.go @@ -51,7 +51,7 @@ func (b *BaseHandler) printTimetable(timetable map[models.Date]map[int]models.Of return template.HTML("

Aktuell sind keine passenden Sprechstunden eingetragen.

") } var tableBody string - for hour := 8; hour < 19; hour += 1 { + for hour := b.config.Date.EarliestStartTime.Hour; hour < b.config.Date.LatestStartTime.Hour+b.config.Date.MaxDuration/60; hour += 1 { for minute := 0; minute < 60; minute += b.config.Date.MinuteGranularity { tableBody += "" if minute == 0 { diff --git a/templating/templates/addMask.html b/templating/templates/addMask.html index 1b36f24..ab7ed6a 100644 --- a/templating/templates/addMask.html +++ b/templating/templates/addMask.html @@ -90,7 +90,7 @@