gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit28e9c93828e9c938ticket list: draw the newest 50 rows and a Show more button (500 rows were a 2-4 s first paint, 740 KB, a 90 000 px phone page)mre28e9c938/components/ticket.hl

28.1 KB

  1. // components/ticket.hl — `/:projectSlug/:ticketNumber` (ticket #25; was /projects/…): one ticket, its
  2. // append-only event history, a comment form and the state change. (Old URLs `/tickets/<n>`,
  3. // `/projects/<slug>/<n>`, `/projects/<slug>/tickets/<n>` are 301-redirected here by lib/api.hl.) Live: an event on THIS ticket (from any browser or
  4. // the API) is appended here and the state badge follows, without a reload.
  5. // Ticket #6 (mission 014): the summary, comments and state notes are MARKDOWN, rendered by the
  6. // child component Markdown (components/markdown.hl) from markdown.hl's blocks — safe: no HTML
  7. // string, links checked. Ticket #8: the ticket's AUTHOR (a ticket from before the login: the
  8. // creator) gets "Edit" — subject + summary; the edit is a history event that keeps the previous
  9. // values ("edited the ticket", the previous summary folded under it), pushed live like a comment.
  10. // Ticket #4 (mission 017): RELATIONS — "Part of <parent>", the children with their states and
  11. // "all children confirmed" / "n of m children confirmed", "Blocked by" and "Blocks" (each with
  12. // states); logged-in users get the forms "Parent" (set / remove) and "Blocked by" (add / remove per
  13. // row) — the store decides who may (the author of either ticket, or the creator). Live: the
  14. // `ticketsRelated` push carries the relation view of every ticket involved in a write.
  15. // Ticket #12 (mission 024): the Markdown fields are edited visually; since mission 016 with the Hybriel MdEditor (below).
  16. // Ctrl/Cmd+Enter in an editor sends its form.
  17. // Ticket #20 (roles): a member of the project may comment; `use` also moves the ticket between open and
  18. // review; `edit` / `admin` edit it, assign it (a member; "Assigned to …" is shown) and set any state; a
  19. // visitor without a role only reads. The server decides in every case; the page only shows what it may.
  20. // A ticket opened through a FORMER slug of its project shows a note with the current address.
  21. // Mission 016 (layouts#2): THE COMMENTS are drawn by the shared Comments block (components/comments/, copied verbatim from
  22. // components.hybriel.worldapi.org — tools/sync-components.sh): in the history every run of comments that follow each other is
  23. // one block, in place between the state changes etc. (`entries`, entriesOf); "write a comment" is a last block under
  24. // "Respond". The block shows Edit / Delete on the user's own comments (it asks before a delete) and a like; it tells this
  25. // page through the four functions it is handed (posted / edited / deleted / liked), the faces below write (lib/comments.hl
  26. // decides who may: the author edits and deletes, any member likes), and the push `commentChanged` swaps the row in every
  27. // open page. A deleted comment stays one line in the history ("commented (deleted …)"). Signed out / no member: user ''
  28. // (read only). The block's count line and its form are hidden inside the history (styles.hl): it has no switch for them.
  29. // The Markdown fields (edit summary, state note) are the Hybriel MdEditor (components/md-editor/, the block's editor); the
  30. // old <md-editor> of shared/md-editor.js is gone — it would have taken over the block's own <md-editor> elements.
  31. // tickets#27 (mission 017): ATTACHMENTS. The "Respond" block has attach = "true": its form sits in the shared FilesUpload (pick
  32. // mode; components/files-upload/, copied verbatim) — files chosen, photographed, dropped or pasted (Ctrl+V, also into the editor)
  33. // wait under it and go with the post (face commentWithFiles; lib/attachments.hl checks and stores them). Each comment shows its
  34. // files: pictures as thumbnails that open the full picture, other files as rows. Only members may fetch them, so for anybody else
  35. // the block gets the files without `url` (names and sizes, no link).
  36. parent './main.hl'
  37. import { ticketRowAt, ticketRecord, eventRows, stateChoices, addComment, changeComment, changeState, assignTicket, editTicket, mayEditId, ticketRights, relatedViews, setParent, changeBlocker } from '../lib/tickets.hl'
  38. import { assignChoices, isMember } from '../lib/projects.hl'
  39. import { relationViewOf, noRef } from '../lib/tickets-helpers.hl'
  40. import { pageEventsOf, pageEventOf } from '../lib/events.hl'
  41. import { markdownBlocks } from '../lib/markdown.hl'
  42. import { siteName } from '../project.hl'
  43. import { canWriteSession, writerOfSession, userOfSession } from '../lib/users.hl'
  44. import Markdown from './markdown.hl'
  45. import Comments from './comments/comments.hl'
  46. import MdEditor from './md-editor/md-editor.hl'
  47. projectSlug = null
  48. ticketNumber = null
  49. row = ticketRowAt(projectSlug, ticketNumber)
  50. present = row != null
  51. gone = row == null
  52. ticketId = row != null ? row.id : ''
  53. ref = row != null ? row.ref : ''
  54. movedNote = row != null && projectSlug != row.project
  55. currentHref = row != null ? row.href : ''
  56. assignee = row != null ? row.assignee : ''
  57. hasAssignee = row != null && row.hasAssignee
  58. createdBy = row != null ? row.createdBy : ''
  59. hasOld = row != null && row.hasOld
  60. oldRef = row != null ? row.oldRef : ''
  61. subject = row != null ? row.subject : 'No such ticket'
  62. summary = row != null ? row.summary : ''
  63. hasSummary = row != null && row.summary != ''
  64. summaryMd = row != null ? markdownBlocks(row.summary) : []
  65. project = row != null ? row.project : ''
  66. projectHref = row != null ? row.projectHref : '/'
  67. state = row != null ? row.state : ''
  68. stateSlug = row != null ? row.stateSlug : ''
  69. created = row != null ? row.created : ''
  70. updated = row != null ? row.updated : ''
  71. events = row != null ? pageEventsOf(eventRows(row.id)) : []
  72. __title = siteName + ' | ' + (row != null ? row.project + ' ' + row.ref + ' ' + row.subject : 'no such ticket')
  73. // the forms: only for a logged-in user with a display name (ticket #7); the author is that
  74. // user (the faces read the session). Confirm / reject: the server refuses a non-creator.
  75. session = null
  76. me = userOfSession(session)
  77. canWrite = row != null && me != null && isMember(row.projectId, me)
  78. mustLogIn = me == null
  79. notMember = me != null && !canWrite
  80. options = row != null ? stateChoices(ticketRecord(row.id), me) : []
  81. hasOptions = options.length > 0
  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, canWrite)
  88. noComments = []
  89. newState = options.length > 0 ? options[0].value : ''
  90. stateNote = ''
  91. // the MdEditor is built once per element: a new key (noteSeq) gives the next note an empty editor
  92. noteSeq = 0
  93. noteForms = [{ id = 'note-0' }]
  94. message = ''
  95. // editing (ticket #8): only the author (the server decides; the face checks again)
  96. canEdit = row != null && mayEditId(row.id, me)
  97. assignDraft = row != null ? row.assigneeId : ''
  98. assignMessage = ''
  99. editing = false
  100. showEdit = canEdit
  101. showEdit2 = canEdit
  102. editSubject = ''
  103. editSummary = ''
  104. editStart = ''
  105. editMessage = ''
  106. // relations (ticket #4): the view of lib/tickets-helpers.hl relationViewOf, flat members for the View
  107. rel = row != null ? relationViewOf(row) : null
  108. hasRelations = rel != null && rel.hasRelations
  109. hasParent = rel != null && rel.hasParent
  110. parentRef = rel != null ? rel.parent : noRef
  111. hasChildren = rel != null && rel.hasChildren
  112. children = rel != null ? rel.children : []
  113. childNote = rel != null ? rel.childNote : ''
  114. childClass = rel != null ? rel.childClass : ''
  115. hasBlockedBy = rel != null && rel.hasBlockedBy
  116. blockedBy = rel != null ? rel.blockedBy : []
  117. hasBlocks = rel != null && rel.hasBlocks
  118. blocks = rel != null ? rel.blocks : []
  119. parentDraft = ''
  120. blockerDraft = ''
  121. linkMessage = ''
  122. View {
  123. ticketView {
  124. if (gone) { p { id = "gone" class = "empty" "There is no such ticket." } }
  125. if (present) {
  126. header {
  127. p { a { id = "project" href = projectHref project } " " ticketRef { id = "ref" ref }
  128. if (hasOld) { formerRef { id = "oldref" "formerly " oldRef } }
  129. }
  130. h1 { id = "subject" subject }
  131. ticketState { id = "state" class = stateSlug state }
  132. p { class = "people" "opened by " strong { id = "createdby" createdBy }
  133. if (hasAssignee) { " · assigned to " strong { id = "assignee" assignee } }
  134. }
  135. if (movedNote) { p { id = "movednote" class = "hint" "This project has a new address: " a { id = "movedlink" href = currentHref currentHref } } }
  136. p { class = "dates" "opened " time { created } " · updated " time { id = "updated" updated } }
  137. if (showEdit) { button { id = "editbutton" type = "button" class = "quiet" "Edit" on click(e) { emit startEdit(e) } } }
  138. }
  139. if (editing) {
  140. form { id = "editform"
  141. on submit(e) {
  142. e.preventDefault()
  143. emit saveEdit(e)
  144. }
  145. label { "Subject"
  146. input { id = "editsubject" name = "subject" required = "required" maxlength = "200" value = editSubject on input(e) { emit setEditSubject(e.target.value) } }
  147. }
  148. mdField { id = "editsummary" on input(e) { emit setEditSummary(e.target.name, e.target.value) }
  149. span { "Summary" }
  150. MdEditor { name = "summary" value = editStart rows = 8 files = "off" }
  151. }
  152. formButtons {
  153. button { id = "editsave" type = "submit" "Save" }
  154. button { id = "editcancel" type = "button" class = "quiet" "Cancel" on click(e) { emit cancelEdit(e) } }
  155. }
  156. p { id = "editmessage" class = "message" editMessage }
  157. }
  158. }
  159. if (hasSummary) { ticketSummary { id = "summary" Markdown { blocks = summaryMd } } }
  160. if (hasRelations) { ticketRelations { id = "relations"
  161. if (hasParent) { p { id = "parent" "Part of "
  162. a { href = parentRef.href parentRef.project " " parentRef.ref }
  163. " " span { class = "refsubject" parentRef.subject }
  164. " " ticketState { class = parentRef.stateSlug parentRef.state }
  165. } }
  166. if (hasChildren) { div { id = "childrenbox"
  167. h2 { "Children" }
  168. p { id = "childnote" class = childClass childNote }
  169. ul { id = "children" class = "refs"
  170. for (c of children) { li {
  171. ticketState { class = c.stateSlug c.state }
  172. a { href = c.href c.project " " c.ref }
  173. span { class = "refsubject" c.subject }
  174. } }
  175. }
  176. } }
  177. if (hasBlockedBy) { div { id = "blockedbybox"
  178. h2 { "Blocked by" }
  179. ul { id = "blockedby" class = "refs"
  180. for (c of blockedBy) { li {
  181. ticketState { class = c.stateSlug c.state }
  182. a { href = c.href c.project " " c.ref }
  183. span { class = "refsubject" c.subject }
  184. if (showEdit2) { button { type = "button" class = "quiet unblock" value = c.key "Remove" on click(e) { emit removeBlocker(e.target.value) } } }
  185. } }
  186. }
  187. } }
  188. if (hasBlocks) { div { id = "blocksbox"
  189. h2 { "Blocks" }
  190. ul { id = "blocks" class = "refs"
  191. for (c of blocks) { li {
  192. ticketState { class = c.stateSlug c.state }
  193. a { href = c.href c.project " " c.ref }
  194. span { class = "refsubject" c.subject }
  195. } }
  196. }
  197. } }
  198. } }
  199. section {
  200. h2 { "History" }
  201. ol { id = "events"
  202. for (en of entries) {
  203. if (en.isGroup) { li { class = "comments"
  204. Comments { comments = en.comments user = writer onPost = posted onEdit = edited onDelete = deleted onLike = liked }
  205. } }
  206. if (en.isEvent) { li { class = en.cls
  207. eventHead {
  208. strong { en.ev.author }
  209. " " en.ev.label
  210. if (en.ev.isState) { " " ticketState { class = en.ev.toSlug en.ev.to } }
  211. " " time { en.ev.when }
  212. }
  213. if (en.ev.isEdit) { eventText { class = "edit"
  214. if (en.ev.subjectChanged) { p { class = "was" "Subject before: " s { en.ev.oldSubject } } }
  215. if (en.ev.summaryChanged) { details { class = "was"
  216. summary { "Summary before" }
  217. Markdown { blocks = en.ev.oldSummaryMd }
  218. } }
  219. } }
  220. if (en.ev.hasText) { eventText { Markdown { blocks = en.ev.md } } }
  221. } }
  222. }
  223. }
  224. }
  225. if (mustLogIn) {
  226. p { id = "loginhint" class = "hint" "Reading is open to everyone. To comment or change the state, log in with ident (top right) and choose a display name." }
  227. }
  228. if (notMember) {
  229. p { id = "memberhint" class = "hint" "You are not a member of this project — ask an admin to invite you to comment." }
  230. }
  231. if (canWrite) { section {
  232. h2 { "Respond" }
  233. commentForm { id = "commentform"
  234. Comments { comments = noComments user = writer onPost = posted emptyText = "" placeholder = "Write a comment (Markdown; Ctrl+Enter sends)" attach = "true" maxFileSize = 10485760 attachText = "Add pictures or files: drop or paste them here, or" }
  235. }
  236. if (hasOptions) { form { id = "stateform"
  237. on submit(e) {
  238. e.preventDefault()
  239. emit sendState(e)
  240. }
  241. label { "State"
  242. select { id = "newstate" name = "state" value = newState
  243. on change(e) { emit setNewState(e.target.value) }
  244. for (o of options) { option { value = o.value o.label } }
  245. }
  246. }
  247. mdField { id = "statenote" on input(e) { emit setStateNote(e.target.name, e.target.value) }
  248. span { "Note (optional)" }
  249. for (f of noteForms) { MdEditor { name = "note" value = "" rows = 1 placeholder = "" files = "off" } }
  250. }
  251. button { id = "statesend" type = "submit" "Change state" }
  252. } }
  253. p { id = "message" class = "message" message }
  254. } }
  255. if (showEdit2) { section {
  256. h2 { "Manage" }
  257. form { id = "assignform"
  258. on submit(e) {
  259. e.preventDefault()
  260. emit sendAssign(e)
  261. }
  262. label { "Assigned to"
  263. select { id = "assignselect" name = "assignee" value = assignDraft on change(e) { emit setAssignDraft(e.target.value) }
  264. option { value = "" "nobody" }
  265. for (o of memberOptions) { option { value = o.value o.label } }
  266. }
  267. }
  268. button { id = "assignsave" type = "submit" "Assign" }
  269. }
  270. p { id = "assignmessage" class = "message" assignMessage }
  271. form { id = "parentform"
  272. on submit(e) {
  273. e.preventDefault()
  274. emit sendParent(e)
  275. }
  276. label { "Parent ticket (project#number)"
  277. input { id = "parentkey" name = "parent" placeholder = "e.g. ident.worldapi.org#1" autocomplete = "off" value = parentDraft on input(e) { emit setParentDraft(e.target.value) } }
  278. }
  279. formButtons {
  280. button { id = "parentsave" type = "submit" "Set parent" }
  281. if (hasParent) { button { id = "parentremove" type = "button" class = "quiet" "Remove parent" on click(e) { emit removeParent(e) } } }
  282. }
  283. }
  284. form { id = "blockerform"
  285. on submit(e) {
  286. e.preventDefault()
  287. emit sendBlocker(e)
  288. }
  289. label { "Blocked by (project#number)"
  290. input { id = "blockerkey" name = "blocker" placeholder = "e.g. hybriel#12" autocomplete = "off" value = blockerDraft on input(e) { emit setBlockerDraft(e.target.value) } }
  291. }
  292. button { id = "blockeradd" type = "submit" "Add blocker" }
  293. }
  294. p { id = "linkmessage" class = "message" linkMessage }
  295. } }
  296. }
  297. }
  298. }
  299. on setEditSubject(v) { editSubject = v }
  300. // the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not it
  301. on setEditSummary(name, v) { if (name == 'summary') { editSummary = v } }
  302. on startEdit(e) {
  303. editSubject = subject
  304. editSummary = summary
  305. editStart = summary
  306. editMessage = ''
  307. editing = true
  308. showEdit = false
  309. }
  310. on cancelEdit(e) {
  311. editing = false
  312. showEdit = canEdit
  313. editMessage = ''
  314. }
  315. on saveEdit(e) {
  316. r = emit server ticketEdit(ticketId, editSubject, editSummary)
  317. if (r != null && r.error != null) {
  318. editMessage = r.error
  319. return null
  320. }
  321. editing = false
  322. showEdit = canEdit
  323. editMessage = ''
  324. }
  325. on setNewState(v) { newState = v }
  326. on setAssignDraft(v) { assignDraft = v }
  327. on sendAssign(e) {
  328. r = emit server ticketAssign(ticketId, assignDraft)
  329. if (r != null && r.error != null) { assignMessage = r.error } else { assignMessage = '' }
  330. }
  331. on setParentDraft(v) { parentDraft = v }
  332. on setBlockerDraft(v) { blockerDraft = v }
  333. // relations (ticket #4): the answer is only ok / error — the page follows the push
  334. on sendParent(e) {
  335. if (parentDraft.trim() == '') {
  336. linkMessage = 'name the parent as project#number'
  337. return null
  338. }
  339. r = emit server ticketSetParent(ticketId, parentDraft)
  340. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' parentDraft = '' }
  341. }
  342. on removeParent(e) {
  343. r = emit server ticketSetParent(ticketId, '')
  344. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }
  345. }
  346. on sendBlocker(e) {
  347. if (blockerDraft.trim() == '') {
  348. linkMessage = 'name the blocking ticket as project#number'
  349. return null
  350. }
  351. r = emit server ticketAddBlocker(ticketId, blockerDraft)
  352. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' blockerDraft = '' }
  353. }
  354. on removeBlocker(key) {
  355. r = emit server ticketRemoveBlocker(ticketId, key)
  356. if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }
  357. }
  358. on setStateNote(name, v) { if (name == 'note') { stateNote = v } }
  359. on sendState(e) {
  360. r = emit server setTicketState(ticketId, newState, stateNote)
  361. if (r != null && r.error != null) {
  362. message = r.error
  363. return null
  364. }
  365. message = ''
  366. stateNote = ''
  367. noteSeq = noteSeq + 1
  368. noteForms = [{ id = 'note-' + noteSeq }]
  369. }
  370. // ---- the comments (mission 016): the history as entries — a run of comments is one block, every other event one line.
  371. // A comment entry is the block's record { id, author, when, text, likes, liked, history, files }; a deleted comment is a line.
  372. // `see` (tickets#27): may the user looking fetch the attachments (a member)? If not, the files come without url.
  373. entriesOf(list, uid, see) {
  374. out = []
  375. let run = []
  376. for (ev of list) {
  377. if (ev.kind == 'comment' && ev.deleted != true) {
  378. run.push({ 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, see) })
  379. } else {
  380. if (run.length > 0) {
  381. out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} })
  382. run = []
  383. }
  384. out.push({ id = '' + ev.id isGroup = false isEvent = true comments = [] cls = ev.deleted == true ? 'comment deleted' : ev.kind ev = ev })
  385. }
  386. }
  387. if (run.length > 0) { out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} }) }
  388. return out
  389. }
  390. // a comment's attachments as the block shows them: { name, url ('' = may not fetch), image, size }
  391. filesOf(list, see) {
  392. out = []
  393. if (list == null) { return out }
  394. for (a of list) { out.push({ name = a.name url = see == true ? a.url : '' image = a.image size = a.size }) }
  395. return out
  396. }
  397. // what the blocks tell this page: the faces write; every open page (this one too) follows the push. A refusal shows in
  398. // #message; a refused post answers false, so the block keeps the typed text (and the files). With files (tickets#27) the post is
  399. // the face commentWithFiles: the framework uploads them first; a file it refuses (over uploadMax) ends the emit with null.
  400. posted = (text, files) => {
  401. let r = null
  402. if (files != null && files.length > 0) {
  403. r = emit server commentWithFiles(ticketId, text, files)
  404. if (r == null) {
  405. message = 'the comment was not sent: a file could not be uploaded (at most 10 MB each)'
  406. return false
  407. }
  408. } else {
  409. r = emit server commentOn(ticketId, text)
  410. }
  411. if (r != null && r.error != null) {
  412. message = r.error
  413. return false
  414. }
  415. message = ''
  416. return true
  417. }
  418. edited = (id, text) => {
  419. r = emit server ticketCommentEdit(ticketId, id, text)
  420. message = r != null && r.error != null ? r.error : ''
  421. }
  422. deleted = (id) => {
  423. r = emit server ticketCommentDelete(ticketId, id)
  424. message = r != null && r.error != null ? r.error : ''
  425. }
  426. liked = (id) => {
  427. r = emit server ticketCommentLike(ticketId, id)
  428. message = r != null && r.error != null ? r.error : ''
  429. }
  430. // ---- what the server pushes: an event on some ticket -----------------------------------
  431. on client ticketEvent(evTicket, ev, changed, count) {
  432. if ('' + evTicket == '' + ticketId) {
  433. next = []
  434. for (x of events) { next.push(x) }
  435. next.push(ev)
  436. events = next
  437. entries = entriesOf(next, meId, canWrite)
  438. state = changed.state
  439. stateSlug = changed.stateSlug
  440. updated = changed.updated
  441. assignee = changed.assignee
  442. hasAssignee = changed.hasAssignee
  443. assignDraft = changed.assigneeId
  444. rights = emit server ticketRights(ticketId)
  445. takeRights(rights)
  446. if (ev.isEdit == true) {
  447. subject = changed.subject
  448. summary = changed.summary
  449. hasSummary = changed.summary != ''
  450. summaryMd = ev.summaryMd
  451. }
  452. }
  453. }
  454. // mission 016: a comment of THIS ticket was edited, deleted or (un)liked — its row is swapped
  455. on client commentChanged(evTicket, ev) {
  456. if ('' + evTicket == '' + ticketId) {
  457. next = []
  458. for (x of events) {
  459. if ('' + x.id == '' + ev.id) { next.push(ev) } else { next.push(x) }
  460. }
  461. events = next
  462. entries = entriesOf(next, meId, canWrite)
  463. }
  464. }
  465. // relations changed (a write on this ticket or on a related one): take over this ticket's view
  466. on client ticketsRelated(views) {
  467. for (v of views) {
  468. if ('' + v.id == '' + ticketId) {
  469. hasRelations = v.hasRelations
  470. hasParent = v.hasParent
  471. parentRef = v.parent
  472. hasChildren = v.hasChildren
  473. children = v.children
  474. childNote = v.childNote
  475. childClass = v.childClass
  476. hasBlockedBy = v.hasBlockedBy
  477. blockedBy = v.blockedBy
  478. hasBlocks = v.hasBlocks
  479. blocks = v.blocks
  480. }
  481. }
  482. }
  483. // login / logout in the shell (this session's tabs): the forms come and go without a reload
  484. // what this session's user may do on this ticket now (the face answers from their role)
  485. takeRights = (r) => {
  486. if (r == null || r.error != null) { return null }
  487. canWrite = r.comment == true
  488. meName = r.name
  489. meId = r.userId
  490. writer = r.comment == true ? r.name : ''
  491. entries = entriesOf(events, r.userId, canWrite)
  492. mustLogIn = false
  493. notMember = !canWrite
  494. canEdit = r.edit == true
  495. showEdit = canEdit && !editing
  496. showEdit2 = canEdit
  497. options = r.options
  498. hasOptions = r.options.length > 0
  499. memberOptions = r.members
  500. newState = r.options.length > 0 ? r.options[0].value : ''
  501. }
  502. on client signedIn(tag, info) {
  503. r = emit server ticketRights(ticketId)
  504. takeRights(r)
  505. }
  506. on client signedOut(tag) {
  507. canWrite = false
  508. writer = ''
  509. meName = ''
  510. meId = ''
  511. entries = entriesOf(events, '', false)
  512. mustLogIn = true
  513. notMember = false
  514. canEdit = false
  515. showEdit = false
  516. showEdit2 = false
  517. hasOptions = false
  518. editing = false
  519. }
  520. // ---- the faces: the writer is the session's user (#31: a forged trailing argument is not
  521. // a real session → refused) ---------------------------------------------------------------
  522. on server commentOn(ticketId, text, session) {
  523. w = writerOfSession(session)
  524. if (w.error != null) { return { error = w.error } }
  525. r = addComment('' + ticketId, w.user, text, null)
  526. if (r.error != null) { return { error = r.error } }
  527. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  528. return { ok = true }
  529. }
  530. // tickets#27: a comment with files — `files` arrive as [{ bytes, name, type, size }] (the framework took them from /__hl/upload);
  531. // lib/attachments.hl checks the limits and the content, a refusal comes back as the message
  532. on server commentWithFiles(ticketId, text, files, session) {
  533. w = writerOfSession(session)
  534. if (w.error != null) { return { error = w.error } }
  535. if (hlTypeName(text) != 'String') { return { error = 'the comment must be text' } }
  536. r = addComment('' + ticketId, w.user, text, files)
  537. if (r.error != null) { return { error = r.error } }
  538. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  539. return { ok = true }
  540. }
  541. on server setTicketState(ticketId, state, note, session) {
  542. w = writerOfSession(session)
  543. if (w.error != null) { return { error = w.error } }
  544. r = changeState('' + ticketId, state, w.user, note)
  545. if (r.error != null) { return { error = r.error } }
  546. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  547. if (r.assignEvent != null) { emit client ticketEvent(r.ticket.id, pageEventOf(r.assignEvent), r.ticket) }
  548. emit client ticketsRelated(relatedViews(r.ticket.id, []))
  549. return { ok = true }
  550. }
  551. // mission 016: the comment's author edits / deletes it, a member likes it (again = takes it back) — lib/comments.hl decides
  552. on server ticketCommentEdit(ticketId, commentId, text, session) {
  553. w = writerOfSession(session)
  554. if (w.error != null) { return { error = w.error } }
  555. if (hlTypeName(text) != 'String') { return { error = 'the comment must be text' } }
  556. r = changeComment('' + ticketId, '' + commentId, w.user, 'edit', text)
  557. if (r.error != null) { return { error = r.error } }
  558. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  559. return { ok = true }
  560. }
  561. on server ticketCommentDelete(ticketId, commentId, session) {
  562. w = writerOfSession(session)
  563. if (w.error != null) { return { error = w.error } }
  564. r = changeComment('' + ticketId, '' + commentId, w.user, 'delete', '')
  565. if (r.error != null) { return { error = r.error } }
  566. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  567. return { ok = true }
  568. }
  569. on server ticketCommentLike(ticketId, commentId, session) {
  570. w = writerOfSession(session)
  571. if (w.error != null) { return { error = w.error } }
  572. r = changeComment('' + ticketId, '' + commentId, w.user, 'like', '')
  573. if (r.error != null) { return { error = r.error } }
  574. emit client commentChanged(r.ticket.id, pageEventOf(r.event))
  575. return { ok = true }
  576. }
  577. // ticket #20: assign the ticket to a member ('' = nobody); the store wants the role edit or admin
  578. on server ticketAssign(ticketId, userId, session) {
  579. w = writerOfSession(session)
  580. if (w.error != null) { return { error = w.error } }
  581. if (hlTypeName(userId) != 'String') { return { error = 'the assignee must be text' } }
  582. r = assignTicket('' + ticketId, w.user, userId)
  583. if (r.error != null) { return { error = r.error } }
  584. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  585. return { ok = true }
  586. }
  587. // ticket #8: the author edits subject + summary (the store refuses anyone else)
  588. on server ticketEdit(ticketId, subject, summary, session) {
  589. w = writerOfSession(session)
  590. if (w.error != null) { return { error = w.error } }
  591. if (hlTypeName(subject) != 'String' || hlTypeName(summary) != 'String') { return { error = 'subject and summary must be text' } }
  592. r = editTicket('' + ticketId, w.user, subject, summary)
  593. if (r.error != null) { return { error = r.error } }
  594. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  595. emit client ticketsRelated(relatedViews(r.ticket.id, []))
  596. return { ok = true }
  597. }
  598. // ticket #4: relations — the store refuses a user who may not (author of either ticket / creator)
  599. on server ticketSetParent(ticketId, key, session) {
  600. w = writerOfSession(session)
  601. if (w.error != null) { return { error = w.error } }
  602. if (hlTypeName(key) != 'String') { return { error = 'the parent must be text' } }
  603. r = setParent('' + ticketId, w.user, key)
  604. if (r.error != null) { return { error = r.error } }
  605. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  606. emit client ticketsRelated(r.related)
  607. return { ok = true }
  608. }
  609. on server ticketAddBlocker(ticketId, key, session) {
  610. w = writerOfSession(session)
  611. if (w.error != null) { return { error = w.error } }
  612. if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }
  613. r = changeBlocker('' + ticketId, w.user, key, true, 'add')
  614. if (r.error != null) { return { error = r.error } }
  615. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  616. emit client ticketsRelated(r.related)
  617. return { ok = true }
  618. }
  619. on server ticketRemoveBlocker(ticketId, key, session) {
  620. w = writerOfSession(session)
  621. if (w.error != null) { return { error = w.error } }
  622. if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }
  623. r = changeBlocker('' + ticketId, w.user, key, false, 'remove')
  624. if (r.error != null) { return { error = r.error } }
  625. emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)
  626. emit client ticketsRelated(r.related)
  627. return { ok = true }
  628. }
  629. // what the session's user may do on this ticket: comment (a member), edit / assign (edit, admin), the states
  630. // they may move it to, and the members it can be assigned to
  631. on server ticketRights(ticketId, session) {
  632. u = userOfSession(session)
  633. if (u == null) { return { error = 'log in first' } }
  634. t = ticketRecord('' + ticketId)
  635. if (t == null) { return { error = 'no such ticket' } }
  636. r = ticketRights(t, u)
  637. // mission 016: who the comment blocks compare authors with, and whose likes count as "liked"
  638. r.name = u.name
  639. r.userId = u.id
  640. return r
  641. }

