gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf83d9c0df83d9c0dtickets (mission 016): report reports/016-comments-block.md, LOG, STATUS, README gate countmref83d9c0d/components/ticket.hl

25.8 KB

  1. // components/ticket.hl — `/:projectSlug/:ticketNumber` (ticket #25; was /projects/…): one ticket, its
  2. // append-only event history, a comment form and the state change. (Old URLs `/tickets/<n>`,
  3. // `/projects/<slug>/<n>`, `/projects/<slug>/tickets/<n>` are 301-redirected here by lib/api.hl.) Live: an event on THIS ticket (from any browser or
  4. // the API) is appended here and the state badge follows, without a reload.
  5. // Ticket #6 (mission 014): the summary, comments and state notes are MARKDOWN, rendered by the
  6. // child component Markdown (components/markdown.hl) from markdown.hl's blocks — safe: no HTML
  7. // string, links checked. Ticket #8: the ticket's AUTHOR (a ticket from before the login: the
  8. // creator) gets "Edit" — subject + summary; the edit is a history event that keeps the previous
  9. // values ("edited the ticket", the previous summary folded under it), pushed live like a comment.
  10. // Ticket #4 (mission 017): RELATIONS — "Part of <parent>", the children with their states and
  11. // "all children confirmed" / "n of m children confirmed", "Blocked by" and "Blocks" (each with
  12. // states); logged-in users get the forms "Parent" (set / remove) and "Blocked by" (add / remove per
  13. // row) — the store decides who may (the author of either ticket, or the creator). Live: the
  14. // `ticketsRelated` push carries the relation view of every ticket involved in a write.
  15. // Ticket #12 (mission 024): the Markdown fields are edited visually; since mission 016 with the Hybriel MdEditor (below).
  16. // Ctrl/Cmd+Enter in an editor sends its form.
  17. // Ticket #20 (roles): a member of the project may comment; `use` also moves the ticket between open and
  18. // review; `edit` / `admin` edit it, assign it (a member; "Assigned to …" is shown) and set any state; a
  19. // visitor without a role only reads. The server decides in every case; the page only shows what it may.
  20. // A ticket opened through a FORMER slug of its project shows a note with the current address.
  21. // Mission 016 (layouts#2): THE COMMENTS are drawn by the shared Comments block (components/comments/, copied verbatim from
  22. // components.hybriel.worldapi.org — tools/sync-components.sh): in the history every run of comments that follow each other is
  23. // one block, in place between the state changes etc. (`entries`, entriesOf); "write a comment" is a last block under
  24. // "Respond". The block shows Edit / Delete on the user's own comments (it asks before a delete) and a like; it tells this
  25. // page through the four functions it is handed (posted / edited / deleted / liked), the faces below write (lib/comments.hl
  26. // decides who may: the author edits and deletes, any member likes), and the push `commentChanged` swaps the row in every
  27. // open page. A deleted comment stays one line in the history ("commented (deleted …)"). Signed out / no member: user ''
  28. // (read only). The block's count line and its form are hidden inside the history (styles.hl): it has no switch for them.
  29. // The Markdown fields (edit summary, state note) are the Hybriel MdEditor (components/md-editor/, the block's editor); the
  30. // old <md-editor> of shared/md-editor.js is gone — it would have taken over the block's own <md-editor> elements.
  31. parent './main.hl'
  32. import { ticketRowAt, ticketRecord, eventRows, stateChoices, addComment, changeComment, changeState, assignTicket, editTicket, mayEditId, ticketRights, relatedViews, setParent, changeBlocker } from '../lib/tickets.hl'
  33. import { assignChoices, isMember } from '../lib/projects.hl'
  34. import { relationViewOf, noRef } from '../lib/tickets-helpers.hl'
  35. import { pageEventsOf, pageEventOf } from '../lib/events.hl'
  36. import { markdownBlocks } from '../lib/markdown.hl'
  37. import { siteName } from '../project.hl'
  38. import { canWriteSession, writerOfSession, userOfSession } from '../lib/users.hl'
  39. import Markdown from './markdown.hl'
  40. import Comments from './comments/comments.hl'
  41. import MdEditor from './md-editor/md-editor.hl'
  42. projectSlug = null
  43. ticketNumber = null
  44. row = ticketRowAt(projectSlug, ticketNumber)
  45. present = row != null
  46. gone = row == null
  47. ticketId = row != null ? row.id : ''
  48. ref = row != null ? row.ref : ''
  49. movedNote = row != null && projectSlug != row.project
  50. currentHref = row != null ? row.href : ''
  51. assignee = row != null ? row.assignee : ''
  52. hasAssignee = row != null && row.hasAssignee
  53. createdBy = row != null ? row.createdBy : ''
  54. hasOld = row != null && row.hasOld
  55. oldRef = row != null ? row.oldRef : ''
  56. subject = row != null ? row.subject : 'No such ticket'
  57. summary = row != null ? row.summary : ''
  58. hasSummary = row != null && row.summary != ''
  59. summaryMd = row != null ? markdownBlocks(row.summary) : []
  60. project = row != null ? row.project : ''
  61. projectHref = row != null ? row.projectHref : '/'
  62. state = row != null ? row.state : ''
  63. stateSlug = row != null ? row.stateSlug : ''
  64. created = row != null ? row.created : ''
  65. updated = row != null ? row.updated : ''
  66. events = row != null ? pageEventsOf(eventRows(row.id)) : []
  67. __title = siteName + ' | ' + (row != null ? row.project + ' ' + row.ref + ' ' + row.subject : 'no such ticket')
  68. // the forms: only for a logged-in user with a display name (ticket #7); the author is that
  69. // user (the faces read the session). Confirm / reject: the server refuses a non-creator.
  70. session = null
  71. me = userOfSession(session)
  72. canWrite = row != null && me != null && isMember(row.projectId, me)
  73. mustLogIn = me == null
  74. notMember = me != null && !canWrite
  75. options = row != null ? stateChoices(ticketRecord(row.id), me) : []
  76. hasOptions = options.length > 0
  77. memberOptions = row != null ? assignChoices(row.projectId) : []
  78. // the comments (mission 016): the user the blocks compare authors with ('' = read only) and the history as entries
  79. meName = me != null ? me.name : ''
  80. meId = me != null ? me.id : ''
  81. writer = canWrite ? meName : ''
  82. entries = entriesOf(events, meId)
  83. noComments = []
  84. newState = options.length > 0 ? options[0].value : ''
  85. stateNote = ''
  86. // the MdEditor is built once per element: a new key (noteSeq) gives the next note an empty editor
  87. noteSeq = 0
  88. noteForms = [{ id = 'note-0' }]
  89. message = ''
  90. // editing (ticket #8): only the author (the server decides; the face checks again)
  91. canEdit = row != null && mayEditId(row.id, me)
  92. assignDraft = row != null ? row.assigneeId : ''
  93. assignMessage = ''
  94. editing = false
  95. showEdit = canEdit
  96. showEdit2 = canEdit
  97. editSubject = ''
  98. editSummary = ''
  99. editStart = ''
  100. editMessage = ''
  101. // relations (ticket #4): the view of lib/tickets-helpers.hl relationViewOf, flat members for the View
  102. rel = row != null ? relationViewOf(row) : null
  103. hasRelations = rel != null && rel.hasRelations
  104. hasParent = rel != null && rel.hasParent
  105. parentRef = rel != null ? rel.parent : noRef
  106. hasChildren = rel != null && rel.hasChildren
  107. children = rel != null ? rel.children : []
  108. childNote = rel != null ? rel.childNote : ''
  109. childClass = rel != null ? rel.childClass : ''
  110. hasBlockedBy = rel != null && rel.hasBlockedBy
  111. blockedBy = rel != null ? rel.blockedBy : []
  112. hasBlocks = rel != null && rel.hasBlocks
  113. blocks = rel != null ? rel.blocks : []
  114. parentDraft = ''
  115. blockerDraft = ''
  116. linkMessage = ''
  117. View {
  118. ticketView {
  119. if (gone) { p { id = "gone" class = "empty" "There is no such ticket." } }
  120. if (present) {
  121. header {
  122. p { a { id = "project" href = projectHref project } " " ticketRef { id = "ref" ref }
  123. if (hasOld) { formerRef { id = "oldref" "formerly " oldRef } }
  124. }
  125. h1 { id = "subject" subject }
  126. ticketState { id = "state" class = stateSlug state }
  127. p { class = "people" "opened by " strong { id = "createdby" createdBy }
  128. if (hasAssignee) { " · assigned to " strong { id = "assignee" assignee } }
  129. }
  130. if (movedNote) { p { id = "movednote" class = "hint" "This project has a new address: " a { id = "movedlink" href = currentHref currentHref } } }
  131. p { class = "dates" "opened " time { created } " · updated " time { id = "updated" updated } }
  132. if (showEdit) { button { id = "editbutton" type = "button" class = "quiet" "Edit" on click(e) { emit startEdit(e) } } }
  133. }
  134. if (editing) {
  135. form { id = "editform"
  136. on submit(e) {
  137. e.preventDefault()
  138. emit saveEdit(e)
  139. }
  140. label { "Subject"
  141. input { id = "editsubject" name = "subject" required = "required" maxlength = "200" value = editSubject on input(e) { emit setEditSubject(e.target.value) } }
  142. }
  143. mdField { id = "editsummary" on input(e) { emit setEditSummary(e.target.name, e.target.value) }
  144. span { "Summary" }
  145. MdEditor { name = "summary" value = editStart rows = 8 }
  146. }
  147. formButtons {
  148. button { id = "editsave" type = "submit" "Save" }
  149. button { id = "editcancel" type = "button" class = "quiet" "Cancel" on click(e) { emit cancelEdit(e) } }
  150. }
  151. p { id = "editmessage" class = "message" editMessage }
  152. }
  153. }
  154. if (hasSummary) { ticketSummary { id = "summary" Markdown { blocks = summaryMd } } }
  155. if (hasRelations) { ticketRelations { id = "relations"
  156. if (hasParent) { p { id = "parent" "Part of "
  157. a { href = parentRef.href parentRef.project " " parentRef.ref }
  158. " " span { class = "refsubject" parentRef.subject }
  159. " " ticketState { class = parentRef.stateSlug parentRef.state }
  160. } }
  161. if (hasChildren) { div { id = "childrenbox"
  162. h2 { "Children" }
  163. p { id = "childnote" class = childClass childNote }
  164. ul { id = "children" class = "refs"
  165. for (c of children) { li {
  166. ticketState { class = c.stateSlug c.state }
  167. a { href = c.href c.project " " c.ref }
  168. span { class = "refsubject" c.subject }
  169. } }
  170. }
  171. } }
  172. if (hasBlockedBy) { div { id = "blockedbybox"
  173. h2 { "Blocked by" }
  174. ul { id = "blockedby" class = "refs"
  175. for (c of blockedBy) { li {
  176. ticketState { class = c.stateSlug c.state }
  177. a { href = c.href c.project " " c.ref }
  178. span { class = "refsubject" c.subject }
  179. if (showEdit2) { button { type = "button" class = "quiet unblock" value = c.key "Remove" on click(e) { emit removeBlocker(e.target.value) } } }
  180. } }
  181. }
  182. } }
  183. if (hasBlocks) { div { id = "blocksbox"
  184. h2 { "Blocks" }
  185. ul { id = "blocks" class = "refs"
  186. for (c of blocks) { li {
  187. ticketState { class = c.stateSlug c.state }
  188. a { href = c.href c.project " " c.ref }
  189. span { class = "refsubject" c.subject }
  190. } }
  191. }
  192. } }
  193. } }
  194. section {
  195. h2 { "History" }
  196. ol { id = "events"
  197. for (en of entries) {
  198. if (en.isGroup) { li { class = "comments"
  199. Comments { comments = en.comments user = writer onPost = posted onEdit = edited onDelete = deleted onLike = liked }
  200. } }
  201. if (en.isEvent) { li { class = en.cls
  202. eventHead {
  203. strong { en.ev.author }
  204. " " en.ev.label
  205. if (en.ev.isState) { " " ticketState { class = en.ev.toSlug en.ev.to } }
  206. " " time { en.ev.when }
  207. }
  208. if (en.ev.isEdit) { eventText { class = "edit"
  209. if (en.ev.subjectChanged) { p { class = "was" "Subject before: " s { en.ev.oldSubject } } }
  210. if (en.ev.summaryChanged) { details { class = "was"
  211. summary { "Summary before" }
  212. Markdown { blocks = en.ev.oldSummaryMd }
  213. } }
  214. } }
  215. if (en.ev.hasText) { eventText { Markdown { blocks = en.ev.md } } }
  216. } }
  217. }
  218. }
  219. }
  220. if (mustLogIn) {
  221. p { id = "loginhint" class = "hint" "Reading is open to everyone. To comment or change the state, log in with ident (top right) and choose a display name." }
  222. }
  223. if (notMember) {
  224. p { id = "memberhint" class = "hint" "You are not a member of this project — ask an admin to invite you to comment." }
  225. }
  226. if (canWrite) { section {
  227. h2 { "Respond" }
  228. commentForm { id = "commentform"
  229. Comments { comments = noComments user = writer onPost = posted emptyText = "" placeholder = "Write a comment (Markdown; Ctrl+Enter sends)" }
  230. }
  231. if (hasOptions) { form { id = "stateform"
  232. on submit(e) {
  233. e.preventDefault()
  234. emit sendState(e)
  235. }
  236. label { "State"
  237. select { id = "newstate" name = "state" value = newState
  238. on change(e) { emit setNewState(e.target.value) }
  239. for (o of options) { option { value = o.value o.label } }
  240. }
  241. }
  242. mdField { id = "statenote" on input(e) { emit setStateNote(e.target.name, e.target.value) }
  243. span { "Note (optional)" }
  244. for (f of noteForms) { MdEditor { name = "note" value = "" rows = 2 placeholder = "" } }
  245. }
  246. button { id = "statesend" type = "submit" "Change state" }
  247. } }
  248. p { id = "message" class = "message" message }
  249. } }
  250. if (showEdit2) { section {
  251. h2 { "Manage" }
  252. form { id = "assignform"
  253. on submit(e) {
  254. e.preventDefault()
  255. emit sendAssign(e)
  256. }
  257. label { "Assigned to"
  258. select { id = "assignselect" name = "assignee" value = assignDraft on change(e) { emit setAssignDraft(e.target.value) }
  259. option { value = "" "nobody" }
  260. for (o of memberOptions) { option { value = o.value o.label } }
  261. }
  262. }
  263. button { id = "assignsave" type = "submit" "Assign" }
  264. }
  265. p { id = "assignmessage" class = "message" assignMessage }
  266. form { id = "parentform"
  267. on submit(e) {
  268. e.preventDefault()
  269. emit sendParent(e)
  270. }
  271. label { "Parent ticket (project#number)"
  272. input { id = "parentkey" name = "parent" placeholder = "e.g. ident.worldapi.org#1" autocomplete = "off" value = parentDraft on input(e) { emit setParentDraft(e.target.value) } }
  273. }
  274. formButtons {
  275. button { id = "parentsave" type = "submit" "Set parent" }
  276. if (hasParent) { button { id = "parentremove" type = "button" class = "quiet" "Remove parent" on click(e) { emit removeParent(e) } } }
  277. }
  278. }
  279. form { id = "blockerform"
  280. on submit(e) {
  281. e.preventDefault()
  282. emit sendBlocker(e)
  283. }
  284. label { "Blocked by (project#number)"
  285. input { id = "blockerkey" name = "blocker" placeholder = "e.g. hybriel#12" autocomplete = "off" value = blockerDraft on input(e) { emit setBlockerDraft(e.target.value) } }
  286. }
  287. button { id = "blockeradd" type = "submit" "Add blocker" }
  288. }
  289. p { id = "linkmessage" class = "message" linkMessage }
  290. } }
  291. }
  292. }
  293. }
  294. on setEditSubject(v) { editSubject = v }
  295. // the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not it
  296. on setEditSummary(name, v) { if (name == 'summary') { editSummary = v } }
  297. on startEdit(e) {
  298. editSubject = subject
  299. editSummary = summary
  300. editStart = summary
  301. editMessage = ''
  302. editing = true
  303. showEdit = false
  304. }
  305. on cancelEdit(e) {
  306. editing = false
  307. showEdit = canEdit
  308. editMessage = ''
  309. }
  310. on saveEdit(e) {
  311. r = emit server ticketEdit(ticketId, editSubject, editSummary)
  312. if (r != null && r.error != null) {
  313. editMessage = r.error
  314. return null
  315. }
  316. editing = false
  317. showEdit = canEdit
  318. editMessage = ''
  319. }
  320. on setNewState(v) { newState = v }
  321. on setAssignDraft(v) { assignDraft = v }
  322. on sendAssign(e) {
  323. r = emit server ticketAssign(ticketId, assignDraft)
  324. if (r != null && r.error != null) { assignMessage = r.error } else { assignMessage = '' }
  325. }
  326. on setParentDraft(v) { parentDraft = v }
  327. on setBlockerDraft(v) { blockerDraft = v }
  328. // relations (ticket #4): the answer is only ok / error — the page follows the push
  329. on sendParent(e) {
  330. if (parentDraft.trim() == '') {
  331. linkMessage = 'name the parent as project#number'
  332. return null
  333. }
  334. r = emit server ticketSetParent(ticketId, parentDraft)
  335. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' parentDraft = '' }
  336. }
  337. on removeParent(e) {
  338. r = emit server ticketSetParent(ticketId, '')
  339. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }
  340. }
  341. on sendBlocker(e) {
  342. if (blockerDraft.trim() == '') {
  343. linkMessage = 'name the blocking ticket as project#number'
  344. return null
  345. }
  346. r = emit server ticketAddBlocker(ticketId, blockerDraft)
  347. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' blockerDraft = '' }
  348. }
  349. on removeBlocker(key) {
  350. r = emit server ticketRemoveBlocker(ticketId, key)
  351. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }
  352. }
  353. on setStateNote(name, v) { if (name == 'note') { stateNote = v } }
  354. on sendState(e) {
  355. r = emit server setTicketState(ticketId, newState, stateNote)
  356. if (r != null && r.error != null) {
  357. message = r.error
  358. return null
  359. }
  360. message = ''
  361. stateNote = ''
  362. noteSeq = noteSeq + 1
  363. noteForms = [{ id = 'note-' + noteSeq }]
  364. }
  365. // ---- the comments (mission 016): the history as entries — a run of comments is one block, every other event one line.
  366. // A comment entry is the block's record { id, author, when, text, likes, liked, history }; a deleted comment is a line.
  367. entriesOf(list, uid) {
  368. out = []
  369. let run = []
  370. for (ev of list) {
  371. if (ev.kind == 'comment' && ev.deleted != true) {
  372. run.push({ id = '' + ev.id author = ev.author when = ev.when text = ev.text likes = ev.likes != null ? ev.likes : 0 liked = uid != '' && ev.likedBy != null && ev.likedBy.includes(uid) history = ev.earlier != null ? ev.earlier : [] })
  373. } else {
  374. if (run.length > 0) {
  375. out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} })
  376. run = []
  377. }
  378. out.push({ id = '' + ev.id isGroup = false isEvent = true comments = [] cls = ev.deleted == true ? 'comment deleted' : ev.kind ev = ev })
  379. }
  380. }
  381. if (run.length > 0) { out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} }) }
  382. return out
  383. }
  384. // what the blocks tell this page: the faces write; every open page (this one too) follows the push. A refusal shows in
  385. // #message; a refused post answers false, so the block keeps the typed text.
  386. posted = (text) => {
  387. r = emit server commentOn(ticketId, text)
  388. if (r != null && r.error != null) {
  389. message = r.error
  390. return false
  391. }
  392. message = ''
  393. return true
  394. }
  395. edited = (id, text) => {
  396. r = emit server ticketCommentEdit(ticketId, id, text)
  397. message = r != null && r.error != null ? r.error : ''
  398. }
  399. deleted = (id) => {
  400. r = emit server ticketCommentDelete(ticketId, id)
  401. message = r != null && r.error != null ? r.error : ''
  402. }
  403. liked = (id) => {
  404. r = emit server ticketCommentLike(ticketId, id)
  405. message = r != null && r.error != null ? r.error : ''
  406. }
  407. // ---- what the server pushes: an event on some ticket -----------------------------------
  408. on client ticketEvent(evTicket, ev, changed, count) {
  409. if ('' + evTicket == '' + ticketId) {
  410. next = []
  411. for (x of events) { next.push(x) }
  412. next.push(ev)
  413. events = next
  414. entries = entriesOf(next, meId)
  415. state = changed.state
  416. stateSlug = changed.stateSlug
  417. updated = changed.updated
  418. assignee = changed.assignee
  419. hasAssignee = changed.hasAssignee
  420. assignDraft = changed.assigneeId
  421. rights = emit server ticketRights(ticketId)
  422. takeRights(rights)
  423. if (ev.isEdit == true) {
  424. subject = changed.subject
  425. summary = changed.summary
  426. hasSummary = changed.summary != ''
  427. summaryMd = ev.summaryMd
  428. }
  429. }
  430. }
  431. // mission 016: a comment of THIS ticket was edited, deleted or (un)liked — its row is swapped
  432. on client commentChanged(evTicket, ev) {
  433. if ('' + evTicket == '' + ticketId) {
  434. next = []
  435. for (x of events) {
  436. if ('' + x.id == '' + ev.id) { next.push(ev) } else { next.push(x) }
  437. }
  438. events = next
  439. entries = entriesOf(next, meId)
  440. }
  441. }
  442. // relations changed (a write on this ticket or on a related one): take over this ticket's view
  443. on client ticketsRelated(views) {
  444. for (v of views) {
  445. if ('' + v.id == '' + ticketId) {
  446. hasRelations = v.hasRelations
  447. hasParent = v.hasParent
  448. parentRef = v.parent
  449. hasChildren = v.hasChildren
  450. children = v.children
  451. childNote = v.childNote
  452. childClass = v.childClass
  453. hasBlockedBy = v.hasBlockedBy
  454. blockedBy = v.blockedBy
  455. hasBlocks = v.hasBlocks
  456. blocks = v.blocks
  457. }
  458. }
  459. }
  460. // login / logout in the shell (this session's tabs): the forms come and go without a reload
  461. // what this session's user may do on this ticket now (the face answers from their role)
  462. takeRights = (r) => {
  463. if (r == null || r.error != null) { return null }
  464. canWrite = r.comment == true
  465. meName = r.name
  466. meId = r.userId
  467. writer = r.comment == true ? r.name : ''
  468. entries = entriesOf(events, r.userId)
  469. mustLogIn = false
  470. notMember = !canWrite
  471. canEdit = r.edit == true
  472. showEdit = canEdit && !editing
  473. showEdit2 = canEdit
  474. options = r.options
  475. hasOptions = r.options.length > 0
  476. memberOptions = r.members
  477. newState = r.options.length > 0 ? r.options[0].value : ''
  478. }
  479. on client signedIn(tag, info) {
  480. r = emit server ticketRights(ticketId)
  481. takeRights(r)
  482. }
  483. on client signedOut(tag) {
  484. canWrite = false
  485. writer = ''
  486. meName = ''
  487. meId = ''
  488. entries = entriesOf(events, '')
  489. mustLogIn = true
  490. notMember = false
  491. canEdit = false
  492. showEdit = false
  493. showEdit2 = false
  494. hasOptions = false
  495. editing = false
  496. }
  497. // ---- the faces: the writer is the session's user (#31: a forged trailing argument is not
  498. // a real session → refused) ---------------------------------------------------------------
  499. on server commentOn(ticketId, text, session) {
  500. w = writerOfSession(session)
  501. if (w.error != null) { return { error = w.error } }
  502. r = addComment('' + ticketId, w.user, text)
  503. if (r.error != null) { return { error = r.error } }
  504. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  505. return { ok = true }
  506. }
  507. on server setTicketState(ticketId, state, note, session) {
  508. w = writerOfSession(session)
  509. if (w.error != null) { return { error = w.error } }
  510. r = changeState('' + ticketId, state, w.user, note)
  511. if (r.error != null) { return { error = r.error } }
  512. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  513. if (r.assignEvent != null) { emit client ticketEvent(r.ticket.id, pageEventOf(r.assignEvent), r.ticket) }
  514. emit client ticketsRelated(relatedViews(r.ticket.id, []))
  515. return { ok = true }
  516. }
  517. // mission 016: the comment's author edits / deletes it, a member likes it (again = takes it back) — lib/comments.hl decides
  518. on server ticketCommentEdit(ticketId, commentId, text, session) {
  519. w = writerOfSession(session)
  520. if (w.error != null) { return { error = w.error } }
  521. if (hlTypeName(text) != 'String') { return { error = 'the comment must be text' } }
  522. r = changeComment('' + ticketId, '' + commentId, w.user, 'edit', text)
  523. if (r.error != null) { return { error = r.error } }
  524. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  525. return { ok = true }
  526. }
  527. on server ticketCommentDelete(ticketId, commentId, session) {
  528. w = writerOfSession(session)
  529. if (w.error != null) { return { error = w.error } }
  530. r = changeComment('' + ticketId, '' + commentId, w.user, 'delete', '')
  531. if (r.error != null) { return { error = r.error } }
  532. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  533. return { ok = true }
  534. }
  535. on server ticketCommentLike(ticketId, commentId, session) {
  536. w = writerOfSession(session)
  537. if (w.error != null) { return { error = w.error } }
  538. r = changeComment('' + ticketId, '' + commentId, w.user, 'like', '')
  539. if (r.error != null) { return { error = r.error } }
  540. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  541. return { ok = true }
  542. }
  543. // ticket #20: assign the ticket to a member ('' = nobody); the store wants the role edit or admin
  544. on server ticketAssign(ticketId, userId, session) {
  545. w = writerOfSession(session)
  546. if (w.error != null) { return { error = w.error } }
  547. if (hlTypeName(userId) != 'String') { return { error = 'the assignee must be text' } }
  548. r = assignTicket('' + ticketId, w.user, userId)
  549. if (r.error != null) { return { error = r.error } }
  550. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  551. return { ok = true }
  552. }
  553. // ticket #8: the author edits subject + summary (the store refuses anyone else)
  554. on server ticketEdit(ticketId, subject, summary, session) {
  555. w = writerOfSession(session)
  556. if (w.error != null) { return { error = w.error } }
  557. if (hlTypeName(subject) != 'String' || hlTypeName(summary) != 'String') { return { error = 'subject and summary must be text' } }
  558. r = editTicket('' + ticketId, w.user, subject, summary)
  559. if (r.error != null) { return { error = r.error } }
  560. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  561. emit client ticketsRelated(relatedViews(r.ticket.id, []))
  562. return { ok = true }
  563. }
  564. // ticket #4: relations — the store refuses a user who may not (author of either ticket / creator)
  565. on server ticketSetParent(ticketId, key, session) {
  566. w = writerOfSession(session)
  567. if (w.error != null) { return { error = w.error } }
  568. if (hlTypeName(key) != 'String') { return { error = 'the parent must be text' } }
  569. r = setParent('' + ticketId, w.user, key)
  570. if (r.error != null) { return { error = r.error } }
  571. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  572. emit client ticketsRelated(r.related)
  573. return { ok = true }
  574. }
  575. on server ticketAddBlocker(ticketId, key, session) {
  576. w = writerOfSession(session)
  577. if (w.error != null) { return { error = w.error } }
  578. if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }
  579. r = changeBlocker('' + ticketId, w.user, key, true, 'add')
  580. if (r.error != null) { return { error = r.error } }
  581. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  582. emit client ticketsRelated(r.related)
  583. return { ok = true }
  584. }
  585. on server ticketRemoveBlocker(ticketId, key, session) {
  586. w = writerOfSession(session)
  587. if (w.error != null) { return { error = w.error } }
  588. if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }
  589. r = changeBlocker('' + ticketId, w.user, key, false, 'remove')
  590. if (r.error != null) { return { error = r.error } }
  591. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  592. emit client ticketsRelated(r.related)
  593. return { ok = true }
  594. }
  595. // what the session's user may do on this ticket: comment (a member), edit / assign (edit, admin), the states
  596. // they may move it to, and the members it can be assigned to
  597. on server ticketRights(ticketId, session) {
  598. u = userOfSession(session)
  599. if (u == null) { return { error = 'log in first' } }
  600. t = ticketRecord('' + ticketId)
  601. if (t == null) { return { error = 'no such ticket' } }
  602. r = ticketRights(t, u)
  603. // mission 016: who the comment blocks compare authors with, and whose likes count as "liked"
  604. r.name = u.name
  605. r.userId = u.id
  606. return r
  607. }

