Sprechstunden löschen
This commit is contained in:
parent
78af58a51d
commit
2ce7a1fae1
15 changed files with 100 additions and 34 deletions
|
@ -155,7 +155,7 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
|
|||
}
|
||||
officeHour, _ = b.officeHourRepo.FindById(id)
|
||||
b.requestRepo.Add(officeHour, models.RequestActivate)
|
||||
tmpl, _ := template.ParseFiles("template/addSuccess.html")
|
||||
tmpl, err := template.ParseFiles("templates/addSuccess.html")
|
||||
tmpl.Execute(w, struct{}{})
|
||||
}
|
||||
}
|
||||
|
|
29
controllers/deleteOfficeHourHandler.go
Normal file
29
controllers/deleteOfficeHourHandler.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
// deleteOfficeHourHandler
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"sprechstundentool/models"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (b *BaseHandler) DeleteOfficeHourHandler(w http.ResponseWriter, req *http.Request) {
|
||||
if req.FormValue("id") != "" {
|
||||
id, err := strconv.Atoi(req.FormValue("id"))
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
officeHour, err := b.officeHourRepo.FindById(id)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
_, err = b.requestRepo.Add(officeHour, models.RequestDelete)
|
||||
tmpl, _ := template.New("deleteSuccess.html").ParseFiles("templates/deleteSuccess.html")
|
||||
tmpl.Execute(w, struct{}{})
|
||||
} else {
|
||||
officeHours, _ := b.officeHourRepo.GetAll(true)
|
||||
timetable, slots := GetTimetable(officeHours)
|
||||
b.writeTimetablePage(w, req, printTimetable(timetable, slots, true))
|
||||
}
|
||||
}
|
|
@ -20,7 +20,8 @@ func (b *BaseHandler) GetByRoomHandler(w http.ResponseWriter, req *http.Request)
|
|||
return
|
||||
}
|
||||
officeHours, _ := b.officeHourRepo.FindByRoom(room, true)
|
||||
b.writeTimetablePage(w, req, printTimetable(GetTimetable(officeHours)))
|
||||
timetable, slots := GetTimetable(officeHours)
|
||||
b.writeTimetablePage(w, req, printTimetable(timetable, slots, false))
|
||||
}
|
||||
|
||||
func (b *BaseHandler) GetByCourseHandler(w http.ResponseWriter, req *http.Request) {
|
||||
|
@ -34,7 +35,8 @@ func (b *BaseHandler) GetByCourseHandler(w http.ResponseWriter, req *http.Reques
|
|||
return
|
||||
}
|
||||
officeHours, _ := b.officeHourRepo.FindByCourse(course, true)
|
||||
b.writeTimetablePage(w, req, printTimetable(GetTimetable(officeHours)))
|
||||
timetable, slots := GetTimetable(officeHours)
|
||||
b.writeTimetablePage(w, req, printTimetable(timetable, slots, false))
|
||||
}
|
||||
|
||||
func (b *BaseHandler) writeTimetablePage(w http.ResponseWriter, req *http.Request, timetable template.HTML) {
|
||||
|
|
|
@ -47,10 +47,13 @@ func GetTimetable(officeHours []models.OfficeHour) (timetable map[models.Date]ma
|
|||
return fullTimetable, slots
|
||||
}
|
||||
|
||||
func printTimetable(timetable map[models.Date]map[int]models.OfficeHour, slots []int) template.HTML {
|
||||
func printTimetable(timetable map[models.Date]map[int]models.OfficeHour, slots []int, deleteIcons bool) template.HTML {
|
||||
var tableBody string
|
||||
|
||||
tableCell, _ := template.ParseFiles("templates/td.html")
|
||||
tableCell, _ := template.New("td.html").
|
||||
Funcs(template.FuncMap{"mod": func(i int, j int) int { return i % j },
|
||||
"add": func(i int, j int) int { return i + j },
|
||||
"divide": func(i int, j int) int { return i / j }}).ParseFiles("templates/td.html")
|
||||
for hour := 8; hour < 19; hour += 1 {
|
||||
for minute := 0; minute < 60; minute += models.MinuteGranularity {
|
||||
tableBody += "<tr>"
|
||||
|
@ -82,23 +85,10 @@ func printTimetable(timetable map[models.Date]map[int]models.OfficeHour, slots [
|
|||
} else {
|
||||
var celldata bytes.Buffer
|
||||
data := struct {
|
||||
Rowspan int
|
||||
StartHour int
|
||||
StartMinute int
|
||||
EndHour int
|
||||
EndMinute int
|
||||
CourseName string
|
||||
TutorName string
|
||||
RoomName string
|
||||
}{current.Duration / models.MinuteGranularity,
|
||||
current.Hour,
|
||||
current.Minute,
|
||||
current.Hour + ((current.Minute + current.Duration) / 60),
|
||||
(current.Minute + current.Duration) % 60,
|
||||
template.HTMLEscapeString(current.Course.Name),
|
||||
current.Tutor.Name,
|
||||
current.Room.Name,
|
||||
}
|
||||
OfficeHour models.OfficeHour
|
||||
MinuteGranularity int
|
||||
DeleteIcons bool
|
||||
}{current, models.MinuteGranularity, deleteIcons}
|
||||
tableCell.Execute(&celldata, data)
|
||||
tableBody += celldata.String()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue