gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit1bbbf0ed1bbbf0edtests/browser.mjs: wait for hydration before clicking the login button on / (device B)mre1bbbf0ed/components/ticket_list.hl

9.8 KB

  1. // components/ticket_list.hl — `/`, `/project/:projectName` (also `/:projectName`, ticket #25),
  2. // `/state/:stateSlug` and both:
  3. // the tickets, newest update first, filtered by project and state, and the form that
  4. // opens a new ticket. Live: a ticket created or changed anywhere (web or API) lands in,
  5. // moves within or leaves this list without a reload. Ticket #12: the summary is edited visually — since mission 016 in the
  6. // Hybriel MdEditor (components/md-editor/; its hidden field keeps the Markdown and fires `input`).
  7. // Ticket #20: a project's page (`/<slug>`, also `/project/<slug>`; `/projects/<slug>` answers 301) shows its title, description
  8. // (Markdown), its tickets and — for an admin — the link to its settings page. The new-ticket form needs the
  9. // role edit or admin: its project choice holds only the projects the user may open tickets in.
  10. parent './main.hl'
  11. import { ticketRows, createTicket } from '../lib/tickets.hl'
  12. import { projectLinks, stateLinks, stateOfSlug } from '../lib/tickets-helpers.hl'
  13. import { projectByAnySlug, editableProjects, isAdminOf } from '../lib/projects.hl'
  14. import { markdownBlocks } from '../lib/markdown.hl'
  15. import { siteName } from '../project.hl'
  16. import { canWriteSession, writerOfSession, userOfSession } from '../lib/users.hl'
  17. import { connectionRows, disconnect } from '../lib/connections.hl'
  18. import Markdown from './markdown.hl'
  19. import MdEditor from './md-editor/md-editor.hl'
  20. projectName = null
  21. stateSlug = null
  22. filterState = stateOfSlug(stateSlug)
  23. rows = ticketRows(projectName, filterState)
  24. projects = projectLinks(projectName, filterState)
  25. stateFilters = stateLinks(projectName, filterState)
  26. session = null
  27. project = projectName != null ? projectByAnySlug(projectName) : null
  28. noSuchProject = projectName != null && project == null
  29. projectId = project != null ? project.id : ''
  30. hasDescription = project != null && project.description != null && project.description != ''
  31. descriptionMd = hasDescription ? markdownBlocks(project.description) : []
  32. isAdmin = project != null && isAdminOf(project.id, userOfSession(session))
  33. // ticket #21: the apps connected to this project (connections.hl), shown to everybody; an admin can disconnect
  34. connections = project != null ? connectionRows(project.id) : []
  35. hasConnections = connections.length > 0
  36. connectionMessage = ''
  37. settingsHref = project != null ? '/projects/' + project.slug + '/settings' : ''
  38. isEmpty = rows.length == 0
  39. heading = (projectName != null ? (project != null ? project.title : projectName) : 'All projects') + (filterState != null ? ' · ' + filterState : '')
  40. __title = siteName + ' | ' + heading
  41. // the new-ticket form
  42. myProjects = editableProjects(userOfSession(session))
  43. newProject = projectName != null && project != null ? project.slug : (myProjects.length > 0 ? myProjects[0].slug : '')
  44. newSubject = ''
  45. newSummary = ''
  46. // the MdEditor is built once per element: a new key gives the next ticket an empty editor
  47. summarySeq = 0
  48. summaryForms = [{ id = 'summary-0' }]
  49. // only for a member with the role edit or admin (ticket #20): the author is that user
  50. canWrite = myProjects.length > 0
  51. canCreateProject = canWriteSession(session)
  52. mustLogIn = userOfSession(session) == null
  53. noRole = userOfSession(session) != null && myProjects.length == 0
  54. notice = ''
  55. noticeHref = ''
  56. hasNotice = false
  57. View {
  58. ticketBoard {
  59. h1 { id = "heading" heading }
  60. ticketFilters {
  61. nav { id = "projectfilter"
  62. for (f of projects) { a { href = f.href class = f.cls f.label } }
  63. }
  64. nav { id = "statefilter"
  65. for (f of stateFilters) { a { href = f.href class = f.cls f.label } }
  66. }
  67. }
  68. if (noSuchProject) { p { id = "noproject" class = "empty" "There is no such project." } }
  69. if (hasDescription) { projectDescription { id = "description" Markdown { blocks = descriptionMd } } }
  70. if (hasConnections) { ul { id = "connections" class = "connections"
  71. for (c of connections) {
  72. li { class = "connection"
  73. "Connected to " strong { c.text }
  74. if (isAdmin) { button { type = "button" class = "quiet danger disconnect" "Disconnect" on click(e) { emit dropConnection(c.id) } } }
  75. }
  76. }
  77. } }
  78. p { id = "connectionmessage" class = "message" connectionMessage }
  79. projectActions {
  80. if (canCreateProject) { a { id = "newprojectlink" class = "button" href = "/new-project" "New project" } }
  81. if (isAdmin) { a { id = "settingslink" class = "button" href = settingsHref "Project settings" } }
  82. }
  83. if (mustLogIn) { p { id = "loginhint" class = "hint" "Reading is open to everyone. To open a ticket, log in with ident (top right)." } }
  84. if (noRole) { p { id = "rolehint" class = "hint" "To open a ticket you need the role edit or admin in a project — ask an admin of the project to invite you." } }
  85. if (canWrite) { details { id = "newticket"
  86. summary { "New ticket" }
  87. form { id = "newticketform"
  88. on submit(e) {
  89. e.preventDefault()
  90. emit create(e)
  91. }
  92. label { "Project"
  93. select { id = "newproject" name = "project" value = newProject on change(e) { emit setProject(e.target.value) }
  94. for (p of myProjects) { option { value = p.slug p.title } }
  95. }
  96. }
  97. label { "Subject"
  98. input { id = "newsubject" name = "subject" required = "required" maxlength = "200" value = newSubject on input(e) { emit setSubject(e.target.value) } }
  99. }
  100. mdField { id = "newsummary" on input(e) { emit setSummary(e.target.name, e.target.value) }
  101. span { "Summary" }
  102. for (f of summaryForms) { MdEditor { name = "summary" value = "" rows = 4 placeholder = "" files = "off" } }
  103. }
  104. button { id = "newsubmit" type = "submit" "Open ticket" }
  105. }
  106. } }
  107. if (hasNotice) { p { id = "notice" class = "notice" notice " " a { id = "noticelink" href = noticeHref "open it" } } }
  108. if (isEmpty) { p { id = "empty" class = "empty" "No tickets here." } }
  109. ol { id = "tickets" class = "tickets"
  110. for (row of rows) {
  111. li {
  112. ticketState { class = row.stateSlug row.state }
  113. a { class = "subject" href = row.href ticketRef { row.ref } row.subject }
  114. ticketMeta {
  115. a { href = row.projectHref row.projectTitle }
  116. if (row.hasAssignee) { assignee { row.assignee } }
  117. time { row.updated }
  118. }
  119. }
  120. }
  121. }
  122. }
  123. }
  124. on setProject(v) { newProject = v }
  125. on setSubject(v) { newSubject = v }
  126. // the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not it
  127. on setSummary(name, v) { if (name == 'summary') { newSummary = v } }
  128. on create(e) {
  129. if (newProject.trim() == '' || newSubject.trim() == '') { return null }
  130. r = emit server openTicket(newProject, newSubject, newSummary)
  131. if (r != null && r.error == null) {
  132. notice = 'Opened ' + r.project + ' ' + r.ref + '.'
  133. noticeHref = r.href
  134. hasNotice = true
  135. newSubject = ''
  136. newSummary = ''
  137. summarySeq = summarySeq + 1
  138. summaryForms = [{ id = 'summary-' + summarySeq }]
  139. } else {
  140. notice = r != null ? r.error : 'could not open the ticket'
  141. noticeHref = ''
  142. hasNotice = true
  143. }
  144. }
  145. // does a row belong in THIS list (its filters)?
  146. belongs = (row) => {
  147. return (projectName == null || row.projectId == projectId) && (filterState == null || row.state == filterState)
  148. }
  149. // the row goes to the top (newest update first) if it belongs, and out if not
  150. place = (row) => {
  151. next = []
  152. if (belongs(row)) { next.push(row) }
  153. for (r of rows) { if (r.id != row.id) { next.push(r) } }
  154. rows = next
  155. isEmpty = next.length == 0
  156. }
  157. on client ticketCreated(row) { place(row) }
  158. on dropConnection(id) {
  159. r = emit server disconnectApp(projectId, id)
  160. if (r == null || r.error != null) {
  161. connectionMessage = r != null ? r.error : 'could not disconnect'
  162. return null
  163. }
  164. connectionMessage = ''
  165. connections = r.connections
  166. hasConnections = r.connections.length > 0
  167. }
  168. on client connectionsChanged(slug) {
  169. r = emit server connectionsOfProject(projectId)
  170. if (r != null && r.connections != null) {
  171. connections = r.connections
  172. hasConnections = r.connections.length > 0
  173. }
  174. }
  175. on client signedIn(tag, info) {
  176. r = emit server whatICanOpen(projectName != null ? projectName : '')
  177. if (r != null && r.projects != null) {
  178. myProjects = r.projects
  179. canWrite = r.projects.length > 0
  180. noRole = r.projects.length == 0 && info.named
  181. canCreateProject = info.named
  182. mustLogIn = false
  183. isAdmin = r.admin == true
  184. if (newProject == '' && r.projects.length > 0) { newProject = r.projects[0].slug }
  185. }
  186. }
  187. on client signedOut(tag) {
  188. canWrite = false
  189. canCreateProject = false
  190. isAdmin = false
  191. noRole = false
  192. mustLogIn = true
  193. myProjects = []
  194. }
  195. on client ticketEvent(ticketId, ev, row) { place(row) }
  196. // THE FACE: a ticket opened from the web by the session's user (#31: only a real session).
  197. // The same push the API sends.
  198. on server openTicket(project, subject, summary, session) {
  199. w = writerOfSession(session)
  200. if (w.error != null) { return { error = w.error } }
  201. r = createTicket(project, subject, summary, w.user, null, null)
  202. if (r.error != null) { return { error = r.error } }
  203. emit client ticketCreated(r.ticket)
  204. return r.ticket
  205. }
  206. // what this session's user may do here after a login without a reload: the projects they may open tickets in,
  207. // and whether they are an admin of THIS page's project (`slug` null = the all-projects page)
  208. on server whatICanOpen(slug, session) {
  209. u = userOfSession(session)
  210. if (u == null) { return { error = 'log in first' } }
  211. p = slug != null && slug != '' ? projectByAnySlug(slug) : null
  212. return { projects = editableProjects(u) admin = p != null && isAdminOf(p.id, u) }
  213. }
  214. // ticket #21: an admin ends a connection — the key is dead at once (connections.hl)
  215. on server disconnectApp(projectId, connectionId, session) {
  216. w = writerOfSession(session)
  217. if (w.error != null) { return { error = w.error } }
  218. r = disconnect('' + projectId, w.user, '' + connectionId)
  219. if (r.error != null) { return { error = r.error } }
  220. emit client connectionsChanged('')
  221. return { connections = r.connections }
  222. }
  223. on server connectionsOfProject(projectId, session) {
  224. return { connections = connectionRows('' + projectId) }
  225. }

