gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita5d45d00a5d45d00records: D38 cause, GOmrea5d45d00/components/ticket.hl

33.8 KB

  1. // components/ticket.hl — `/:projectSlug/:ticketNumber` (ticket #25; was /projects/…): one ticket, its
  2. // append-only event history, a comment form and the state change. (Old URLs `/tickets/<n>`,
  3. // `/projects/<slug>/<n>`, `/projects/<slug>/tickets/<n>` are 301-redirected here by lib/api.hl.) Live: an event on THIS ticket (from any browser or
  4. // the API) is appended here and the state badge follows, without a reload.
  5. // Ticket #6 (mission 014): the summary, comments and state notes are MARKDOWN, rendered by the
  6. // child component Markdown (components/markdown.hl) from markdown.hl's blocks — safe: no HTML
  7. // string, links checked. Ticket #8: the ticket's AUTHOR (a ticket from before the login: the
  8. // creator) gets "Edit" — subject + summary; the edit is a history event that keeps the previous
  9. // values ("edited the ticket", the previous summary folded under it), pushed live like a comment.
  10. // Ticket #4 (mission 017): RELATIONS — "Part of <parent>", the children with their states and
  11. // "all children confirmed" / "n of m children confirmed", "Blocked by" and "Blocks" (each with
  12. // states); logged-in users get the forms "Parent" (set / remove) and "Blocked by" (add / remove per
  13. // row) — the store decides who may (the author of either ticket, or the creator). Live: the
  14. // `ticketsRelated` push carries the relation view of every ticket involved in a write.
  15. // Ticket #12 (mission 024): the Markdown fields are edited visually; since mission 016 with the Hybriel MdEditor (below).
  16. // Ctrl/Cmd+Enter in an editor sends its form.
  17. // Ticket #20 (roles): a member of the project may comment; `use` also moves the ticket between open and
  18. // review; `edit` / `admin` edit it, assign it (a member; "Assigned to …" is shown) and set any state; a
  19. // visitor without a role only reads. The server decides in every case; the page only shows what it may.
  20. // A ticket opened through a FORMER slug of its project shows a note with the current address.
  21. // Mission 016 (layouts#2): THE COMMENTS are drawn by the shared Comments block (components/comments/, copied verbatim from
  22. // components.hybriel.worldapi.org — tools/sync-components.sh): in the history every run of comments that follow each other is
  23. // one block, in place between the state changes etc. (`entries`, entriesOf); "write a comment" is a last block under
  24. // "Respond". The block shows Edit / Delete on the user's own comments (it asks before a delete) and a like; it tells this
  25. // page through the four functions it is handed (posted / edited / deleted / liked), the faces below write (lib/comments.hl
  26. // decides who may: the author edits and deletes, any member likes), and the push `commentChanged` swaps the row in every
  27. // open page. A deleted comment stays one line in the history ("commented (deleted …)"). Signed out / no member: user ''
  28. // (read only). The block's count line and its form are hidden inside the history (styles.hl): it has no switch for them.
  29. // The Markdown fields (edit summary, state note) are the Hybriel MdEditor (components/md-editor/, the block's editor); the
  30. // old <md-editor> of shared/md-editor.js is gone — it would have taken over the block's own <md-editor> elements.
  31. // 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) { " " ticketState { class = en.ev.toSlug en.ev.to } }
  465. " " time { en.ev.when }
  466. }
  467. if (en.ev.isEdit) { eventText { class = "edit"
  468. if (en.ev.subjectChanged) { p { class = "was" "Subject before: " s { en.ev.oldSubject } } }
  469. if (en.ev.summaryChanged) { details { class = "was"
  470. summary { "Summary before" }
  471. Markdown { blocks = en.ev.oldSummaryMd }
  472. } }
  473. } }
  474. if (en.ev.hasText) { eventText { Markdown { blocks = en.ev.md } } }
  475. } }
  476. }
  477. }
  478. }
  479. if (mustLogIn) {
  480. 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." }
  481. }
  482. if (notMember) {
  483. p { id = "memberhint" Style.pHint "You are not a member of this project — ask an admin to invite you to comment." }
  484. }
  485. if (canWrite) { section {
  486. h2 { "Respond" }
  487. commentForm { id = "commentform"
  488. 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" }
  489. }
  490. p { id = "message" Style.pMessage message }
  491. } }
  492. if (showEdit2) { section {
  493. h2 { "Manage" }
  494. form { id = "assignform"
  495. on submit(e) {
  496. e.preventDefault()
  497. emit sendAssign(e)
  498. }
  499. label { "Assigned to"
  500. select { id = "assignselect" name = "assignee" value = assignDraft on change(e) { emit setAssignDraft(e.target.value) }
  501. option { value = "" "nobody" }
  502. for (o of memberOptions) { option { value = o.value o.label } }
  503. }
  504. }
  505. button { id = "assignsave" type = "submit" "Assign" }
  506. }
  507. p { id = "assignmessage" Style.pMessage assignMessage }
  508. form { id = "parentform"
  509. on submit(e) {
  510. e.preventDefault()
  511. emit sendParent(e)
  512. }
  513. label { "Parent ticket (project#number)"
  514. input { id = "parentkey" name = "parent" placeholder = "e.g. ident.worldapi.org#1" autocomplete = "off" value = parentDraft on input(e) { emit setParentDraft(e.target.value) } }
  515. }
  516. formButtons {
  517. button { id = "parentsave" type = "submit" "Set parent" }
  518. if (hasParent) { button { id = "parentremove" type = "button" class = "quiet" "Remove parent" on click(e) { emit removeParent(e) } } }
  519. }
  520. }
  521. form { id = "blockerform"
  522. on submit(e) {
  523. e.preventDefault()
  524. emit sendBlocker(e)
  525. }
  526. label { "Blocked by (project#number)"
  527. input { id = "blockerkey" name = "blocker" placeholder = "e.g. hybriel#12" autocomplete = "off" value = blockerDraft on input(e) { emit setBlockerDraft(e.target.value) } }
  528. }
  529. button { id = "blockeradd" type = "submit" "Add blocker" }
  530. }
  531. p { id = "linkmessage" Style.pMessage linkMessage }
  532. } }
  533. }
  534. }
  535. }
  536. on setEditSubject(v) { editSubject = v }
  537. // the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not it
  538. on setEditSummary(name, v) { if (name == 'summary') { editSummary = v } }
  539. on startEdit(e) {
  540. editSubject = subject
  541. editSummary = summary
  542. editStart = summary
  543. editMessage = ''
  544. editing = true
  545. showEdit = false
  546. }
  547. on cancelEdit(e) {
  548. editing = false
  549. showEdit = canEdit
  550. editMessage = ''
  551. }
  552. on saveEdit(e) {
  553. r = emit server ticketEdit(ticketId, editSubject, editSummary)
  554. if (r != null && r.error != null) {
  555. editMessage = r.error
  556. return null
  557. }
  558. editing = false
  559. showEdit = canEdit
  560. editMessage = ''
  561. }
  562. on setAssignDraft(v) { assignDraft = v }
  563. on sendAssign(e) {
  564. r = emit server ticketAssign(ticketId, assignDraft)
  565. if (r != null && r.error != null) { assignMessage = r.error } else { assignMessage = '' }
  566. }
  567. on setParentDraft(v) { parentDraft = v }
  568. on setBlockerDraft(v) { blockerDraft = v }
  569. // relations (ticket #4): the answer is only ok / error — the page follows the push
  570. on sendParent(e) {
  571. if (parentDraft.trim() == '') {
  572. linkMessage = 'name the parent as project#number'
  573. return null
  574. }
  575. r = emit server ticketSetParent(ticketId, parentDraft)
  576. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' parentDraft = '' }
  577. }
  578. on removeParent(e) {
  579. r = emit server ticketSetParent(ticketId, '')
  580. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }
  581. }
  582. on sendBlocker(e) {
  583. if (blockerDraft.trim() == '') {
  584. linkMessage = 'name the blocking ticket as project#number'
  585. return null
  586. }
  587. r = emit server ticketAddBlocker(ticketId, blockerDraft)
  588. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' blockerDraft = '' }
  589. }
  590. on removeBlocker(key) {
  591. r = emit server ticketRemoveBlocker(ticketId, key)
  592. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }
  593. }
  594. // ---- the comments (mission 016): the history as entries — a run of comments is one block, every other event one line.
  595. // A comment entry is the block's record { id, author, when, text, likes, liked, history, files }; a deleted comment is a line.
  596. // every viewer who sees a comment gets its files' url (tickets#37): reading is public, so the thumbnail and the file are too.
  597. entriesOf(list, uid) {
  598. out = []
  599. let run = []
  600. for (ev of list) {
  601. if (ev.kind == 'comment' && ev.deleted != true) {
  602. run.push(commentOf(ev, uid))
  603. } else {
  604. let shown = ev
  605. // 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
  606. if (ev.kind == 'state' && ev.hasText == true) {
  607. run.push(commentOf(ev, uid))
  608. 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 }
  609. }
  610. if (run.length > 0) {
  611. out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} })
  612. run = []
  613. }
  614. out.push({ id = '' + ev.id isGroup = false isEvent = true comments = [] cls = ev.deleted == true ? 'comment deleted' : ev.kind ev = shown })
  615. }
  616. }
  617. if (run.length > 0) { out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} }) }
  618. return out
  619. }
  620. // the block's record of a comment (or of the note of a state change)
  621. commentOf(ev, uid) {
  622. 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) }
  623. }
  624. // a comment's attachments as the block shows them: { name, url, image, size }
  625. filesOf(list) {
  626. out = []
  627. if (list == null) { return out }
  628. for (a of list) { out.push({ name = a.name url = a.url image = a.image size = a.size }) }
  629. return out
  630. }
  631. // what the blocks tell this page: the faces write; every open page (this one too) follows the push. A refusal shows in
  632. // #message; a refused post answers false, so the block keeps the typed text (and the files). With files (tickets#27) the post is
  633. // the face commentWithFiles: the framework uploads them first; a file it refuses (over uploadMax) ends the emit with null.
  634. posted = (text, files) => {
  635. let r = null
  636. if (files != null && files.length > 0) {
  637. r = emit server commentWithFiles(ticketId, text, files)
  638. if (r == null) {
  639. message = 'the comment was not sent: a file could not be uploaded (at most 10 MB each)'
  640. return false
  641. }
  642. } else {
  643. r = emit server commentOn(ticketId, text)
  644. }
  645. if (r != null && r.error != null) {
  646. message = r.error
  647. return false
  648. }
  649. message = ''
  650. return true
  651. }
  652. // THE ONE COMPOSER of "Respond": a comment (with its files), a state change, or both — one request each, the comment first. The block
  653. // tells what is there: the text, the files and the state chosen ('' = no change). A comment that is refused keeps everything in the form
  654. // (false); a comment that went through and a state change that is refused clears the form and shows the refusal; a state change
  655. // alone that is refused keeps the form.
  656. respond = (text, files, state) => {
  657. words = text.trim() != '' || (files != null && files.length > 0)
  658. if (words) {
  659. ok = posted(text, files)
  660. if (ok == false) { return false }
  661. }
  662. if (state != '') {
  663. r = emit server setTicketState(ticketId, state, '')
  664. if (r != null && r.error != null) {
  665. message = r.error
  666. return words
  667. }
  668. message = ''
  669. }
  670. return true
  671. }
  672. edited = (id, text) => {
  673. r = emit server ticketCommentEdit(ticketId, id, text)
  674. message = r != null && r.error != null ? r.error : ''
  675. }
  676. deleted = (id) => {
  677. r = emit server ticketCommentDelete(ticketId, id)
  678. message = r != null && r.error != null ? r.error : ''
  679. }
  680. liked = (id) => {
  681. r = emit server ticketCommentLike(ticketId, id)
  682. message = r != null && r.error != null ? r.error : ''
  683. }
  684. // ---- what the server pushes: an event on some ticket -----------------------------------
  685. on client ticketEvent(evTicket, ev, changed, count) {
  686. if ('' + evTicket == '' + ticketId) {
  687. next = []
  688. for (x of events) { next.push(x) }
  689. next.push(ev)
  690. events = next
  691. entries = entriesOf(next, meId)
  692. state = changed.state
  693. stateSlug = changed.stateSlug
  694. updated = changed.updated
  695. assignee = changed.assignee
  696. hasAssignee = changed.hasAssignee
  697. assignDraft = changed.assigneeId
  698. rights = emit server ticketRights(ticketId)
  699. takeRights(rights)
  700. if (ev.isEdit == true) {
  701. subject = changed.subject
  702. summary = changed.summary
  703. hasSummary = changed.summary != ''
  704. summaryMd = ev.summaryMd
  705. }
  706. }
  707. }
  708. // mission 016: a comment of THIS ticket was edited, deleted or (un)liked — its row is swapped
  709. on client commentChanged(evTicket, ev) {
  710. if ('' + evTicket == '' + ticketId) {
  711. next = []
  712. for (x of events) {
  713. if ('' + x.id == '' + ev.id) { next.push(ev) } else { next.push(x) }
  714. }
  715. events = next
  716. entries = entriesOf(next, meId)
  717. }
  718. }
  719. // relations changed (a write on this ticket or on a related one): take over this ticket's view
  720. on client ticketsRelated(views) {
  721. for (v of views) {
  722. if ('' + v.id == '' + ticketId) {
  723. hasRelations = v.hasRelations
  724. hasParent = v.hasParent
  725. parentRef = v.parent
  726. hasChildren = v.hasChildren
  727. children = v.children
  728. childNote = v.childNote
  729. childClass = v.childClass
  730. hasBlockedBy = v.hasBlockedBy
  731. blockedBy = v.blockedBy
  732. hasBlocks = v.hasBlocks
  733. blocks = v.blocks
  734. }
  735. }
  736. }
  737. // login / logout in the shell (this session's tabs): the forms come and go without a reload
  738. // what this session's user may do on this ticket now (the face answers from their role)
  739. takeRights = (r) => {
  740. if (r == null || r.error != null) { return null }
  741. canWrite = r.comment == true
  742. meName = r.name
  743. meId = r.userId
  744. writer = r.comment == true ? r.name : ''
  745. entries = entriesOf(events, r.userId)
  746. mustLogIn = false
  747. notMember = !canWrite
  748. canEdit = r.edit == true
  749. showEdit = canEdit && !editing
  750. showEdit2 = canEdit
  751. // the Respond block is rebuilt (and loses a draft) when a value bound into it changes: the choices only when they really changed
  752. if (!sameChoices(options, r.options)) { options = r.options }
  753. memberOptions = r.members
  754. }
  755. on client signedIn(tag, info) {
  756. r = emit server ticketRights(ticketId)
  757. takeRights(r)
  758. }
  759. on client signedOut(tag) {
  760. canWrite = false
  761. writer = ''
  762. meName = ''
  763. meId = ''
  764. entries = entriesOf(events, '')
  765. mustLogIn = true
  766. notMember = false
  767. canEdit = false
  768. showEdit = false
  769. showEdit2 = false
  770. editing = false
  771. }
  772. sameChoices(a, b) {
  773. if (a.length != b.length) { return false }
  774. let i = 0
  775. while (i < a.length) {
  776. if (a[i].value != b[i].value) { return false }
  777. i = i + 1
  778. }
  779. return true
  780. }
  781. // ---- the faces: the writer is the session's user (#31: a forged trailing argument is not
  782. // a real session → refused) ---------------------------------------------------------------
  783. on server commentOn(ticketId, text, session) {
  784. w = writerOfSession(session)
  785. if (w.error != null) { return { error = w.error } }
  786. r = addComment('' + ticketId, w.user, text, null)
  787. if (r.error != null) { return { error = r.error } }
  788. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  789. return { ok = true }
  790. }
  791. // tickets#27: a comment with files — `files` arrive as [{ bytes, name, type, size }] (the framework took them from /__hl/upload);
  792. // lib/attachments.hl checks the limits and the content, a refusal comes back as the message
  793. on server commentWithFiles(ticketId, text, files, session) {
  794. w = writerOfSession(session)
  795. if (w.error != null) { return { error = w.error } }
  796. if (hlTypeName(text) != 'String') { return { error = 'the comment must be text' } }
  797. r = addComment('' + ticketId, w.user, text, files)
  798. if (r.error != null) { return { error = r.error } }
  799. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  800. return { ok = true }
  801. }
  802. on server setTicketState(ticketId, state, note, session) {
  803. w = writerOfSession(session)
  804. if (w.error != null) { return { error = w.error } }
  805. r = changeState('' + ticketId, state, w.user, note)
  806. if (r.error != null) { return { error = r.error } }
  807. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  808. if (r.assignEvent != null) { emit client ticketEvent(r.ticket.id, pageEventOf(r.assignEvent), r.ticket) }
  809. emit client ticketsRelated(relatedViews(r.ticket.id, []))
  810. return { ok = true }
  811. }
  812. // mission 016: the comment's author edits / deletes it, a member likes it (again = takes it back) — lib/comments.hl decides
  813. on server ticketCommentEdit(ticketId, commentId, text, session) {
  814. w = writerOfSession(session)
  815. if (w.error != null) { return { error = w.error } }
  816. if (hlTypeName(text) != 'String') { return { error = 'the comment must be text' } }
  817. r = changeComment('' + ticketId, '' + commentId, w.user, 'edit', text)
  818. if (r.error != null) { return { error = r.error } }
  819. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  820. return { ok = true }
  821. }
  822. on server ticketCommentDelete(ticketId, commentId, session) {
  823. w = writerOfSession(session)
  824. if (w.error != null) { return { error = w.error } }
  825. r = changeComment('' + ticketId, '' + commentId, w.user, 'delete', '')
  826. if (r.error != null) { return { error = r.error } }
  827. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  828. return { ok = true }
  829. }
  830. on server ticketCommentLike(ticketId, commentId, session) {
  831. w = writerOfSession(session)
  832. if (w.error != null) { return { error = w.error } }
  833. r = changeComment('' + ticketId, '' + commentId, w.user, 'like', '')
  834. if (r.error != null) { return { error = r.error } }
  835. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  836. return { ok = true }
  837. }
  838. // ticket #20: assign the ticket to a member ('' = nobody); the store wants the role edit or admin
  839. on server ticketAssign(ticketId, userId, session) {
  840. w = writerOfSession(session)
  841. if (w.error != null) { return { error = w.error } }
  842. if (hlTypeName(userId) != 'String') { return { error = 'the assignee must be text' } }
  843. r = assignTicket('' + ticketId, w.user, userId)
  844. if (r.error != null) { return { error = r.error } }
  845. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  846. return { ok = true }
  847. }
  848. // ticket #8: the author edits subject + summary (the store refuses anyone else)
  849. on server ticketEdit(ticketId, subject, summary, session) {
  850. w = writerOfSession(session)
  851. if (w.error != null) { return { error = w.error } }
  852. if (hlTypeName(subject) != 'String' || hlTypeName(summary) != 'String') { return { error = 'subject and summary must be text' } }
  853. r = editTicket('' + ticketId, w.user, subject, summary)
  854. if (r.error != null) { return { error = r.error } }
  855. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  856. emit client ticketsRelated(relatedViews(r.ticket.id, []))
  857. return { ok = true }
  858. }
  859. // ticket #4: relations — the store refuses a user who may not (edit / admin in this ticket's project)
  860. on server ticketSetParent(ticketId, key, session) {
  861. w = writerOfSession(session)
  862. if (w.error != null) { return { error = w.error } }
  863. if (hlTypeName(key) != 'String') { return { error = 'the parent must be text' } }
  864. r = setParent('' + ticketId, w.user, key)
  865. if (r.error != null) { return { error = r.error } }
  866. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  867. emit client ticketsRelated(r.related)
  868. return { ok = true }
  869. }
  870. on server ticketAddBlocker(ticketId, key, session) {
  871. w = writerOfSession(session)
  872. if (w.error != null) { return { error = w.error } }
  873. if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }
  874. r = changeBlocker('' + ticketId, w.user, key, true, 'add')
  875. if (r.error != null) { return { error = r.error } }
  876. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  877. emit client ticketsRelated(r.related)
  878. return { ok = true }
  879. }
  880. on server ticketRemoveBlocker(ticketId, key, session) {
  881. w = writerOfSession(session)
  882. if (w.error != null) { return { error = w.error } }
  883. if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }
  884. r = changeBlocker('' + ticketId, w.user, key, false, 'remove')
  885. if (r.error != null) { return { error = r.error } }
  886. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  887. emit client ticketsRelated(r.related)
  888. return { ok = true }
  889. }
  890. // what the session's user may do on this ticket: comment (a member), edit / assign (edit, admin), the states
  891. // they may move it to, and the members it can be assigned to
  892. on server ticketRights(ticketId, session) {
  893. u = userOfSession(session)
  894. if (u == null) { return { error = 'log in first' } }
  895. t = ticketRecord('' + ticketId)
  896. if (t == null) { return { error = 'no such ticket' } }
  897. r = ticketRights(t, u)
  898. // mission 016: who the comment blocks compare authors with, and whose likes count as "liked"
  899. r.name = u.name
  900. r.userId = u.id
  901. return r
  902. }

Branches

Latest commits

  • a5d45d00records: D38 cause, GOmre
  • 19eeb938records: D38 gates, two day38b failuresmre
  • 94d6ca2arecords: D38 startedmre
  • 9df09aacmission 029: day38b re-vendor + deploymre
  • d2834f65records: #94 backup planmre
  • 4467d8cbrecords: #94 purge readymre
  • 506a4efdmission 028: #94, identity rulemre
  • 78c7f48eRefine mpackdb holdmre
  • 3d7d89c8Record mpackdb hold until day38mre
  • f1bf7195#51 done; my subscription idmre
  • 9870b945status: #51 proof greenmre
  • e92173c6log: #51 live push proofmre
  • 72d87041log: Hermes push livemre
  • 1d69bf7dTickets conductor: park until Hermes pushmre
  • 80d8cfd1Tickets conductor: #51 livemre
  • 61641dd9Complete subscriptions deployment evidencemre
  • c980856cRecord successful subscriptions deployment and live checksmre
  • 4b4710adMerge branch 's51-subscriptions'mre
  • a731ef7eTickets conductor: S51 reviewed, deploy stepmre
  • b487b05aRecord verified direct push protocol handoffmre