gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf83d9c0df83d9c0dtickets (mission 016): report reports/016-comments-block.md, LOG, STATUS, README gate countmref83d9c0d/components/main.hl

7.8 KB

  1. // components/main.hl — THE SHELL: the application header (brand, All tickets, Inbox with
  2. // its live count, and TOP RIGHT the login: ident's identity selector + "Log in with ident",
  3. // or who you are + Log out), the display-name prompt of a first login, and the slot every
  4. // page renders into. All CSS is in styles.hl.
  5. //
  6. // LOGIN (ticket #7, CONCEPT.md "Login via ident"; ident README "How apps use ident"):
  7. // * THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js. Choosing an
  8. // identity fires `ident-login` with a one-time code. hl:webex cannot listen to a custom DOM
  9. // event, so /login.js (plain JS) hands the code to the hidden input #identcode and fires its
  10. // `change` — the handler below sends it to the face `identLogin`, which exchanges it SERVER
  11. // SIDE and logs this session in. No reload: the face answers who you are and pushes
  12. // `signedIn` to this session's tabs (the pages show their forms).
  13. // * THE HOST TELLS THE SELECTOR: the element's class is `in` / `out` (a member); /login.js
  14. // mirrors it into the selector's `loggedIn` (the `logged-in` attribute). Log out → `out`
  15. // → the selector is reset.
  16. // * THE LOGIN BUTTON: a plain link to <ident>/login?key=&return=<TICKETS_PUBLIC_URL>/login/callback
  17. // (project.hl loginCallback). /login.js adds `?next=<this page>` to the return URL at the
  18. // click, so the user comes back to the page the login started from (ticket #10).
  19. // * /login.js RUNS AGAIN whenever this View flips between logged in / out (hl:webex
  20. // re-creates the header and the <script> elements; ticket #9): it installs itself once
  21. // per document and hands each one-time code to #identcode only once.
  22. // * FIRST LOGIN: no display name yet → the name prompt below; writing waits for it.
  23. import { inboxCountOf } from '../lib/tickets.hl'
  24. import { siteName } from '../project.hl'
  25. import { identKey, selectorScript, loginHref, infoOfSession, exchangeCode, ensureUser, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  26. import { randomBytes } from 'hl:crypto'
  27. slot = null
  28. session = null
  29. // the inbox is PERSONAL (ticket #20): the tickets assigned to this session's user in pending and review
  30. inbox = inboxCountOf(userOfSession(session))
  31. hasInbox = inbox > 0
  32. // who this session is: { name, named, creator } — never the identity id
  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. selectorClass = me != null ? 'in' : 'out'
  39. selectorKey = identKey
  40. identScript = selectorScript
  41. buttonHref = loginHref
  42. loginError = ''
  43. hasLoginError = false
  44. nameDraft = ''
  45. nameError = ''
  46. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network;
  47. // the shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  48. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  49. // write only when it changed. (An `img` error or a socket event would race the hydration and be missed.)
  50. offline = false
  51. View {
  52. body {
  53. applicationHeader {
  54. a { class = "brand" href = "/" siteName }
  55. nav {
  56. a { id = "navall" href = "/" "All tickets" }
  57. a { id = "navinbox" href = "/inbox" "Inbox"
  58. if (hasInbox) { inboxBadge { id = "inboxcount" inbox } }
  59. }
  60. }
  61. userBox { id = "userbox"
  62. identSelector { id = "selector" key = selectorKey class = selectorClass }
  63. if (loggedIn) {
  64. a { id = "whoami" href = "/you" myName }
  65. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  66. }
  67. if (loggedOut) {
  68. a { id = "loginbutton" class = "button" href = buttonHref "Log in with ident" }
  69. }
  70. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  71. }
  72. }
  73. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  74. if (offline) { offlineNote { id = "offline" "You are offline. The list is the one last loaded here; tickets and changes need the network." } }
  75. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  76. if (needsName) {
  77. namePrompt {
  78. form { id = "nameform"
  79. on submit(e) {
  80. e.preventDefault()
  81. emit saveName(e)
  82. }
  83. label { "Welcome! Choose the display name others see as the author of what you write"
  84. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  85. }
  86. button { id = "namesave" type = "submit" "Save" }
  87. p { id = "nameerror" class = "message" nameError }
  88. }
  89. }
  90. }
  91. main { slot }
  92. script { src = identScript }
  93. script { src = "/login.js" }
  94. // (mission 016: no /md-editor.js any more — the pages use the Hybriel MdEditor, components/md-editor/; the old
  95. // custom element would take over its <md-editor> elements)
  96. }
  97. }
  98. // ---- the session as the page sees it ------------------------------------------------------
  99. showMe = (info) => {
  100. loggedIn = true
  101. loggedOut = false
  102. needsName = !info.named
  103. myName = info.named ? info.name : 'you'
  104. selectorClass = 'in'
  105. loginError = ''
  106. hasLoginError = false
  107. }
  108. showOut = () => {
  109. loggedIn = false
  110. loggedOut = true
  111. needsName = false
  112. myName = 'you'
  113. selectorClass = 'out'
  114. inbox = 0
  115. hasInbox = false
  116. }
  117. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  118. on gotCode(e) {
  119. code = e.target.value
  120. e.target.value = ''
  121. if (code == null || code == '') { return null }
  122. r = emit server identLogin(code)
  123. if (r == null || r.error != null) {
  124. loginError = r != null ? r.error : 'the login failed'
  125. hasLoginError = true
  126. return null
  127. }
  128. showMe(r)
  129. emit refreshInbox()
  130. }
  131. on setNameDraft(v) { nameDraft = v }
  132. on netTick(e) {
  133. down = window.navigator.onLine == false
  134. if (down != offline) { offline = down }
  135. }
  136. on saveName(e) {
  137. r = emit server saveDisplayName(nameDraft)
  138. if (r == null || r.error != null) {
  139. nameError = r != null ? r.error : 'could not save the name'
  140. return null
  141. }
  142. nameError = ''
  143. showMe(r)
  144. }
  145. on doLogout(e) {
  146. emit server logOut()
  147. showOut()
  148. }
  149. // the inbox is personal: a ticket event asks the server how many tickets are assigned to this session now
  150. on refreshInbox() {
  151. r = emit server myInboxCount()
  152. if (r != null && r.count != null) {
  153. inbox = r.count
  154. hasInbox = r.count > 0
  155. }
  156. }
  157. on client ticketCreated(row) { emit refreshInbox() }
  158. on client ticketEvent(ticketId, ev, row) { emit refreshInbox() }
  159. // this session's other tabs follow a login / name / logout
  160. on client signedIn(tag, info) {
  161. showMe(info)
  162. emit refreshInbox()
  163. }
  164. on client signedOut(tag) { showOut() }
  165. // ---- the faces (#31: hl:web fills `session` itself and refuses a trailing argument, hybriel#16) --
  166. on server identLogin(code, session) {
  167. if (session == null) { return { error = 'no session — reload the page' } }
  168. x = exchangeCode(code)
  169. if (x.error != null) { return { error = x.error } }
  170. u = ensureUser(x.identity)
  171. if (u == null) { return { error = 'could not store the user' } }
  172. tag = randomBytes(16)
  173. session.user = { id = u.id }
  174. session.data.tag = tag
  175. info = userInfo(u)
  176. emit client signedIn(tag, info)
  177. return info
  178. }
  179. on server saveDisplayName(name, session) {
  180. u = userOfSession(session)
  181. if (u == null) { return { error = 'log in with ident first' } }
  182. r = setUserName(u.id, name)
  183. if (r.error != null) { return { error = r.error } }
  184. info = userInfo(r.user)
  185. emit client signedIn(session.data.tag, info)
  186. return info
  187. }
  188. on server myInboxCount(session) {
  189. return { count = inboxCountOf(userOfSession(session)) }
  190. }
  191. on server logOut(session) {
  192. if (session == null) { return { error = 'no session' } }
  193. // the tag stays (the push may fan out after this face returns); the next login replaces it
  194. emit client signedOut(session.data.tag)
  195. session.user = null
  196. return { ok = true }
  197. }

Branches

Latest commits

  • f83d9c0dtickets (mission 016): report reports/016-comments-block.md, LOG, STATUS, README gate countmre
  • eef80f55tickets (mission 016): comments through the shared Comments block (layouts#2) — edit (author, earlier versions kept), delete (author, asks; leaves one line in the history), like (members, toggle) on the server (lib/comments.hl, append-only tables), faces + API …/comments/:comment/{edit,delete,like}, push commentChanged; every run of comments is a block in place in the history; Markdown fields on the Hybriel MdEditor (shared/md-editor.js retired: it took over the block's <md-editor>); blocks copied verbatim from components.hybriel 9db927d (tools/sync-components.sh); gates browser 351/0 (old 326/0), events 52/0 (old 52/0)mre
  • eb7aeeb9mission brief 016mre
  • e4c34759paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • 26efb23freport w6-events (events test)mre
  • c6bfab04mission 015: re-vendor Hybriel 0f396652 (static build), reportmre
  • b7ec5981mission brief 015mre
  • 5dc68731docker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • 8a460b16mission 014: Apollo's 'stream opened right after the start gets no live events' is not a tickets bug — events.mjs checks early streamsmre
  • 6309ca81mission brief 014mre
  • c1161469mission 013: GitHub pipe tables on ticket pages (lib/markdown.hl + View + CSS) and re-vendor hybriel master a832f73bmre
  • a30b5d12mission brief (w13)mre
  • b50a6f93w9 (tickets): re-vendor hybriel 9f912f3b (#146 emit in a lib static, #147) — the 12 live-push emits in lib/api.hl compile as they are; cold start (#148): tests wait TICKETS_COLD_MS for every start, deploy.sh gates browser + events and waits up to 120 s for the URL, container /tmp tmpfs + hybriel-cache volume; events-client stops at EVENTS_MAX inside a chunk; connect.mjs ports by env. bin/hybriel sha256 7421907868ac07d8a7d08296b083c6f8b20407d0e099ce4bebbf7ae053d9060a. Gates (8720–8739): browser 315/0 (+ all-cold 315/0), events 48/0 cold, connect 60/0, short-id 19/0; real-data copy old 0e8a41c vs new: 2,425 reads + 72 writes identical after masking ?v hashes, offline at, route order; event stream on the copy delivers. Not deployed.mre
  • 43be6578w9: re-vendor hybriel master edfd400a; event stream imports sseStart/sseSend/sseAlive from hl:http1 (hybriel#144), useTransport gone; tools/import.hl plain declarations. BLOCKED: hybriel-native refuses `emit client` in a static (lib/api.hl) — the server does not compile on edfd400a, gates fail at start; scratch copy without those emits: events 48/0, gate 254 ok up to the first live pushmre
  • 0e8a41caw6 (ticket #26): event stream for programs — GET /api/events (Server-Sent Events)mre
  • bb64d57cmission 012 (ticket #25 API part): every /api/projects/<x>/… route takes the project's id (12-char record id) as well as its slug, same answers byte for byte; tickets stay under their project, no global /api/tickets/<x>. gate 315/0 (old code: the 13 id checks fail), connect 60/0, live-data copy old vs new 1,484 identical, slug vs id 772 identicalmre
  • 7538b034mission 011 (ticket #25 web part): short page URLs /<slug> and /<slug>/<number>; /projects/<slug>, /projects/<slug>/<n>, /projects/<slug>/tickets/<n> and /tickets/<ref> answer 301 (current slug); slug pages moved behind hl:web's own routes after construction (they answered /__hl/* and /components/*.hl); reserved slugs refused; API paths unchanged. gate 293/0, connect 60/0, live-data copy 187/0, API old vs new: only page links differmre
  • 0369106emission 010 (code order) 4/4: README file map + import order + 'Same output' test, STATUS (entry, lessons, how to verify), LOG, report; tests/realdata-baseline.mjs + realdata-compare*.py (a cleanup answers the same on live data), tests/letcount.pymre
  • a75e0279mission 010 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (456 lets → plain declarations; Hybriel refuses a plain declaration inside a loop on its 2nd pass). gate 249/0, connect 60/0, real-data reads identical, a 50-step write sequence (API + faces) identical to the old codemre
  • e9d5c618mission 010 (code order) 2/4: one lib/ file per topic — store.hl split into projects / tickets (+ relations) / events / tickets-helpers, util.hl shared helpers (env, storage dir, URLs, sorts, Vienna time), the function routes out of project.hl into lib/api.hl (thin; auth/filters/Accept in api-helpers.hl), invite + member-removal logic out of the faces/routes into invites.hl / tickets.hl; project.hl is the map. /login/callback gets req + the session store by reference. gate 249/0, connect 60/0, real-data reads identicalmre