Branches

Latest commits

  • 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
  • b7ec5981mission brief 015mre
  • 5dc68731docker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • 8a460b16mission 014: Apollo's 'stream opened right after the start gets no live events' is not a tickets bug — events.mjs checks early streamsmre
  • 6309ca81mission brief 014mre
  • c1161469mission 013: GitHub pipe tables on ticket pages (lib/markdown.hl + View + CSS) and re-vendor hybriel master a832f73bmre
  • a30b5d12mission brief (w13)mre
  • b50a6f93w9 (tickets): re-vendor hybriel 9f912f3b (#146 emit in a lib static, #147) — the 12 live-push emits in lib/api.hl compile as they are; cold start (#148): tests wait TICKETS_COLD_MS for every start, deploy.sh gates browser + events and waits up to 120 s for the URL, container /tmp tmpfs + hybriel-cache volume; events-client stops at EVENTS_MAX inside a chunk; connect.mjs ports by env. bin/hybriel sha256 7421907868ac07d8a7d08296b083c6f8b20407d0e099ce4bebbf7ae053d9060a. Gates (8720–8739): browser 315/0 (+ all-cold 315/0), events 48/0 cold, connect 60/0, short-id 19/0; real-data copy old 0e8a41c vs new: 2,425 reads + 72 writes identical after masking ?v hashes, offline at, route order; event stream on the copy delivers. Not deployed.mre
  • 43be6578w9: re-vendor hybriel master edfd400a; event stream imports sseStart/sseSend/sseAlive from hl:http1 (hybriel#144), useTransport gone; tools/import.hl plain declarations. BLOCKED: hybriel-native refuses `emit client` in a static (lib/api.hl) — the server does not compile on edfd400a, gates fail at start; scratch copy without those emits: events 48/0, gate 254 ok up to the first live pushmre
  • 0e8a41caw6 (ticket #26): event stream for programs — GET /api/events (Server-Sent Events)mre
  • bb64d57cmission 012 (ticket #25 API part): every /api/projects/<x>/… route takes the project's id (12-char record id) as well as its slug, same answers byte for byte; tickets stay under their project, no global /api/tickets/<x>. gate 315/0 (old code: the 13 id checks fail), connect 60/0, live-data copy old vs new 1,484 identical, slug vs id 772 identicalmre
  • 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