gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5803cf4f5803cf4f|||PR vendor: Hybriel set-day59 and GC budget 32 MiBmre5803cf4f/components/tickets.hl

6.8 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. tickets.remove(row.@id)
  99. tickets = [row, for (x of tickets) { x }]
  100. ticketsShown = true
  101. ticketsNone = false
  102. }
  103. // a ticket opened here by anyone: every open tickets page of that repo follows
  104. on client ticketOpened(slugOf, row) {
  105. if (!hasRepo || slugOf != slug) { return null }
  106. addTicket(row)
  107. }
  108. // this session's tabs follow a login / name / logout (the shell's faces push them)
  109. on client gitoriaSignedIn(tag, info) {
  110. canCreate = repo != null && repo.ticketsOn && info.named
  111. needsLogin = false
  112. }
  113. on client gitoriaSignedOut(tag) {
  114. canCreate = false
  115. needsLogin = repo != null && repo.ticketsOn
  116. }
  117. on server gitoriaOpenTicket(slugOf, subject, summary, session) {
  118. if (repoAt(slugOf, session) == null) { return { error = 'no such repository' } }
  119. u = userOfSession(session)
  120. if (u == null) { return { error = 'log in with ident (top right) to open a ticket' } }
  121. if (u.name == '') { return { error = 'choose a display name first (top of the page)' } }
  122. r = openTicket(slugOf, u.identity, subject, summary)
  123. if (r.error != null) { return { error = r.error } }
  124. emit client ticketOpened(slugOf, r.ticket)
  125. return r
  126. }
  127. Style {
  128. repoTickets {
  129. display = 'grid'
  130. gap = '1rem'
  131. minWidth = '0'
  132. // Direct-child and sibling combinators have no bare language form.
  133. '> *' {
  134. margin = '0'
  135. }
  136. }
  137. #newticketform {
  138. display = 'grid'
  139. gap = '.75rem'
  140. // Direct-child and sibling combinators have no bare language form.
  141. '> *' {
  142. margin = '0'
  143. }
  144. }
  145. #newticket {
  146. summary {
  147. padding = '.7rem .9rem'
  148. color = 'var(--color-accent)'
  149. }
  150. }
  151. #ticketlist {
  152. display = 'grid'
  153. gap = '.4rem'
  154. margin = '0'
  155. padding = '0'
  156. listStyle = 'none'
  157. li {
  158. display = 'grid'
  159. flexWrap = 'wrap'
  160. alignItems = 'center'
  161. gap = '0 .8rem'
  162. margin = '0'
  163. padding = '.1rem 1rem .3rem'
  164. background = 'var(--color-surface)'
  165. borderRadius = 'var(--radius-large)'
  166. overflowWrap = 'anywhere'
  167. gridTemplateColumns = '3.25rem minmax(0, 1fr) minmax(3.5rem, auto)'
  168. columnGap = '.5rem'
  169. // Direct-child and sibling combinators have no bare language form.
  170. '> a' {
  171. display = 'inline-flex'
  172. alignItems = 'center'
  173. minHeight = '2.75rem'
  174. }
  175. }
  176. time {
  177. gridColumn = '2 / -1'
  178. }
  179. }
  180. aNumber {
  181. justifyContent = 'flex-start'
  182. minWidth = '2.75rem'
  183. color = 'var(--color-text-muted)'
  184. }
  185. aTicketSubject {
  186. fontWeight = '600'
  187. paddingBlock = '.2rem'
  188. }
  189. #span {
  190. fontSize = '.875rem'
  191. color = 'var(--color-text-muted)'
  192. }
  193. #ticketserror {
  194. margin = '0'
  195. color = 'var(--color-danger)'
  196. empty { display = 'none' }
  197. }
  198. #newticketerror {
  199. margin = '0'
  200. color = 'var(--color-danger)'
  201. empty { display = 'none' }
  202. }
  203. #ticketnotice {
  204. margin = '0'
  205. color = 'var(--color-success)'
  206. }
  207. }

Branches

Latest commits

  • 5803cf4f|||PR vendor: Hybriel set-day59 and GC budget 32 MiBmre
  • 9eff6627Merge branch 'f2-api-bugs' into mainGitoria
  • 26117255|||PR apps API: review comments on files with spaces in their namemre
  • b8796cecMerge branch 'f1-broken-json' into mainGitoria
  • 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
  • f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
  • 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
  • 16a3530fMerge branch 'heap-revert' into mainGitoria
  • 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
  • 13f0c342Merge branch 'hl25-records' into mainGitoria
  • a002ecb7|||PR records: HL25 report, heap helper, logmre
  • 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
  • fefaedd2log: tracker PR-only, HL25 startedmre
  • 21aa57calog: parkmre
  • e9f950a8reports: G25c soakmre
  • a7783686log: deploy 9f41ffcmre
  • 9f41ffc1log: W30b mergedmre
  • bef635c1Merge branch 'w30b'mre
  • 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
  • c4f6d9e3reports: G25c growth huntmre