Clone the people page: urls with legacy redirects, chrome, tabs, search

This commit is contained in:
Ian Gulliver
2026-08-15 18:08:31 -07:00
parent 07190dadb4
commit a37f148657
11 changed files with 848 additions and 221 deletions
+39 -6
View File
@@ -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)
}
}
+9
View File
@@ -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"`