Compare commits
1 commit
deced3e596
...
e05d30b886
Author | SHA1 | Date | |
---|---|---|---|
e05d30b886 |
11 changed files with 42 additions and 34 deletions
|
@ -69,6 +69,13 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
|
|||
errors = append(errors, "Der Raum muss existieren.")
|
||||
}
|
||||
//Parse date
|
||||
week, err := strconv.Atoi(req.FormValue("woche"))
|
||||
if err != nil {
|
||||
errors = append(errors, "Die Vorlesungswoche muss eine ganze Zahl sein.")
|
||||
}
|
||||
if !(week >= 0 && week <= 5) {
|
||||
errors = append(errors, "Bitte wähle eine der vorgegebenen Optionen für Vorlesungswochen.")
|
||||
}
|
||||
day, err := strconv.Atoi(req.FormValue("tag"))
|
||||
if err != nil {
|
||||
errors = append(errors, "Der Tag muss eine ganze Zahl sein.")
|
||||
|
@ -99,7 +106,7 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
|
|||
errors = append(errors, fmt.Sprintf("Sprechstunden dürfen nur alle %d Minuten starten.", b.config.Date.MinuteGranularity))
|
||||
}
|
||||
}
|
||||
date := models.Date{Week: req.FormValue("woche"), Day: day, Hour: hour, Minute: minute}
|
||||
date := models.Date{Week: week, Day: day, Hour: hour, Minute: minute}
|
||||
duration, err := strconv.Atoi(req.FormValue("dauer"))
|
||||
if err != nil {
|
||||
errors = append(errors, "Die Dauer muss eine ganze Zahl sein.")
|
||||
|
|
|
@ -61,16 +61,16 @@ func (b *BaseHandler) printTimetable(timetable map[models.Date]map[int]models.Of
|
|||
}
|
||||
for day := 0; day < 5; day += 1 {
|
||||
for slot := 0; slot < slots[day]; slot += 1 {
|
||||
current, currentExists := timetable[models.Date{Week: "", Day: day, Hour: hour, Minute: minute}][slot]
|
||||
current, currentExists := timetable[models.Date{Week: 0, Day: day, Hour: hour, Minute: minute}][slot]
|
||||
|
||||
if currentExists { // This slot is taken by some office hour
|
||||
var continued bool = false // is this slot occupied by the same office hour the previous minute?
|
||||
var predecessorExists bool
|
||||
var predecessor models.OfficeHour
|
||||
if hour > 0 && minute < b.config.Date.MinuteGranularity {
|
||||
predecessor, predecessorExists = timetable[models.Date{Week: "", Day: day, Hour: hour - 1, Minute: 60 - b.config.Date.MinuteGranularity}][slot]
|
||||
predecessor, predecessorExists = timetable[models.Date{Week: 0, Day: day, Hour: hour - 1, Minute: 60 - b.config.Date.MinuteGranularity}][slot]
|
||||
} else {
|
||||
predecessor, predecessorExists = timetable[models.Date{Week: "", Day: day, Hour: hour, Minute: minute - b.config.Date.MinuteGranularity}][slot]
|
||||
predecessor, predecessorExists = timetable[models.Date{Week: 0, Day: day, Hour: hour, Minute: minute - b.config.Date.MinuteGranularity}][slot]
|
||||
}
|
||||
if predecessorExists {
|
||||
continued = (predecessor == current)
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
type Date struct {
|
||||
Week string
|
||||
Week int // Set whether the date is all weeks (0), weeks with exercise session (1) or weeks without exercise session (2), even weeks (3), odd weeks (4) or other (5).
|
||||
Day int
|
||||
Hour int
|
||||
Minute int
|
||||
|
@ -54,7 +54,7 @@ func DateLess(first Date, second Date) bool {
|
|||
func GetEndDate(date Date, duration int, ignoreWeek bool) Date {
|
||||
var endDate Date
|
||||
if ignoreWeek {
|
||||
endDate = Date{"", date.Day, date.Hour, date.Minute} // deep copy
|
||||
endDate = Date{0, date.Day, date.Hour, date.Minute} // deep copy
|
||||
} else {
|
||||
endDate = Date{date.Week, date.Day, date.Hour, date.Minute}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ func TestEndDate(t *testing.T) {
|
|||
duration int
|
||||
endDate Date
|
||||
}{
|
||||
{Date{Week: "", Day: 0, Hour: 8, Minute: 0}, 10, Date{Week: "", Day: 0, Hour: 8, Minute: 10}},
|
||||
{Date{Week: "", Day: 0, Hour: 8, Minute: 0}, 90, Date{Week: "", Day: 0, Hour: 9, Minute: 30}}, // More than one hour
|
||||
{Date{Week: "", Day: 0, Hour: 8, Minute: 0}, 130, Date{Week: "", Day: 0, Hour: 10, Minute: 10}}, // More than two hours
|
||||
{Date{Week: "", Day: 0, Hour: 8, Minute: 15}, 90, Date{Week: "", Day: 0, Hour: 9, Minute: 45}}, // More than one hour and start not 0
|
||||
{Date{Week: "", Day: 0, Hour: 23, Minute: 15}, 90, Date{Week: "", Day: 1, Hour: 0, Minute: 45}}, // More than one day
|
||||
{Date{Week: 0, Day: 0, Hour: 8, Minute: 0}, 10, Date{Week: 0, Day: 0, Hour: 8, Minute: 10}},
|
||||
{Date{Week: 0, Day: 0, Hour: 8, Minute: 0}, 90, Date{Week: 0, Day: 0, Hour: 9, Minute: 30}}, // More than one hour
|
||||
{Date{Week: 0, Day: 0, Hour: 8, Minute: 0}, 130, Date{Week: 0, Day: 0, Hour: 10, Minute: 10}}, // More than two hours
|
||||
{Date{Week: 0, Day: 0, Hour: 8, Minute: 15}, 90, Date{Week: 0, Day: 0, Hour: 9, Minute: 45}}, // More than one hour and start not 0
|
||||
{Date{Week: 0, Day: 0, Hour: 23, Minute: 15}, 90, Date{Week: 0, Day: 1, Hour: 0, Minute: 45}}, // More than one day
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(fmt.Sprintf("%d:%d, Dauer %d", tc.startDate.Hour, tc.startDate.Minute, tc.duration), func(t *testing.T) {
|
||||
|
@ -35,21 +35,21 @@ func TestDateLess(t *testing.T) {
|
|||
less bool
|
||||
}{
|
||||
{"earlier day",
|
||||
Date{Week: "", Day: 1, Hour: 8, Minute: 10}, Date{Week: "", Day: 0, Hour: 7, Minute: 10}, false},
|
||||
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 0, Hour: 7, Minute: 10}, false},
|
||||
{"earlier hour",
|
||||
Date{Week: "", Day: 1, Hour: 8, Minute: 10}, Date{Week: "", Day: 1, Hour: 7, Minute: 10}, false},
|
||||
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 7, Minute: 10}, false},
|
||||
{"earlier minute",
|
||||
Date{Week: "", Day: 1, Hour: 8, Minute: 10}, Date{Week: "", Day: 1, Hour: 8, Minute: 0}, false},
|
||||
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 8, Minute: 0}, false},
|
||||
{"same date",
|
||||
Date{Week: "", Day: 1, Hour: 8, Minute: 10}, Date{Week: "", Day: 1, Hour: 8, Minute: 10}, false},
|
||||
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, false},
|
||||
{"later minute",
|
||||
Date{Week: "", Day: 1, Hour: 8, Minute: 10}, Date{Week: "", Day: 1, Hour: 8, Minute: 20}, true},
|
||||
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 8, Minute: 20}, true},
|
||||
{"later hour",
|
||||
Date{Week: "", Day: 1, Hour: 8, Minute: 10}, Date{Week: "", Day: 1, Hour: 9, Minute: 10}, true},
|
||||
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 9, Minute: 10}, true},
|
||||
{"later day",
|
||||
Date{Week: "", Day: 1, Hour: 8, Minute: 10}, Date{Week: "", Day: 2, Hour: 8, Minute: 10}, true},
|
||||
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 2, Hour: 8, Minute: 10}, true},
|
||||
{"week should not matter",
|
||||
Date{Week: "", Day: 1, Hour: 8, Minute: 10}, Date{Week: "every", Day: 1, Hour: 9, Minute: 30}, true},
|
||||
Date{Week: 1, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 9, Minute: 30}, true},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
|
|
@ -47,7 +47,7 @@ CREATE TABLE `officeHour` (
|
|||
`room` int DEFAULT NULL,
|
||||
`roomname` text DEFAULT NULL,
|
||||
`course` int DEFAULT NULL,
|
||||
`week` varchar(255) DEFAULT NULL,
|
||||
`week` int DEFAULT NULL,
|
||||
`info` text DEFAULT NULL,
|
||||
`active` bool DEFAULT NULL,
|
||||
`duration` int DEFAULT NULL,
|
||||
|
|
|
@ -36,7 +36,7 @@ CREATE TABLE `officeHour` (
|
|||
`room` int DEFAULT NULL,
|
||||
`roomname` text DEFAULT NULL,
|
||||
`course` int DEFAULT NULL,
|
||||
`week` tinytext DEFAULT NULL,
|
||||
`week` int DEFAULT NULL,
|
||||
`info` text DEFAULT NULL,
|
||||
`active` bool DEFAULT NULL,
|
||||
`duration` int DEFAULT NULL,
|
||||
|
|
|
@ -157,8 +157,7 @@ func (r *OfficeHourRepo) Delete(officeHour models.OfficeHour) error {
|
|||
|
||||
func (r *OfficeHourRepo) getFromRow(row *sql.Row) (models.OfficeHour, error) {
|
||||
var officeHour models.OfficeHour
|
||||
var day, hour, minute, tutorId, courseId, roomId int
|
||||
var week string
|
||||
var week, day, hour, minute, tutorId, courseId, roomId int
|
||||
err := row.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &officeHour.RoomName, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error getting single officeHour row from database: %w", err)
|
||||
|
@ -191,8 +190,7 @@ func (r *OfficeHourRepo) getFromRows(rows *sql.Rows) ([]models.OfficeHour, error
|
|||
var officeHours []models.OfficeHour
|
||||
for rows.Next() {
|
||||
var officeHour models.OfficeHour
|
||||
var day, hour, minute, tutorId, roomId, courseId int
|
||||
var week string
|
||||
var week, day, hour, minute, tutorId, roomId, courseId int
|
||||
var err error
|
||||
if err := rows.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &officeHour.RoomName, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration); err != nil {
|
||||
return officeHours, fmt.Errorf("error getting multiple officeHour rows from database: %w", err)
|
||||
|
|
|
@ -58,13 +58,15 @@
|
|||
<div class="col-md-6">
|
||||
|
||||
<div class="form-floating mb-3">
|
||||
<input class="form-control form-text" type="text" name="woche" id="woche" list="woche_list" value="{{$.Date.Week}}">
|
||||
<datalist id="woche_list">
|
||||
<option>Jede Woche</option>
|
||||
<option>In Wochen mit Übung</option>
|
||||
<option>In Wochen ohne Übung</option>
|
||||
</datalist>
|
||||
<label for="woche">Vorlesungswoche (z.B. jede / mit Übung / ohne Übung)</label>
|
||||
<select class="form-control form-select required" required name="woche" id="woche">
|
||||
<option value="0"{{if eq 0 $.Date.Week}} selected{{end}}>Jede Woche</option>
|
||||
<option value="1"{{if eq 1 $.Date.Week}} selected{{end}}>In Wochen mit Übung</option>
|
||||
<option value="2"{{if eq 2 $.Date.Week}} selected{{end}}>In Wochen ohne Übung</option>
|
||||
<option value="1"{{if eq 3 $.Date.Week}} selected{{end}}>In geraden Vorlesungswochen</option>
|
||||
<option value="2"{{if eq 4 $.Date.Week}} selected{{end}}>In ungeraden Vorlesungswochen</option>
|
||||
<option value="2"{{if eq 5 $.Date.Week}} selected{{end}}>Etwas anderes (nutze Infofeld)</option>
|
||||
</select>
|
||||
<label for="woche">Vorlesungswoche</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -5,6 +5,7 @@ mit deiner Emailadresse soll eine Sprechstunde mit folgenden Daten {{if eq .Requ
|
|||
{{.Request.OfficeHour.Course.Name}}
|
||||
{{DayName .Request.OfficeHour.Date.Day}}
|
||||
{{printf "%02d" .Request.OfficeHour.Date.Hour}}:{{printf "%02d" .Request.OfficeHour.Date.Minute}} Uhr bis {{printf "%02d" .Request.OfficeHour.EndDate.Hour}}:{{printf "%02d" .Request.OfficeHour.EndDate.Minute}} Uhr
|
||||
{{if eq 0 .Request.OfficeHour.Date.Week}}Jede Woche{{end}}{{if eq 1 .Request.OfficeHour.Date.Week}}In Wochen mit Übung{{end}}{{if eq 2 .Request.OfficeHour.Date.Week}}In Wochen ohne Übung{{end}}{{if eq 3 .Request.OfficeHour.Date.Week}}In geraden Vorlesungswochen{{end}}{{if eq 4 .Request.OfficeHour.Date.Week}}In ungeraden Vorlesungswochen{{end}}
|
||||
{{.Request.OfficeHour.Tutor.Name}}
|
||||
{{.Request.OfficeHour.Room.Name}}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<p>
|
||||
Willst du die Sprechstunde<br>
|
||||
{{printf "%02d" .OfficeHour.Date.Hour}}:{{printf "%02d" .OfficeHour.Date.Minute}} - {{printf "%02d" .OfficeHour.EndDate.Hour}}:{{printf "%02d" .OfficeHour.EndDate.Minute}}<br>
|
||||
{{if not (eq .OfficeHour.Date.Week "")}}{{ .OfficeHour.Date.Week }}<br>{{end}}
|
||||
{{if eq 0 $.Date.Week}}>Jede Woche<br>{{end}}{{if eq 1 $.Date.Week}}In Wochen mit Übung<br>{{end}}{{if eq 2 $.Date.Week}}In Wochen ohne Übung<br>{{end}}{{if eq 3 $.Date.Week}}In geraden Vorlesungswochen<br>{{end}}{{if eq 4 $.Date.Week}}In ungeraden Vorlesungswochen<br>{{end}}
|
||||
{{.OfficeHour.Course.Name}}<br>
|
||||
{{.OfficeHour.Tutor.Name}}<br>
|
||||
{{.OfficeHour.Room.Name}}<br>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<td class="officeHour" rowspan="{{divide .OfficeHour.Duration .MinuteGranularity}}">
|
||||
{{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 not (eq .OfficeHour.Date.Week "")}}{{.OfficeHour.Date.Week}}<br>{{end}}
|
||||
{{if eq 1 .OfficeHour.Date.Week}}In Wochen mit Übung<br>{{end}}{{if eq 2 .OfficeHour.Date.Week}}In Wochen ohne Übung<br>{{end}}{{if eq 3 .OfficeHour.Date.Week}}In geraden Vorlesungswochen<br>{{end}}{{if eq 4 .OfficeHour.Date.Week}}In ungeraden Vorlesungswochen<br>{{end}}
|
||||
{{.OfficeHour.Course.Name}}<br>
|
||||
{{.OfficeHour.Tutor.Name}}<br>
|
||||
{{.OfficeHour.Room.Name}}
|
||||
|
|
Loading…
Add table
Reference in a new issue