Merge remote-tracking branch 'origin/main' into styling
This commit is contained in:
commit
961a10915b
13 changed files with 193 additions and 74 deletions
|
@ -2,6 +2,7 @@ package controllers
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/mail"
|
||||
"officeHours/config"
|
||||
|
@ -151,9 +152,16 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
|
|||
b.serveTemplate(w, "addFailure", err)
|
||||
return
|
||||
}
|
||||
officeHour, _ = b.officeHourRepo.FindById(id)
|
||||
b.requestRepo.Add(officeHour, models.RequestActivate)
|
||||
officeHour, err = b.officeHourRepo.FindById(id)
|
||||
if err != nil {
|
||||
log.Printf("Error finding new office hour by id %d: %s", id, err.Error())
|
||||
}
|
||||
_, err = b.requestRepo.Add(officeHour, models.RequestActivate)
|
||||
if err != nil {
|
||||
log.Printf("Error adding request: %s", err.Error())
|
||||
}
|
||||
b.serveTemplate(w, "addSuccess", nil)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,12 +9,14 @@ func (b *BaseHandler) ConfirmRequestHandler(w http.ResponseWriter, req *http.Req
|
|||
request, err := b.requestRepo.FindBySecret(secret)
|
||||
|
||||
if err != nil {
|
||||
// TODO: header 404
|
||||
b.serveTemplate(w, "requestNotFound", nil)
|
||||
return
|
||||
}
|
||||
|
||||
err = b.requestRepo.Execute(request)
|
||||
if err != nil {
|
||||
// TODO: write header 500
|
||||
b.serveTemplate(w, "executeFailure", err.Error())
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package controllers
|
|||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"officeHours/models"
|
||||
"strconv"
|
||||
|
@ -18,7 +19,10 @@ func (b *BaseHandler) GetByRoomHandler(w http.ResponseWriter, req *http.Request)
|
|||
b.RootHandler(w, req)
|
||||
return
|
||||
}
|
||||
officeHours, _ := b.officeHourRepo.FindByRoom(room, true)
|
||||
officeHours, err := b.officeHourRepo.FindByRoom(room, true)
|
||||
if err != nil {
|
||||
log.Printf("Error getting office hours for room %s: %s", room.Name, err.Error())
|
||||
}
|
||||
timetable, slots := b.GetTimetable(officeHours)
|
||||
b.writeTimetablePage(w, req, b.printTimetable(timetable, slots, false))
|
||||
}
|
||||
|
@ -34,7 +38,10 @@ func (b *BaseHandler) GetByCourseHandler(w http.ResponseWriter, req *http.Reques
|
|||
b.RootHandler(w, req)
|
||||
return
|
||||
}
|
||||
officeHours, _ := b.officeHourRepo.FindByCourse(course, true)
|
||||
officeHours, err := b.officeHourRepo.FindByCourse(course, true)
|
||||
if err != nil {
|
||||
log.Printf("Error getting office hours for course %s: %s", course.Name, err.Error())
|
||||
}
|
||||
timetable, slots := b.GetTimetable(officeHours)
|
||||
b.writeTimetablePage(w, req, b.printTimetable(timetable, slots, false))
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func (b *BaseHandler) serveTemplate(w http.ResponseWriter, name string, data any
|
|||
}
|
||||
|
||||
// standalone templates that should not be wrapped into the base.html
|
||||
var RawTemplates = template.Must(template.New("").Funcs(funcs).ParseFiles(
|
||||
var RawTemplates, TemplateError = template.New("").Funcs(funcs).ParseFiles(
|
||||
"templates/confirmationMail",
|
||||
"templates/td.html",
|
||||
"templates/officeHourTable.html"))
|
||||
"templates/officeHourTable.html")
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"officeHours/models"
|
||||
)
|
||||
|
||||
|
@ -84,7 +85,10 @@ func (b *BaseHandler) printTimetable(timetable map[models.Date]map[int]models.Of
|
|||
MinuteGranularity int
|
||||
DeleteIcons bool
|
||||
}{OfficeHour: current, MinuteGranularity: b.config.Date.MinuteGranularity, DeleteIcons: deleteIcons}
|
||||
RawTemplates.ExecuteTemplate(&celldata, "td.html", data)
|
||||
templateError := RawTemplates.ExecuteTemplate(&celldata, "td.html", data)
|
||||
if templateError != nil {
|
||||
log.Printf("Error executing template td.html: %s", templateError.Error())
|
||||
}
|
||||
tableBody += celldata.String()
|
||||
}
|
||||
} else {
|
||||
|
@ -116,6 +120,9 @@ func (b *BaseHandler) printTimetable(timetable map[models.Date]map[int]models.Of
|
|||
slots[4],
|
||||
template.HTML(tableBody),
|
||||
}
|
||||
RawTemplates.ExecuteTemplate(&table, "officeHourTable.html", tableData)
|
||||
templateError := RawTemplates.ExecuteTemplate(&table, "officeHourTable.html", tableData)
|
||||
if templateError != nil {
|
||||
log.Printf("Error executing template officeHourTable.html: %s", templateError.Error())
|
||||
}
|
||||
return template.HTML(table.String())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue