oficina / mapa Public

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

Plain git — no account needed to clone.

Download

Download this file

1package mapa
2
3import (
4 "net/http"
5
6 "amadan.net/oficina/estilo.git/chrome"
7 "amadan.net/oficina/estilo.git/menu"
8)
9
10// NavItem is one entry in the rail.
11type NavItem struct {
12 Label, Href, Icon string
13 Current bool
14 // Holds marks the place the page on screen belongs to when the
15 // page has a sidebar row of its own (side.go's light): the open
16 // sidebar lights the row, and the rail, which hides it, the place.
17 Holds bool
18}
19
20// nav is the sidebar's places, the same on every page (level-up §3.2).
21func nav(current string) []NavItem {
22 items := []NavItem{
23 {Label: "Today", Href: "/", Icon: "calendar"},
24 {Label: "Search", Href: "/search", Icon: "search"},
25 {Label: "All pages", Href: "/pages", Icon: "files"},
26 {Label: "Scratch", Href: "/scratch", Icon: "file"},
27 }
28 for index := range items {
29 items[index].Current = items[index].Href == current
30 }
31 return items
32}
33
34// view is what every shell page is drawn from. A handler fills Title,
35// Nav's current place and its own Data; page fills the rest.
36type view struct {
37 Title string
38 Nav []NavItem
39 Account *chrome.Account
40 Theme string
41 Viewer Viewer
42 Data any
43 // Chrome is what the handler says about its screen (frame.go); nil
44 // for a list or form screen.
45 Chrome *pageChrome
46 // Frame is the bar and the sidebar, built by show.
47 Frame frame
48 // Return is this page's own path, for the view forms to come back
49 // to.
50 Return string
51 name string
52}
53
54// show renders a shell page for the signed-in viewer.
55func (app *app) show(writer http.ResponseWriter, request *http.Request,
56 status int, name string, page view) {
57 address, _ := app.identity(request)
58 page.Account = app.account(request, address)
59 page.Theme = themeAttr(request)
60 page.name, page.Return = name, returnTarget(request)
61 if panel := historyIn(request); panel != nil {
62 page.Frame.History = panel
63 }
64 if err := app.buildFrame(request, &page); err != nil {
65 app.fail(writer, request, err)
66 return
67 }
68 writer.Header().Set("Cache-Control", "no-store")
69 speculate(writer)
70 if status != http.StatusOK {
71 writer.WriteHeader(status)
72 }
73 render(writer, request, name, page)
74}
75
76// account is the suite's account menu at the bar's end (estilo chrome):
77// who is signed in, "All apps" with a hub directory, Appearance, Sign out.
78// Import from Notion is File's alone (level-up build note 87).
79func (app *app) account(request *http.Request,
80 address string) *chrome.Account {
81 account := &chrome.Account{
82 TriggerLabel: "Account: " + address,
83 Initials: chrome.Initials("", address),
84 Address: address,
85 Labels: chrome.AccountLabels{SignedInAs: "Signed in as",
86 Appearance: "Appearance", Help: "Help"},
87 Appearance: &chrome.AppearanceMenu{Action: "/appearance",
88 Return: returnTarget(request),
89 Options: chrome.AppearanceOptions(chrome.Appearance(request),
90 "Light", "Dark", "System")},
91 SignOut: chrome.SignOut{Action: "/signout", Label: "Sign out"},
92 }
93 account.Items = []menu.Item{{Href: "/settings", Label: "Settings"},
94 {Href: "/deleted", Label: "Deleted pages"}}
95 if app.config.Directory != "" {
96 account.Items = append(account.Items, menu.Item{
97 Href: app.config.Directory + "/", Label: "All apps"})
98 }
99 return account
100}
101
102// returnTarget is where Appearance brings a person back to: this page if
103// it is one, else Today.
104func returnTarget(request *http.Request) string {
105 if request.Method != http.MethodGet && request.Method != http.MethodHead {
106 return "/"
107 }
108 return request.URL.RequestURI()
109}
110
111// fail is a 500 with the error logged and nothing about it shown.
112func (app *app) fail(writer http.ResponseWriter, request *http.Request,
113 err error) {
114 app.logger.Error("request failed", "path", request.URL.Path, "err", err)
115 ErrorPage(writer, request, http.StatusInternalServerError, "")
116}
117