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)
|
officeHour, _ = b.officeHourRepo.FindById(id)
|
||||||
b.requestRepo.Add(officeHour, models.RequestActivate)
|
b.requestRepo.Add(officeHour, models.RequestActivate)
|
||||||
tmpl, _ := template.ParseFiles("template/addSuccess.html")
|
tmpl, err := template.ParseFiles("templates/addSuccess.html")
|
||||||
tmpl.Execute(w, struct{}{})
|
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
|
return
|
||||||
}
|
}
|
||||||
officeHours, _ := b.officeHourRepo.FindByRoom(room, true)
|
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) {
|
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
|
return
|
||||||
}
|
}
|
||||||
officeHours, _ := b.officeHourRepo.FindByCourse(course, true)
|
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) {
|
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
|
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
|
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 hour := 8; hour < 19; hour += 1 {
|
||||||
for minute := 0; minute < 60; minute += models.MinuteGranularity {
|
for minute := 0; minute < 60; minute += models.MinuteGranularity {
|
||||||
tableBody += "<tr>"
|
tableBody += "<tr>"
|
||||||
|
@ -82,23 +85,10 @@ func printTimetable(timetable map[models.Date]map[int]models.OfficeHour, slots [
|
||||||
} else {
|
} else {
|
||||||
var celldata bytes.Buffer
|
var celldata bytes.Buffer
|
||||||
data := struct {
|
data := struct {
|
||||||
Rowspan int
|
OfficeHour models.OfficeHour
|
||||||
StartHour int
|
MinuteGranularity int
|
||||||
StartMinute int
|
DeleteIcons bool
|
||||||
EndHour int
|
}{current, models.MinuteGranularity, deleteIcons}
|
||||||
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,
|
|
||||||
}
|
|
||||||
tableCell.Execute(&celldata, data)
|
tableCell.Execute(&celldata, data)
|
||||||
tableBody += celldata.String()
|
tableBody += celldata.String()
|
||||||
}
|
}
|
||||||
|
|
1
main.go
1
main.go
|
@ -22,6 +22,7 @@ func main() {
|
||||||
http.HandleFunc("/getByCourse", h.GetByCourseHandler)
|
http.HandleFunc("/getByCourse", h.GetByCourseHandler)
|
||||||
http.HandleFunc("/addOfficeHour", h.AddOfficeHourHandler)
|
http.HandleFunc("/addOfficeHour", h.AddOfficeHourHandler)
|
||||||
http.HandleFunc("/confirmRequest", h.ConfirmRequestHandler)
|
http.HandleFunc("/confirmRequest", h.ConfirmRequestHandler)
|
||||||
|
http.HandleFunc("/deleteOfficeHour", h.DeleteOfficeHourHandler)
|
||||||
http.HandleFunc("/", h.RootHandler)
|
http.HandleFunc("/", h.RootHandler)
|
||||||
|
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
|
|
|
@ -50,6 +50,10 @@ func (r *RequestRepo) FindByOfficeHour(officeHour models.OfficeHour) ([]models.R
|
||||||
if err := rows.Scan(&request.Id, &officeHourId, &request.Action, &request.Secret); err != nil {
|
if err := rows.Scan(&request.Id, &officeHourId, &request.Action, &request.Secret); err != nil {
|
||||||
return requests, err
|
return requests, err
|
||||||
}
|
}
|
||||||
|
request.OfficeHour, err = r.officeHourRepo.FindById(officeHourId)
|
||||||
|
if err != nil {
|
||||||
|
return requests, err
|
||||||
|
}
|
||||||
requests = append(requests, request)
|
requests = append(requests, request)
|
||||||
}
|
}
|
||||||
return requests, nil
|
return requests, nil
|
||||||
|
@ -118,6 +122,7 @@ func (r *RequestRepo) newSecret() (string, error) {
|
||||||
func sendConfirmationMail(request models.Request) error {
|
func sendConfirmationMail(request models.Request) error {
|
||||||
to := []string{request.OfficeHour.Tutor.Email}
|
to := []string{request.OfficeHour.Tutor.Email}
|
||||||
tmpl, err := template.New("confirmationMail").Funcs(template.FuncMap{"DayName": models.DayName}).ParseFiles("templates/confirmationMail")
|
tmpl, err := template.New("confirmationMail").Funcs(template.FuncMap{"DayName": models.DayName}).ParseFiles("templates/confirmationMail")
|
||||||
|
|
||||||
var message bytes.Buffer
|
var message bytes.Buffer
|
||||||
err = tmpl.Execute(&message, request)
|
err = tmpl.Execute(&message, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -6,5 +6,9 @@
|
||||||
Irgendetwas ist schief gegangen. Bitte sende folgende Daten an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a> mit einer Beschreibung, was du tun wolltest.
|
Irgendetwas ist schief gegangen. Bitte sende folgende Daten an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a> mit einer Beschreibung, was du tun wolltest.
|
||||||
<br />
|
<br />
|
||||||
{{.}}
|
{{.}}
|
||||||
|
<footer>
|
||||||
|
<a href="/addOfficeHour">Sprechstunde anlegen</a><br />
|
||||||
|
Technische Fragen an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a>
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -45,5 +45,9 @@
|
||||||
{{range $room := .Rooms}}
|
{{range $room := .Rooms}}
|
||||||
<dt>{{$room.Name}}</dt><dl>{{$room.MaxOccupy}} Sprechstunde{{if gt $room.MaxOccupy 1}}n{{end}}</dl><br />{{end}}
|
<dt>{{$room.Name}}</dt><dl>{{$room.MaxOccupy}} Sprechstunde{{if gt $room.MaxOccupy 1}}n{{end}}</dl><br />{{end}}
|
||||||
</dl>
|
</dl>
|
||||||
|
<footer>
|
||||||
|
<a href="/addOfficeHour">Sprechstunde anlegen</a><br />
|
||||||
|
Technische Fragen an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a>
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -5,6 +5,9 @@
|
||||||
<body>
|
<body>
|
||||||
Die Sprechstunde wurde angelegt. Du solltest eine Mail mit einem Aktivierungslink erhalten haben.
|
Die Sprechstunde wurde angelegt. Du solltest eine Mail mit einem Aktivierungslink erhalten haben.
|
||||||
<br />
|
<br />
|
||||||
{{.}}
|
<footer>
|
||||||
|
<a href="/addOfficeHour">Sprechstunde anlegen</a><br />
|
||||||
|
Technische Fragen an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a>
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,11 +1,9 @@
|
||||||
To: {{.OfficeHour.Tutor.Email}}
|
To: {{.OfficeHour.Tutor.Email}}
|
||||||
|
Subject: Sprechstunde {{if eq .Action 1}}anlegen{{end}}{{if eq .Action 2}}löschen{{end}}
|
||||||
Subject: Sprechstunde anlegen
|
|
||||||
|
|
||||||
|
|
||||||
Hallo {{.OfficeHour.Tutor.Name}},
|
Hallo {{.OfficeHour.Tutor.Name}},
|
||||||
|
|
||||||
mit deiner Emailadresse soll eine Sprechstunde mit folgenden Daten angelegt werden:
|
mit deiner Emailadresse soll eine Sprechstunde mit folgenden Daten {{if eq .Action 1}}angelegt werden{{end}}{{if eq .Action 2}}gelöscht werden{{end}}:
|
||||||
|
|
||||||
{{.OfficeHour.Course.Name}}
|
{{.OfficeHour.Course.Name}}
|
||||||
{{DayName .OfficeHour.Date.Day}}
|
{{DayName .OfficeHour.Date.Day}}
|
||||||
|
@ -13,7 +11,7 @@ ab {{.OfficeHour.Date.Hour}}:{{printf "%02d" .OfficeHour.Date.Minute}} Uhr
|
||||||
{{.OfficeHour.Duration}} Minuten
|
{{.OfficeHour.Duration}} Minuten
|
||||||
{{.OfficeHour.Tutor.Name}}
|
{{.OfficeHour.Tutor.Name}}
|
||||||
|
|
||||||
Wenn diese Daten richtig sind, so bestätige die Sprechstunde durch Abrufen der folgenden URL:
|
Wenn dies richtig ist, so bestätige die Sprechstunde durch Abrufen der folgenden URL:
|
||||||
https://sprechstunden.mathebau.de/confirmRequest?code={{.Secret}}
|
https://sprechstunden.mathebau.de/confirmRequest?code={{.Secret}}
|
||||||
Solltest du diese Email nicht erwartet haben, so kannst du sie einfach ignorieren.
|
Solltest du diese Email nicht erwartet haben, so kannst du sie einfach ignorieren.
|
||||||
|
|
||||||
|
|
13
templates/deleteSuccess.html
Normal file
13
templates/deleteSuccess.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Sprechstunde löschen</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Du solltest eine Mail mit einem Bestätigungslink erhalten haben.
|
||||||
|
<br />
|
||||||
|
<footer>
|
||||||
|
<a href="/addOfficeHour">Sprechstunde anlegen</a><br />
|
||||||
|
Technische Fragen an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -6,5 +6,9 @@
|
||||||
Irgendetwas ist schief gegangen. Bitte sende folgende Daten an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a> mit einer Beschreibung, was du tun wolltest.
|
Irgendetwas ist schief gegangen. Bitte sende folgende Daten an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a> mit einer Beschreibung, was du tun wolltest.
|
||||||
<br />
|
<br />
|
||||||
{{.}}
|
{{.}}
|
||||||
|
<footer>
|
||||||
|
<a href="/addOfficeHour">Sprechstunde anlegen</a><br />
|
||||||
|
Technische Fragen an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a>
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -24,6 +24,7 @@
|
||||||
{{.Timetable}}
|
{{.Timetable}}
|
||||||
<footer>
|
<footer>
|
||||||
<a href="/addOfficeHour">Sprechstunde anlegen</a><br />
|
<a href="/addOfficeHour">Sprechstunde anlegen</a><br />
|
||||||
|
<a href="/deleteOfficeHour">Sprechstunde löschen</a><br />
|
||||||
Technische Fragen an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a>
|
Technische Fragen an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -3,6 +3,17 @@
|
||||||
<title>Anfrage bestätigen fehlgeschlagen</title>
|
<title>Anfrage bestätigen fehlgeschlagen</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
Dieser Bestätigungscode ist nicht verfügbar.
|
<p>
|
||||||
|
Dieser Bestätigungscode ist nicht verfügbar. <br />
|
||||||
|
Bitte gib deinen Bestätigungscode hier ein.
|
||||||
|
</p>
|
||||||
|
<form action="/confirmRequest">
|
||||||
|
<label for="code">Bestätigungscode</label>: <input type="text" name="code"/>
|
||||||
|
<input type="submit" />
|
||||||
|
</form>
|
||||||
|
<footer>
|
||||||
|
<a href="/addOfficeHour">Sprechstunde anlegen</a><br />
|
||||||
|
Technische Fragen an <a href="mailto:sprechstundentool@mathebau.de">sprechstundentool@mathebau.de</a>
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,6 +1,7 @@
|
||||||
<td rowspan="{{.Rowspan}}" style="border: 1px solid">
|
<td rowspan="{{divide .OfficeHour.Duration .MinuteGranularity}}" style="border: 1px solid">
|
||||||
{{.StartHour}}:{{printf "%02d" .StartMinute}} - {{.EndHour}}:{{printf "%02d" .EndMinute}}<br />
|
{{if .DeleteIcons}}<div style="text-align: right;"><a href="/deleteOfficeHour?id={{.OfficeHour.Id}}">❌</a></div>{{end}}
|
||||||
{{.CourseName}}<br />
|
{{printf "%02d" .OfficeHour.Date.Hour}}:{{printf "%02d" .OfficeHour.Date.Minute}} - {{printf "%02d" (add .OfficeHour.Date.Hour (divide .OfficeHour.Duration 60))}}:{{printf "%02d" (mod (add .OfficeHour.Date.Minute .OfficeHour.Duration) 60)}}<br />
|
||||||
{{.TutorName}}<br />
|
{{.OfficeHour.Course.Name}}<br />
|
||||||
{{.RoomName}}
|
{{.OfficeHour.Tutor.Name}}<br />
|
||||||
|
{{.OfficeHour.Room.Name}}
|
||||||
</td>
|
</td>
|
Loading…
Reference in a new issue