tickets
All repositories: gitoria
8.6 KB
// lib/events.hl — THE HISTORY OF A TICKET: an append-only event per change. Statics only, the server realm.// eventsTable pk @id index @ticket APPEND ONLY: { ticket (ticket @id), seq// (1, 2, … per ticket), kind, author, user?, text, from, to, created, oldId? }// kind = 'created' | 'comment' | 'state' | 'edit' | 'link' | 'assign'// 'assign' (ticket #20): { assignee (users @id, '' = unassigned), previous (users @id, '') }// 'link' (ticket #4, mission 017): { linkKind ('parent' | 'blockedBy'), action// ('set' | 'removed'), other, otherProject, otherNumber, previous?, previousProject?,// previousNumber? } — on the CHILD / the BLOCKED ticket (the one whose relation changed).// 'edit' (ticket #8, mission 014): { oldSubject, oldSummary, subject, summary } —// the values before AND after; the ticket record then carries the new ones.// `user` (users @id, users.hl) since ticket #7: the event's author is that// user's CURRENT display name; `author` keeps the name at writing time.// 'comment' (mission 016): the event keeps the FIRST text; edits, a deletion and likes are kept by// lib/comments.hl, and the rows here show the comment as it is now (commentStateOf). Its files// (tickets#27): lib/attachments.hl (the row's `attachments`).// tickets.hl writes the events (putEvent) together with the ticket record; this file shapes and reads them.import { MPackDB } from 'hl:mpackdb'import { storageDir, countOf, localStamp, ticketHref } from './util.hl'import { nameOfUser } from './users.hl'import { projectSlugOf } from './projects.hl'import { slugOf } from './tickets-helpers.hl'import { markdownBlocks } from './markdown.hl'import { commentStateOf, likersOf } from './comments.hl'import { attachmentsOf } from './attachments.hl'static eventsTable = new MPackDB(file = storageDir + '/events.db', primaryKey = '@id', indexes = ['@ticket'])// ---- writing -------------------------------------------------------------------------------------// appends one event record (built field by field by tickets.hl); answers its id, or null (eventsError says why)static putEvent = (rec) => { return eventsTable.put(rec) }static eventsError = () => { return eventsTable.lastError() }// one stored event record, or null (the event stream numbers it, lib/stream.hl)static eventRecord = (eventId) => { return eventId == null ? null : eventsTable.fetch(eventId) }// the API row of a stored eventstatic eventRowAt = (eventId, t) => { return eventRowOf(eventsTable.fetch(eventId), t) }// ---- reading -------------------------------------------------------------------------------------// the history of a ticket (a record), oldest first: by stored time, then seqstatic historyOf = (t) => {out = []all = eventsTable.find('ticket', t.id)if (countOf(all) == 0) { return out }for (e of all) { out.push(eventRowOf(e, t)) }let i = 1while (i < out.length) {let cur = out[i]let j = i - 1while (j >= 0 && (out[j].createdMs > cur.createdMs || (out[j].createdMs == cur.createdMs && out[j].seq > cur.seq))) {out[j + 1] = out[j]j = j - 1}out[j + 1] = curi = i + 1}return out}// a ticket from before the login has no createdBy: the free-text author of its 'created' eventstatic creatorNameOf = (t) => {all = eventsTable.find('ticket', t.id)if (countOf(all) == 0) { return '' }for (e of all) { if (e.kind == 'created') { return e.author != null ? e.author : '' } }return ''}// ---- the shapes ----------------------------------------------------------------------------------static eventRowOf = (e, t) => {let kind = e.kind// computed BEFORE the literal: inside a literal that has an `id` entry, a called function's// parameter named `id` read that entry instead (mission 011, reported as a Hybriel issue)who = e.user != null ? nameOfUser(e.user) : e.authorlet label = kind == 'created' ? 'opened the ticket' : (kind == 'state' ? 'changed the state' : (kind == 'edit' ? 'edited the ticket' : 'commented'))if (kind == 'link') { label = linkLabelOf(e) }let assignedTo = ''let assignedWas = ''if (kind == 'assign') {assignedTo = e.assignee != null && e.assignee != '' ? nameOfUser(e.assignee) : ''assignedWas = e.previous != null && e.previous != '' ? nameOfUser(e.previous) : ''label = assignedTo != '' ? 'assigned the ticket to ' + assignedTo : 'unassigned the ticket' + (assignedWas != '' ? ' (was ' + assignedWas + ')' : '')}row = {id = e.idticket = e.ticketproject = t != null ? projectSlugOf(t) : ''number = t != null ? t.number : 0seq = e.seq != null ? e.seq : 0kind = kindauthor = whouserId = e.user != null ? e.user : ''text = e.text != null ? e.text : ''hasText = e.text != null && e.text != ''from = e.from != null ? e.from : ''to = e.to != null ? e.to : ''toSlug = slugOf(e.to)isState = kind == 'state'isComment = kind == 'comment'isCreated = kind == 'created'label = labelwhen = localStamp(e.created)createdMs = e.created}// ticket #8: only an edit event carries these (the JSON of every other event is unchanged)if (kind == 'edit') {row.isEdit = truerow.oldSubject = e.oldSubject != null ? e.oldSubject : ''row.oldSummary = e.oldSummary != null ? e.oldSummary : ''row.newSubject = e.subject != null ? e.subject : ''row.newSummary = e.summary != null ? e.summary : ''row.subjectChanged = row.oldSubject != row.newSubjectrow.summaryChanged = row.oldSummary != row.newSummary}// ticket #4: only a link event carries theseif (kind == 'link') {row.isLink = truerow.linkKind = e.linkKindrow.linkAction = e.actionrow.otherRef = e.otherProject + ' #' + e.otherNumberrow.otherHref = ticketHref(e.otherProject, e.otherNumber)row.previousRef = e.previous != null ? e.previousProject + ' #' + e.previousNumber : ''}// mission 016: a comment as it is NOW (lib/comments.hl). Only a changed comment carries the extra keys: an edited one// `edited`, `editedWhen`, `earlier` ([{ when, text }], the versions before, oldest first) and the newest `text`; a// deleted one `deleted`, `deletedWhen`, no text, the label "commented (deleted …)"; a liked one `likes` (the count).// Every other comment row has exactly the keys it had before.if (kind == 'comment') {cs = commentStateOf(e)if (cs.edited) {row.text = cs.textrow.hasText = cs.text != ''row.edited = truerow.editedWhen = localStamp(cs.editedMs)row.earlier = versionsOf(cs.earlier)}if (cs.deleted) {row.text = ''row.hasText = falserow.label = 'commented (deleted ' + localStamp(cs.deletedMs) + ')'row.deleted = truerow.deletedWhen = localStamp(cs.deletedMs)}if (cs.likes > 0) { row.likes = cs.likes }// tickets#27: only a comment with files carries `attachments` ([{ id, name, type, size, image, url }]; a deleted one has none)if (!cs.deleted) {files = attachmentsOf(e.id)if (files.length > 0) { row.attachments = files }}}// ticket #20: only an assign event carries theseif (kind == 'assign') {row.isAssign = truerow.assignee = assignedTorow.previousAssignee = assignedWas}return row}static versionsOf = (list) => {out = []for (v of list) { out.push({ when = v.when text = v.text }) }return out}// "set the parent to ident.worldapi.org #1", "removed the blocker tickets.worldapi.org #6", …static linkLabelOf = (e) => {other = e.otherProject + ' #' + e.otherNumberif (e.linkKind == 'parent') {if (e.action == 'removed') { return 'removed the parent ' + other }was = e.previous != null ? ' (was ' + e.previousProject + ' #' + e.previousNumber + ')' : ''return 'set the parent to ' + other + was}if (e.action == 'removed') { return 'removed the blocker ' + other }return 'marked it blocked by ' + other}// THE PAGE'S EVENT ROW (ticket #6): the API row + its text as Markdown blocks (`md`), and for an// edit the previous summary's blocks (`oldSummaryMd`) and the new one's (`summaryMd`, the ticket// page takes it over live). Only pages and pushes carry these — the JSON API does not.static pageEventOf = (ev) => {out = {}for (k of ev.keys()) { out[k] = ev[k] }out.md = markdownBlocks(ev.text)// mission 016: who likes a comment (users @ids) — the page works out `liked` for the user lookingif (ev.isComment == true) { out.likedBy = likersOf(ev.id) }if (ev.isEdit == true) {out.oldSummaryMd = markdownBlocks(ev.oldSummary)out.summaryMd = markdownBlocks(ev.newSummary)}return out}static pageEventsOf = (evs) => {out = []for (ev of evs) { out.push(pageEventOf(ev)) }return out}
Branches
Latest commits
- d74a5482sync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
- 9d02c540sync components.hybriel 6b0936a: the 'edited' foldable drops the theme's border and marginmre
- 22751914sync components.hybriel 8d79ff7: bubble hugs its content, quiet 'edited' label; gate checksmre
- c8452453sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
- 52ba11e8sync-components: copy icons/icons.hl + README (F4); testsmre
- 138d198dmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
- 18d2df60md-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
- f6764bedreports/H1-hydrate.mdmre
- 1bbbf0edtests/browser.mjs: wait for hydration before clicking the login button on / (device B)mre
- 6f503cfctests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
- e17e2855re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- 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