gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3698438636984386Preserve state transitions when their notes are editedmre36984386/components/ticket.hl

34.0 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 {
  121. display = 'grid'
  122. gridTemplateColumns = 'minmax(0, 1fr)'
  123. gap = '1.2rem'
  124. header {
  125. display = 'grid'
  126. gap = '.4rem'
  127. p {
  128. margin = '0'
  129. }
  130. ticketState {
  131. justifySelf = 'start'
  132. }
  133. button {
  134. justifySelf = 'start'
  135. }
  136. }
  137. section {
  138. display = 'grid'
  139. gap = '.7rem'
  140. }
  141. form {
  142. display = 'grid'
  143. gap = '.5rem'
  144. }
  145. }
  146. '#dates' {
  147. color = 'var(--color-text-muted)'
  148. fontSize = '.875rem'
  149. }
  150. '#people' {
  151. margin = '0'
  152. color = 'var(--color-text-muted)'
  153. fontSize = '.9rem'
  154. strong {
  155. color = 'var(--color-text)'
  156. }
  157. }
  158. formerRef {
  159. marginLeft = '.2rem'
  160. fontSize = '.875rem'
  161. color = 'var(--color-text-muted)'
  162. }
  163. ticketSummary {
  164. display = 'block'
  165. padding = '.8rem'
  166. overflowWrap = 'anywhere'
  167. background = 'var(--color-surface)'
  168. borderRadius = 'var(--radius-large)'
  169. }
  170. '#events' {
  171. listStyle = 'none'
  172. margin = '0'
  173. padding = '0'
  174. display = 'grid'
  175. gap = '.5rem'
  176. // Keep the combinator as a quoted nested key.
  177. '> li' {
  178. marginLeft = '.8rem'
  179. padding = '.5rem .7rem'
  180. background = 'var(--color-surface)'
  181. borderRadius = 'var(--radius-small)'
  182. }
  183. // Keep the combinator as a quoted nested key.
  184. '> li.state' {
  185. background = 'transparent'
  186. padding = '.2rem .7rem'
  187. }
  188. // Keep the combinator as a quoted nested key.
  189. '> li.link' {
  190. background = 'transparent'
  191. padding = '.2rem .7rem'
  192. }
  193. // Keep the combinator as a quoted nested key.
  194. '> li.comments' {
  195. padding = '.3rem 0'
  196. background = 'transparent'
  197. contain = 'inline-size'
  198. }
  199. // Keep the combinator as a quoted nested key.
  200. '> li.comment.deleted' {
  201. background = 'transparent'
  202. padding = '.2rem .7rem'
  203. fontStyle = 'italic'
  204. color = 'var(--color-text-muted)'
  205. }
  206. }
  207. // Keep the selector into a composed component; this View does not own its elements.
  208. '#events comments-block h2.comments-count' {
  209. display = 'none'
  210. }
  211. // Keep the selector into a composed component; this View does not own its elements.
  212. '#events comments-block .comments-empty' {
  213. display = 'none'
  214. }
  215. // Keep the selector into a composed component; this View does not own its elements.
  216. '#events comments-block form.comment-form' {
  217. display = 'none'
  218. }
  219. // Keep the selector into a composed component; this View does not own its elements.
  220. '#events comments-block ol.comment-list' {
  221. margin = '0'
  222. }
  223. // Keep the selector into a composed component; this View does not own its elements.
  224. '#commentform h2.comments-count' {
  225. display = 'none'
  226. }
  227. // Keep the selector into a composed component; this View does not own its elements.
  228. '#commentform .comments-empty' {
  229. display = 'none'
  230. }
  231. // Keep the selector into a composed component; this View does not own its elements.
  232. '#commentform ol.comment-list' {
  233. display = 'none'
  234. }
  235. commentForm {
  236. display = 'block'
  237. }
  238. eventHead {
  239. display = 'block'
  240. fontSize = '.9rem'
  241. strong {
  242. color = 'var(--color-text-strong)'
  243. }
  244. }
  245. eventText {
  246. display = 'block'
  247. marginTop = '.3rem'
  248. overflowWrap = 'anywhere'
  249. }
  250. // Keep the compound class selector; there is no same-element bare form.
  251. 'event-text.edit' {
  252. fontSize = '.9rem'
  253. color = 'var(--color-text-muted)'
  254. p {
  255. margin = '0'
  256. }
  257. s {
  258. color = 'var(--color-text)'
  259. }
  260. details {
  261. marginTop = '.3rem'
  262. background = 'var(--color-background-sunken)'
  263. }
  264. summary {
  265. padding = '.3rem .6rem'
  266. fontWeight = '400'
  267. fontSize = '.875rem'
  268. }
  269. }
  270. // Keep the selector into a composed component; this View does not own its elements.
  271. 'event-text.edit markdown-text' {
  272. padding = '0 .6rem .5rem'
  273. color = 'var(--color-text)'
  274. }
  275. '#editform' {
  276. padding = '.8rem'
  277. background = 'var(--color-surface)'
  278. borderRadius = 'var(--radius-large)'
  279. }
  280. formButtons {
  281. display = 'grid'
  282. gridTemplateColumns = 'repeat(auto-fit, minmax(9rem, 1fr))'
  283. gap = '.5rem'
  284. @media {
  285. minWidth = '60rem'
  286. display = 'flex'
  287. flexWrap = 'wrap'
  288. }
  289. }
  290. mdField {
  291. display = 'grid'
  292. gap = '.25rem'
  293. // Keep the combinator as a quoted nested key.
  294. '> span' {
  295. fontSize = '.9rem'
  296. color = 'var(--color-text-muted)'
  297. }
  298. }
  299. ticketRelations {
  300. display = 'grid'
  301. gap = '.8rem'
  302. padding = '.8rem'
  303. background = 'var(--color-surface)'
  304. borderRadius = 'var(--radius-large)'
  305. h2 {
  306. margin = '0 0 .4rem'
  307. fontSize = '1rem'
  308. }
  309. p {
  310. margin = '0'
  311. }
  312. }
  313. '#parent' {
  314. a {
  315. display = 'inline-flex'
  316. alignItems = 'center'
  317. minHeight = 'var(--layout-tap)'
  318. fontWeight = '600'
  319. whiteSpace = 'nowrap'
  320. }
  321. }
  322. spanRefsubject {
  323. color = 'var(--color-text-strong)'
  324. overflowWrap = 'anywhere'
  325. }
  326. '#childnote' {
  327. margin = '0 0 .4rem'
  328. fontSize = '.9rem'
  329. color = 'var(--color-text-muted)'
  330. }
  331. // Keep the compound class selector; there is no same-element bare form.
  332. '#childnote.done' {
  333. fontWeight = '600'
  334. color = 'var(--color-success)'
  335. }
  336. ulRefs {
  337. listStyle = 'none'
  338. margin = '0'
  339. padding = '0'
  340. display = 'grid'
  341. gap = '.35rem'
  342. a {
  343. display = 'inline-flex'
  344. alignItems = 'center'
  345. minHeight = 'var(--layout-tap)'
  346. fontWeight = '600'
  347. whiteSpace = 'nowrap'
  348. }
  349. li {
  350. display = 'flex'
  351. flexWrap = 'wrap'
  352. alignItems = 'baseline'
  353. gap = '.2rem .6rem'
  354. }
  355. }
  356. buttonUnblock {
  357. padding = '.1rem .6rem'
  358. fontSize = '.875rem'
  359. marginLeft = 'auto'
  360. }
  361. '#parentform' {
  362. @media {
  363. minWidth = '60rem'
  364. gridTemplateColumns = 'minmax(0, 1fr) auto'
  365. alignItems = 'end'
  366. }
  367. }
  368. '#blockerform' {
  369. @media {
  370. minWidth = '60rem'
  371. gridTemplateColumns = 'minmax(0, 1fr) auto'
  372. alignItems = 'end'
  373. }
  374. }
  375. }
  376. View {
  377. ticketView {
  378. if (gone) { p { id = "gone" class = "empty" "There is no such ticket." } }
  379. if (present) {
  380. header {
  381. p { a { id = "project" href = projectHref project } " " ticketRef { id = "ref" ref }
  382. if (hasOld) { formerRef { id = "oldref" "formerly " oldRef } }
  383. }
  384. h1 { id = "subject" subject }
  385. ticketState { id = "state" class = stateSlug state }
  386. p { id = "people" "opened by " strong { id = "createdby" createdBy }
  387. if (hasAssignee) { " · assigned to " strong { id = "assignee" assignee } }
  388. }
  389. if (movedNote) { p { id = "movednote" Style.pHint "This project has a new address: " a { id = "movedlink" href = currentHref currentHref } } }
  390. p { id = "dates" "opened " time { created } " · updated " time { id = "updated" updated } }
  391. if (showEdit) { button { id = "editbutton" type = "button" class = "quiet" "Edit" on click(e) { emit startEdit(e) } } }
  392. }
  393. if (editing) {
  394. form { id = "editform"
  395. on submit(e) {
  396. e.preventDefault()
  397. emit saveEdit(e)
  398. }
  399. label { "Subject"
  400. input { id = "editsubject" name = "subject" required = "required" maxlength = "200" value = editSubject on input(e) { emit setEditSubject(e.target.value) } }
  401. }
  402. mdField { id = "editsummary" on input(e) { emit setEditSummary(e.target.name, e.target.value) }
  403. span { "Summary" }
  404. MdEditor { name = "summary" value = editStart rows = 8 files = "off" }
  405. }
  406. formButtons {
  407. button { id = "editsave" type = "submit" "Save" }
  408. button { id = "editcancel" type = "button" class = "quiet" "Cancel" on click(e) { emit cancelEdit(e) } }
  409. }
  410. p { id = "editmessage" Style.pMessage editMessage }
  411. }
  412. }
  413. if (hasSummary) { ticketSummary { id = "summary" Markdown { blocks = summaryMd } } }
  414. if (hasRelations) { ticketRelations { id = "relations"
  415. if (hasParent) { p { id = "parent" "Part of "
  416. a { href = parentRef.href parentRef.project " " parentRef.ref }
  417. " " span { Style.spanRefsubject parentRef.subject }
  418. " " ticketState { class = parentRef.stateSlug parentRef.state }
  419. } }
  420. if (hasChildren) { div { id = "childrenbox"
  421. h2 { "Children" }
  422. p { id = "childnote" class = childClass childNote }
  423. ul { id = "children" Style.ulRefs
  424. for (c of children) { li {
  425. ticketState { class = c.stateSlug c.state }
  426. a { href = c.href c.project " " c.ref }
  427. span { Style.spanRefsubject c.subject }
  428. } }
  429. }
  430. } }
  431. if (hasBlockedBy) { div { id = "blockedbybox"
  432. h2 { "Blocked by" }
  433. ul { id = "blockedby" Style.ulRefs
  434. for (c of blockedBy) { li {
  435. ticketState { class = c.stateSlug c.state }
  436. a { href = c.href c.project " " c.ref }
  437. span { Style.spanRefsubject c.subject }
  438. if (showEdit2) { button { type = "button" class = "quiet" Style.buttonUnblock value = c.key "Remove" on click(e) { emit removeBlocker(e.target.value) } } }
  439. } }
  440. }
  441. } }
  442. if (hasBlocks) { div { id = "blocksbox"
  443. h2 { "Blocks" }
  444. ul { id = "blocks" Style.ulRefs
  445. for (c of blocks) { li {
  446. ticketState { class = c.stateSlug c.state }
  447. a { href = c.href c.project " " c.ref }
  448. span { Style.spanRefsubject c.subject }
  449. } }
  450. }
  451. } }
  452. } }
  453. section {
  454. h2 { "History" }
  455. ol { id = "events"
  456. for (en of entries) {
  457. if (en.isGroup) { li { class = "comments"
  458. Comments { comments = en.comments user = writer onPost = posted onEdit = edited onDelete = deleted onLike = liked }
  459. } }
  460. if (en.isEvent) { li { class = en.cls
  461. eventHead {
  462. strong { en.ev.author }
  463. " " en.ev.label
  464. if (en.ev.isState) {
  465. ": " en.ev.from " → " ticketState { class = en.ev.toSlug en.ev.to }
  466. if (en.ev.edited) { " (edited " en.ev.editedWhen ")" }
  467. }
  468. " " time { en.ev.when }
  469. }
  470. if (en.ev.isEdit) { eventText { class = "edit"
  471. if (en.ev.subjectChanged) { p { class = "was" "Subject before: " s { en.ev.oldSubject } } }
  472. if (en.ev.summaryChanged) { details { class = "was"
  473. summary { "Summary before" }
  474. Markdown { blocks = en.ev.oldSummaryMd }
  475. } }
  476. } }
  477. if (en.ev.hasText) { eventText { Markdown { blocks = en.ev.md } } }
  478. } }
  479. }
  480. }
  481. }
  482. if (mustLogIn) {
  483. 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." }
  484. }
  485. if (notMember) {
  486. p { id = "memberhint" Style.pHint "You are not a member of this project — ask an admin to invite you to comment." }
  487. }
  488. if (canWrite) { section {
  489. h2 { "Respond" }
  490. commentForm { id = "commentform"
  491. 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" }
  492. }
  493. p { id = "message" Style.pMessage message }
  494. } }
  495. if (showEdit2) { section {
  496. h2 { "Manage" }
  497. form { id = "assignform"
  498. on submit(e) {
  499. e.preventDefault()
  500. emit sendAssign(e)
  501. }
  502. label { "Assigned to"
  503. select { id = "assignselect" name = "assignee" value = assignDraft on change(e) { emit setAssignDraft(e.target.value) }
  504. option { value = "" "nobody" }
  505. for (o of memberOptions) { option { value = o.value o.label } }
  506. }
  507. }
  508. button { id = "assignsave" type = "submit" "Assign" }
  509. }
  510. p { id = "assignmessage" Style.pMessage assignMessage }
  511. form { id = "parentform"
  512. on submit(e) {
  513. e.preventDefault()
  514. emit sendParent(e)
  515. }
  516. label { "Parent ticket (project#number)"
  517. input { id = "parentkey" name = "parent" placeholder = "e.g. ident.worldapi.org#1" autocomplete = "off" value = parentDraft on input(e) { emit setParentDraft(e.target.value) } }
  518. }
  519. formButtons {
  520. button { id = "parentsave" type = "submit" "Set parent" }
  521. if (hasParent) { button { id = "parentremove" type = "button" class = "quiet" "Remove parent" on click(e) { emit removeParent(e) } } }
  522. }
  523. }
  524. form { id = "blockerform"
  525. on submit(e) {
  526. e.preventDefault()
  527. emit sendBlocker(e)
  528. }
  529. label { "Blocked by (project#number)"
  530. input { id = "blockerkey" name = "blocker" placeholder = "e.g. hybriel#12" autocomplete = "off" value = blockerDraft on input(e) { emit setBlockerDraft(e.target.value) } }
  531. }
  532. button { id = "blockeradd" type = "submit" "Add blocker" }
  533. }
  534. p { id = "linkmessage" Style.pMessage linkMessage }
  535. } }
  536. }
  537. }
  538. }
  539. on setEditSubject(v) { editSubject = v }
  540. // the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not it
  541. on setEditSummary(name, v) { if (name == 'summary') { editSummary = v } }
  542. on startEdit(e) {
  543. editSubject = subject
  544. editSummary = summary
  545. editStart = summary
  546. editMessage = ''
  547. editing = true
  548. showEdit = false
  549. }
  550. on cancelEdit(e) {
  551. editing = false
  552. showEdit = canEdit
  553. editMessage = ''
  554. }
  555. on saveEdit(e) {
  556. r = emit server ticketEdit(ticketId, editSubject, editSummary)
  557. if (r != null && r.error != null) {
  558. editMessage = r.error
  559. return null
  560. }
  561. editing = false
  562. showEdit = canEdit
  563. editMessage = ''
  564. }
  565. on setAssignDraft(v) { assignDraft = v }
  566. on sendAssign(e) {
  567. r = emit server ticketAssign(ticketId, assignDraft)
  568. if (r != null && r.error != null) { assignMessage = r.error } else { assignMessage = '' }
  569. }
  570. on setParentDraft(v) { parentDraft = v }
  571. on setBlockerDraft(v) { blockerDraft = v }
  572. // relations (ticket #4): the answer is only ok / error — the page follows the push
  573. on sendParent(e) {
  574. if (parentDraft.trim() == '') {
  575. linkMessage = 'name the parent as project#number'
  576. return null
  577. }
  578. r = emit server ticketSetParent(ticketId, parentDraft)
  579. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' parentDraft = '' }
  580. }
  581. on removeParent(e) {
  582. r = emit server ticketSetParent(ticketId, '')
  583. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }
  584. }
  585. on sendBlocker(e) {
  586. if (blockerDraft.trim() == '') {
  587. linkMessage = 'name the blocking ticket as project#number'
  588. return null
  589. }
  590. r = emit server ticketAddBlocker(ticketId, blockerDraft)
  591. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' blockerDraft = '' }
  592. }
  593. on removeBlocker(key) {
  594. r = emit server ticketRemoveBlocker(ticketId, key)
  595. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }
  596. }
  597. // ---- the comments (mission 016): the history as entries — a run of comments is one block, every other event one line.
  598. // A comment entry is the block's record { id, author, when, text, likes, liked, history, files }; a deleted comment is a line.
  599. // every viewer who sees a comment gets its files' url (tickets#37): reading is public, so the thumbnail and the file are too.
  600. entriesOf(list, uid) {
  601. out = []
  602. let run = []
  603. for (ev of list) {
  604. if (ev.kind == 'comment' && ev.deleted != true) {
  605. run.push(commentOf(ev, uid))
  606. } else {
  607. let shown = ev
  608. // 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
  609. if (ev.kind == 'state' && ev.hasText == true) {
  610. run.push(commentOf(ev, uid))
  611. shown = { id = ev.id kind = ev.kind author = ev.author label = ev.label isState = true isEdit = false from = ev.from edited = ev.edited editedWhen = ev.editedWhen to = ev.to toSlug = ev.toSlug when = ev.when hasText = false deleted = false }
  612. }
  613. if (run.length > 0) {
  614. out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} })
  615. run = []
  616. }
  617. out.push({ id = '' + ev.id isGroup = false isEvent = true comments = [] cls = ev.deleted == true ? 'comment deleted' : ev.kind ev = shown })
  618. }
  619. }
  620. if (run.length > 0) { out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} }) }
  621. return out
  622. }
  623. // the block's record of a comment (or of the note of a state change)
  624. commentOf(ev, uid) {
  625. 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) }
  626. }
  627. // a comment's attachments as the block shows them: { name, url, image, size }
  628. filesOf(list) {
  629. out = []
  630. if (list == null) { return out }
  631. for (a of list) { out.push({ name = a.name url = a.url image = a.image size = a.size }) }
  632. return out
  633. }
  634. // what the blocks tell this page: the faces write; every open page (this one too) follows the push. A refusal shows in
  635. // #message; a refused post answers false, so the block keeps the typed text (and the files). With files (tickets#27) the post is
  636. // the face commentWithFiles: the framework uploads them first; a file it refuses (over uploadMax) ends the emit with null.
  637. posted = (text, files) => {
  638. let r = null
  639. if (files != null && files.length > 0) {
  640. r = emit server commentWithFiles(ticketId, text, files)
  641. if (r == null) {
  642. message = 'the comment was not sent: a file could not be uploaded (at most 10 MB each)'
  643. return false
  644. }
  645. } else {
  646. r = emit server commentOn(ticketId, text)
  647. }
  648. if (r != null && r.error != null) {
  649. message = r.error
  650. return false
  651. }
  652. message = ''
  653. return true
  654. }
  655. // THE ONE COMPOSER of "Respond": a comment (with its files), a state change, or both — one request each, the comment first. The block
  656. // tells what is there: the text, the files and the state chosen ('' = no change). A comment that is refused keeps everything in the form
  657. // (false); a comment that went through and a state change that is refused clears the form and shows the refusal; a state change
  658. // alone that is refused keeps the form.
  659. respond = (text, files, state) => {
  660. words = text.trim() != '' || (files != null && files.length > 0)
  661. if (words) {
  662. ok = posted(text, files)
  663. if (ok == false) { return false }
  664. }
  665. if (state != '') {
  666. r = emit server setTicketState(ticketId, state, '')
  667. if (r != null && r.error != null) {
  668. message = r.error
  669. return words
  670. }
  671. message = ''
  672. }
  673. return true
  674. }
  675. edited = (id, text) => {
  676. r = emit server ticketCommentEdit(ticketId, id, text)
  677. message = r != null && r.error != null ? r.error : ''
  678. }
  679. deleted = (id) => {
  680. r = emit server ticketCommentDelete(ticketId, id)
  681. message = r != null && r.error != null ? r.error : ''
  682. }
  683. liked = (id) => {
  684. r = emit server ticketCommentLike(ticketId, id)
  685. message = r != null && r.error != null ? r.error : ''
  686. }
  687. // ---- what the server pushes: an event on some ticket -----------------------------------
  688. on client ticketEvent(evTicket, ev, changed, count) {
  689. if ('' + evTicket == '' + ticketId) {
  690. next = []
  691. for (x of events) { next.push(x) }
  692. next.push(ev)
  693. events = next
  694. entries = entriesOf(next, meId)
  695. state = changed.state
  696. stateSlug = changed.stateSlug
  697. updated = changed.updated
  698. assignee = changed.assignee
  699. hasAssignee = changed.hasAssignee
  700. assignDraft = changed.assigneeId
  701. rights = emit server ticketRights(ticketId)
  702. takeRights(rights)
  703. if (ev.isEdit == true) {
  704. subject = changed.subject
  705. summary = changed.summary
  706. hasSummary = changed.summary != ''
  707. summaryMd = ev.summaryMd
  708. }
  709. }
  710. }
  711. // mission 016: a comment of THIS ticket was edited, deleted or (un)liked — its row is swapped
  712. on client commentChanged(evTicket, ev) {
  713. if ('' + evTicket == '' + ticketId) {
  714. next = []
  715. for (x of events) {
  716. if ('' + x.id == '' + ev.id) { next.push(ev) } else { next.push(x) }
  717. }
  718. events = next
  719. entries = entriesOf(next, meId)
  720. }
  721. }
  722. // relations changed (a write on this ticket or on a related one): take over this ticket's view
  723. on client ticketsRelated(views) {
  724. for (v of views) {
  725. if ('' + v.id == '' + ticketId) {
  726. hasRelations = v.hasRelations
  727. hasParent = v.hasParent
  728. parentRef = v.parent
  729. hasChildren = v.hasChildren
  730. children = v.children
  731. childNote = v.childNote
  732. childClass = v.childClass
  733. hasBlockedBy = v.hasBlockedBy
  734. blockedBy = v.blockedBy
  735. hasBlocks = v.hasBlocks
  736. blocks = v.blocks
  737. }
  738. }
  739. }
  740. // login / logout in the shell (this session's tabs): the forms come and go without a reload
  741. // what this session's user may do on this ticket now (the face answers from their role)
  742. takeRights = (r) => {
  743. if (r == null || r.error != null) { return null }
  744. canWrite = r.comment == true
  745. meName = r.name
  746. meId = r.userId
  747. writer = r.comment == true ? r.name : ''
  748. entries = entriesOf(events, r.userId)
  749. mustLogIn = false
  750. notMember = !canWrite
  751. canEdit = r.edit == true
  752. showEdit = canEdit && !editing
  753. showEdit2 = canEdit
  754. // the Respond block is rebuilt (and loses a draft) when a value bound into it changes: the choices only when they really changed
  755. if (!sameChoices(options, r.options)) { options = r.options }
  756. memberOptions = r.members
  757. }
  758. on client signedIn(tag, info) {
  759. r = emit server ticketRights(ticketId)
  760. takeRights(r)
  761. }
  762. on client signedOut(tag) {
  763. canWrite = false
  764. writer = ''
  765. meName = ''
  766. meId = ''
  767. entries = entriesOf(events, '')
  768. mustLogIn = true
  769. notMember = false
  770. canEdit = false
  771. showEdit = false
  772. showEdit2 = false
  773. editing = false
  774. }
  775. sameChoices(a, b) {
  776. if (a.length != b.length) { return false }
  777. let i = 0
  778. while (i < a.length) {
  779. if (a[i].value != b[i].value) { return false }
  780. i = i + 1
  781. }
  782. return true
  783. }
  784. // ---- the faces: the writer is the session's user (#31: a forged trailing argument is not
  785. // a real session → refused) ---------------------------------------------------------------
  786. on server commentOn(ticketId, text, session) {
  787. w = writerOfSession(session)
  788. if (w.error != null) { return { error = w.error } }
  789. r = addComment('' + ticketId, w.user, text, null)
  790. if (r.error != null) { return { error = r.error } }
  791. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  792. return { ok = true }
  793. }
  794. // tickets#27: a comment with files — `files` arrive as [{ bytes, name, type, size }] (the framework took them from /__hl/upload);
  795. // lib/attachments.hl checks the limits and the content, a refusal comes back as the message
  796. on server commentWithFiles(ticketId, text, files, session) {
  797. w = writerOfSession(session)
  798. if (w.error != null) { return { error = w.error } }
  799. if (hlTypeName(text) != 'String') { return { error = 'the comment must be text' } }
  800. r = addComment('' + ticketId, w.user, text, files)
  801. if (r.error != null) { return { error = r.error } }
  802. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  803. return { ok = true }
  804. }
  805. on server setTicketState(ticketId, state, note, session) {
  806. w = writerOfSession(session)
  807. if (w.error != null) { return { error = w.error } }
  808. r = changeState('' + ticketId, state, w.user, note)
  809. if (r.error != null) { return { error = r.error } }
  810. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  811. if (r.assignEvent != null) { emit client ticketEvent(r.ticket.id, pageEventOf(r.assignEvent), r.ticket) }
  812. emit client ticketsRelated(relatedViews(r.ticket.id, []))
  813. return { ok = true }
  814. }
  815. // mission 016: the comment's author edits / deletes it, a member likes it (again = takes it back) — lib/comments.hl decides
  816. on server ticketCommentEdit(ticketId, commentId, text, session) {
  817. w = writerOfSession(session)
  818. if (w.error != null) { return { error = w.error } }
  819. if (hlTypeName(text) != 'String') { return { error = 'the comment must be text' } }
  820. r = changeComment('' + ticketId, '' + commentId, w.user, 'edit', text)
  821. if (r.error != null) { return { error = r.error } }
  822. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  823. return { ok = true }
  824. }
  825. on server ticketCommentDelete(ticketId, commentId, session) {
  826. w = writerOfSession(session)
  827. if (w.error != null) { return { error = w.error } }
  828. r = changeComment('' + ticketId, '' + commentId, w.user, 'delete', '')
  829. if (r.error != null) { return { error = r.error } }
  830. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  831. return { ok = true }
  832. }
  833. on server ticketCommentLike(ticketId, commentId, session) {
  834. w = writerOfSession(session)
  835. if (w.error != null) { return { error = w.error } }
  836. r = changeComment('' + ticketId, '' + commentId, w.user, 'like', '')
  837. if (r.error != null) { return { error = r.error } }
  838. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  839. return { ok = true }
  840. }
  841. // ticket #20: assign the ticket to a member ('' = nobody); the store wants the role edit or admin
  842. on server ticketAssign(ticketId, userId, session) {
  843. w = writerOfSession(session)
  844. if (w.error != null) { return { error = w.error } }
  845. if (hlTypeName(userId) != 'String') { return { error = 'the assignee must be text' } }
  846. r = assignTicket('' + ticketId, w.user, userId)
  847. if (r.error != null) { return { error = r.error } }
  848. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  849. return { ok = true }
  850. }
  851. // ticket #8: the author edits subject + summary (the store refuses anyone else)
  852. on server ticketEdit(ticketId, subject, summary, session) {
  853. w = writerOfSession(session)
  854. if (w.error != null) { return { error = w.error } }
  855. if (hlTypeName(subject) != 'String' || hlTypeName(summary) != 'String') { return { error = 'subject and summary must be text' } }
  856. r = editTicket('' + ticketId, w.user, subject, summary)
  857. if (r.error != null) { return { error = r.error } }
  858. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  859. emit client ticketsRelated(relatedViews(r.ticket.id, []))
  860. return { ok = true }
  861. }
  862. // ticket #4: relations — the store refuses a user who may not (edit / admin in this ticket's project)
  863. on server ticketSetParent(ticketId, key, session) {
  864. w = writerOfSession(session)
  865. if (w.error != null) { return { error = w.error } }
  866. if (hlTypeName(key) != 'String') { return { error = 'the parent must be text' } }
  867. r = setParent('' + ticketId, w.user, key)
  868. if (r.error != null) { return { error = r.error } }
  869. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  870. emit client ticketsRelated(r.related)
  871. return { ok = true }
  872. }
  873. on server ticketAddBlocker(ticketId, key, session) {
  874. w = writerOfSession(session)
  875. if (w.error != null) { return { error = w.error } }
  876. if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }
  877. r = changeBlocker('' + ticketId, w.user, key, true, 'add')
  878. if (r.error != null) { return { error = r.error } }
  879. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  880. emit client ticketsRelated(r.related)
  881. return { ok = true }
  882. }
  883. on server ticketRemoveBlocker(ticketId, key, session) {
  884. w = writerOfSession(session)
  885. if (w.error != null) { return { error = w.error } }
  886. if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }
  887. r = changeBlocker('' + ticketId, w.user, key, false, 'remove')
  888. if (r.error != null) { return { error = r.error } }
  889. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  890. emit client ticketsRelated(r.related)
  891. return { ok = true }
  892. }
  893. // what the session's user may do on this ticket: comment (a member), edit / assign (edit, admin), the states
  894. // they may move it to, and the members it can be assigned to
  895. on server ticketRights(ticketId, session) {
  896. u = userOfSession(session)
  897. if (u == null) { return { error = 'log in first' } }
  898. t = ticketRecord('' + ticketId)
  899. if (t == null) { return { error = 'no such ticket' } }
  900. r = ticketRights(t, u)
  901. // mission 016: who the comment blocks compare authors with, and whose likes count as "liked"
  902. r.name = u.name
  903. r.userId = u.id
  904. return r
  905. }

