oficina / calendar Public

Clone
git clone https://amadan.net/oficina/calendar

Plain git — no account needed to clone.

Download

Download this file

1package calendar
2
3import (
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
13func (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
20func 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 // The app switcher, only with a hub directory configured: the suite's
38 // six apps as tiles, each at its own host under the directory's
39 // (estilo's chrome.SuiteApps), Calendar marked current, then "All apps".
40 if directory != "" {
41 bar.Switcher = &chrome.Switcher{Label: "Oficina apps", CurrentLabel: "(this app)", Apps: chrome.SuiteApps(directory, "calendar"), AllApps: estilomenu.Item{Href: strings.TrimSuffix(directory, "/") + "/", Label: "All apps"}}
42 }
43 // A live session whose person could not be resolved (a removed Home
44 // person on an error page) still gets the menu, to sign out from, but
45 // names nobody: "Signed in", the person glyph, no address (spec §8.2,
46 // as the hub directory does).
47 trigger, signedInAs := "Account: "+address, "Signed in as"
48 if address == "" {
49 trigger, signedInAs = "Account", "Signed in"
50 }
51 bar.Account = &chrome.Account{TriggerLabel: trigger, Initials: chrome.Initials("", address), Address: address,
52 Labels: chrome.AccountLabels{SignedInAs: signedInAs, Appearance: "Appearance", Help: "Help"},
53 Items: []estilomenu.Item{{Href: "/settings", Label: "Settings"}, {Href: "/settings/booking", Label: "Booking pages"}, {Href: "/import", Label: "Import a calendar"}},
54 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"}}
55 return bar
56}
57