gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit07ab845b07ab845bvendor: Hybriel set-day50 (run() leak fix #335)mre07ab845b/components/tickets.hl

6.9 KB

  1. // components/tickets.hl — THE TICKETS of a repo (gitoria#10, gitoria#16): `/tickets` on <slug>.<domain>, its own
  2. // route, rendered on the SERVER with its list: the repo comes from the request's host, the tickets from
  3. // tickets.worldapi.org (lib/tickets.hl — hl:fetch answers at once, so the list is in the first HTML and in every
  4. // hl:web navigation). The repo must be connected to a tickets project first (gitoria#18, /settings). A named user
  5. // opens a ticket AS THEMSELVES (the repo's key + their ident id, tickets.hl); a ticket opened here reaches every open
  6. // tickets page of the repo (push `ticketOpened`).
  7. parent './repo.hl'
  8. import { siteName } from '../project.hl'
  9. import { slugOfRequest } from '../lib/orgs.hl'
  10. import { infoOfSession, userOfSession } from '../lib/users.hl'
  11. import { titleSlug, repoAt } from '../lib/repos.hl'
  12. import { pageTitle } from '../lib/repos-helpers.hl'
  13. import { loadTickets, openTicket } from '../lib/tickets.hl'
  14. host = null
  15. orepo = ''
  16. session = null
  17. slug = slugOfRequest(host, orepo)
  18. repo = repoAt(slug, session)
  19. hasRepo = repo != null
  20. me = infoOfSession(session)
  21. canCreate = repo != null && repo.ticketsOn && me != null && me.named
  22. needsLogin = repo != null && repo.ticketsOn && me == null
  23. notConnected = repo != null && repo.ticketsOff
  24. loaded = repo != null && repo.ticketsOn ? loadTickets(slug) : null
  25. ticketsErrorShown = loaded != null && loaded.error != null
  26. ticketsError = loaded != null && loaded.error != null ? loaded.error : ''
  27. tickets = loaded != null && loaded.tickets != null ? loaded.tickets : []
  28. ticketsTruncated = loaded != null && loaded.truncated == true
  29. ticketsHref = loaded != null && loaded.url != null ? loaded.url : ''
  30. ticketsShown = tickets.length > 0
  31. ticketsNone = loaded != null && loaded.error == null && tickets.length == 0
  32. ticketSubject = ''
  33. ticketSummary = ''
  34. ticketError = ''
  35. ticketNotice = ''
  36. hasTicketNotice = false
  37. __title = pageTitle(siteName, titleSlug(host, orepo, session), 'Tickets')
  38. View {
  39. repoPage {
  40. if (hasRepo) {
  41. repoTickets { id = "tickets"
  42. if (notConnected) { p { id = "ticketsnotconnected" class = "empty" "This repository is not connected to a tickets project. The owner connects it under " a { id = "tosettings" href = "/settings" "Settings" } "." } }
  43. if (ticketsErrorShown) { p { id = "ticketserror" ticketsError } }
  44. if (canCreate) {
  45. details { id = "newticket"
  46. summary { "New ticket" }
  47. form { id = "newticketform"
  48. on submit(e) {
  49. e.preventDefault()
  50. emit openIt(e)
  51. }
  52. label { "Subject"
  53. input { id = "ticketsubject" name = "subject" required = "required" maxlength = "200" autocomplete = "off" value = ticketSubject on input(e) { ticketSubject = e.target.value } }
  54. }
  55. label { "Text (Markdown, optional)"
  56. textarea { id = "ticketsummary" name = "summary" rows = "5" value = ticketSummary on input(e) { ticketSummary = e.target.value } }
  57. }
  58. button { id = "ticketsave" type = "submit" "Open ticket" }
  59. p { id = "newticketerror" ticketError }
  60. }
  61. }
  62. }
  63. if (needsLogin) { p { id = "ticketsloginhint" class = "muted" "Log in with ident (top right) to open a ticket." } }
  64. if (hasTicketNotice) { p { id = "ticketnotice" ticketNotice } }
  65. if (ticketsNone) { p { id = "noticketsyet" class = "empty" "No ticket yet in this project." } }
  66. if (ticketsShown) {
  67. ol { id = "ticketlist"
  68. for (t of tickets) {
  69. li {
  70. a { Style.aNumber href = t.url "#" t.number }
  71. a { Style.aTicketSubject href = t.url t.subject }
  72. span { t.state }
  73. time { t.updated }
  74. }
  75. }
  76. }
  77. p { class = "muted" "Open a ticket to read and answer it in " a { id = "ticketsall" href = ticketsHref "tickets.worldapi.org" } "." }
  78. if (ticketsTruncated) { p { id = "ticketstruncated" class = "muted" "Only the latest tickets are listed here." } }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. on openIt(e) {
  85. r = emit server gitoriaOpenTicket(slug, ticketSubject, ticketSummary)
  86. if (r == null || r.error != null) {
  87. ticketError = r != null ? r.error : 'could not open the ticket'
  88. return null
  89. }
  90. ticketError = ''
  91. ticketSubject = ''
  92. ticketSummary = ''
  93. ticketNotice = 'Opened ticket #' + r.ticket.number + '.'
  94. hasTicketNotice = true
  95. addTicket(r.ticket)
  96. }
  97. addTicket = (row) => {
  98. next = [row]
  99. for (x of tickets) { if (x.number != row.number) { next.push(x) } }
  100. tickets = next
  101. ticketsShown = true
  102. ticketsNone = false
  103. }
  104. // a ticket opened here by anyone: every open tickets page of that repo follows
  105. on client ticketOpened(slugOf, row) {
  106. if (!hasRepo || slugOf != slug) { return null }
  107. addTicket(row)
  108. }
  109. // this session's tabs follow a login / name / logout (the shell's faces push them)
  110. on client gitoriaSignedIn(tag, info) {
  111. canCreate = repo != null && repo.ticketsOn && info.named
  112. needsLogin = false
  113. }
  114. on client gitoriaSignedOut(tag) {
  115. canCreate = false
  116. needsLogin = repo != null && repo.ticketsOn
  117. }
  118. on server gitoriaOpenTicket(slugOf, subject, summary, session) {
  119. if (repoAt(slugOf, session) == null) { return { error = 'no such repository' } }
  120. u = userOfSession(session)
  121. if (u == null) { return { error = 'log in with ident (top right) to open a ticket' } }
  122. if (u.name == '') { return { error = 'choose a display name first (top of the page)' } }
  123. r = openTicket(slugOf, u.identity, subject, summary)
  124. if (r.error != null) { return { error = r.error } }
  125. emit client ticketOpened(slugOf, r.ticket)
  126. return r
  127. }
  128. Style {
  129. repoTickets {
  130. display = 'grid'
  131. gap = '1rem'
  132. minWidth = '0'
  133. // Direct-child and sibling combinators have no bare language form.
  134. '> *' {
  135. margin = '0'
  136. }
  137. }
  138. #newticketform {
  139. display = 'grid'
  140. gap = '.75rem'
  141. // Direct-child and sibling combinators have no bare language form.
  142. '> *' {
  143. margin = '0'
  144. }
  145. }
  146. #newticket {
  147. summary {
  148. padding = '.7rem .9rem'
  149. color = 'var(--color-accent)'
  150. }
  151. }
  152. #ticketlist {
  153. display = 'grid'
  154. gap = '.4rem'
  155. margin = '0'
  156. padding = '0'
  157. listStyle = 'none'
  158. li {
  159. display = 'grid'
  160. flexWrap = 'wrap'
  161. alignItems = 'center'
  162. gap = '0 .8rem'
  163. margin = '0'
  164. padding = '.1rem 1rem .3rem'
  165. background = 'var(--color-surface)'
  166. borderRadius = 'var(--radius-large)'
  167. overflowWrap = 'anywhere'
  168. gridTemplateColumns = '3.25rem minmax(0, 1fr) minmax(3.5rem, auto)'
  169. columnGap = '.5rem'
  170. // Direct-child and sibling combinators have no bare language form.
  171. '> a' {
  172. display = 'inline-flex'
  173. alignItems = 'center'
  174. minHeight = '2.75rem'
  175. }
  176. }
  177. time {
  178. gridColumn = '2 / -1'
  179. }
  180. }
  181. aNumber {
  182. justifyContent = 'flex-start'
  183. minWidth = '2.75rem'
  184. color = 'var(--color-text-muted)'
  185. }
  186. aTicketSubject {
  187. fontWeight = '600'
  188. paddingBlock = '.2rem'
  189. }
  190. #span {
  191. fontSize = '.875rem'
  192. color = 'var(--color-text-muted)'
  193. }
  194. #ticketserror {
  195. margin = '0'
  196. color = 'var(--color-danger)'
  197. empty { display = 'none' }
  198. }
  199. #newticketerror {
  200. margin = '0'
  201. color = 'var(--color-danger)'
  202. empty { display = 'none' }
  203. }
  204. #ticketnotice {
  205. margin = '0'
  206. color = 'var(--color-success)'
  207. }
  208. }

Branches

Latest commits

  • 07ab845bvendor: Hybriel set-day50 (run() leak fix #335)mre
  • 71b2fa4blog: hybriel#335mre
  • bd94cc7elog: #25 cause found (run() leak)mre
  • 565cb508log: H25 round 1mre
  • 90a0af84log: H25 startedmre
  • 87bd53b8mission H25mre
  • 71a746cflog: day48 livemre
  • bf568e14log: V48 mergedmre
  • 09955dedMerge v48: Hybriel set-day48, theme layouts ce4a0bamre
  • f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
  • 5d0834e7log: Apollo model rulemre
  • fe8e5bd5log: #25 sample, V48 missionmre
  • 8580c5d9log: theme fix from Atlasmre
  • 46823d93log: Apollo budget correctionmre
  • f6d32341log: Apollo on budget and #25 nextmre
  • d7184f53log: batch live, #25 evidencemre
  • 5e25e816log: W61 mergedmre
  • aafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmre
  • aca1fda1Merge W61: theme from layouts 17e0f03, Views refer to Style rules (gitoria#37 #27)mre
  • 03cb650blog: W61 theme decisionmre