gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitaef32f3baef32f3b|||PR Drive offline note from framework connection statemreaef32f3b/components/main.hl

11.8 KB

  1. // components/main.hl — THE SHELL (mission 022, phone first on the WorldAPI theme): the theme's AppHeader (brand · main menu
  2. // All tickets / Inbox with its live count · ident's selector · user icon), the phone's Sidebar (☰ → the main menu), the display-name
  3. // prompt of a first login, and the slot every page renders into (ContentFirst). IDENT'S SELECTOR STANDS IN THE HEADER, visible signed in
  4. // and signed out, on the phone and on the desktop (creator 2026-10-24: it was hidden behind an icon / replaced by the user menu in
  5. // missions 022 — never again; the gate checks it at 390 and 1280). Signed in your name (it opens Account and tokens) and Log out stand beside it, as before the theme missions (no user icon). Nothing else stands beside the selector: no second "Log in" button (creator 2026-10-24). The theme's shell files theme/shell/*.hl are never
  6. // edited here. App CSS is in styles.hl.
  7. //
  8. // LOGIN (ticket #7, CONCEPT.md "Login via ident"; ident README "How apps use ident"):
  9. // * THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js. Choosing an
  10. // identity fires `ident-login` with a one-time code. hl:webex cannot listen to a custom DOM
  11. // event, so /login.js (plain JS) hands the code to the hidden input #identcode and fires its
  12. // `change` — the handler below sends it to the face `identLogin`, which exchanges it SERVER
  13. // SIDE and logs this session in. No reload: the face answers who you are and pushes
  14. // `signedIn` to this session's tabs (the pages show their forms).
  15. // * THE HOST TELLS THE SELECTOR: the element's class is `in` / `out` (a member); /login.js
  16. // mirrors it into the selector's `loggedIn` (the `logged-in` attribute). Log out → `out`
  17. // → the selector is reset.
  18. // * THE LOGIN BUTTON: a plain link to <ident>/login?key=&return=<TICKETS_PUBLIC_URL>/login/callback
  19. // (project.hl loginCallback). /login.js adds `?next=<this page>` to the return URL at the
  20. // click, so the user comes back to the page the login started from (ticket #10).
  21. // * /login.js RUNS AGAIN whenever this View flips between logged in / out (hl:webex
  22. // re-creates the header and the <script> elements; ticket #9): it installs itself once
  23. // per document and hands each one-time code to #identcode only once.
  24. // * FIRST LOGIN: no display name yet → the name prompt below; writing waits for it.
  25. import { inboxCountOf } from '../lib/tickets.hl'
  26. import { encode } from '../lib/util.hl'
  27. import { siteName } from '../project.hl'
  28. import { identKey, callbackUrl, selectorScript, infoOfSession, exchangeCode, ensureUser, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  29. import { randomBytes } from 'hl:crypto'
  30. import AppHeader from '../theme/shell/app-header.hl'
  31. import MainMenu from '../theme/shell/main-menu.hl'
  32. import Sidebar from '../theme/shell/app-sidebar.hl'
  33. import ContentFirst from '../theme/shell/content-first.hl'
  34. import { messageLook } from '../lib/looks.hl'
  35. slot = null
  36. session = null
  37. // the inbox is PERSONAL (ticket #20): the tickets assigned to this session's user in pending and review
  38. inbox = inboxCountOf(userOfSession(session))
  39. hasInbox = inbox > 0
  40. // the main menu: the header from 60rem, the phone's sidebar below — one list. The Inbox's live count is its badge (`count`)
  41. // which menu entry the page belongs to: MainMenu takes it from the route (hybriel#197: `route = null` below, in the server's HTML
  42. // too, so the marker is in the first paint). A ticket's /<slug>/<n>, a project's /<slug> and the state filters match no item's path,
  43. // so the shell says '/' for them (All tickets); /inbox marks Inbox by itself; account, settings, new project, connect: none.
  44. route = null
  45. path = route == null ? '' : route.path
  46. menuSay = path == '/inbox' || path == '/you' || path == '/new-project' || path.startsWith('/connect/') || path.startsWith('/login/') || path.endsWith('/settings') ? '' : '/'
  47. menu = [ { label = 'All tickets' href = '/' } { label = 'Inbox' href = '/inbox' count = hasInbox ? inbox : null } ]
  48. // who this session is: { name, named, creator } — never the identity id
  49. me = infoOfSession(session)
  50. loggedIn = me != null
  51. loggedOut = me == null
  52. needsName = me != null && !me.named
  53. myName = me != null && me.named ? me.name : 'you'
  54. selectorClass = me != null ? 'in' : 'out'
  55. selectorKey = identKey
  56. // where the selector's sign-in panel (ident#31) sends the browser: the login button's callback, with the page the user is on as `next`
  57. // (the callback takes it back there). An unknown path (first paint without a route) leaves `next` empty = the start page.
  58. selectorReturn = callbackUrl + (path == '' ? '' : '?next=' + encode(path))
  59. identScript = selectorScript
  60. loginError = ''
  61. hasLoginError = false
  62. nameDraft = ''
  63. nameError = ''
  64. // hl:web updates this shell member at boot and on browser connection changes.
  65. __hlOnline = true
  66. Style {
  67. pMessage = messageLook + { }
  68. offlineNote {
  69. display = 'block'
  70. padding = '.5rem var(--layout-gutter)'
  71. color = 'var(--color-text-strong)'
  72. background = 'var(--color-surface)'
  73. }
  74. '#whoami' {
  75. marginRight = '.5rem'
  76. fontWeight = '600'
  77. color = 'var(--color-text-strong)'
  78. fontSize = '.875rem'
  79. maxWidth = '6rem'
  80. overflow = 'hidden'
  81. textOverflow = 'ellipsis'
  82. whiteSpace = 'nowrap'
  83. flex = '0 1 auto'
  84. minWidth = '0'
  85. display = 'inline-flex'
  86. alignItems = 'center'
  87. minHeight = '2.75rem'
  88. }
  89. '#logout' {
  90. flex = 'none'
  91. whiteSpace = 'nowrap'
  92. padding = '.25rem .5rem'
  93. }
  94. identSelector {
  95. '--ident-accent' = 'var(--color-accent)'
  96. '--ident-accent-text' = 'var(--color-accent-text)'
  97. '--ident-background' = 'var(--color-surface)'
  98. '--ident-border' = 'var(--color-surface)'
  99. '--ident-font' = '600 .9rem/1.3 system-ui, sans-serif'
  100. position = 'relative'
  101. flex = '0 1 auto'
  102. minWidth = '0'
  103. }
  104. // Keep the whole pseudo-element selector; there is no bare form.
  105. 'ident-selector::part(button)' {
  106. minHeight = '2.75rem'
  107. padding = '.25rem .6rem'
  108. whiteSpace = 'nowrap'
  109. }
  110. // Keep the whole pseudo-element selector; there is no bare form.
  111. 'ident-selector::part(status)' {
  112. minHeight = '2.75rem'
  113. padding = '.25rem .6rem'
  114. whiteSpace = 'nowrap'
  115. overflow = 'hidden'
  116. textOverflow = 'ellipsis'
  117. }
  118. // Keep the whole pseudo-element selector; there is no bare form.
  119. 'ident-selector::part(identity)' {
  120. minHeight = '2.75rem'
  121. }
  122. // Keep the whole pseudo-element selector; there is no bare form.
  123. 'ident-selector::part(panel)' {
  124. position = 'absolute'
  125. top = '100%'
  126. right = '0'
  127. zIndex = '30'
  128. width = 'min(20rem, calc(100vw - 2 * var(--layout-gutter)))'
  129. maxWidth = 'none'
  130. boxShadow = '0 .75rem 2rem ' + 'var(--color-background-sunken)'
  131. }
  132. '#loginerror' {
  133. margin = '0'
  134. padding = '.5rem var(--layout-gutter)'
  135. background = 'var(--color-background-sunken)'
  136. }
  137. namePrompt {
  138. display = 'block'
  139. paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))'
  140. paddingTop = '1rem'
  141. }
  142. '#nameform' {
  143. display = 'grid'
  144. gap = '.6rem'
  145. padding = '1rem'
  146. background = 'var(--color-surface)'
  147. borderRadius = 'var(--radius-large)'
  148. }
  149. }
  150. View {
  151. body {
  152. AppHeader { brand = siteName
  153. MainMenu { items = menu current = menuSay }
  154. // ident's selector stands in the header, visible signed in AND signed out, on the phone and on the desktop (it shows the
  155. // chosen identity once signed in). /login.js mirrors its state from the class (`in` / `out`). Signed out the plain login link
  156. // stands beside it.
  157. identSelector { id = "selector" key = selectorKey return = selectorReturn class = selectorClass }
  158. // signed in, like before the theme missions: your name (it opens Account and tokens) and Log out stand beside the selector
  159. if (loggedIn) {
  160. a { id = "whoami" href = "/you" myName }
  161. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  162. }
  163. }
  164. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  165. if (hasLoginError) { p { id = "loginerror" Style.pMessage class = "banner" loginError } }
  166. if (!__hlOnline) { offlineNote { id = "offline" "You are offline. The list is the one last loaded here; tickets and changes need the network." } }
  167. if (needsName) {
  168. namePrompt {
  169. form { id = "nameform"
  170. on submit(e) {
  171. e.preventDefault()
  172. emit saveName(e)
  173. }
  174. label { "Welcome! Choose the display name others see as the author of what you write"
  175. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  176. }
  177. button { id = "namesave" type = "submit" "Save" }
  178. p { id = "nameerror" Style.pMessage nameError }
  179. }
  180. }
  181. }
  182. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  183. // page — `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)
  184. Sidebar { desktop = "false" MainMenu { items = menu current = menuSay } }
  185. main {
  186. ContentFirst { slot }
  187. }
  188. script { src = identScript }
  189. script { src = "/login.js" }
  190. // (mission 016: no /md-editor.js any more — the pages use the Hybriel MdEditor, components/md-editor/; the old
  191. // custom element would take over its <md-editor> elements)
  192. }
  193. }
  194. // ---- the session as the page sees it ------------------------------------------------------
  195. showMe = (info) => {
  196. loggedIn = true
  197. loggedOut = false
  198. needsName = !info.named
  199. myName = info.named ? info.name : 'you'
  200. selectorClass = 'in'
  201. loginError = ''
  202. hasLoginError = false
  203. }
  204. showOut = () => {
  205. loggedIn = false
  206. loggedOut = true
  207. needsName = false
  208. myName = 'you'
  209. selectorClass = 'out'
  210. inbox = 0
  211. hasInbox = false
  212. }
  213. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  214. on gotCode(e) {
  215. code = e.target.value
  216. e.target.value = ''
  217. if (code == null || code == '') { return null }
  218. r = emit server identLogin(code)
  219. if (r == null || r.error != null) {
  220. loginError = r != null ? r.error : 'the login failed'
  221. hasLoginError = true
  222. return null
  223. }
  224. showMe(r)
  225. emit refreshInbox()
  226. }
  227. on setNameDraft(v) { nameDraft = v }
  228. on saveName(e) {
  229. r = emit server saveDisplayName(nameDraft)
  230. if (r == null || r.error != null) {
  231. nameError = r != null ? r.error : 'could not save the name'
  232. return null
  233. }
  234. nameError = ''
  235. showMe(r)
  236. }
  237. on doLogout(e) {
  238. emit server logOut()
  239. showOut()
  240. }
  241. // the inbox is personal: a ticket event asks the server how many tickets are assigned to this session now
  242. on refreshInbox() {
  243. r = emit server myInboxCount()
  244. if (r != null && r.count != null) {
  245. inbox = r.count
  246. hasInbox = r.count > 0
  247. }
  248. }
  249. on client ticketCreated(row) { emit refreshInbox() }
  250. on client ticketEvent(ticketId, ev, row) { emit refreshInbox() }
  251. // this session's other tabs follow a login / name / logout
  252. on client signedIn(tag, info) {
  253. showMe(info)
  254. emit refreshInbox()
  255. }
  256. on client signedOut(tag) { showOut() }
  257. // ---- the faces (#31: hl:web fills `session` itself and refuses a trailing argument, hybriel#16) --
  258. on server identLogin(code, session) {
  259. if (session == null) { return { error = 'no session — reload the page' } }
  260. x = exchangeCode(code)
  261. if (x.error != null) { return { error = x.error } }
  262. u = ensureUser(x.identity)
  263. if (u == null) { return { error = 'could not store the user' } }
  264. tag = randomBytes(16)
  265. session.user = { id = u.id }
  266. session.data.tag = tag
  267. info = userInfo(u)
  268. emit client signedIn(tag, info)
  269. return info
  270. }
  271. on server saveDisplayName(name, session) {
  272. u = userOfSession(session)
  273. if (u == null) { return { error = 'log in with ident first' } }
  274. r = setUserName(u.id, name)
  275. if (r.error != null) { return { error = r.error } }
  276. info = userInfo(r.user)
  277. emit client signedIn(session.data.tag, info)
  278. return info
  279. }
  280. on server myInboxCount(session) {
  281. return { count = inboxCountOf(userOfSession(session)) }
  282. }
  283. on server logOut(session) {
  284. if (session == null) { return { error = 'no session' } }
  285. // the tag stays (the push may fan out after this face returns); the next login replaces it
  286. emit client signedOut(session.data.tag)
  287. session.user = null
  288. return { ok = true }
  289. }