Branches

Latest commits

  • 36984386Preserve state transitions when their notes are editedmre
  • d75cb946Log E30 startmre
  • 0bf3fefaMission 030: edited state note labelmre
  • 691565c6Log neutral-ticket rule checkmre
  • bc3bdecerecords: day38b live, #94 purgedmre
  • f6c5aa0dMerge main (records)mre
  • e23d42acconnect gate: wait for hydration before clicking Disconnectmre
  • a5d45d00records: D38 cause, GOmre
  • 19eeb938records: D38 gates, two day38b failuresmre
  • f8e42a85Re-vendor tickets to Hybriel set day38b (1e554d7)mre
  • 51645016Merge purge-94 (#94, identity rule)mre
  • 94d6ca2arecords: D38 startedmre
  • 9df09aacmission 029: day38b re-vendor + deploymre
  • d2834f65records: #94 backup planmre
  • 4467d8cbrecords: #94 purge readymre
  • aa2d124eREADME: the #94 purge gatemre
  • e843ff7cOne-time purge of miserit-anthar#94 (#94, identity rule): idempotent step in lib/migrate.hl, fixture gate tests/purge94.mjsmre
  • 506a4efdmission 028: #94, identity rulemre
  • 78c7f48eRefine mpackdb holdmre
  • 3d7d89c8Record mpackdb hold until day38mre