| 1 | package calendar |
| 2 | |
| 3 | import ( |
| 4 | "html/template" |
| 5 | "net/http" |
| 6 | "strings" |
| 7 | |
| 8 | "amadan.net/oficina/estilo.git/chrome" |
| 9 | estilomenu "amadan.net/oficina/estilo.git/menu" |
| 10 | rauth "amadan.net/rastrillo/rastrillo/auth" |
| 11 | ) |
| 12 | |
| 13 | func (h *handlers) viewer(r *http.Request) (rauth.Identity, bool) { |
| 14 | if h.viewerFrom != nil { |
| 15 | return h.viewerFrom(r) |
| 16 | } |
| 17 | return viewer(r) |
| 18 | } |
| 19 | |
| 20 | func calendarChrome(r *http.Request, signedIn bool, address string, mode chrome.Mode, title, directory string) chrome.Bar { |
| 21 | current := func(prefix string) bool { |
| 22 | return r.URL.Path == prefix || (prefix != "/" && len(r.URL.Path) > len(prefix) && r.URL.Path[:len(prefix)] == prefix) |
| 23 | } |
| 24 | // No bar actions: every view's header carries Quick add and New event, |
| 25 | // and the same primary button twice on one screen was the audit's |
| 26 | // "New event is a nav tab and also a primary button" (calendar.md §B2). |
| 27 | bar := chrome.Bar{ |
| 28 | App: chrome.App{Name: "Calendar", Slug: "calendar", Home: "/", Icon: assets.Path("static/brand/icon.svg")}, Sticky: true, |
| 29 | Labels: chrome.BarLabels{Skip: "Skip to content", Menu: "Menu"}, NavLabel: "Calendar", |
| 30 | Nav: []chrome.Link{{Href: "/today", Label: "Today", Current: current("/today") || current("/day/") || current("/week/") || current("/month/")}, {Href: "/agenda", Label: "Agenda", Current: current("/agenda")}, {Href: "/calendars", Label: "Calendars", Current: current("/calendars")}}, |
| 31 | } |
| 32 | if !signedIn { |
| 33 | bar.Nav = nil |
| 34 | bar.SignIn = &chrome.Link{Href: "/signin?return_to=" + template.URLQueryEscaper(r.URL.RequestURI()), Label: "Sign in"} |
| 35 | return bar |
| 36 | } |
| 37 | if directory != "" { |
| 38 | bar.Switcher = &chrome.Switcher{Label: "Oficina apps", AllApps: estilomenu.Item{Href: strings.TrimSuffix(directory, "/") + "/", Label: "All apps"}} |
| 39 | } |
| 40 | // A live session whose person could not be resolved (a removed Home |
| 41 | // person on an error page) still gets the menu, to sign out from, but |
| 42 | // names nobody: "Signed in", the person glyph, no address (spec §8.2, |
| 43 | // as the hub directory does). |
| 44 | trigger, signedInAs := "Account: "+address, "Signed in as" |
| 45 | if address == "" { |
| 46 | trigger, signedInAs = "Account", "Signed in" |
| 47 | } |
| 48 | bar.Account = &chrome.Account{TriggerLabel: trigger, Initials: chrome.Initials("", address), Address: address, |
| 49 | Labels: chrome.AccountLabels{SignedInAs: signedInAs, Appearance: "Appearance", Help: "Help"}, |
| 50 | Items: []estilomenu.Item{{Href: "/settings", Label: "Settings"}, {Href: "/settings/booking", Label: "Booking pages"}, {Href: "/import", Label: "Import a calendar"}}, |
| 51 | Appearance: &chrome.AppearanceMenu{Action: "/appearance", Return: r.URL.RequestURI(), Options: chrome.AppearanceOptions(mode, "Light", "Dark", "System")}, Help: []estilomenu.Item{{Href: "/help/open-source", Label: "Open source"}}, SignOut: chrome.SignOut{Action: "/signout", Label: "Sign out"}} |
| 52 | return bar |
| 53 | } |
| 54 | |