gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita6ddccd2a6ddccd2re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mrea6ddccd2/lib/events.hl

8.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. // 'comment' (mission 016): the event keeps the FIRST text; edits, a deletion and likes are kept by
  14. // lib/comments.hl, and the rows here show the comment as it is now (commentStateOf). Its files
  15. // (tickets#27): lib/attachments.hl (the row's `attachments`).
  16. // tickets.hl writes the events (putEvent) together with the ticket record; this file shapes and reads them.
  17. import { MPackDB } from 'hl:mpackdb'
  18. import { storageDir, countOf, localStamp, ticketHref } from './util.hl'
  19. import { nameOfUser } from './users.hl'
  20. import { projectSlugOf } from './projects.hl'
  21. import { slugOf } from './tickets-helpers.hl'
  22. import { markdownBlocks } from './markdown.hl'
  23. import { commentStateOf, likersOf } from './comments.hl'
  24. import { attachmentsOf } from './attachments.hl'
  25. static eventsTable = new MPackDB(file = storageDir + '/events.db', primaryKey = '@id', indexes = ['@ticket'])
  26. // ---- writing -------------------------------------------------------------------------------------
  27. // appends one event record (built field by field by tickets.hl); answers its id, or null (eventsError says why)
  28. static putEvent = (rec) => { return eventsTable.put(rec) }
  29. static eventsError = () => { return eventsTable.lastError() }
  30. // one stored event record, or null (the event stream numbers it, lib/stream.hl)
  31. static eventRecord = (eventId) => { return eventId == null ? null : eventsTable.fetch(eventId) }
  32. // the API row of a stored event
  33. static eventRowAt = (eventId, t) => { return eventRowOf(eventsTable.fetch(eventId), t) }
  34. // ---- reading -------------------------------------------------------------------------------------
  35. // the history of a ticket (a record), oldest first: by stored time, then seq
  36. static historyOf = (t) => {
  37. out = []
  38. all = eventsTable.find('ticket', t.id)
  39. if (countOf(all) == 0) { return out }
  40. for (e of all) { out.push(eventRowOf(e, t)) }
  41. let i = 1
  42. while (i < out.length) {
  43. let cur = out[i]
  44. let j = i - 1
  45. while (j >= 0 && (out[j].createdMs > cur.createdMs || (out[j].createdMs == cur.createdMs && out[j].seq > cur.seq))) {
  46. out[j + 1] = out[j]
  47. j = j - 1
  48. }
  49. out[j + 1] = cur
  50. i = i + 1
  51. }
  52. return out
  53. }
  54. // a ticket from before the login has no createdBy: the free-text author of its 'created' event
  55. static creatorNameOf = (t) => {
  56. all = eventsTable.find('ticket', t.id)
  57. if (countOf(all) == 0) { return '' }
  58. for (e of all) { if (e.kind == 'created') { return e.author != null ? e.author : '' } }
  59. return ''
  60. }
  61. // ---- the shapes ----------------------------------------------------------------------------------
  62. static eventRowOf = (e, t) => {
  63. let kind = e.kind
  64. // computed BEFORE the literal: inside a literal that has an `id` entry, a called function's
  65. // parameter named `id` read that entry instead (mission 011, reported as a Hybriel issue)
  66. who = e.user != null ? nameOfUser(e.user) : e.author
  67. let label = kind == 'created' ? 'opened the ticket' : (kind == 'state' ? 'changed the state' : (kind == 'edit' ? 'edited the ticket' : 'commented'))
  68. if (kind == 'link') { label = linkLabelOf(e) }
  69. let assignedTo = ''
  70. let assignedWas = ''
  71. if (kind == 'assign') {
  72. assignedTo = e.assignee != null && e.assignee != '' ? nameOfUser(e.assignee) : ''
  73. assignedWas = e.previous != null && e.previous != '' ? nameOfUser(e.previous) : ''
  74. label = assignedTo != '' ? 'assigned the ticket to ' + assignedTo : 'unassigned the ticket' + (assignedWas != '' ? ' (was ' + assignedWas + ')' : '')
  75. }
  76. row = {
  77. id = e.id
  78. ticket = e.ticket
  79. project = t != null ? projectSlugOf(t) : ''
  80. number = t != null ? t.number : 0
  81. seq = e.seq != null ? e.seq : 0
  82. kind = kind
  83. author = who
  84. userId = e.user != null ? e.user : ''
  85. text = e.text != null ? e.text : ''
  86. hasText = e.text != null && e.text != ''
  87. from = e.from != null ? e.from : ''
  88. to = e.to != null ? e.to : ''
  89. toSlug = slugOf(e.to)
  90. isState = kind == 'state'
  91. isComment = kind == 'comment'
  92. isCreated = kind == 'created'
  93. label = label
  94. when = localStamp(e.created)
  95. createdMs = e.created
  96. }
  97. // ticket #8: only an edit event carries these (the JSON of every other event is unchanged)
  98. if (kind == 'edit') {
  99. row.isEdit = true
  100. row.oldSubject = e.oldSubject != null ? e.oldSubject : ''
  101. row.oldSummary = e.oldSummary != null ? e.oldSummary : ''
  102. row.newSubject = e.subject != null ? e.subject : ''
  103. row.newSummary = e.summary != null ? e.summary : ''
  104. row.subjectChanged = row.oldSubject != row.newSubject
  105. row.summaryChanged = row.oldSummary != row.newSummary
  106. }
  107. // ticket #4: only a link event carries these
  108. if (kind == 'link') {
  109. row.isLink = true
  110. row.linkKind = e.linkKind
  111. row.linkAction = e.action
  112. row.otherRef = e.otherProject + ' #' + e.otherNumber
  113. row.otherHref = ticketHref(e.otherProject, e.otherNumber)
  114. row.previousRef = e.previous != null ? e.previousProject + ' #' + e.previousNumber : ''
  115. }
  116. // mission 016: a comment as it is NOW (lib/comments.hl). Only a changed comment carries the extra keys: an edited one
  117. // `edited`, `editedWhen`, `earlier` ([{ when, text }], the versions before, oldest first) and the newest `text`; a
  118. // deleted one `deleted`, `deletedWhen`, no text, the label "commented (deleted …)"; a liked one `likes` (the count).
  119. // Every other comment row has exactly the keys it had before.
  120. if (kind == 'comment') {
  121. cs = commentStateOf(e)
  122. if (cs.edited) {
  123. row.text = cs.text
  124. row.hasText = cs.text != ''
  125. row.edited = true
  126. row.editedWhen = localStamp(cs.editedMs)
  127. row.earlier = versionsOf(cs.earlier)
  128. }
  129. if (cs.deleted) {
  130. row.text = ''
  131. row.hasText = false
  132. row.label = 'commented (deleted ' + localStamp(cs.deletedMs) + ')'
  133. row.deleted = true
  134. row.deletedWhen = localStamp(cs.deletedMs)
  135. }
  136. if (cs.likes > 0) { row.likes = cs.likes }
  137. // tickets#27: only a comment with files carries `attachments` ([{ id, name, type, size, image, url }]; a deleted one has none)
  138. if (!cs.deleted) {
  139. files = attachmentsOf(e.id)
  140. if (files.length > 0) { row.attachments = files }
  141. }
  142. }
  143. // ticket #20: only an assign event carries these
  144. if (kind == 'assign') {
  145. row.isAssign = true
  146. row.assignee = assignedTo
  147. row.previousAssignee = assignedWas
  148. }
  149. return row
  150. }
  151. static versionsOf = (list) => {
  152. out = []
  153. for (v of list) { out.push({ when = v.when text = v.text }) }
  154. return out
  155. }
  156. // "set the parent to ident.worldapi.org #1", "removed the blocker tickets.worldapi.org #6", …
  157. static linkLabelOf = (e) => {
  158. other = e.otherProject + ' #' + e.otherNumber
  159. if (e.linkKind == 'parent') {
  160. if (e.action == 'removed') { return 'removed the parent ' + other }
  161. was = e.previous != null ? ' (was ' + e.previousProject + ' #' + e.previousNumber + ')' : ''
  162. return 'set the parent to ' + other + was
  163. }
  164. if (e.action == 'removed') { return 'removed the blocker ' + other }
  165. return 'marked it blocked by ' + other
  166. }
  167. // THE PAGE'S EVENT ROW (ticket #6): the API row + its text as Markdown blocks (`md`), and for an
  168. // edit the previous summary's blocks (`oldSummaryMd`) and the new one's (`summaryMd`, the ticket
  169. // page takes it over live). Only pages and pushes carry these — the JSON API does not.
  170. static pageEventOf = (ev) => {
  171. out = {}
  172. for (k of ev.keys()) { out[k] = ev[k] }
  173. out.md = markdownBlocks(ev.text)
  174. // mission 016: who likes a comment (users @ids) — the page works out `liked` for the user looking
  175. if (ev.isComment == true) { out.likedBy = likersOf(ev.id) }
  176. if (ev.isEdit == true) {
  177. out.oldSummaryMd = markdownBlocks(ev.oldSummary)
  178. out.summaryMd = markdownBlocks(ev.newSummary)
  179. }
  180. return out
  181. }
  182. static pageEventsOf = (evs) => {
  183. out = []
  184. for (ev of evs) { out.push(pageEventOf(ev)) }
  185. return out
  186. }

Branches

Latest commits

  • a6ddccd2re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • 81e036b7docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 5d8d2cf6deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • 58e8c02cmission 024: report, LOG, STATUS, e2e fixmre
  • 50778073tests/e2e-route-marker.mjs: first paint marker, comments post/edit redrawmre
  • c5203298mission 024: MainMenu marks the page from the route (layouts 0bcc629 main-menu.hl); browser-side marker removed; gate: marker in the server HTMLmre
  • b1a4c270re-vendor Hybriel master f9614007: bin/ (git-ignored) and plugins wholemre
  • 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