Phase 6b/7b: dashboard codes editor, decode events, human-readable briefs (AUD-115)
- New /codes dashboard page (behind the session login, linked in the top bar):
lists every mapping by kind with Add, inline Edit+Save and Delete. Sam can put
real teacher surnames in without a rebuild (FR-17).
- Decode timetable EVENTS through the same map as periods, so an ensemble reads
'JAZZ ENSEMBLE - Ensemble Room - Mr KWO' instead of raw codes.
- teacherName splits comma- or space-separated codes ('HHL, OFG').
- SeedCodes is a one-time bootstrap while the table is empty, so a correction or
a delete is never overwritten or restored.
- Tests: decode Label/Event, the /codes page (save, refuse, csrf, delete, auth),
store re-seed behaviour. go test ./internal/... passes.
This commit is contained in:
@@ -38,11 +38,12 @@ func Period(title string, m store.CodeMap) string {
|
||||
}
|
||||
|
||||
// teacherName decodes a teacher field. Compass sometimes carries several codes
|
||||
// in the one field ("GT SMH"), so every token is decoded and joined.
|
||||
// in the one field, separated by spaces ("GT SMH") or commas ("HHL, OFG"), so
|
||||
// every token is decoded and joined. An unmapped token stays raw (FR-17).
|
||||
func teacherName(m store.CodeMap, field string) string {
|
||||
tokens := strings.Fields(field)
|
||||
if len(tokens) <= 1 {
|
||||
return codeName(m, store.CodeTeacher, field)
|
||||
tokens := teacherTokens(field)
|
||||
if len(tokens) == 0 {
|
||||
return strings.TrimSpace(field)
|
||||
}
|
||||
out := make([]string, 0, len(tokens))
|
||||
for _, tok := range tokens {
|
||||
@@ -51,6 +52,43 @@ func teacherName(m store.CodeMap, field string) string {
|
||||
return strings.Join(out, " / ")
|
||||
}
|
||||
|
||||
// teacherTokens splits a teacher field on commas and whitespace.
|
||||
func teacherTokens(field string) []string {
|
||||
return strings.Fields(strings.ReplaceAll(field, ",", " "))
|
||||
}
|
||||
|
||||
// Label renders any Compass timetable label as plain English: a lesson label
|
||||
// through Period, anything else (an ensemble, a concert, an excursion) through
|
||||
// Event. It is the decoder the briefs use. An unmapped code stays raw (FR-17).
|
||||
func Label(title string, m store.CodeMap) string {
|
||||
if _, _, _, _, ok := period.Split(strings.TrimSpace(title)); ok {
|
||||
return Period(title, m)
|
||||
}
|
||||
return Event(title, m)
|
||||
}
|
||||
|
||||
// Event renders a timetable event label as plain English:
|
||||
//
|
||||
// "JUNIOR GUITAR ENSEMBLE - THEATRE - HHL, OFG" -> "JUNIOR GUITAR ENSEMBLE — Theatre — Mr HHL / Mr OFG"
|
||||
//
|
||||
// The event name is kept as the school wrote it; the room and teacher codes are
|
||||
// decoded. A label with no room or teacher is returned with just its name, and
|
||||
// an unmapped code stays raw (FR-17).
|
||||
func Event(title string, m store.CodeMap) string {
|
||||
parts := period.SplitDash(strings.TrimSpace(title))
|
||||
if len(parts) <= 1 {
|
||||
return strings.TrimSpace(title)
|
||||
}
|
||||
out := []string{parts[0]}
|
||||
if parts[1] != "" {
|
||||
out = append(out, codeName(m, store.CodeRoom, parts[1]))
|
||||
}
|
||||
if len(parts) >= 3 && parts[2] != "" {
|
||||
out = append(out, teacherName(m, parts[2]))
|
||||
}
|
||||
return strings.Join(out, " — ")
|
||||
}
|
||||
|
||||
// periodName renders the period slot: a word label such as "C" uses the map
|
||||
// ("Connect"), a number becomes "Period 3", and anything unknown stays raw.
|
||||
func periodName(slot string, m store.CodeMap) string {
|
||||
|
||||
Reference in New Issue
Block a user