gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf04afc43f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mref04afc43/lib/events.hl

9.1 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. // a state change with a note is shown as a comment card too (tickets#33): it gets the same extra keys, except that a deleted note
  121. // only loses its text (the state line stays as it was)
  122. if (kind == 'state' && e.text != null && e.text != '') {
  123. ns = commentStateOf(e)
  124. row.text = ns.text
  125. row.hasText = ns.text != ''
  126. if (ns.edited) {
  127. row.edited = true
  128. row.editedWhen = localStamp(ns.editedMs)
  129. row.earlier = versionsOf(ns.earlier)
  130. }
  131. if (ns.likes > 0) { row.likes = ns.likes }
  132. }
  133. if (kind == 'comment') {
  134. cs = commentStateOf(e)
  135. if (cs.edited) {
  136. row.text = cs.text
  137. row.hasText = cs.text != ''
  138. row.edited = true
  139. row.editedWhen = localStamp(cs.editedMs)
  140. row.earlier = versionsOf(cs.earlier)
  141. }
  142. if (cs.deleted) {
  143. row.text = ''
  144. row.hasText = false
  145. row.label = 'commented (deleted ' + localStamp(cs.deletedMs) + ')'
  146. row.deleted = true
  147. row.deletedWhen = localStamp(cs.deletedMs)
  148. }
  149. if (cs.likes > 0) { row.likes = cs.likes }
  150. // tickets#27: only a comment with files carries `attachments` ([{ id, name, type, size, image, url }]; a deleted one has none)
  151. if (!cs.deleted) {
  152. files = attachmentsOf(e.id)
  153. if (files.length > 0) { row.attachments = files }
  154. }
  155. }
  156. // ticket #20: only an assign event carries these
  157. if (kind == 'assign') {
  158. row.isAssign = true
  159. row.assignee = assignedTo
  160. row.previousAssignee = assignedWas
  161. }
  162. return row
  163. }
  164. static versionsOf = (list) => {
  165. out = []
  166. for (v of list) { out.push({ when = v.when text = v.text }) }
  167. return out
  168. }
  169. // "set the parent to ident.worldapi.org #1", "removed the blocker tickets.worldapi.org #6", …
  170. static linkLabelOf = (e) => {
  171. other = e.otherProject + ' #' + e.otherNumber
  172. if (e.linkKind == 'parent') {
  173. if (e.action == 'removed') { return 'removed the parent ' + other }
  174. was = e.previous != null ? ' (was ' + e.previousProject + ' #' + e.previousNumber + ')' : ''
  175. return 'set the parent to ' + other + was
  176. }
  177. if (e.action == 'removed') { return 'removed the blocker ' + other }
  178. return 'marked it blocked by ' + other
  179. }
  180. // THE PAGE'S EVENT ROW (ticket #6): the API row + its text as Markdown blocks (`md`), and for an
  181. // edit the previous summary's blocks (`oldSummaryMd`) and the new one's (`summaryMd`, the ticket
  182. // page takes it over live). Only pages and pushes carry these — the JSON API does not.
  183. static pageEventOf = (ev) => {
  184. out = {}
  185. for (k of ev.keys()) { out[k] = ev[k] }
  186. out.md = markdownBlocks(ev.text)
  187. // mission 016: who likes a comment (users @ids) — the page works out `liked` for the user looking
  188. if (ev.isComment == true || (ev.isState == true && ev.hasText == true)) { out.likedBy = likersOf(ev.id) }
  189. if (ev.isEdit == true) {
  190. out.oldSummaryMd = markdownBlocks(ev.oldSummary)
  191. out.summaryMd = markdownBlocks(ev.newSummary)
  192. }
  193. return out
  194. }
  195. static pageEventsOf = (evs) => {
  196. out = []
  197. for (ev of evs) { out.push(pageEventOf(ev)) }
  198. return out
  199. }

Branches

Latest commits

  • f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mre
  • 06599fa0tickets: MdEditor from components b0f1ec2 (a clipboard with text always pastes the text, tickets#49); real Ctrl+V gatemre
  • 2e1b116ftickets: re-vendor Hybriel master acaceaf3 (framework ec8d6c1d): plugins/web patch queue while a page is built, anonymous session cookies refresh; gate waits for the comment editors to draw (W174) and clicks the form editor when it stands still; security gate: main's code runs on its own binary, lazy-session cookie checksmre
  • 361bc0fetickets: re-vendor Hybriel 7a684920 (WIP, not deployed); on Error exits 1 at startup; migrate passes its log by reference; gate checks follow lazy sessions and the 413 refusalmre
  • 8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre
  • 337e9b21tickets#37: a comment's files are open to everyone who can read the commentmre
  • 1800600ftickets: write the standby service out in full so the boot gate can read the main servicemre
  • 8179d287tickets: standby service on its port plus 10 and a deploy that hands over through it without a gapmre
  • 0398145ctickets: the table grid rule is marked functional for check-thememre
  • 40fddc20tickets takes components e54f83a: tables get thin grey lines from the theme, desktop toolbar stays one row with the Table button, F4 check counts 11 buttonsmre
  • c1b77d61tickets#35: text typed before the editor is built is taken in once by the build (the input handler no longer writes it to the field first, which doubled the first letters); the gate failure shows the surfacemre
  • 32bf1873tickets#35: the gate types right after the load with the CPU slowed, no waitingmre
  • 64ea9ca2tickets#35: text typed into the reply editor before the page has finished starting is kept; the gate types right after loadmre
  • ccd3a327tickets: the security gate expects frame-src to be exactly the ident address (the sign-in frame), still no wildcard or selfmre
  • 4348dbabident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 66ef3005Merge branch 'iw-ident-widget'mre
  • bc0ad663tickets: a gap between your name and Log out in the phone header (they touched); gate checks itmre
  • 2f818d46UX2: report, LOG line, e2e fixes, gate pause after loadmre
  • af3ef7c4gate: the legacy state line says progressmre
  • 62480a00tickets#33: a state change with a note is a comment card in the feed (same framework rendering, can be liked, edited, deleted), its state line stands alone; gate checks for a new comment with and without a state change, at once and after a reloadmre