gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit7f992d627f992d62gitoria#23: phone first on the shared theme — brand, branch and pull links 44 px, readme code 14 px; gate block "phone first" (15 pages at 390 + the three dropdowns, fails 20 on old), dropdown-aware login/logout clicks, check-theme in GATESmre7f992d62/components/main.hl

8.5 KB

  1. // components/main.hl — THE SHELL (gitoria#23): the WorldAPI theme's header and content-first shell (theme/shell/*, copied from
  2. // layouts.worldapi.org — never edited here, the way tracker.worldapi.org wears it) around the slot every page renders into, plus
  3. // the display-name prompt of a first login. All CSS is in styles.hl (the shell files carry their own Style).
  4. // THE HEADER: phone — ☰ (the sidebar overlay with the main menu) · brand · the user icon far right (its dropdown: your name,
  5. // Access tokens, SSH keys, Log out); signed out the ident icon stands there, its dropdown holds ident's selector and "Log in with
  6. // ident". From 60rem: brand · main menu · user icon; signed out the selector and the login button stand in the header themselves.
  7. // The main menu is the app's top level, on the main address: Repositories. The repo's own tabs stay in the repo head (repohead.hl).
  8. // THE SELECTOR (gitoria#14): `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in tickets.
  9. // Choosing an identity fires `ident-login` (one-time code); /login.js hands it to the hidden input
  10. // #identcode, whose `change` goes to the face gitoriaLogin (server-side exchange, no reload). The element's
  11. // class is `in` / `out`; /login.js mirrors it into the selector's `loggedIn`. ident only answers a REGISTERED
  12. // origin (the main address), so on a repo address (the request's host, `host = null`, hybriel#74) the selector
  13. // carries the class `onrepo` and styles.hl hides it — the button stays there.
  14. // LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (lib/api.hl
  15. // loginCallback); /login.js adds `?next=<this page>` at the click so the login returns here.
  16. // FIRST LOGIN: no display name yet → the name prompt; creating a repo waits for it.
  17. import { siteName } from '../project.hl'
  18. import { slugOfHost, publicUrl } from '../lib/util.hl'
  19. import { identKey, selectorScript, loginHref, infoOfSession, userOfLoginCode, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  20. import { randomBytes } from 'hl:crypto'
  21. import AppHeader from '../theme/shell/app-header.hl'
  22. import MainMenu from '../theme/shell/main-menu.hl'
  23. import UserMenu from '../theme/shell/user-menu.hl'
  24. import Sidebar from '../theme/shell/app-sidebar.hl'
  25. import ContentFirst from '../theme/shell/content-first.hl'
  26. // the main menu: the header from 60rem, the phone's sidebar below — one list (every repo address links back to the main one)
  27. static menu = [
  28. { label = 'Repositories' href = publicUrl + '/' }
  29. ]
  30. slot = null
  31. session = null
  32. host = null
  33. me = infoOfSession(session)
  34. loggedIn = me != null
  35. loggedOut = me == null
  36. needsName = me != null && !me.named
  37. myName = me != null && me.named ? me.name : 'you'
  38. buttonHref = loginHref
  39. onRepoHost = slugOfHost(host) != ''
  40. selectorClass = (me != null ? 'in' : 'out') + (onRepoHost ? ' onrepo' : '')
  41. tokensHref = publicUrl + '/#tokens'
  42. keysHref = publicUrl + '/#sshkeys'
  43. selectorKey = identKey
  44. identScript = selectorScript
  45. loginError = ''
  46. hasLoginError = false
  47. nameDraft = ''
  48. nameError = ''
  49. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network; the
  50. // shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  51. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  52. // write only when it changed.
  53. offline = false
  54. View {
  55. body {
  56. AppHeader { brand = siteName
  57. MainMenu { items = menu }
  58. if (loggedIn) {
  59. UserMenu {
  60. p { id = "whoami" class = "who" myName }
  61. a { id = "tokenslink" href = tokensHref "Access tokens" }
  62. a { id = "keyslink" href = keysHref "SSH keys" }
  63. button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }
  64. }
  65. }
  66. // signed out: the ident icon (phone) and its dropdown — from 60rem the dropdown stands open in the header. Signed in it
  67. // is hidden (class `in`), the selector element stays: /login.js mirrors its state (gitoria#14)
  68. identMenu { class = selectorClass
  69. button { type = "button" class = "ident-toggle" popovertarget = "ident-panel" title = "Log in with ident" "aria-label" = "Log in with ident"
  70. // the ident icon (as tracker's): a small i standing beside a big D lying on the floor; the D's lower face is its thickness
  71. svg { class = "ident-icon" viewBox = "1 10 20 13.2" "aria-hidden" = "true"
  72. path { class = "ident-d-side" d = "M5 22.6 L7.8 14.2 C15.1 14.2 19 16.6 19.6 18.4 C20.2 20.2 16.2 22.6 5 22.6 Z" }
  73. path { class = "ident-d" "fill-rule" = "evenodd" d = "M5 21 L7.8 12.6 C15.1 12.6 19 15 19.6 16.8 C20.2 18.6 16.2 21 5 21 Z M10.7 14.4 C13.6 14.4 15.4 15.3 15.6 16.8 C15.8 18.3 13.7 19.2 10 19.2 Z" }
  74. rect { class = "ident-i" x = "1.6" y = "14.2" width = "1.9" height = "6.8" rx = ".5" }
  75. circle { class = "ident-i" cx = "2.55" cy = "11.6" r = "1.15" }
  76. }
  77. }
  78. identPanel { id = "ident-panel" popover = "auto"
  79. identSelector { id = "selector" key = selectorKey class = selectorClass }
  80. if (loggedOut) {
  81. a { id = "loginbutton" class = "button primary" href = buttonHref "Log in with ident" }
  82. }
  83. }
  84. }
  85. }
  86. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  87. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  88. if (offline) { offlineNote { id = "offline" "You are offline. Repositories and code need the network." } }
  89. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  90. if (needsName) {
  91. namePrompt {
  92. form { id = "nameform"
  93. on submit(e) {
  94. e.preventDefault()
  95. emit saveName(e)
  96. }
  97. label { "Welcome! Choose the display name others see as the owner of your repositories"
  98. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  99. }
  100. button { id = "namesave" type = "submit" "Save" }
  101. p { id = "nameerror" class = "message" nameError }
  102. }
  103. }
  104. }
  105. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  106. // page — `Sidebar` + `main { ContentFirst { slot } }`, as tracker does: the page slot must start its own line (hybriel#130)
  107. Sidebar { desktop = "false" MainMenu { items = menu } }
  108. main {
  109. ContentFirst { slot }
  110. }
  111. script { src = identScript }
  112. script { src = "/login.js" }
  113. }
  114. }
  115. showMe = (info) => {
  116. loggedIn = true
  117. loggedOut = false
  118. needsName = !info.named
  119. myName = info.named ? info.name : 'you'
  120. selectorClass = onRepoHost ? 'in onrepo' : 'in'
  121. loginError = ''
  122. hasLoginError = false
  123. }
  124. showOut = () => {
  125. loggedIn = false
  126. loggedOut = true
  127. needsName = false
  128. myName = 'you'
  129. selectorClass = onRepoHost ? 'out onrepo' : 'out'
  130. }
  131. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  132. on gotCode(e) {
  133. code = e.target.value
  134. e.target.value = ''
  135. if (code == null || code == '') { return null }
  136. r = emit server gitoriaLogin(code)
  137. if (r == null || r.error != null) {
  138. loginError = r != null ? r.error : 'the login failed'
  139. hasLoginError = true
  140. return null
  141. }
  142. showMe(r)
  143. }
  144. on client gitoriaSignedIn(tag, info) { showMe(info) }
  145. on client gitoriaSignedOut(tag) { showOut() }
  146. on setNameDraft(v) { nameDraft = v }
  147. on netTick(e) {
  148. down = window.navigator.onLine == false
  149. if (down != offline) { offline = down }
  150. }
  151. on saveName(e) {
  152. r = emit server gitoriaSaveName(nameDraft)
  153. if (r == null || r.error != null) {
  154. nameError = r != null ? r.error : 'could not save the name'
  155. return null
  156. }
  157. nameError = ''
  158. showMe(r)
  159. }
  160. on doLogout(e) {
  161. emit server gitoriaLogOut()
  162. showOut()
  163. }
  164. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  165. on server gitoriaLogin(code, session) {
  166. if (session == null) { return { error = 'no session — reload the page' } }
  167. x = userOfLoginCode(code)
  168. if (x.error != null) { return { error = x.error } }
  169. tag = randomBytes(16)
  170. session.user = { id = x.user.id }
  171. session.data.tag = tag
  172. info = userInfo(x.user)
  173. emit client gitoriaSignedIn(tag, info)
  174. return info
  175. }
  176. on server gitoriaSaveName(name, session) {
  177. u = userOfSession(session)
  178. if (u == null) { return { error = 'log in with ident first' } }
  179. r = setUserName(u.id, name)
  180. if (r.error != null) { return { error = r.error } }
  181. info = userInfo(r.user)
  182. emit client gitoriaSignedIn(session.data.tag, info)
  183. return info
  184. }
  185. on server gitoriaLogOut(session) {
  186. if (session == null) { return { error = 'no session' } }
  187. emit client gitoriaSignedOut(session.data.tag)
  188. session.user = null
  189. return { ok = true }
  190. }

