Mache maximale Sprechstundenlänge konfigurierbar

This commit is contained in:
Gonne 2023-10-26 11:29:42 +02:00
parent a631c33883
commit 5a8a248c53
5 changed files with 12 additions and 4 deletions

View file

@ -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())

View file

@ -7,6 +7,7 @@
},
"date": {
"minuteGranularity": 5,
"maxDuration": 120,
"earliestStartTime": {
"hour" : 8,
"minute" : 0

View file

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

View file

@ -51,7 +51,7 @@ func (b *BaseHandler) printTimetable(timetable map[models.Date]map[int]models.Of
return template.HTML("<p class=\"text-center\">Aktuell sind keine passenden Sprechstunden eingetragen.</p>")
}
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 += "<tr>"
if minute == 0 {

View file

@ -90,7 +90,7 @@
<div class="form-floating mb-3">
<input class="form-control required" required name="dauer" id="dauer" type="number"
min="{{.MinuteGranularity}}" max="120" step="{{.MinuteGranularity}}"
min="{{.MinuteGranularity}}" max="{{.MaxDuration}}" step="{{.MinuteGranularity}}"
{{ if ne .Duration 0}}value="{{.Duration}}"{{end}} placeholder="">
<label for="dauer">Dauer in Minuten</label>
</div>