gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit090ee809090ee809tickets: 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)mre090ee809/components/ticket.hl

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

Branches

Latest commits

  • 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
  • 8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre
  • 337e9b21tickets#37: a comment's files are open to everyone who can read the commentmre
  • 1800600ftickets: write the standby service out in full so the boot gate can read the main servicemre
  • 8179d287tickets: standby service on its port plus 10 and a deploy that hands over through it without a gapmre
  • 0398145ctickets: the table grid rule is marked functional for check-thememre
  • 40fddc20tickets takes components e54f83a: tables get thin grey lines from the theme, desktop toolbar stays one row with the Table button, F4 check counts 11 buttonsmre
  • c1b77d61tickets#35: text typed before the editor is built is taken in once by the build (the input handler no longer writes it to the field first, which doubled the first letters); the gate failure shows the surfacemre
  • 32bf1873tickets#35: the gate types right after the load with the CPU slowed, no waitingmre
  • 64ea9ca2tickets#35: text typed into the reply editor before the page has finished starting is kept; the gate types right after loadmre
  • ccd3a327tickets: the security gate expects frame-src to be exactly the ident address (the sign-in frame), still no wildcard or selfmre
  • 4348dbabident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 66ef3005Merge branch 'iw-ident-widget'mre