gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commiteef80f55eef80f55tickets (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)mreeef80f55/project.hl

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

Branches

Latest commits

  • 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
  • 97e269b5mission 010 (code order) 1/4: .hl files out of the root — lib/ (store, users, connections, invites, migrate, markdown, mdview, import = ticketfile, util = localtime, jsoncheck, api-helpers = api), tools/import.hl, components/styles.hl; import paths only. gate 249/0, connect 60/0, real-data reads identicalmre