gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit31cabfcc31cabfccmission 021: E2E script, report, LOG, STATUSmre31cabfcc/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

  • 31cabfccmission 021: E2E script, report, LOG, STATUSmre
  • 6aea8683editor look: .empty rule only for p.empty, files off where tickets has no upload, state note one line, events test scrolls the editor into view; synced md-editor (components d702d76+6f27ad3); gate 377/0, events 52/0mre
  • dce6ffa6Merge branch 'w28-deflake'mre
  • 536092a1tickets (mission 019): de-flake the m016 comment clicks (B: unliked) — calmClick waits until the button stops moving; test only, no app changemre
  • 9c5fd42amission 020: attachments E2E proof (lisbeth Chrome, real-data copy), reportmre
  • 1206404fREADME attachments, report 018, LOG/STATUSmre
  • 3d9e7f3ctests: m017 gate fixes (list count, waits before delete clicks); gate 373/0mre
  • dd41d5bcre-sync components 15be2ac; mission 018mre
  • 420ad1bbtickets (mission 017 WIP, tickets#27): comment attachments — lib/attachments.hl (storage/attachments, limits, type by content, members-only GET /api/attachments/:id, delete drops, edit keeps), multipart POST …/comments (lib/multipart.hl), Respond block in FilesUpload (blocks verbatim from components w27c 1f8d79d), gate m017 checks written (not yet run); report, LOG, STATUSmre
  • a7a1380dmission brief 017mre
  • 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