gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchk40-lists9af8e780|||PR Use keyed list mutations for live ticket updatesmrek40-lists/components/ticket.hl

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

Branches

Latest commits

  • 9af8e780|||PR Use keyed list mutations for live ticket updatesmre
  • 610d8e8aMerge branch 'records-t39' into mainTickets
  • 32bcdf24|||PR records: GO P39 K40mre
  • 4123c6d1Merge branch 'records-t38' into mainTickets
  • cd3641a1|||PR records: day72 deploy live, tickets closedmre
  • 7d44d852Merge branch 'records-t37' into mainTickets
  • 926f7061|||PR records: merges, D36 deploymre
  • bf58534eMerge branch 'l33-final' into mainTickets
  • 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
  • 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
  • 5822cb3aMerge branch 'o34-clean' into mainTickets
  • 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
  • 14cf96b4Merge branch 'records-t36' into mainTickets
  • 07749fa1|||PR records: day72 + #40 mergedmre
  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre
  • 6dea1c60Merge branch 'r35-day72' into mainTickets
  • 7bcfdc22|||PR drop worker edits to conductor recordsmre
  • 2617b6ee|||PR dialogs: host flag cleared on close, dialog gate (tickets#40)mre
  • 6e701371|||PR record partial day72 dialog validationmre
  • b9fb9a91|||PR bind ticket dialog visibility to member flagsmre