gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2558f56c2558f56cst2-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 GATESmre2558f56c/components/ticket_list.hl

11.4 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, firstRows, 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. // the page draws the newest 50 and a button asks for 50 more: all ~500 rows at once (server-built, shipped, drawn) were a 2–4 s first
  24. // paint and a 90 000 px page on a phone. `total` = how many tickets the filters match
  25. pageSize = 50
  26. limit = pageSize
  27. first = firstRows(projectName, filterState, limit)
  28. rows = first.rows
  29. total = first.total
  30. projects = projectLinks(projectName, filterState)
  31. stateFilters = stateLinks(projectName, filterState)
  32. session = null
  33. project = projectName != null ? projectByAnySlug(projectName) : null
  34. noSuchProject = projectName != null && project == null
  35. projectId = project != null ? project.id : ''
  36. hasDescription = project != null && project.description != null && project.description != ''
  37. descriptionMd = hasDescription ? markdownBlocks(project.description) : []
  38. isAdmin = project != null && isAdminOf(project.id, userOfSession(session))
  39. // ticket #21: the apps connected to this project (connections.hl), shown to everybody; an admin can disconnect
  40. connections = project != null ? connectionRows(project.id) : []
  41. hasConnections = connections.length > 0
  42. connectionMessage = ''
  43. settingsHref = project != null ? '/projects/' + project.slug + '/settings' : ''
  44. isEmpty = rows.length == 0
  45. hasMore = rows.length < total
  46. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  47. heading = (projectName != null ? (project != null ? project.title : projectName) : 'All projects') + (filterState != null ? ' · ' + filterState : '')
  48. __title = siteName + ' | ' + heading
  49. // the new-ticket form
  50. myProjects = editableProjects(userOfSession(session))
  51. newProject = projectName != null && project != null ? project.slug : (myProjects.length > 0 ? myProjects[0].slug : '')
  52. newSubject = ''
  53. newSummary = ''
  54. // the MdEditor is built once per element: a new key gives the next ticket an empty editor
  55. summarySeq = 0
  56. summaryForms = [{ id = 'summary-0' }]
  57. // only for a member with the role edit or admin (ticket #20): the author is that user
  58. canWrite = myProjects.length > 0
  59. canCreateProject = canWriteSession(session)
  60. mustLogIn = userOfSession(session) == null
  61. noRole = userOfSession(session) != null && myProjects.length == 0
  62. notice = ''
  63. noticeHref = ''
  64. hasNotice = false
  65. View {
  66. ticketBoard {
  67. h1 { id = "heading" heading }
  68. ticketFilters {
  69. nav { id = "projectfilter"
  70. for (f of projects) { a { href = f.href class = f.cls f.label } }
  71. }
  72. nav { id = "statefilter"
  73. for (f of stateFilters) { a { href = f.href class = f.cls f.label } }
  74. }
  75. }
  76. if (noSuchProject) { p { id = "noproject" class = "empty" "There is no such project." } }
  77. if (hasDescription) { projectDescription { id = "description" Markdown { blocks = descriptionMd } } }
  78. if (hasConnections) { ul { id = "connections" class = "connections"
  79. for (c of connections) {
  80. li { class = "connection"
  81. "Connected to " strong { c.text }
  82. if (isAdmin) { button { type = "button" class = "quiet danger disconnect" "Disconnect" on click(e) { emit dropConnection(c.id) } } }
  83. }
  84. }
  85. } }
  86. p { id = "connectionmessage" class = "message" connectionMessage }
  87. projectActions {
  88. if (canCreateProject) { a { id = "newprojectlink" class = "button" href = "/new-project" "New project" } }
  89. if (isAdmin) { a { id = "settingslink" class = "button" href = settingsHref "Project settings" } }
  90. }
  91. if (mustLogIn) { p { id = "loginhint" class = "hint" "Reading is open to everyone. To open a ticket, log in with ident (top right)." } }
  92. 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." } }
  93. if (canWrite) { details { id = "newticket"
  94. summary { "New ticket" }
  95. form { id = "newticketform"
  96. on submit(e) {
  97. e.preventDefault()
  98. emit create(e)
  99. }
  100. label { "Project"
  101. select { id = "newproject" name = "project" value = newProject on change(e) { emit setProject(e.target.value) }
  102. for (p of myProjects) { option { value = p.slug p.title } }
  103. }
  104. }
  105. label { "Subject"
  106. input { id = "newsubject" name = "subject" required = "required" maxlength = "200" value = newSubject on input(e) { emit setSubject(e.target.value) } }
  107. }
  108. mdField { id = "newsummary" on input(e) { emit setSummary(e.target.name, e.target.value) }
  109. span { "Summary" }
  110. for (f of summaryForms) { MdEditor { name = "summary" value = "" rows = 4 placeholder = "" files = "off" } }
  111. }
  112. button { id = "newsubmit" type = "submit" "Open ticket" }
  113. }
  114. } }
  115. if (hasNotice) { p { id = "notice" class = "notice" notice " " a { id = "noticelink" href = noticeHref "open it" } } }
  116. if (isEmpty) { p { id = "empty" class = "empty" "No tickets here." } }
  117. ol { id = "tickets" class = "tickets"
  118. for (row of rows) {
  119. li {
  120. ticketState { class = row.stateSlug row.state }
  121. a { class = "subject" href = row.href ticketRef { row.ref } row.subject }
  122. ticketMeta {
  123. a { href = row.projectHref row.projectTitle }
  124. if (row.hasAssignee) { assignee { row.assignee } }
  125. time { row.updated }
  126. }
  127. }
  128. }
  129. }
  130. if (hasMore) { button { id = "moretickets" type = "button" class = "quiet" moreLabel on click(e) { emit showMore(e) } } }
  131. }
  132. }
  133. on showMore(e) {
  134. limit = limit + pageSize
  135. r = emit server moreRows(projectName != null ? projectName : '', filterState != null ? filterState : '', limit)
  136. if (r != null && r.rows != null) {
  137. rows = r.rows
  138. total = r.total
  139. isEmpty = rows.length == 0
  140. hasMore = rows.length < total
  141. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  142. }
  143. }
  144. on server moreRows(project, state, n, session) {
  145. return firstRows(project != '' ? project : null, state != '' ? state : null, n)
  146. }
  147. on setProject(v) { newProject = v }
  148. on setSubject(v) { newSubject = v }
  149. // the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not it
  150. on setSummary(name, v) { if (name == 'summary') { newSummary = v } }
  151. on create(e) {
  152. if (newProject.trim() == '' || newSubject.trim() == '') { return null }
  153. r = emit server openTicket(newProject, newSubject, newSummary)
  154. if (r != null && r.error == null) {
  155. notice = 'Opened ' + r.project + ' ' + r.ref + '.'
  156. noticeHref = r.href
  157. hasNotice = true
  158. newSubject = ''
  159. newSummary = ''
  160. summarySeq = summarySeq + 1
  161. summaryForms = [{ id = 'summary-' + summarySeq }]
  162. } else {
  163. notice = r != null ? r.error : 'could not open the ticket'
  164. noticeHref = ''
  165. hasNotice = true
  166. }
  167. }
  168. // does a row belong in THIS list (its filters)?
  169. belongs = (row) => {
  170. return (projectName == null || row.projectId == projectId) && (filterState == null || row.state == filterState)
  171. }
  172. // the row goes to the top (newest update first) if it belongs, and out if not
  173. place = (row) => {
  174. let wasIn = false
  175. for (r of rows) { if (r.id == row.id) { wasIn = true } }
  176. let allShown = rows.length >= total
  177. next = []
  178. if (belongs(row)) { next.push(row) }
  179. for (r of rows) { if (r.id != row.id) { next.push(r) } }
  180. // a new ticket joins the count when everything was on the page; one that left the filter leaves it
  181. if (belongs(row) && !wasIn && allShown) { total = total + 1 }
  182. if (!belongs(row) && wasIn) { total = total - 1 }
  183. if (allShown && next.length > limit) { limit = next.length }
  184. rows = next.length > limit ? next.slice(0, limit) : next
  185. isEmpty = rows.length == 0
  186. hasMore = rows.length < total
  187. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  188. }
  189. on client ticketCreated(row) { place(row) }
  190. on dropConnection(id) {
  191. r = emit server disconnectApp(projectId, id)
  192. if (r == null || r.error != null) {
  193. connectionMessage = r != null ? r.error : 'could not disconnect'
  194. return null
  195. }
  196. connectionMessage = ''
  197. connections = r.connections
  198. hasConnections = r.connections.length > 0
  199. }
  200. on client connectionsChanged(slug) {
  201. r = emit server connectionsOfProject(projectId)
  202. if (r != null && r.connections != null) {
  203. connections = r.connections
  204. hasConnections = r.connections.length > 0
  205. }
  206. }
  207. on client signedIn(tag, info) {
  208. r = emit server whatICanOpen(projectName != null ? projectName : '')
  209. if (r != null && r.projects != null) {
  210. myProjects = r.projects
  211. canWrite = r.projects.length > 0
  212. noRole = r.projects.length == 0 && info.named
  213. canCreateProject = info.named
  214. mustLogIn = false
  215. isAdmin = r.admin == true
  216. if (newProject == '' && r.projects.length > 0) { newProject = r.projects[0].slug }
  217. }
  218. }
  219. on client signedOut(tag) {
  220. canWrite = false
  221. canCreateProject = false
  222. isAdmin = false
  223. noRole = false
  224. mustLogIn = true
  225. myProjects = []
  226. }
  227. on client ticketEvent(ticketId, ev, row) { place(row) }
  228. // THE FACE: a ticket opened from the web by the session's user (#31: only a real session).
  229. // The same push the API sends.
  230. on server openTicket(project, subject, summary, session) {
  231. w = writerOfSession(session)
  232. if (w.error != null) { return { error = w.error } }
  233. r = createTicket(project, subject, summary, w.user, null, null)
  234. if (r.error != null) { return { error = r.error } }
  235. emit client ticketCreated(r.ticket)
  236. return r.ticket
  237. }
  238. // what this session's user may do here after a login without a reload: the projects they may open tickets in,
  239. // and whether they are an admin of THIS page's project (`slug` null = the all-projects page)
  240. on server whatICanOpen(slug, session) {
  241. u = userOfSession(session)
  242. if (u == null) { return { error = 'log in first' } }
  243. p = slug != null && slug != '' ? projectByAnySlug(slug) : null
  244. return { projects = editableProjects(u) admin = p != null && isAdminOf(p.id, u) }
  245. }
  246. // ticket #21: an admin ends a connection — the key is dead at once (connections.hl)
  247. on server disconnectApp(projectId, connectionId, session) {
  248. w = writerOfSession(session)
  249. if (w.error != null) { return { error = w.error } }
  250. r = disconnect('' + projectId, w.user, '' + connectionId)
  251. if (r.error != null) { return { error = r.error } }
  252. emit client connectionsChanged('')
  253. return { connections = r.connections }
  254. }
  255. on server connectionsOfProject(projectId, session) {
  256. return { connections = connectionRows('' + projectId) }
  257. }

Branches

Latest commits

  • 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
  • ea2e440esecurity audit (ST): JSON body cap, relation rights, login session rotation, __Host- Secure cookie, API security headers, CSP+referrer meta, /connect cap, one-line subjects, tests/security.mjs, reportmre
  • 7c8c2282sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • b6277497report MT-mobile, LOGmre
  • 6709398blist paging: the newest rows come first (the sorted array was not used); filter rows hide their scrollbar; gate checks the ordermre
  • 31736a80gate: member-name check fails on the old row layout toomre
  • e03ae537gate: the phone checks run on without the Show more button (so old code reports every failed check)mre
  • adf7f132gate: 390 px checks for the mobile audit fixes (row number, filters, field widths, Edit, member names, relation taps, paging)mre
  • 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