gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit40fddc2040fddc20tickets takes components e54f83a: tables get thin grey lines from the theme, desktop toolbar stays one row with the Table button, F4 check counts 11 buttonsmre40fddc20/components/ticket.hl

28.5 KB

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

Branches

Latest commits

  • 40fddc20tickets takes components e54f83a: tables get thin grey lines from the theme, desktop toolbar stays one row with the Table button, F4 check counts 11 buttonsmre
  • c1b77d61tickets#35: text typed before the editor is built is taken in once by the build (the input handler no longer writes it to the field first, which doubled the first letters); the gate failure shows the surfacemre
  • 32bf1873tickets#35: the gate types right after the load with the CPU slowed, no waitingmre
  • 64ea9ca2tickets#35: text typed into the reply editor before the page has finished starting is kept; the gate types right after loadmre
  • ccd3a327tickets: the security gate expects frame-src to be exactly the ident address (the sign-in frame), still no wildcard or selfmre
  • 4348dbabident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 66ef3005Merge branch 'iw-ident-widget'mre
  • bc0ad663tickets: a gap between your name and Log out in the phone header (they touched); gate checks itmre
  • 2f818d46UX2: report, LOG line, e2e fixes, gate pause after loadmre
  • af3ef7c4gate: the legacy state line says progressmre
  • 62480a00tickets#33: a state change with a note is a comment card in the feed (same framework rendering, can be liked, edited, deleted), its state line stands alone; gate checks for a new comment with and without a state change, at once and after a reloadmre
  • 4ae80007UX: Respond is one composer (state in its footer, button says what happens); New ticket / New project windows in the list heading row; project form shared; theme copied from layouts; gates and a lisbeth e2emre
  • f03b438atickets header: the selector alone top right plus your name and Log out as before the theme missions; the user icon is gonemre
  • 81f10e4eident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • e9f428e7tools: reown-authors (tracker#36: every author that is not Caramboleyo or Apollo becomes the project's conductor; antcolony, miserit-anthar, hybrilior, termuplex stay) and a read-only author surveymre
  • f51029abMerge branch 'sy-sync'mre
  • eae6e8c7sync components.hybriel 4922f9c: comments like / Edit / Delete / 'edited' are 44 px targets; gate: 'edited' hit-area padding, thread targets check (SY)mre
  • 0de4750btheme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 4eeb7bfeST2 report wordingmre
  • 2558f56cst2-sec: keep the hlsid session cookie name (no one is signed out), Secure flag only; gate: a cookie issued by main stays signed in; ident stub serves selector.js; security.mjs in deploy GATESmre