Branches

Latest commits

  • 7f992d62gitoria#23: phone first on the shared theme — brand, branch and pull links 44 px, readme code 14 px; gate block "phone first" (15 pages at 390 + the three dropdowns, fails 20 on old), dropdown-aware login/logout clicks, check-theme in GATESmre
  • a2a840a5gitoria#23 WIP (quota stop): theme from layouts, styles inherit it, shell on the theme's header/menus/sidebar, phone measurement script; gates not runmre
  • 12b665b0mission brief 005mre
  • b680c483Revert "gitoria#22: RepoTabs wrapping component for the repo tabs (active tab, no content for a missing repo)"mre
  • 4fda244fgitoria#22: RepoTabs wrapping component for the repo tabs (active tab, no content for a missing repo)mre
  • 0fd5e280mission brief 004mre
  • e1d425e7paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • e59ff114deploy.sh: wait up to DEPLOY_URL_WAIT (120 s) for 200 after the restart, as the other apps (cold compile, hybriel#148)mre
  • bcafcceb003: compose cache volume + tmpfs /tmp, gate start waits 120 s, report/LOG/STATUSmre
  • bed3f2d5Re-vendor Hybriel to the shared static build 0f396652 (plugins; bin/ is git-ignored)mre
  • 3207e128mission brief 003mre
  • 18ab71fbtests/ticketskit: wait up to 120 s for tickets (native Hybriel cold compile ~25 s, hybriel#148)mre
  • 4fffa966docker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • 4f47843egate: ticket links use the tickets short URL (/<slug>/<n>, tickets#25)mre
  • 86605446mission 002 (code order) 4/4: README file map + import order + 'Same output' test + gate run with a tickets HEAD copy, STATUS (entry, lessons), LOG, report; tests/realdata-baseline.mjs + realdata-compare.py (a cleanup answers the same on live data: pages, modules, API, git over HTTPS and SSH, faces), tests/letcount.pymre
  • cc7bf7bamission 002 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (289 lets → plain declarations; 213 left: 125 reassigned, 88 loop-bound; no member/import/param clash). gates 200/0, 46/0, 44/0; real-data reads + writes identical (browser modules: var → const only)mre
  • 090a20c6mission 002 (code order) 2/4: one lib/ file per topic — git.hl split into git (calls, branches, init, temp folder) / homepage / code / pulls / releases (+ git-helpers: paths, ids, |||PR/|||RL markers); repos-helpers, tickets-helpers, transport-helpers; util.hl = localtime + env, storage dir, addresses, lists, text checks, one newest-first sort (was 3 copies); the function routes out of project.hl into lib/api.hl (thin; plumbing in api-helpers.hl), sshgate.hl folded into api.hl + sshkeys.hl keyLine + repos.hl mayPush; 'Make main' and the merge answer out of the faces (code.hl makeMain, pulls.hl pullsView), one login helper (users.hl userOfLoginCode); project.hl is the map. Session-writing routes get &req + &server.sessions. gates 200/0, 46/0, 44/0; real-data identical except /login/failed now shows the parked reason for a browser that already had a session (the old copy-of-req lost it)mre
  • 110c2799mission 002 (code order) 1/4: .hl files out of the root — lib/ (api, git, localtime, markdown, repos, sshgate, sshkeys, tickets, tokens, transport, users), components/styles.hl; jsoncheck.hl removed (imported nowhere); import paths only. gates 200/0, 46/0, 44/0; real-data reads + writes identicalmre
  • fdfb4b1bgitoria: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gates 200/0, 46/0, 44/0mre
  • 5b46ac84antcolony#40: LOG.md — missions 069/072 are antcolony missions (report paths on Byrodin)mre