Branches

Latest commits

  • 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
  • c5203298mission 024: MainMenu marks the page from the route (layouts 0bcc629 main-menu.hl); browser-side marker removed; gate: marker in the server HTMLmre
  • b1a4c270re-vendor Hybriel master f9614007: bin/ (git-ignored) and plugins wholemre
  • 866397a0mission 023: theme from layouts 76f99f6 (current marker, menu count badge), components from 3794c59 (MdEditor keys); Inbox count as badge, current by address; gates and E2E; reportmre
  • 7ed2e5e5deploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the script silently (grep under pipefail), as gitoria/layoutsmre
  • bf9064a3mission 022: tickets on the layouts theme (step 1): shell, styles, gates, audit, E2E; reportmre
  • f3d61711mission 022 WIP: tickets on the layouts theme (dbe3de7): AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst shell, styles reduced to the app's own, check-theme in the gates, 390 audit + real-Chrome walk scriptmre
  • 31cabfccmission 021: E2E script, report, LOG, STATUSmre
  • 6aea8683editor look: .empty rule only for p.empty, files off where tickets has no upload, state note one line, events test scrolls the editor into view; synced md-editor (components d702d76+6f27ad3); gate 377/0, events 52/0mre
  • dce6ffa6Merge branch 'w28-deflake'mre
  • 536092a1tickets (mission 019): de-flake the m016 comment clicks (B: unliked) — calmClick waits until the button stops moving; test only, no app changemre
  • 9c5fd42amission 020: attachments E2E proof (lisbeth Chrome, real-data copy), reportmre
  • 1206404fREADME attachments, report 018, LOG/STATUSmre