diff --git a/config/config.go b/config/config.go
index 15bd87a..76e8846 100644
--- a/config/config.go
+++ b/config/config.go
@@ -23,6 +23,14 @@ type Config struct {
}
Date struct {
MinuteGranularity int // Restricts the minutes on which office hours can start and end to multiples of it.
+ EarliestStartTime struct {
+ Hour int
+ Minute int
+ }
+ LatestStartTime struct {
+ Hour int
+ Minute int
+ }
}
Request struct {
SecretLength int // Length of the secret token for requests
@@ -86,6 +94,26 @@ func validateConfig(conf *Config) error {
err = fmt.Errorf("Validating config: Minute granularity must be between 1 and 60, but is %d.", conf.Date.MinuteGranularity)
log.Println(err.Error())
}
+ if !(conf.Date.EarliestStartTime.Hour >= 0 && conf.Date.EarliestStartTime.Hour <= 23) {
+ err = fmt.Errorf("Validating config: Earliest start time hour must be between 0 and 23, but is %d.", conf.Date.EarliestStartTime.Hour)
+ log.Println(err.Error())
+ }
+ if !(conf.Date.EarliestStartTime.Minute >= 0 && conf.Date.EarliestStartTime.Minute <= 60) {
+ 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.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())
+ }
+ if !(conf.Date.LatestStartTime.Minute >= 0 && conf.Date.LatestStartTime.Minute <= 60) {
+ err = fmt.Errorf("Validating config: Latest start time minute must be between 0 and 60, but is %d.", conf.Date.LatestStartTime.Minute)
+ log.Println(err.Error())
+ }
+ if !(conf.Date.EarliestStartTime.Hour < conf.Date.LatestStartTime.Hour || (conf.Date.EarliestStartTime.Hour == conf.Date.LatestStartTime.Hour && conf.Date.EarliestStartTime.Minute < conf.Date.LatestStartTime.Minute)) {
+ err = fmt.Errorf("Validating config: Latest start time minute must be after earliest start time.")
+ log.Println(err.Error())
+ }
if !(conf.Request.SecretLength >= 5 && conf.Request.SecretLength <= 50) {
err = fmt.Errorf("Validating config: Requests' secret length must be between 5 and 50, but is %d.", conf.Request.SecretLength)
log.Println(err.Error())
diff --git a/config/config.json b/config/config.json
index b96993d..40b1bb3 100644
--- a/config/config.json
+++ b/config/config.json
@@ -6,7 +6,15 @@
"domain": "localhost:8080"
},
"date": {
- "minuteGranularity": 5
+ "minuteGranularity": 5,
+ "earliestStartTime": {
+ "hour" : 8,
+ "minute" : 0
+ },
+ "latestStartTime": {
+ "hour" : 20,
+ "minute" : 0
+ }
},
"request": {
"secretLength": 15
diff --git a/controllers/addOfficeHourHandler.go b/controllers/addOfficeHourHandler.go
index e358cc8..0025ac2 100644
--- a/controllers/addOfficeHourHandler.go
+++ b/controllers/addOfficeHourHandler.go
@@ -16,16 +16,24 @@ type maskData struct {
Courses []models.Course
Rooms []models.Room
MinuteGranularity int
- SelectedCourse int
- SelectedRoom int
- Date models.Date
- Duration int
- Roomname string
- Name string
- Email string
- Info string
- Errors []string
- Config config.Config
+ EarliestStartTime struct {
+ Hour int
+ Minute int
+ }
+ LatestStartTime struct {
+ Hour int
+ Minute int
+ }
+ SelectedCourse int
+ SelectedRoom int
+ Date models.Date
+ Duration int
+ Roomname string
+ Name string
+ Email string
+ Info string
+ Errors []string
+ Config config.Config
}
// Offer a form to add office hours and validate its input on receiving.
@@ -81,8 +89,11 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
if err != nil {
errors = append(errors, "Die Stunde muss eine ganze Zahl sein.")
}
- if !(hour >= 8 && hour <= 17) {
- errors = append(errors, fmt.Sprintf("Sprechstunden müssen zwischen 08:00 Uhr und 17:%d starten.", 60-b.config.Date.MinuteGranularity))
+ if !(hour > b.config.Date.EarliestStartTime.Hour || (hour == b.config.Date.EarliestStartTime.Hour && minute >= b.config.Date.EarliestStartTime.Minute)) {
+ errors = append(errors, fmt.Sprintf("Sprechstunden müssen nach %02d:%02d Uhr starten.", b.config.Date.EarliestStartTime.Hour, b.config.Date.EarliestStartTime.Minute))
+ }
+ if !(hour < b.config.Date.LatestStartTime.Hour || (hour == b.config.Date.LatestStartTime.Hour && minute <= b.config.Date.LatestStartTime.Minute)) {
+ errors = append(errors, fmt.Sprintf("Sprechstunden müssen vor %02d:%02d Uhr starten.", b.config.Date.LatestStartTime.Hour, b.config.Date.LatestStartTime.Minute))
}
minute, err = strconv.Atoi(time[1])
if err != nil {
@@ -132,6 +143,8 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
courses,
rooms,
b.config.Date.MinuteGranularity,
+ b.config.Date.EarliestStartTime,
+ b.config.Date.LatestStartTime,
courseid,
roomid,
date,
diff --git a/templating/templates/addMask.html b/templating/templates/addMask.html
index de74138..7864090 100644
--- a/templating/templates/addMask.html
+++ b/templating/templates/addMask.html
@@ -24,7 +24,7 @@
- :
+ :
:
: