gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit01fad59301fad593inbox: format Style with nested language rulesmre01fad593/components/ticket.hl

33.3 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. // tickets#27 (mission 017): ATTACHMENTS. The "Respond" block has attach = "true": its form sits in the shared FilesUpload (pick
  32. // mode; components/files-upload/, copied verbatim) — files chosen, photographed, dropped or pasted (Ctrl+V, also into the editor)
  33. // wait under it and go with the post (face commentWithFiles; lib/attachments.hl checks and stores them). Each comment shows its
  34. // files: pictures as thumbnails that open the full picture, other files as rows. Only members may fetch them, so for anybody else
  35. // the block gets the files without `url` (names and sizes, no link).
  36. parent './main.hl'
  37. import { ticketRowAt, ticketRecord, eventRows, stateChoices, addComment, changeComment, changeState, assignTicket, editTicket, mayEditId, ticketRights, relatedViews, setParent, changeBlocker } from '../lib/tickets.hl'
  38. import { assignChoices, isMember } from '../lib/projects.hl'
  39. import { relationViewOf, noRef } from '../lib/tickets-helpers.hl'
  40. import { pageEventsOf, pageEventOf } from '../lib/events.hl'
  41. import { markdownBlocks } from '../lib/markdown.hl'
  42. import { siteName } from '../project.hl'
  43. import { canWriteSession, writerOfSession, userOfSession } from '../lib/users.hl'
  44. import Markdown from './markdown.hl'
  45. import Comments from './comments/comments.hl'
  46. import MdEditor from './md-editor/md-editor.hl'
  47. import { hintLook, messageLook } from '../lib/looks.hl'
  48. projectSlug = null
  49. ticketNumber = null
  50. row = ticketRowAt(projectSlug, ticketNumber)
  51. present = row != null
  52. gone = row == null
  53. ticketId = row != null ? row.id : ''
  54. ref = row != null ? row.ref : ''
  55. movedNote = row != null && projectSlug != row.project
  56. currentHref = row != null ? row.href : ''
  57. assignee = row != null ? row.assignee : ''
  58. hasAssignee = row != null && row.hasAssignee
  59. createdBy = row != null ? row.createdBy : ''
  60. hasOld = row != null && row.hasOld
  61. oldRef = row != null ? row.oldRef : ''
  62. subject = row != null ? row.subject : 'No such ticket'
  63. summary = row != null ? row.summary : ''
  64. hasSummary = row != null && row.summary != ''
  65. summaryMd = row != null ? markdownBlocks(row.summary) : []
  66. project = row != null ? row.project : ''
  67. projectHref = row != null ? row.projectHref : '/'
  68. state = row != null ? row.state : ''
  69. stateSlug = row != null ? row.stateSlug : ''
  70. created = row != null ? row.created : ''
  71. updated = row != null ? row.updated : ''
  72. events = row != null ? pageEventsOf(eventRows(row.id)) : []
  73. __title = siteName + ' | ' + (row != null ? row.project + ' ' + row.ref + ' ' + row.subject : 'no such ticket')
  74. // the forms: only for a logged-in user with a display name (ticket #7); the author is that
  75. // user (the faces read the session). Confirm / reject: the server refuses a non-creator.
  76. session = null
  77. me = userOfSession(session)
  78. canWrite = row != null && me != null && isMember(row.projectId, me)
  79. mustLogIn = me == null
  80. notMember = me != null && !canWrite
  81. options = row != null ? stateChoices(ticketRecord(row.id), me) : []
  82. memberOptions = row != null ? assignChoices(row.projectId) : []
  83. // the comments (mission 016): the user the blocks compare authors with ('' = read only) and the history as entries
  84. meName = me != null ? me.name : ''
  85. meId = me != null ? me.id : ''
  86. writer = canWrite ? meName : ''
  87. entries = entriesOf(events, meId)
  88. noComments = []
  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. Style {
  118. pHint = hintLook + { }
  119. pMessage = messageLook + { }
  120. ticketView { display = 'grid' gridTemplateColumns = 'minmax(0, 1fr)' gap = '1.2rem'
  121. header { display = 'grid' gap = '.4rem'
  122. p { margin = '0' }
  123. ticketState { justifySelf = 'start' }
  124. button { justifySelf = 'start' }
  125. }
  126. section { display = 'grid' gap = '.7rem' }
  127. form { display = 'grid' gap = '.5rem' }
  128. }
  129. pDates { color = 'var(--color-text-muted)' fontSize = '.875rem' }
  130. pPeople { margin = '0' color = 'var(--color-text-muted)' fontSize = '.9rem'
  131. strong { color = 'var(--color-text)' }
  132. }
  133. formerRef { marginLeft = '.2rem' fontSize = '.875rem' color = 'var(--color-text-muted)' }
  134. ticketSummary { display = 'block' padding = '.8rem' overflowWrap = 'anywhere' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)' }
  135. // the history: one list of events, comment blocks and links
  136. '#events' { listStyle = 'none' margin = '0' padding = '0' display = 'grid' gap = '.5rem'
  137. '> li' { marginLeft = '.8rem' padding = '.5rem .7rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-small)' }
  138. '> li.state' { background = 'transparent' padding = '.2rem .7rem' }
  139. '> li.link' { background = 'transparent' padding = '.2rem .7rem' }
  140. // mission 016: the comments (components/comments/, the shared block with its own Style). In the history every run of comments is
  141. // one block in place: its count line, its "no comments" line and its form are not shown there (the block has no switch for them);
  142. // the form is the last block, under "Respond", which shows only the form. A deleted comment is one quiet line. `contain:
  143. // inline-size`: the history is a grid of auto columns, which would grow to a wide table's min-content width inside a comment
  144. '> li.comments' { padding = '.3rem 0' background = 'transparent' contain = 'inline-size' }
  145. '> li.comment.deleted' { background = 'transparent' padding = '.2rem .7rem' fontStyle = 'italic' color = 'var(--color-text-muted)' }
  146. }
  147. // the tags of the comments block are the vendored component's, not in this View: flat
  148. '#events comments-block h2.comments-count' { display = 'none' }
  149. '#events comments-block .comments-empty' { display = 'none' }
  150. '#events comments-block form.comment-form' { display = 'none' }
  151. '#events comments-block ol.comment-list' { margin = '0' }
  152. '#commentform h2.comments-count' { display = 'none' }
  153. '#commentform .comments-empty' { display = 'none' }
  154. '#commentform ol.comment-list' { display = 'none' }
  155. commentForm { display = 'block' }
  156. eventHead { display = 'block' fontSize = '.9rem'
  157. strong { color = 'var(--color-text-strong)' }
  158. }
  159. eventText { display = 'block' marginTop = '.3rem' overflowWrap = 'anywhere' }
  160. // ticket #8: an edit in the history keeps what was before
  161. 'event-text.edit' { fontSize = '.9rem' color = 'var(--color-text-muted)'
  162. p { margin = '0' }
  163. s { color = 'var(--color-text)' }
  164. details { marginTop = '.3rem' background = 'var(--color-background-sunken)' }
  165. summary { padding = '.3rem .6rem' fontWeight = '400' fontSize = '.875rem' }
  166. }
  167. 'event-text.edit markdown-text' { padding = '0 .6rem .5rem' color = 'var(--color-text)' }
  168. '#editform' { padding = '.8rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)' }
  169. formButtons { display = 'grid' gridTemplateColumns = 'repeat(auto-fit, minmax(9rem, 1fr))' gap = '.5rem' }
  170. // a Markdown field: the caption above the editor, as a label looks. Not inside a <label>: a label hands its clicks to its first
  171. // button, the editor's toolbar "B"
  172. mdField { display = 'grid' gap = '.25rem'
  173. '> span' { fontSize = '.9rem' color = 'var(--color-text-muted)' }
  174. }
  175. // ticket #4: relations (parent, children, blocked by, blocks)
  176. ticketRelations { display = 'grid' gap = '.8rem' padding = '.8rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)'
  177. h2 { margin = '0 0 .4rem' fontSize = '1rem' }
  178. p { margin = '0' }
  179. }
  180. '#parent' { a { display = 'inline-flex' alignItems = 'center' minHeight = 'var(--layout-tap)' fontWeight = '600' whiteSpace = 'nowrap' } }
  181. spanRefsubject { color = 'var(--color-text-strong)' overflowWrap = 'anywhere' }
  182. '#childnote' { margin = '0 0 .4rem' fontSize = '.9rem' color = 'var(--color-text-muted)' }
  183. '#childnote.done' { fontWeight = '600' color = 'var(--color-success)' }
  184. ulRefs { listStyle = 'none' margin = '0' padding = '0' display = 'grid' gap = '.35rem'
  185. a { display = 'inline-flex' alignItems = 'center' minHeight = 'var(--layout-tap)' fontWeight = '600' whiteSpace = 'nowrap' }
  186. li { display = 'flex' flexWrap = 'wrap' alignItems = 'baseline' gap = '.2rem .6rem' }
  187. }
  188. buttonUnblock { padding = '.1rem .6rem' fontSize = '.875rem' marginLeft = 'auto' }
  189. '@media (min-width: 60rem)' {
  190. '#parentform' { gridTemplateColumns = 'minmax(0, 1fr) auto' alignItems = 'end' }
  191. '#blockerform' { gridTemplateColumns = 'minmax(0, 1fr) auto' alignItems = 'end' }
  192. formButtons { display = 'flex' flexWrap = 'wrap' }
  193. }
  194. }
  195. View {
  196. ticketView {
  197. if (gone) { p { id = "gone" class = "empty" "There is no such ticket." } }
  198. if (present) {
  199. header {
  200. p { a { id = "project" href = projectHref project } " " ticketRef { id = "ref" ref }
  201. if (hasOld) { formerRef { id = "oldref" "formerly " oldRef } }
  202. }
  203. h1 { id = "subject" subject }
  204. ticketState { id = "state" class = stateSlug state }
  205. p { Style.pPeople "opened by " strong { id = "createdby" createdBy }
  206. if (hasAssignee) { " · assigned to " strong { id = "assignee" assignee } }
  207. }
  208. if (movedNote) { p { id = "movednote" Style.pHint "This project has a new address: " a { id = "movedlink" href = currentHref currentHref } } }
  209. p { Style.pDates "opened " time { created } " · updated " time { id = "updated" updated } }
  210. if (showEdit) { button { id = "editbutton" type = "button" class = "quiet" "Edit" on click(e) { emit startEdit(e) } } }
  211. }
  212. if (editing) {
  213. form { id = "editform"
  214. on submit(e) {
  215. e.preventDefault()
  216. emit saveEdit(e)
  217. }
  218. label { "Subject"
  219. input { id = "editsubject" name = "subject" required = "required" maxlength = "200" value = editSubject on input(e) { emit setEditSubject(e.target.value) } }
  220. }
  221. mdField { id = "editsummary" on input(e) { emit setEditSummary(e.target.name, e.target.value) }
  222. span { "Summary" }
  223. MdEditor { name = "summary" value = editStart rows = 8 files = "off" }
  224. }
  225. formButtons {
  226. button { id = "editsave" type = "submit" "Save" }
  227. button { id = "editcancel" type = "button" class = "quiet" "Cancel" on click(e) { emit cancelEdit(e) } }
  228. }
  229. p { id = "editmessage" Style.pMessage editMessage }
  230. }
  231. }
  232. if (hasSummary) { ticketSummary { id = "summary" Markdown { blocks = summaryMd } } }
  233. if (hasRelations) { ticketRelations { id = "relations"
  234. if (hasParent) { p { id = "parent" "Part of "
  235. a { href = parentRef.href parentRef.project " " parentRef.ref }
  236. " " span { Style.spanRefsubject parentRef.subject }
  237. " " ticketState { class = parentRef.stateSlug parentRef.state }
  238. } }
  239. if (hasChildren) { div { id = "childrenbox"
  240. h2 { "Children" }
  241. p { id = "childnote" class = childClass childNote }
  242. ul { id = "children" Style.ulRefs
  243. for (c of children) { li {
  244. ticketState { class = c.stateSlug c.state }
  245. a { href = c.href c.project " " c.ref }
  246. span { Style.spanRefsubject c.subject }
  247. } }
  248. }
  249. } }
  250. if (hasBlockedBy) { div { id = "blockedbybox"
  251. h2 { "Blocked by" }
  252. ul { id = "blockedby" Style.ulRefs
  253. for (c of blockedBy) { li {
  254. ticketState { class = c.stateSlug c.state }
  255. a { href = c.href c.project " " c.ref }
  256. span { Style.spanRefsubject c.subject }
  257. if (showEdit2) { button { type = "button" class = "quiet" Style.buttonUnblock value = c.key "Remove" on click(e) { emit removeBlocker(e.target.value) } } }
  258. } }
  259. }
  260. } }
  261. if (hasBlocks) { div { id = "blocksbox"
  262. h2 { "Blocks" }
  263. ul { id = "blocks" Style.ulRefs
  264. for (c of blocks) { li {
  265. ticketState { class = c.stateSlug c.state }
  266. a { href = c.href c.project " " c.ref }
  267. span { Style.spanRefsubject c.subject }
  268. } }
  269. }
  270. } }
  271. } }
  272. section {
  273. h2 { "History" }
  274. ol { id = "events"
  275. for (en of entries) {
  276. if (en.isGroup) { li { class = "comments"
  277. Comments { comments = en.comments user = writer onPost = posted onEdit = edited onDelete = deleted onLike = liked }
  278. } }
  279. if (en.isEvent) { li { class = en.cls
  280. eventHead {
  281. strong { en.ev.author }
  282. " " en.ev.label
  283. if (en.ev.isState) { " " ticketState { class = en.ev.toSlug en.ev.to } }
  284. " " time { en.ev.when }
  285. }
  286. if (en.ev.isEdit) { eventText { class = "edit"
  287. if (en.ev.subjectChanged) { p { class = "was" "Subject before: " s { en.ev.oldSubject } } }
  288. if (en.ev.summaryChanged) { details { class = "was"
  289. summary { "Summary before" }
  290. Markdown { blocks = en.ev.oldSummaryMd }
  291. } }
  292. } }
  293. if (en.ev.hasText) { eventText { Markdown { blocks = en.ev.md } } }
  294. } }
  295. }
  296. }
  297. }
  298. if (mustLogIn) {
  299. p { id = "loginhint" Style.pHint "Reading is open to everyone. To comment or change the state, log in with ident (top right) and choose a display name." }
  300. }
  301. if (notMember) {
  302. p { id = "memberhint" Style.pHint "You are not a member of this project — ask an admin to invite you to comment." }
  303. }
  304. if (canWrite) { section {
  305. h2 { "Respond" }
  306. commentForm { id = "commentform"
  307. Comments { comments = noComments user = writer onPost = respond states = options emptyText = "" placeholder = "Write a comment (Markdown; Ctrl+Enter sends)" attach = "true" maxFileSize = 10485760 attachText = "Choose pictures or files — or drop or paste them anywhere in the box" }
  308. }
  309. p { id = "message" Style.pMessage message }
  310. } }
  311. if (showEdit2) { section {
  312. h2 { "Manage" }
  313. form { id = "assignform"
  314. on submit(e) {
  315. e.preventDefault()
  316. emit sendAssign(e)
  317. }
  318. label { "Assigned to"
  319. select { id = "assignselect" name = "assignee" value = assignDraft on change(e) { emit setAssignDraft(e.target.value) }
  320. option { value = "" "nobody" }
  321. for (o of memberOptions) { option { value = o.value o.label } }
  322. }
  323. }
  324. button { id = "assignsave" type = "submit" "Assign" }
  325. }
  326. p { id = "assignmessage" Style.pMessage assignMessage }
  327. form { id = "parentform"
  328. on submit(e) {
  329. e.preventDefault()
  330. emit sendParent(e)
  331. }
  332. label { "Parent ticket (project#number)"
  333. input { id = "parentkey" name = "parent" placeholder = "e.g. ident.worldapi.org#1" autocomplete = "off" value = parentDraft on input(e) { emit setParentDraft(e.target.value) } }
  334. }
  335. formButtons {
  336. button { id = "parentsave" type = "submit" "Set parent" }
  337. if (hasParent) { button { id = "parentremove" type = "button" class = "quiet" "Remove parent" on click(e) { emit removeParent(e) } } }
  338. }
  339. }
  340. form { id = "blockerform"
  341. on submit(e) {
  342. e.preventDefault()
  343. emit sendBlocker(e)
  344. }
  345. label { "Blocked by (project#number)"
  346. input { id = "blockerkey" name = "blocker" placeholder = "e.g. hybriel#12" autocomplete = "off" value = blockerDraft on input(e) { emit setBlockerDraft(e.target.value) } }
  347. }
  348. button { id = "blockeradd" type = "submit" "Add blocker" }
  349. }
  350. p { id = "linkmessage" Style.pMessage linkMessage }
  351. } }
  352. }
  353. }
  354. }
  355. on setEditSubject(v) { editSubject = v }
  356. // the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not it
  357. on setEditSummary(name, v) { if (name == 'summary') { editSummary = v } }
  358. on startEdit(e) {
  359. editSubject = subject
  360. editSummary = summary
  361. editStart = summary
  362. editMessage = ''
  363. editing = true
  364. showEdit = false
  365. }
  366. on cancelEdit(e) {
  367. editing = false
  368. showEdit = canEdit
  369. editMessage = ''
  370. }
  371. on saveEdit(e) {
  372. r = emit server ticketEdit(ticketId, editSubject, editSummary)
  373. if (r != null && r.error != null) {
  374. editMessage = r.error
  375. return null
  376. }
  377. editing = false
  378. showEdit = canEdit
  379. editMessage = ''
  380. }
  381. on setAssignDraft(v) { assignDraft = v }
  382. on sendAssign(e) {
  383. r = emit server ticketAssign(ticketId, assignDraft)
  384. if (r != null && r.error != null) { assignMessage = r.error } else { assignMessage = '' }
  385. }
  386. on setParentDraft(v) { parentDraft = v }
  387. on setBlockerDraft(v) { blockerDraft = v }
  388. // relations (ticket #4): the answer is only ok / error — the page follows the push
  389. on sendParent(e) {
  390. if (parentDraft.trim() == '') {
  391. linkMessage = 'name the parent as project#number'
  392. return null
  393. }
  394. r = emit server ticketSetParent(ticketId, parentDraft)
  395. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' parentDraft = '' }
  396. }
  397. on removeParent(e) {
  398. r = emit server ticketSetParent(ticketId, '')
  399. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }
  400. }
  401. on sendBlocker(e) {
  402. if (blockerDraft.trim() == '') {
  403. linkMessage = 'name the blocking ticket as project#number'
  404. return null
  405. }
  406. r = emit server ticketAddBlocker(ticketId, blockerDraft)
  407. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' blockerDraft = '' }
  408. }
  409. on removeBlocker(key) {
  410. r = emit server ticketRemoveBlocker(ticketId, key)
  411. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }
  412. }
  413. // ---- the comments (mission 016): the history as entries — a run of comments is one block, every other event one line.
  414. // A comment entry is the block's record { id, author, when, text, likes, liked, history, files }; a deleted comment is a line.
  415. // every viewer who sees a comment gets its files' url (tickets#37): reading is public, so the thumbnail and the file are too.
  416. entriesOf(list, uid) {
  417. out = []
  418. let run = []
  419. for (ev of list) {
  420. if (ev.kind == 'comment' && ev.deleted != true) {
  421. run.push(commentOf(ev, uid))
  422. } else {
  423. let shown = ev
  424. // tickets#33: a state change that carries a note is a comment card (put into the feed like any comment) followed by the state line alone
  425. if (ev.kind == 'state' && ev.hasText == true) {
  426. run.push(commentOf(ev, uid))
  427. shown = { id = ev.id kind = ev.kind author = ev.author label = ev.label isState = true isEdit = false to = ev.to toSlug = ev.toSlug when = ev.when hasText = false deleted = false }
  428. }
  429. if (run.length > 0) {
  430. out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} })
  431. run = []
  432. }
  433. out.push({ id = '' + ev.id isGroup = false isEvent = true comments = [] cls = ev.deleted == true ? 'comment deleted' : ev.kind ev = shown })
  434. }
  435. }
  436. if (run.length > 0) { out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} }) }
  437. return out
  438. }
  439. // the block's record of a comment (or of the note of a state change)
  440. commentOf(ev, uid) {
  441. return { 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 : [] files = filesOf(ev.attachments) }
  442. }
  443. // a comment's attachments as the block shows them: { name, url, image, size }
  444. filesOf(list) {
  445. out = []
  446. if (list == null) { return out }
  447. for (a of list) { out.push({ name = a.name url = a.url image = a.image size = a.size }) }
  448. return out
  449. }
  450. // what the blocks tell this page: the faces write; every open page (this one too) follows the push. A refusal shows in
  451. // #message; a refused post answers false, so the block keeps the typed text (and the files). With files (tickets#27) the post is
  452. // the face commentWithFiles: the framework uploads them first; a file it refuses (over uploadMax) ends the emit with null.
  453. posted = (text, files) => {
  454. let r = null
  455. if (files != null && files.length > 0) {
  456. r = emit server commentWithFiles(ticketId, text, files)
  457. if (r == null) {
  458. message = 'the comment was not sent: a file could not be uploaded (at most 10 MB each)'
  459. return false
  460. }
  461. } else {
  462. r = emit server commentOn(ticketId, text)
  463. }
  464. if (r != null && r.error != null) {
  465. message = r.error
  466. return false
  467. }
  468. message = ''
  469. return true
  470. }
  471. // THE ONE COMPOSER of "Respond": a comment (with its files), a state change, or both — one request each, the comment first. The block
  472. // tells what is there: the text, the files and the state chosen ('' = no change). A comment that is refused keeps everything in the form
  473. // (false); a comment that went through and a state change that is refused clears the form and shows the refusal; a state change
  474. // alone that is refused keeps the form.
  475. respond = (text, files, state) => {
  476. words = text.trim() != '' || (files != null && files.length > 0)
  477. if (words) {
  478. ok = posted(text, files)
  479. if (ok == false) { return false }
  480. }
  481. if (state != '') {
  482. r = emit server setTicketState(ticketId, state, '')
  483. if (r != null && r.error != null) {
  484. message = r.error
  485. return words
  486. }
  487. message = ''
  488. }
  489. return true
  490. }
  491. edited = (id, text) => {
  492. r = emit server ticketCommentEdit(ticketId, id, text)
  493. message = r != null && r.error != null ? r.error : ''
  494. }
  495. deleted = (id) => {
  496. r = emit server ticketCommentDelete(ticketId, id)
  497. message = r != null && r.error != null ? r.error : ''
  498. }
  499. liked = (id) => {
  500. r = emit server ticketCommentLike(ticketId, id)
  501. message = r != null && r.error != null ? r.error : ''
  502. }
  503. // ---- what the server pushes: an event on some ticket -----------------------------------
  504. on client ticketEvent(evTicket, ev, changed, count) {
  505. if ('' + evTicket == '' + ticketId) {
  506. next = []
  507. for (x of events) { next.push(x) }
  508. next.push(ev)
  509. events = next
  510. entries = entriesOf(next, meId)
  511. state = changed.state
  512. stateSlug = changed.stateSlug
  513. updated = changed.updated
  514. assignee = changed.assignee
  515. hasAssignee = changed.hasAssignee
  516. assignDraft = changed.assigneeId
  517. rights = emit server ticketRights(ticketId)
  518. takeRights(rights)
  519. if (ev.isEdit == true) {
  520. subject = changed.subject
  521. summary = changed.summary
  522. hasSummary = changed.summary != ''
  523. summaryMd = ev.summaryMd
  524. }
  525. }
  526. }
  527. // mission 016: a comment of THIS ticket was edited, deleted or (un)liked — its row is swapped
  528. on client commentChanged(evTicket, ev) {
  529. if ('' + evTicket == '' + ticketId) {
  530. next = []
  531. for (x of events) {
  532. if ('' + x.id == '' + ev.id) { next.push(ev) } else { next.push(x) }
  533. }
  534. events = next
  535. entries = entriesOf(next, meId)
  536. }
  537. }
  538. // relations changed (a write on this ticket or on a related one): take over this ticket's view
  539. on client ticketsRelated(views) {
  540. for (v of views) {
  541. if ('' + v.id == '' + ticketId) {
  542. hasRelations = v.hasRelations
  543. hasParent = v.hasParent
  544. parentRef = v.parent
  545. hasChildren = v.hasChildren
  546. children = v.children
  547. childNote = v.childNote
  548. childClass = v.childClass
  549. hasBlockedBy = v.hasBlockedBy
  550. blockedBy = v.blockedBy
  551. hasBlocks = v.hasBlocks
  552. blocks = v.blocks
  553. }
  554. }
  555. }
  556. // login / logout in the shell (this session's tabs): the forms come and go without a reload
  557. // what this session's user may do on this ticket now (the face answers from their role)
  558. takeRights = (r) => {
  559. if (r == null || r.error != null) { return null }
  560. canWrite = r.comment == true
  561. meName = r.name
  562. meId = r.userId
  563. writer = r.comment == true ? r.name : ''
  564. entries = entriesOf(events, r.userId)
  565. mustLogIn = false
  566. notMember = !canWrite
  567. canEdit = r.edit == true
  568. showEdit = canEdit && !editing
  569. showEdit2 = canEdit
  570. // the Respond block is rebuilt (and loses a draft) when a value bound into it changes: the choices only when they really changed
  571. if (!sameChoices(options, r.options)) { options = r.options }
  572. memberOptions = r.members
  573. }
  574. on client signedIn(tag, info) {
  575. r = emit server ticketRights(ticketId)
  576. takeRights(r)
  577. }
  578. on client signedOut(tag) {
  579. canWrite = false
  580. writer = ''
  581. meName = ''
  582. meId = ''
  583. entries = entriesOf(events, '')
  584. mustLogIn = true
  585. notMember = false
  586. canEdit = false
  587. showEdit = false
  588. showEdit2 = false
  589. editing = false
  590. }
  591. sameChoices(a, b) {
  592. if (a.length != b.length) { return false }
  593. let i = 0
  594. while (i < a.length) {
  595. if (a[i].value != b[i].value) { return false }
  596. i = i + 1
  597. }
  598. return true
  599. }
  600. // ---- the faces: the writer is the session's user (#31: a forged trailing argument is not
  601. // a real session → refused) ---------------------------------------------------------------
  602. on server commentOn(ticketId, text, session) {
  603. w = writerOfSession(session)
  604. if (w.error != null) { return { error = w.error } }
  605. r = addComment('' + ticketId, w.user, text, null)
  606. if (r.error != null) { return { error = r.error } }
  607. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  608. return { ok = true }
  609. }
  610. // tickets#27: a comment with files — `files` arrive as [{ bytes, name, type, size }] (the framework took them from /__hl/upload);
  611. // lib/attachments.hl checks the limits and the content, a refusal comes back as the message
  612. on server commentWithFiles(ticketId, text, files, session) {
  613. w = writerOfSession(session)
  614. if (w.error != null) { return { error = w.error } }
  615. if (hlTypeName(text) != 'String') { return { error = 'the comment must be text' } }
  616. r = addComment('' + ticketId, w.user, text, files)
  617. if (r.error != null) { return { error = r.error } }
  618. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  619. return { ok = true }
  620. }
  621. on server setTicketState(ticketId, state, note, session) {
  622. w = writerOfSession(session)
  623. if (w.error != null) { return { error = w.error } }
  624. r = changeState('' + ticketId, state, w.user, note)
  625. if (r.error != null) { return { error = r.error } }
  626. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  627. if (r.assignEvent != null) { emit client ticketEvent(r.ticket.id, pageEventOf(r.assignEvent), r.ticket) }
  628. emit client ticketsRelated(relatedViews(r.ticket.id, []))
  629. return { ok = true }
  630. }
  631. // mission 016: the comment's author edits / deletes it, a member likes it (again = takes it back) — lib/comments.hl decides
  632. on server ticketCommentEdit(ticketId, commentId, text, session) {
  633. w = writerOfSession(session)
  634. if (w.error != null) { return { error = w.error } }
  635. if (hlTypeName(text) != 'String') { return { error = 'the comment must be text' } }
  636. r = changeComment('' + ticketId, '' + commentId, w.user, 'edit', text)
  637. if (r.error != null) { return { error = r.error } }
  638. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  639. return { ok = true }
  640. }
  641. on server ticketCommentDelete(ticketId, commentId, session) {
  642. w = writerOfSession(session)
  643. if (w.error != null) { return { error = w.error } }
  644. r = changeComment('' + ticketId, '' + commentId, w.user, 'delete', '')
  645. if (r.error != null) { return { error = r.error } }
  646. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  647. return { ok = true }
  648. }
  649. on server ticketCommentLike(ticketId, commentId, session) {
  650. w = writerOfSession(session)
  651. if (w.error != null) { return { error = w.error } }
  652. r = changeComment('' + ticketId, '' + commentId, w.user, 'like', '')
  653. if (r.error != null) { return { error = r.error } }
  654. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  655. return { ok = true }
  656. }
  657. // ticket #20: assign the ticket to a member ('' = nobody); the store wants the role edit or admin
  658. on server ticketAssign(ticketId, userId, session) {
  659. w = writerOfSession(session)
  660. if (w.error != null) { return { error = w.error } }
  661. if (hlTypeName(userId) != 'String') { return { error = 'the assignee must be text' } }
  662. r = assignTicket('' + ticketId, w.user, userId)
  663. if (r.error != null) { return { error = r.error } }
  664. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  665. return { ok = true }
  666. }
  667. // ticket #8: the author edits subject + summary (the store refuses anyone else)
  668. on server ticketEdit(ticketId, subject, summary, session) {
  669. w = writerOfSession(session)
  670. if (w.error != null) { return { error = w.error } }
  671. if (hlTypeName(subject) != 'String' || hlTypeName(summary) != 'String') { return { error = 'subject and summary must be text' } }
  672. r = editTicket('' + ticketId, w.user, subject, summary)
  673. if (r.error != null) { return { error = r.error } }
  674. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  675. emit client ticketsRelated(relatedViews(r.ticket.id, []))
  676. return { ok = true }
  677. }
  678. // ticket #4: relations — the store refuses a user who may not (edit / admin in this ticket's project)
  679. on server ticketSetParent(ticketId, key, session) {
  680. w = writerOfSession(session)
  681. if (w.error != null) { return { error = w.error } }
  682. if (hlTypeName(key) != 'String') { return { error = 'the parent must be text' } }
  683. r = setParent('' + ticketId, w.user, key)
  684. if (r.error != null) { return { error = r.error } }
  685. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  686. emit client ticketsRelated(r.related)
  687. return { ok = true }
  688. }
  689. on server ticketAddBlocker(ticketId, key, session) {
  690. w = writerOfSession(session)
  691. if (w.error != null) { return { error = w.error } }
  692. if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }
  693. r = changeBlocker('' + ticketId, w.user, key, true, 'add')
  694. if (r.error != null) { return { error = r.error } }
  695. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  696. emit client ticketsRelated(r.related)
  697. return { ok = true }
  698. }
  699. on server ticketRemoveBlocker(ticketId, key, session) {
  700. w = writerOfSession(session)
  701. if (w.error != null) { return { error = w.error } }
  702. if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }
  703. r = changeBlocker('' + ticketId, w.user, key, false, 'remove')
  704. if (r.error != null) { return { error = r.error } }
  705. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  706. emit client ticketsRelated(r.related)
  707. return { ok = true }
  708. }
  709. // what the session's user may do on this ticket: comment (a member), edit / assign (edit, admin), the states
  710. // they may move it to, and the members it can be assigned to
  711. on server ticketRights(ticketId, session) {
  712. u = userOfSession(session)
  713. if (u == null) { return { error = 'log in first' } }
  714. t = ticketRecord('' + ticketId)
  715. if (t == null) { return { error = 'no such ticket' } }
  716. r = ticketRights(t, u)
  717. // mission 016: who the comment blocks compare authors with, and whose likes count as "liked"
  718. r.name = u.name
  719. r.userId = u.id
  720. return r
  721. }

Branches

Latest commits

  • 01fad593inbox: format Style with nested language rulesmre
  • 79dc9392you: format Style with nested language rulesmre
  • 78073baamain: format Style with nested language rulesmre
  • 5499c290Sync theme unchanged from layouts 17e0f03mre
  • fd33ee21Sync reviewed components from 8176eb1mre
  • 93348453Re-vendor tickets to Hybriel set day35mre
  • a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
  • cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
  • 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
  • b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre
  • f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
  • 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre
  • 090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre
  • d395763ftickets: ident-access gate ports 8769/8768 (8797 is taken on loreana)mre
  • afb9a403tickets: an ident access key (Authorization: Bearer idt_…) works in the API (ident#27 app side): lib/ident-access.hl copied from components, read keys GET only, ident down 503; gate tests/ident-access-tickets.mjsmre
  • 48c1ba79tickets: md-paste-files gate with the file manager casesmre
  • 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