Clone the people page: urls with legacy redirects, chrome, tabs, search
This commit is contained in:
@@ -6,27 +6,60 @@ import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"heliosian/internal/auth"
|
||||
)
|
||||
|
||||
var sections = []string{"people", "classrooms", "my-family", "staff", "map", "email-list", "data-view", "bug-report", "about"}
|
||||
|
||||
var legacy = map[string]string{
|
||||
"people": "/people",
|
||||
"explore": "/classrooms",
|
||||
"myfamily": "/my-family",
|
||||
"staff": "/staff",
|
||||
"map": "/map",
|
||||
"emails": "/email-list",
|
||||
"33234e": "/data-view",
|
||||
"ee614d": "/bug-report",
|
||||
"255ce0": "/about",
|
||||
}
|
||||
|
||||
type app struct {
|
||||
cache *Cache
|
||||
}
|
||||
|
||||
func Register(mux *http.ServeMux, cache *Cache) {
|
||||
a := app{cache: cache}
|
||||
mux.HandleFunc("GET /directory/{$}", a.index)
|
||||
mux.HandleFunc("GET /directory/api/model", a.model)
|
||||
mux.Handle("GET /directory/static/", http.StripPrefix("/directory/static/", http.FileServer(http.Dir("web/directory/static"))))
|
||||
for _, section := range sections {
|
||||
mux.HandleFunc("GET /"+section, a.page)
|
||||
}
|
||||
mux.HandleFunc("GET /dl/", a.legacyRedirect)
|
||||
mux.HandleFunc("GET /api/directory/model", a.model)
|
||||
}
|
||||
|
||||
func (a app) index(w http.ResponseWriter, r *http.Request) {
|
||||
func (a app) legacyRedirect(w http.ResponseWriter, r *http.Request) {
|
||||
first, _, _ := strings.Cut(strings.TrimPrefix(r.URL.Path, "/dl/"), "/")
|
||||
target, ok := legacy[first]
|
||||
if !ok {
|
||||
target = "/people"
|
||||
}
|
||||
http.Redirect(w, r, target, http.StatusMovedPermanently)
|
||||
}
|
||||
|
||||
func (a app) page(w http.ResponseWriter, r *http.Request) {
|
||||
t, err := template.ParseFiles("web/directory/index.html")
|
||||
if err != nil {
|
||||
serverError(w, err)
|
||||
return
|
||||
}
|
||||
if err := t.Execute(w, nil); err != nil {
|
||||
log.Printf("[ERROR] render directory index: %v", err)
|
||||
name := a.cache.Model().DisplayName(auth.Email(r))
|
||||
data := map[string]string{
|
||||
"UserName": name,
|
||||
"UserInitial": strings.ToUpper(name[:1]),
|
||||
}
|
||||
if err := t.Execute(w, data); err != nil {
|
||||
log.Printf("[ERROR] render directory page: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,15 @@ type Grade struct {
|
||||
NextBand string `json:"nextBand,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Model) DisplayName(email string) string {
|
||||
for _, p := range m.People {
|
||||
if p.Email == email {
|
||||
return p.FullName
|
||||
}
|
||||
}
|
||||
return email
|
||||
}
|
||||
|
||||
type Model struct {
|
||||
People []Person `json:"people"`
|
||||
Families map[string]Family `json:"families"`
|
||||
|
||||
Reference in New Issue
Block a user