gitoriaLog in with ident

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit7538b0347538b034mission 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 differmre7538b034/lib/events.hl

6.6 KB

  1. // lib/events.hl — THE HISTORY OF A TICKET: an append-only event per change. Statics only, the server realm.
  2. // eventsTable pk @id index @ticket APPEND ONLY: { ticket (ticket @id), seq
  3. // (1, 2, … per ticket), kind, author, user?, text, from, to, created, oldId? }
  4. // kind = 'created' | 'comment' | 'state' | 'edit' | 'link' | 'assign'
  5. // 'assign' (ticket #20): { assignee (users @id, '' = unassigned), previous (users @id, '') }
  6. // 'link' (ticket #4, mission 017): { linkKind ('parent' | 'blockedBy'), action
  7. // ('set' | 'removed'), other, otherProject, otherNumber, previous?, previousProject?,
  8. // previousNumber? } — on the CHILD / the BLOCKED ticket (the one whose relation changed).
  9. // 'edit' (ticket #8, mission 014): { oldSubject, oldSummary, subject, summary } —
  10. // the values before AND after; the ticket record then carries the new ones.
  11. // `user` (users @id, users.hl) since ticket #7: the event's author is that
  12. // user's CURRENT display name; `author` keeps the name at writing time.
  13. // tickets.hl writes the events (putEvent) together with the ticket record; this file shapes and reads them.
  14. import { MPackDB } from 'hl:mpackdb'
  15. import { storageDir, countOf, localStamp, ticketHref } from './util.hl'
  16. import { nameOfUser } from './users.hl'
  17. import { projectSlugOf } from './projects.hl'
  18. import { slugOf } from './tickets-helpers.hl'
  19. import { markdownBlocks } from './markdown.hl'
  20. static eventsTable = new MPackDB(file = storageDir + '/events.db', primaryKey = '@id', indexes = ['@ticket'])
  21. // ---- writing -------------------------------------------------------------------------------------
  22. // appends one event record (built field by field by tickets.hl); answers its id, or null (eventsError says why)
  23. static putEvent = (rec) => { return eventsTable.put(rec) }
  24. static eventsError = () => { return eventsTable.lastError() }
  25. // the API row of a stored event
  26. static eventRowAt = (eventId, t) => { return eventRowOf(eventsTable.fetch(eventId), t) }
  27. // ---- reading -------------------------------------------------------------------------------------
  28. // the history of a ticket (a record), oldest first: by stored time, then seq
  29. static historyOf = (t) => {
  30. out = []
  31. all = eventsTable.find('ticket', t.id)
  32. if (countOf(all) == 0) { return out }
  33. for (e of all) { out.push(eventRowOf(e, t)) }
  34. let i = 1
  35. while (i < out.length) {
  36. let cur = out[i]
  37. let j = i - 1
  38. while (j >= 0 && (out[j].createdMs > cur.createdMs || (out[j].createdMs == cur.createdMs && out[j].seq > cur.seq))) {
  39. out[j + 1] = out[j]
  40. j = j - 1
  41. }
  42. out[j + 1] = cur
  43. i = i + 1
  44. }
  45. return out
  46. }
  47. // a ticket from before the login has no createdBy: the free-text author of its 'created' event
  48. static creatorNameOf = (t) => {
  49. all = eventsTable.find('ticket', t.id)
  50. if (countOf(all) == 0) { return '' }
  51. for (e of all) { if (e.kind == 'created') { return e.author != null ? e.author : '' } }
  52. return ''
  53. }
  54. // ---- the shapes ----------------------------------------------------------------------------------
  55. static eventRowOf = (e, t) => {
  56. let kind = e.kind
  57. // computed BEFORE the literal: inside a literal that has an `id` entry, a called function's
  58. // parameter named `id` read that entry instead (mission 011, reported as a Hybriel issue)
  59. who = e.user != null ? nameOfUser(e.user) : e.author
  60. let label = kind == 'created' ? 'opened the ticket' : (kind == 'state' ? 'changed the state' : (kind == 'edit' ? 'edited the ticket' : 'commented'))
  61. if (kind == 'link') { label = linkLabelOf(e) }
  62. let assignedTo = ''
  63. let assignedWas = ''
  64. if (kind == 'assign') {
  65. assignedTo = e.assignee != null && e.assignee != '' ? nameOfUser(e.assignee) : ''
  66. assignedWas = e.previous != null && e.previous != '' ? nameOfUser(e.previous) : ''
  67. label = assignedTo != '' ? 'assigned the ticket to ' + assignedTo : 'unassigned the ticket' + (assignedWas != '' ? ' (was ' + assignedWas + ')' : '')
  68. }
  69. row = {
  70. id = e.id
  71. ticket = e.ticket
  72. project = t != null ? projectSlugOf(t) : ''
  73. number = t != null ? t.number : 0
  74. seq = e.seq != null ? e.seq : 0
  75. kind = kind
  76. author = who
  77. userId = e.user != null ? e.user : ''
  78. text = e.text != null ? e.text : ''
  79. hasText = e.text != null && e.text != ''
  80. from = e.from != null ? e.from : ''
  81. to = e.to != null ? e.to : ''
  82. toSlug = slugOf(e.to)
  83. isState = kind == 'state'
  84. isComment = kind == 'comment'
  85. isCreated = kind == 'created'
  86. label = label
  87. when = localStamp(e.created)
  88. createdMs = e.created
  89. }
  90. // ticket #8: only an edit event carries these (the JSON of every other event is unchanged)
  91. if (kind == 'edit') {
  92. row.isEdit = true
  93. row.oldSubject = e.oldSubject != null ? e.oldSubject : ''
  94. row.oldSummary = e.oldSummary != null ? e.oldSummary : ''
  95. row.newSubject = e.subject != null ? e.subject : ''
  96. row.newSummary = e.summary != null ? e.summary : ''
  97. row.subjectChanged = row.oldSubject != row.newSubject
  98. row.summaryChanged = row.oldSummary != row.newSummary
  99. }
  100. // ticket #4: only a link event carries these
  101. if (kind == 'link') {
  102. row.isLink = true
  103. row.linkKind = e.linkKind
  104. row.linkAction = e.action
  105. row.otherRef = e.otherProject + ' #' + e.otherNumber
  106. row.otherHref = ticketHref(e.otherProject, e.otherNumber)
  107. row.previousRef = e.previous != null ? e.previousProject + ' #' + e.previousNumber : ''
  108. }
  109. // ticket #20: only an assign event carries these
  110. if (kind == 'assign') {
  111. row.isAssign = true
  112. row.assignee = assignedTo
  113. row.previousAssignee = assignedWas
  114. }
  115. return row
  116. }
  117. // "set the parent to ident.worldapi.org #1", "removed the blocker tickets.worldapi.org #6", …
  118. static linkLabelOf = (e) => {
  119. other = e.otherProject + ' #' + e.otherNumber
  120. if (e.linkKind == 'parent') {
  121. if (e.action == 'removed') { return 'removed the parent ' + other }
  122. was = e.previous != null ? ' (was ' + e.previousProject + ' #' + e.previousNumber + ')' : ''
  123. return 'set the parent to ' + other + was
  124. }
  125. if (e.action == 'removed') { return 'removed the blocker ' + other }
  126. return 'marked it blocked by ' + other
  127. }
  128. // THE PAGE'S EVENT ROW (ticket #6): the API row + its text as Markdown blocks (`md`), and for an
  129. // edit the previous summary's blocks (`oldSummaryMd`) and the new one's (`summaryMd`, the ticket
  130. // page takes it over live). Only pages and pushes carry these — the JSON API does not.
  131. static pageEventOf = (ev) => {
  132. out = {}
  133. for (k of ev.keys()) { out[k] = ev[k] }
  134. out.md = markdownBlocks(ev.text)
  135. if (ev.isEdit == true) {
  136. out.oldSummaryMd = markdownBlocks(ev.oldSummary)
  137. out.summaryMd = markdownBlocks(ev.newSummary)
  138. }
  139. return out
  140. }
  141. static pageEventsOf = (evs) => {
  142. out = []
  143. for (ev of evs) { out.push(pageEventOf(ev)) }
  144. return out
  145. }

Branches

Latest commits

  • 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
  • 38f9d10ftickets: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gate 249/0, connect 60/0mre
  • d3db6139tickets: Hybriel master 190aa11d (fc838894 GC correctness, #126 closure scopes, #127); gate 249/0, connect 60/0mre
  • bce182e3tickets: Hybriel master 7eea0d32 (#126 memory, #48 lambda copies its argument); migrate.hl lambdas take &logmre
  • 4137be0fantcolony#40: mission references point to the moved missionsmre
  • 9bfba36aantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • c7bd2645tickets: Hybriel master 73267707 (#122 fixed); compactNow workaround removed (#110 covered)mre
  • 2ab91ee9tickets: gate checks rows appear once (session sync); re-vendor to ff51cf46 stopped on hybriel#122, stays 837fe120mre
  • e01c2b1dtickets#24: installable app (manifest, service worker, offline list), own icon; gate waits for the hello's pongmre
  • 752fbb7fdeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • 38bdd5e4deploy.sh: never send .git or .gitignore to Byrodinmre
  • f12fa1bcState of 2026-09-27, before the move to gitoriamre