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
- 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
- a7a1380dmission brief 017mre
- f83d9c0dtickets (mission 016): report reports/016-comments-block.md, LOG, STATUS, README gate countmre
- 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