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 "bytes"
5 "html/template"
6 "net/http"
7
8 "amadan.net/oficina/estilo.git/chrome"
9 "amadan.net/oficina/estilo.git/menu"
10)
11
12// frame is the shell around every signed-in page (level-up spec §3):
13// estilo's stacked bar with Mapa's menus, its lead and its actions, and
14// the sidebar that folds to a rail. show builds it from the view.
15type frame struct {
16 Bar chrome.Bar
17 Side sideView
18 // Panel is "open" or "closed": the Links panel's cookie, rendered
19 // so first paint is already right. Empty on screens without one.
20 Panel string
21 // History is the History panel, on the history routes; nil
22 // elsewhere (level-up §4.5).
23 History *historyPanel
24}
25
26// pageChrome is what a handler says about its screen, beyond its title,
27// so the bar can draw the right menus, lead and actions. Nil is a list
28// or a form screen: the plain title and the app's own menus.
29type pageChrome struct {
30 // Page is the page on screen, if there is one.
31 Page *PageView
32 // Editor marks a screen holding the Markdown textarea: Edit and
33 // Insert act on it, and the lead shows its save status.
34 Editor bool
35 // Writable marks a page the editor mounts on (level-up §6): Edit
36 // and Insert act on it, and the lead shows its save status, as for
37 // the textarea; "Edit as Markdown" stays in View (§6.10).
38 Writable bool
39 // Day is a daily note's day pill; nil elsewhere.
40 Day *dayPill
41 // Editing is "Ana is editing" for a team page (base §5).
42 Editing []string
43 // Links marks a screen that carries the Links panel.
44 Links bool
45}
46
47// dayPill is ‹ Today › on a daily note (§4.4), with its month.
48type dayPill struct {
49 Date, Today, Prev, Next string
50 Month *MonthView
51 // Open draws the month open: the person is paging it (?month=).
52 Open bool
53}
54
55// leadView is the lead slot's data: presence, save status, the pill.
56type leadView struct {
57 Editing []string
58 Status bool
59 Day *dayPill
60}
61
62// buildFrame draws the frame for one request. The menubar and the lead
63// are this app's templates, rendered into the bar's trusted slots.
64func (app *app) buildFrame(request *http.Request, page *view) error {
65 tmpl := templateIn(request, page.name)
66 page.Frame.Side = app.side(request, page)
67 // The panel's state first: the Links toggle reads it (review M2).
68 if page.Chrome != nil && page.Chrome.Links {
69 page.Frame.Panel = linksState(request)
70 }
71 address, _ := app.identity(request)
72 menus, err := fragment(tmpl, "mapa-menubar",
73 menusFor(page, app.config.Importer(address)))
74 if err != nil {
75 return err
76 }
77 lead, err := fragment(tmpl, "mapa-lead", leadFor(page.Chrome))
78 if err != nil {
79 return err
80 }
81 page.Frame.Bar = chrome.Bar{
82 App: chrome.App{Name: "Mapa", Slug: themeSlug, Home: "/",
83 Icon: assets.Path("static/brand/icon.svg")},
84 Context: page.Title, ContextEdit: titleEdit(page.Chrome),
85 Nav: placesNav(page.Nav), NavLabel: "Mapa",
86 Actions: barActions(page), Account: app.account(request, address),
87 Sticky: true, Labels: chrome.BarLabels{Skip: "Skip to content",
88 Menu: "Menu"},
89 Menubar: menus, Lead: lead,
90 }
91 return nil
92}
93
94// fragment renders one named template into trusted markup for a slot.
95func fragment(tmpl *template.Template, name string,
96 data any) (template.HTML, error) {
97 var buffer bytes.Buffer
98 if err := tmpl.ExecuteTemplate(&buffer, name, data); err != nil {
99 return "", err
100 }
101 return template.HTML(buffer.String()), nil
102}
103
104// titleEdit is a team page's title, renamed in place through the
105// existing rename POST; nil leaves the read-only title (§3.1).
106func titleEdit(page *pageChrome) *chrome.TitleEdit {
107 if page == nil || page.Page == nil || page.Page.Kind != KindPage {
108 return nil
109 }
110 return &chrome.TitleEdit{
111 Action: "/p/" + page.Page.Public + "/rename", Name: "title",
112 Value: page.Page.Title, Label: "Page title", Submit: "Rename"}
113}
114
115func leadFor(page *pageChrome) leadView {
116 if page == nil {
117 return leadView{}
118 }
119 return leadView{Editing: page.Editing,
120 Status: page.Editor || page.Writable, Day: page.Day}
121}
122
123// placesNav is the sidebar's places as the bar's nav. estilo shows them
124// as rows in the Menu sheet below 800px, where there is no sidebar;
125// mapa.css hides the bar's own copy from 800px, where the sidebar is.
126func placesNav(items []NavItem) []chrome.Link {
127 links := make([]chrome.Link, 0, len(items))
128 for _, item := range items {
129 links = append(links, chrome.Link{Href: item.Href,
130 Label: item.Label, Current: item.Current})
131 }
132 return links
133}
134
135// barActions are History and Links (§3.1). History needs a page with
136// history; Links, a screen with the panel. The bar has no Search (Paul,
137// 2026-11-18: "I think we can just lose the search icon in the
138// header"): Search is a place, the sidebar's row with ⌘K, the rail's
139// icon and the Menu sheet's row below 800px (placesNav).
140func barActions(page *view) []chrome.Action {
141 var actions []chrome.Action
142 chromeOf := page.Chrome
143 if chromeOf != nil && chromeOf.Page != nil && chromeOf.Page.ID != 0 {
144 actions = append(actions, chrome.Action{Item: menu.Item{
145 Href: "/p/" + chromeOf.Page.Public + "/history",
146 Label: "History"}, Icon: iconHTML("history")})
147 }
148 if chromeOf != nil && chromeOf.Links {
149 actions = append(actions, chrome.Action{Item: menu.Item{
150 Label: "Links", Controls: "mapa-links",
151 Expanded: page.Frame.Panel != "closed"},
152 WideOnly: true, Icon: iconHTML("panel-right")})
153 }
154 return actions
155}
156