gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit866397a0866397a0mission 023: theme from layouts 76f99f6 (current marker, menu count badge), components from 3794c59 (MdEditor keys); Inbox count as badge, current by address; gates and E2E; reportmre866397a0/project.hl

12.8 KB

  1. // project.hl — tickets.worldapi.org: THE MAP. Config, routes and WHO HEARS WHAT; the logic lives in lib/.
  2. //
  3. // WHERE THINGS ARE (one line per feature; README.md "Files" has the full list):
  4. // tickets, their states and relations (parent / blocked-by) lib/tickets.hl (state names, page shapes: lib/tickets-helpers.hl)
  5. // the history of a ticket (events) lib/events.hl
  6. // comments: edit, delete, like (mission 016) lib/comments.hl (the page draws them: components/comments/)
  7. // files attached to a comment (tickets#27, mission 017) lib/attachments.hl (the API's multipart body: lib/multipart.hl)
  8. // projects, members, roles, slugs lib/projects.hl
  9. // users, login through ident, API tokens, sessions lib/users.hl
  10. // invites to a project (ident#22) lib/invites.hl
  11. // connecting an app to a project (ticket #21) lib/connections.hl
  12. // Markdown in text fields / the Markdown read view lib/markdown.hl / lib/mdview.hl
  13. // the JSON API + /login/callback, /connect, /tickets/:ref lib/api.hl (plumbing: lib/api-helpers.hl, lib/jsoncheck.hl)
  14. // the event stream for programs, GET /api/events (#26) lib/stream.hl (numbered rows, filters, SSE)
  15. // the ticket #20 data migration (every start) lib/migrate.hl
  16. // the ticket-file format of the import lib/import.hl (the import tool: tools/import.hl)
  17. // shared small helpers (env, storage dir, URLs, sorting, Vienna time) lib/util.hl
  18. // pages: shell, list, ticket, inbox, you, new project, settings, connect components/*.hl; CSS components/styles.hl
  19. import WebFramework from 'hl:web'
  20. import { env } from 'hl:proc'
  21. import Styles from './components/styles.hl'
  22. import { dark, darker } from './shared/tokens.hl'
  23. import { migrateAll } from './lib/migrate.hl'
  24. import { tagOf } from './lib/users.hl'
  25. import { getAttachment, getEvents, postTicket, getTicket, postComment, postCommentEdit, postCommentDelete, postCommentLike, postState, postEdit, postAssign, postParent, postBlockers, getProjects, getInbox, getProject, postMembers, postMemberRemove, postInvites, connectExchange, projectConnections, projectDisconnect, connectStart, projectTickets, getProjectTicket, postProjectComment, postProjectCommentEdit, postProjectCommentDelete, postProjectCommentLike, postProjectState, postProjectEdit, postProjectAssign, postProjectParent, postProjectBlockers, oldTicketPage, oldProjectPage, oldProjectTicketPage, loginCallback } from './lib/api.hl'
  26. import TicketList from './components/ticket_list.hl'
  27. import Ticket from './components/ticket.hl'
  28. import Inbox from './components/inbox.hl'
  29. import You from './components/you.hl'
  30. import NewProject from './components/new_project.hl'
  31. import Settings from './components/settings.hl'
  32. import Connect from './components/connect.hl'
  33. static siteName = "tickets"
  34. appTitle = siteName
  35. styles = Styles
  36. // ---- THE INSTALLABLE APP (mission 046), the same way calendar.worldapi.org does it: hl:web's own web app manifest
  37. // (/__hl/manifest.webmanifest, linked from every head with the apple-touch-icon and theme-color) and service worker
  38. // (/__hl/sw.js) from these settings — no JavaScript of ours. Icons in icons/ (icon.svg, a ticket stub, is the source;
  39. // the PNGs and favicon.ico are rendered from it with rsvg-convert / magick, README "PWA"). The theme colour is the
  40. // header's background (darker, as tracker), the splash background the page's (dark) — both off the tokens, not written out again.
  41. appThemeColor = darker.value
  42. appBackgroundColor = dark.value
  43. appIcons = [
  44. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }
  45. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }
  46. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }
  47. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }
  48. ]
  49. appTouchIcon = '/icons/apple-touch-icon.png'
  50. appFavicon = '/icons/icon.svg'
  51. // OFFLINE: the shell and `/` — `/` IS the ticket list, so offline it shows the list as this browser last loaded it,
  52. // and the shell (components/main.hl) says "You are offline". Its value-form emits are never queued. Other pages are
  53. // not kept, except a project list (/<slug>, same component) this browser visited; the rest get hl:web's
  54. // "Unavailable offline" page.
  55. offline = [ TicketList ]
  56. // ---- THE ROUTES: files, the function routes (lib/api.hl), the pages (components/) ----------------
  57. routes = [
  58. { pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }
  59. // the installable app (mission 046): the icons (manifest and service worker are hl:web's own, from appIcons / offline)
  60. { pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }
  61. { pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }
  62. { pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }
  63. { pattern = "/icons/icon.svg" file = "./icons/icon.svg" headers = { 'Cache-Control' = 'no-cache' } }
  64. // the login button's return (ticket #7): it needs the request's session and the framework's session store, BY REFERENCE
  65. { pattern = "/login/callback" function = (route, req) => { return loginCallback(route, &req, &server.sessions) } }
  66. { pattern = "/login.js" file = "./login.js" headers = { 'Cache-Control' = 'no-cache' } }
  67. // ticket #26: every change, live, for programs (Server-Sent Events; lib/stream.hl)
  68. { pattern = "/api/events" function = getEvents }
  69. { pattern = "/api/tickets" function = postTicket }
  70. { pattern = "/api/tickets/:ref" function = getTicket }
  71. { pattern = "/api/tickets/:ref/comments" function = postComment }
  72. // mission 016: a comment's author edits / deletes it, a member likes it (lib/comments.hl); :comment = its event id
  73. { pattern = "/api/tickets/:ref/comments/:comment/edit" function = postCommentEdit }
  74. { pattern = "/api/tickets/:ref/comments/:comment/delete" function = postCommentDelete }
  75. { pattern = "/api/tickets/:ref/comments/:comment/like" function = postCommentLike }
  76. { pattern = "/api/tickets/:ref/state" function = postState }
  77. // tickets#27: an attached file, for the members of its project (lib/attachments.hl)
  78. { pattern = "/api/attachments/:id" function = getAttachment }
  79. { pattern = "/api/tickets/:ref/edit" function = postEdit }
  80. { pattern = "/api/tickets/:ref/assign" function = postAssign }
  81. { pattern = "/api/tickets/:ref/parent" function = postParent }
  82. { pattern = "/api/tickets/:ref/blocked-by" function = postBlockers }
  83. { pattern = "/api/projects" function = getProjects }
  84. { pattern = "/api/inbox" function = getInbox }
  85. { pattern = "/api/projects/:slug" function = getProject }
  86. { pattern = "/api/projects/:slug/members" function = postMembers }
  87. { pattern = "/api/projects/:slug/members/remove" function = postMemberRemove }
  88. { pattern = "/api/projects/:slug/invites" function = postInvites }
  89. { pattern = "/api/connect/exchange" function = connectExchange }
  90. { pattern = "/api/projects/:slug/connections" function = projectConnections }
  91. { pattern = "/api/projects/:slug/connections/remove" function = projectDisconnect }
  92. { pattern = "/connect" function = connectStart }
  93. { pattern = "/api/projects/:slug/tickets" function = projectTickets }
  94. { pattern = "/api/projects/:slug/tickets/:number" function = getProjectTicket }
  95. { pattern = "/api/projects/:slug/tickets/:number/comments" function = postProjectComment }
  96. { pattern = "/api/projects/:slug/tickets/:number/comments/:comment/edit" function = postProjectCommentEdit }
  97. { pattern = "/api/projects/:slug/tickets/:number/comments/:comment/delete" function = postProjectCommentDelete }
  98. { pattern = "/api/projects/:slug/tickets/:number/comments/:comment/like" function = postProjectCommentLike }
  99. { pattern = "/api/projects/:slug/tickets/:number/state" function = postProjectState }
  100. { pattern = "/api/projects/:slug/tickets/:number/edit" function = postProjectEdit }
  101. { pattern = "/api/projects/:slug/tickets/:number/assign" function = postProjectAssign }
  102. { pattern = "/api/projects/:slug/tickets/:number/parent" function = postProjectParent }
  103. { pattern = "/api/projects/:slug/tickets/:number/blocked-by" function = postProjectBlockers }
  104. { pattern = "/" component = TicketList }
  105. { pattern = "/project/:projectName" component = TicketList }
  106. { pattern = "/state/:stateSlug" component = TicketList }
  107. { pattern = "/project/:projectName/state/:stateSlug" component = TicketList }
  108. { pattern = "/inbox" component = Inbox }
  109. { pattern = "/new-project" component = NewProject }
  110. { pattern = "/connect/:nonce" component = Connect }
  111. { pattern = "/projects/:projectSlug/settings" component = Settings }
  112. { pattern = "/you" component = You }
  113. // OLD PAGE URLS → 301 to the short ones (ticket #25): `/tickets/<old global number or uuid>`, `/projects/<slug>`,
  114. // `/projects/<slug>/<number>`, `/projects/<slug>/tickets/<number>`
  115. { pattern = "/tickets/:ref" function = oldTicketPage }
  116. { pattern = "/projects/:slug" function = oldProjectPage }
  117. { pattern = "/projects/:slug/:number" function = oldProjectTicketPage }
  118. { pattern = "/projects/:slug/tickets/:number" function = oldProjectTicketPage }
  119. // THE SHORT PAGE URLS (ticket #25): the project `/<slug>`, a ticket `/<slug>/<number>`. They match any first
  120. // segment, so they come last — and below, after the construction, behind hl:web's own urls too (`lastPage`)
  121. { pattern = "/:projectName" component = TicketList lastPage = true }
  122. { pattern = "/:projectSlug/:ticketNumber" component = Ticket lastPage = true }
  123. ]
  124. // WHO GETS THE PUSH: tickets and events are public (reading needs no login). A frame
  125. // reaches a connection only if a mounted component listens for it.
  126. // `signedIn` / `signedOut` (ticket #7) go to the tabs of ONE session: the one whose login
  127. // carries that random tag (session.data.tag, set at login) — every page of it switches to
  128. // logged in / out without a reload.
  129. audience = {
  130. ticketCreated = (row, session) => { return true }
  131. ticketEvent = (ticketId, ev, row, session) => { return true }
  132. // mission 016: a comment was edited, deleted or (un)liked — the ticket page swaps that history row
  133. commentChanged = (ticketId, ev, session) => { return true }
  134. // ticket #4: the relation views (tickets-helpers.hl relationViewOf) of a ticket and its related ones
  135. ticketsRelated = (views, session) => { return true }
  136. // ticket #21: an app was connected / disconnected — the project page refreshes its line
  137. connectionsChanged = (slug, session) => { return true }
  138. signedIn = (tag, info, session) => { return tag != null && tagOf(session) == tag }
  139. signedOut = (tag, session) => { return tag != null && tagOf(session) == tag }
  140. }
  141. sessionDir = env('TICKETS_SESSIONS') != null ? env('TICKETS_SESSIONS') : null
  142. port = env('TICKETS_PORT') != null ? toNumber(env('TICKETS_PORT')) : 8350
  143. // THE LISTENER's interface (mission 010, deploy to Byrodin): hl:web reads HL_HOST (or HOST)
  144. // itself (hybriel#24): 127.0.0.1 on Byrodin behind nginx; unset = 0.0.0.0 (dev on Loreana).
  145. // TICKETS_WATCH=0 turns the dev watcher off (the container: a deploy is an rsync + restart,
  146. // half-copied .hl files must not be re-analysed); unset = on, as before.
  147. watching = env('TICKETS_WATCH') != '0'
  148. // THE MIGRATION of ticket #20 (lib/migrate.hl): idempotent, runs at every start
  149. for (line of migrateAll()) { console.log('migrated: ' + line) }
  150. // uploadMax (tickets#27): the largest file a page's emit may carry = lib/attachments.hl maxFileBytes (10 MiB; inlined, as a manifest value)
  151. server = new WebFramework(routes = routes, styles = styles, minify = true, port = port, watchMode = watching, uploadMax = 10485760)
  152. // THE SHORT PAGE URLS GO BEHIND hl:web's OWN (ticket #25). The first match answers, and hl:web APPENDS its urls
  153. // (/__hl/app.css, /__hl/emit, /__hl/sw.js …, the component modules /components/<file>.hl) to the table while it is
  154. // constructed: left where they are, `/:projectSlug/:ticketNumber` answered /__hl/app.css and /components/ticket.hl
  155. // with a ticket page. They stay in the table above (hl:web serves the modules of the components routes mount, and
  156. // the service worker knows them as pages) and are moved to the end of the router's table here — the one that
  157. // answers requests and that the browser gets for its links. A first segment any route answers is a reserved slug
  158. // (lib/projects.hl reservedSlugs; the gate checks both).
  159. pagesFirst = []
  160. pagesLast = []
  161. for (r of server.router.routes) { if (r.lastPage == true) { pagesLast[] = r } else { pagesFirst[] = r } }
  162. for (r of pagesLast) { pagesFirst[] = r }
  163. server.router.routes = pagesFirst
  164. // THE GLOBAL ERROR HANDLER (ticket #7): a plugin's failure — above all hl:fetch's refused /
  165. // timed-out exchange with ident (users.hl exchangeCode, invites.hl) — arrives here instead of aborting the
  166. // request with a 500 that shows source paths; the failed call yields null and the caller answers
  167. // it ("ident did not answer"). Every absorbed error is logged.
  168. on Error(e) { console.log('error absorbed: ' + e.message) }

Branches

Latest commits

  • 866397a0mission 023: theme from layouts 76f99f6 (current marker, menu count badge), components from 3794c59 (MdEditor keys); Inbox count as badge, current by address; gates and E2E; reportmre
  • 7ed2e5e5deploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the script silently (grep under pipefail), as gitoria/layoutsmre
  • bf9064a3mission 022: tickets on the layouts theme (step 1): shell, styles, gates, audit, E2E; reportmre
  • f3d61711mission 022 WIP: tickets on the layouts theme (dbe3de7): AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst shell, styles reduced to the app's own, check-theme in the gates, 390 audit + real-Chrome walk scriptmre
  • 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