Branches

Latest commits

  • aef32f3b|||PR Drive offline note from framework connection statemre
  • 6dea1c60Merge branch 'r35-day72' into mainTickets
  • 7bcfdc22|||PR drop worker edits to conductor recordsmre
  • 2617b6ee|||PR dialogs: host flag cleared on close, dialog gate (tickets#40)mre
  • 6e701371|||PR record partial day72 dialog validationmre
  • b9fb9a91|||PR bind ticket dialog visibility to member flagsmre
  • 0788e65f|||PR re-vendor Hybriel day72mre
  • e2a6bdcfMerge branch 'records-t35' into mainTickets
  • d8d54df1|||PR records: R35 day72 + #40mre
  • 8a7f475aMerge branch 'records-t33' into mainTickets
  • e685d0c2|||PR records: PROCEDURES merge callmre
  • b42aff2b|||PR records: GO 2026-11-23, workers L33 O34, PROCEDURES.mdmre
  • ed091d44Merge branch 'records' into mainTickets
  • 180c0cdb|||PR records: ticket move live (M32), hybriel#439mre
  • 497cae7bMerge branch 'm32-move' into mainTickets
  • 772e0696|||PR Allow project admins to move tickets between their projectsmre
  • be92a560Merge branch 'records' into mainTickets
  • 0daf2ea8|||PR records: PR-only workflow, #50 donemre
  • 0185d0b6Log PR 1 deploymre
  • f5bf16e2Mission 031: deploy PR 1mre