Branches

Latest commits

  • 28e9c938ticket list: draw the newest 50 rows and a Show more button (500 rows were a 2-4 s first paint, 740 KB, a 90 000 px phone page)mre
  • ccebb0c7mobile: ticket number stays on one line, filter chips one scrolling row, fields full width under their caption, Edit/action buttons, member names whole, 44 px relation linksmre
  • f2dc7741gate: the phone toolbar is two even rows (E2)mre
  • 20f7c33async components.hybriel 214c318: MdEditor on a phone, two even toolbar rows of 44 px targets, label 15 px, table head 16 px (E2)mre
  • d74a5482sync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
  • 9d02c540sync components.hybriel 6b0936a: the 'edited' foldable drops the theme's border and marginmre
  • 22751914sync components.hybriel 8d79ff7: bubble hugs its content, quiet 'edited' label; gate checksmre
  • c8452453sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
  • 52ba11e8sync-components: copy icons/icons.hl + README (F4); testsmre
  • 138d198dmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
  • 18d2df60md-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
  • f6764bedreports/H1-hydrate.mdmre
  • 1bbbf0edtests/browser.mjs: wait for hydration before clicking the login button on / (device B)mre
  • 6f503cfctests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
  • e17e2855re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • a6ddccd2re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • 81e036b7docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 5d8d2cf6deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • 58e8c02cmission 024: report, LOG, STATUS, e2e fixmre
  • 50778073tests/e2e-route-marker.mjs: first paint marker, comments post/edit redrawmre