Commit e9545027 authored by Linus's avatar Linus 🤔
Browse files

Jump between tutoriums

parent 1bdb2827
......@@ -3,6 +3,7 @@ package main
import (
"html/template"
"net/http"
"sort"
"strconv"
"strings"
)
......@@ -15,6 +16,12 @@ func search(w http.ResponseWriter, r *http.Request) error {
return render("templates/search.html", args, w, r, "templates/subject_dropdown.html")
}
type otherTut struct {
Name string
Id string
Subject string
}
func doSearch(w http.ResponseWriter, r *http.Request) error {
err := r.ParseForm()
if err != nil {
......@@ -50,14 +57,60 @@ func doSearch(w http.ResponseWriter, r *http.Request) error {
resultTemplate = "templates/search/result_some.html"
}
var subjectText string
if tut == "" {
subjectText = subj + ": Anzeigen ohne Tutorium"
} else {
subjectText = subj + ": Tutorium " + tut
}
var otherTuts = make([]otherTut, 0)
for entry, stuff := range listings {
if len(stuff) == 0 {
continue
}
if splits := strings.Split(entry, "::"); splits[0] == subj {
toPush := otherTut{}
if splits[1] == "" {
toPush.Name = "Leeres Tutorium"
toPush.Id = ""
} else {
toPush.Name = "Tut. " + splits[1]
toPush.Id = splits[1]
}
toPush.Subject = subj
otherTuts = append(otherTuts, toPush)
}
}
sort.Slice(otherTuts, func(i, j int) bool {
id1, err := strconv.Atoi(otherTuts[i].Id)
if err != nil {
id1 = 0
}
id2, err := strconv.Atoi(otherTuts[j].Id)
if err != nil {
id2 = 0
}
return id1 < id2
})
otherTutsHidden := "hidden"
if len(otherTuts) > 0 {
otherTutsHidden = ""
}
tmpl, err := template.ParseFiles("templates/template.html", "templates/found.html", "templates/disclaimer.html", resultTemplate)
if err != nil {
return err
}
return tmpl.ExecuteTemplate(w, "template", map[string]interface{}{
"FoundListings": results,
"Subject": tutString,
"Title": "Resultate",
"FoundListings": results,
"Subject": tutString,
"Title": "Resultate",
"SubjectText": subjectText,
"OtherTuts": otherTuts,
"OtherTutsHidden": otherTutsHidden,
})
}
......
{{ define "content" }}
<h3>{{ .SubjectText }}</h3>
<div {{ .OtherTutsHidden }}>
In diesem Fach gibt es Anzeigen in den Tutorien:
{{ range .OtherTuts }}
<a href="/dosearch?subject={{ .Subject }}&tutorium={{ .Id }}">{{ .Name }}</a>
{{ end }}
<br>
</div>
{{ template "result" . }}
<link rel="stylesheet" href="static/found_style.css">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment