gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf767b24df767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mref767b24d/components/ticket_list.hl

17.7 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. At the right of the heading: "New ticket" (the accent button) and
  4. // "New project" (a quiet one); each opens its form in the theme's modal window (a full-screen window on a phone). 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. import Modal from './modal/modal.hl'
  21. import ProjectForm from './project-form.hl'
  22. projectName = null
  23. stateSlug = null
  24. filterState = stateOfSlug(stateSlug)
  25. // 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
  26. // paint and a 90 000 px page on a phone. `total` = how many tickets the filters match
  27. pageSize = 50
  28. limit = pageSize
  29. first = firstRows(projectName, filterState, limit)
  30. rows = first.rows
  31. total = first.total
  32. projects = projectLinks(projectName, filterState)
  33. stateFilters = stateLinks(projectName, filterState)
  34. session = null
  35. project = projectName != null ? projectByAnySlug(projectName) : null
  36. noSuchProject = projectName != null && project == null
  37. projectId = project != null ? project.id : ''
  38. hasDescription = project != null && project.description != null && project.description != ''
  39. descriptionMd = hasDescription ? markdownBlocks(project.description) : []
  40. isAdmin = project != null && isAdminOf(project.id, userOfSession(session))
  41. // ticket #21: the apps connected to this project (connections.hl), shown to everybody; an admin can disconnect
  42. connections = project != null ? connectionRows(project.id) : []
  43. hasConnections = connections.length > 0
  44. connectionMessage = ''
  45. settingsHref = project != null ? '/projects/' + project.slug + '/settings' : ''
  46. isEmpty = rows.length == 0
  47. hasMore = rows.length < total
  48. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  49. heading = (projectName != null ? (project != null ? project.title : projectName) : 'All projects') + (filterState != null ? ' · ' + filterState : '')
  50. __title = siteName + ' | ' + heading
  51. // the new-ticket form
  52. myProjects = editableProjects(userOfSession(session))
  53. newProject = projectName != null && project != null ? project.slug : (myProjects.length > 0 ? myProjects[0].slug : '')
  54. newSubject = ''
  55. newSummary = ''
  56. newMessage = ''
  57. // the MdEditor is built once per element: a new key gives the next ticket an empty editor
  58. summarySeq = 0
  59. summaryForms = [{ id = 'summary-0' }]
  60. // only for a member with the role edit or admin (ticket #20): the author is that user
  61. canWrite = myProjects.length > 0
  62. canCreateProject = canWriteSession(session)
  63. mustLogIn = userOfSession(session) == null
  64. noRole = userOfSession(session) != null && myProjects.length == 0
  65. notice = ''
  66. noticeHref = ''
  67. noticeLink = 'open it'
  68. hasNotice = false
  69. Style {
  70. ticketBoard { display = 'grid' gap = '1rem'
  71. // the windows (Modal's element, quoted: it is not in this View): phone first, a full-screen sheet; from 60rem the centred window (below, in the media block; fit-content is the browser's own dialog height)
  72. 'modal-dialog > dialog' { width = '100vw' height = '100dvh' maxHeight = 'none' borderRadius = '0' }
  73. // the empty message line of the board (a disconnect refusal) takes no room (it left a 3 rem hole under the filters)
  74. '> p.message:empty' { display = 'none' }
  75. }
  76. ticketFilters { display = 'grid' gap = '.5rem'
  77. // phone: ONE row each that scrolls sideways inside itself (14 project chips + 8 state chips filled half a screen before the first ticket)
  78. nav { display = 'flex' flexWrap = 'nowrap' gap = '.35rem' overflowX = 'auto' scrollbarWidth = 'none' }
  79. a { flex = 'none' whiteSpace = 'nowrap' display = 'inline-flex' alignItems = 'center' minHeight = 'var(--layout-tap)' padding = '.2rem .8rem' background = 'var(--color-surface)' fontSize = '.875rem' color = 'var(--color-text)' borderRadius = 'var(--radius-small)' }
  80. // the chip classes sit on the same <a> (set from a string): compound selectors, nothing else can say them
  81. 'a.selected' { color = 'var(--color-accent-text)' background = 'var(--color-accent)' }
  82. 'a.selected.open' { color = 'var(--color-accent-text)' }
  83. 'a.selected.progress' { color = 'var(--color-accent-text)' }
  84. 'a.selected.pending' { color = 'var(--color-accent-text)' }
  85. 'a.selected.review' { color = 'var(--color-accent-text)' }
  86. 'a.selected.reopened' { color = 'var(--color-accent-text)' }
  87. 'a.selected.done' { color = 'var(--color-accent-text)' }
  88. 'a.selected.canceled' { color = 'var(--color-accent-text)' }
  89. }
  90. // the ticket rows (this list and /inbox): the class comes from a string in the View
  91. '.tickets' { listStyle = 'none' margin = '0' padding = '0' display = 'grid' gap = '.5rem'
  92. li { display = 'grid' gridTemplateColumns = 'minmax(0, 1fr)' gap = '.3rem' padding = '.7rem .8rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)'
  93. ticketState { justifySelf = 'start' }
  94. }
  95. a { display = 'inline-flex' alignItems = 'center' minWidth = 'var(--layout-tap)' minHeight = 'var(--layout-tap)' }
  96. // the number stands in front of the subject on its first line and never wraps (it was a flex item that shrank: "# / 2 / 6" on the phone)
  97. '.subject' { display = 'flex' alignItems = 'baseline' paddingBlock = '.5rem' color = 'var(--color-text-strong)' fontWeight = '600' overflowWrap = 'anywhere' }
  98. }
  99. ticketRef { flex = 'none' marginRight = '.4rem' color = 'var(--color-text-muted)' fontWeight = '400' whiteSpace = 'nowrap' }
  100. ticketMeta { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.2rem .8rem' fontSize = '.875rem' }
  101. assignee { color = 'var(--color-text-muted)' }
  102. 'assignee::before' { content = '"→ "' }
  103. // the new-ticket form and the new-project form stand in the theme's modal window (components/modal/, not in this View)
  104. 'modal-dialog form' { display = 'grid' gap = '.7rem' }
  105. // the heading row of the ticket list: the title at the left, "New project" (quiet) and "New ticket" (the accent) at the right
  106. headingRow { display = 'flex' flexWrap = 'wrap' alignItems = 'center' justifyContent = 'space-between' gap = '.5rem 1rem'
  107. h1 { margin = '0' }
  108. }
  109. headingActions { display = 'flex' flexWrap = 'wrap' gap = '.5rem' }
  110. // the state badge: one colour per state (also used by /inbox and the ticket page)
  111. ticketState { display = 'inline-block' background = 'var(--color-background-sunken)' padding = '.05rem .55rem' fontSize = '.875rem' fontWeight = '600' whiteSpace = 'nowrap' borderRadius = 'var(--radius-small)' color = 'var(--color-text-muted)' }
  112. 'ticket-state.open' { color = 'var(--color-action)' }
  113. 'ticket-state.progress' { color = 'var(--color-warning)' }
  114. 'ticket-state.pending' { color = 'var(--color-text-muted)' }
  115. 'ticket-state.review' { color = 'var(--color-accent)' }
  116. 'ticket-state.reopened' { color = 'var(--color-danger)' }
  117. 'ticket-state.done' { color = 'var(--color-success)' }
  118. 'ticket-state.canceled' { color = 'var(--color-text-muted)' }
  119. // ticket #20/#21: the project's actions, the apps connected to it, its description
  120. projectActions { display = 'flex' flexWrap = 'wrap' gap = '.5rem'
  121. 'a.button' { background = 'var(--color-surface)' }
  122. }
  123. '.connections' { listStyle = 'none' margin = '0' padding = '0' display = 'grid' gap = '.4rem'
  124. li { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.2rem .6rem' padding = '.4rem .8rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)' fontSize = '.9rem' }
  125. }
  126. projectDescription { display = 'block' padding = '.8rem' overflowWrap = 'anywhere' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)' }
  127. '@media (min-width: 60rem)' {
  128. '.tickets' { li { gridTemplateColumns = '8.5rem minmax(0, 1fr) auto' alignItems = 'center' gap = '1rem' } }
  129. ticketFilters { nav { flexWrap = 'wrap' overflowX = 'visible' } }
  130. ticketBoard { 'modal-dialog > dialog' { width = 'min(34rem, calc(100vw - 2rem))' height = 'fit-content' maxHeight = 'calc(100dvh - 2rem)' borderRadius = 'var(--radius-large)' } }
  131. }
  132. }
  133. View {
  134. ticketBoard {
  135. headingRow {
  136. h1 { id = "heading" heading }
  137. headingActions {
  138. if (canCreateProject) { button { id = "newprojectlink" type = "button" "New project" on click(e) { emit openWindow('newprojectmodal') } } }
  139. if (canWrite) { button { id = "newticketbutton" type = "button" class = "primary" "New ticket" on click(e) { emit openWindow('newticketmodal') } } }
  140. }
  141. }
  142. ticketFilters {
  143. nav { id = "projectfilter"
  144. for (f of projects) { a { href = f.href class = f.cls f.label } }
  145. }
  146. nav { id = "statefilter"
  147. for (f of stateFilters) { a { href = f.href class = f.cls f.label } }
  148. }
  149. }
  150. if (noSuchProject) { p { id = "noproject" class = "empty" "There is no such project." } }
  151. if (hasDescription) { projectDescription { id = "description" Markdown { blocks = descriptionMd } } }
  152. if (hasConnections) { ul { id = "connections" class = "connections"
  153. for (c of connections) {
  154. li { class = "connection"
  155. "Connected to " strong { c.text }
  156. if (isAdmin) { button { type = "button" class = "quiet danger disconnect" "Disconnect" on click(e) { emit dropConnection(c.id) } } }
  157. }
  158. }
  159. } }
  160. p { id = "connectionmessage" class = "message" connectionMessage }
  161. if (isAdmin) { projectActions { a { id = "settingslink" class = "button" href = settingsHref "Project settings" } } }
  162. if (mustLogIn) { p { id = "loginhint" class = "hint" "Reading is open to everyone. To open a ticket, log in with ident (top right)." } }
  163. 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." } }
  164. if (canWrite) { Modal { id = "newticketmodal" title = "New ticket"
  165. form { id = "newticketform"
  166. on submit(e) {
  167. e.preventDefault()
  168. emit create(e)
  169. }
  170. label { "Project"
  171. select { id = "newproject" name = "project" value = newProject on change(e) { emit setProject(e.target.value) }
  172. for (p of myProjects) { option { value = p.slug p.title } }
  173. }
  174. }
  175. label { "Subject"
  176. input { id = "newsubject" name = "subject" required = "required" maxlength = "200" value = newSubject on input(e) { emit setSubject(e.target.value) } }
  177. }
  178. mdField { id = "newsummary" on input(e) { emit setSummary(e.target.name, e.target.value) }
  179. span { "Summary" }
  180. for (f of summaryForms) { MdEditor { name = "summary" value = "" rows = 4 placeholder = "" files = "off" } }
  181. }
  182. button { id = "newsubmit" type = "submit" "Open ticket" }
  183. p { id = "newmessage" class = "message" newMessage }
  184. }
  185. } }
  186. if (canCreateProject) { Modal { id = "newprojectmodal" title = "New project"
  187. ProjectForm { onCreated = projectCreated }
  188. } }
  189. if (hasNotice) { p { id = "notice" class = "notice" notice " " a { id = "noticelink" href = noticeHref noticeLink } } }
  190. if (isEmpty) { p { id = "empty" class = "empty" "No tickets here." } }
  191. ol { id = "tickets" class = "tickets"
  192. for (row of rows) {
  193. li {
  194. ticketState { class = row.stateSlug row.state }
  195. a { class = "subject" href = row.href ticketRef { row.ref } row.subject }
  196. ticketMeta {
  197. a { href = row.projectHref row.projectTitle }
  198. if (row.hasAssignee) { assignee { row.assignee } }
  199. time { row.updated }
  200. }
  201. }
  202. }
  203. }
  204. if (hasMore) { button { id = "moretickets" type = "button" class = "quiet" moreLabel on click(e) { emit showMore(e) } } }
  205. }
  206. }
  207. on showMore(e) {
  208. limit = limit + pageSize
  209. r = emit server moreRows(projectName != null ? projectName : '', filterState != null ? filterState : '', limit)
  210. if (r != null && r.rows != null) {
  211. rows = r.rows
  212. total = r.total
  213. isEmpty = rows.length == 0
  214. hasMore = rows.length < total
  215. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  216. }
  217. }
  218. on server moreRows(project, state, n, session) {
  219. return firstRows(project != '' ? project : null, state != '' ? state : null, n)
  220. }
  221. // the window of a form (Esc, the × and a tap beside it close it)
  222. on openWindow(id) { document.getElementById(id).showModal() }
  223. on setProject(v) { newProject = v }
  224. on setSubject(v) { newSubject = v }
  225. // the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not it
  226. on setSummary(name, v) { if (name == 'summary') { newSummary = v } }
  227. on create(e) {
  228. if (newProject.trim() == '' || newSubject.trim() == '') { return null }
  229. r = emit server openTicket(newProject, newSubject, newSummary)
  230. if (r != null && r.error == null) {
  231. notice = 'Opened ' + r.project + ' ' + r.ref + '.'
  232. noticeHref = r.href
  233. noticeLink = 'open it'
  234. hasNotice = true
  235. newMessage = ''
  236. document.getElementById('newticketmodal').close('opened')
  237. newSubject = ''
  238. newSummary = ''
  239. summarySeq = summarySeq + 1
  240. summaryForms = [{ id = 'summary-' + summarySeq }]
  241. } else {
  242. newMessage = r != null ? r.error : 'could not open the ticket'
  243. }
  244. }
  245. // the project form (components/project-form.hl) tells the page: the window closes, the page says it and links the settings
  246. projectCreated = (title, settingsHref) => {
  247. notice = 'Created ' + title + '.'
  248. noticeHref = settingsHref
  249. noticeLink = 'open its settings'
  250. hasNotice = true
  251. document.getElementById('newprojectmodal').close('created')
  252. }
  253. // does a row belong in THIS list (its filters)?
  254. belongs = (row) => {
  255. return (projectName == null || row.projectId == projectId) && (filterState == null || row.state == filterState)
  256. }
  257. // the row goes to the top (newest update first) if it belongs, and out if not
  258. place = (row) => {
  259. let wasIn = false
  260. for (r of rows) { if (r.id == row.id) { wasIn = true } }
  261. allShown = rows.length >= total
  262. next = []
  263. if (belongs(row)) { next.push(row) }
  264. for (r of rows) { if (r.id != row.id) { next.push(r) } }
  265. // a new ticket joins the count when everything was on the page; one that left the filter leaves it
  266. if (belongs(row) && !wasIn && allShown) { total = total + 1 }
  267. if (!belongs(row) && wasIn) { total = total - 1 }
  268. if (allShown && next.length > limit) { limit = next.length }
  269. rows = next.length > limit ? next.slice(0, limit) : next
  270. isEmpty = rows.length == 0
  271. hasMore = rows.length < total
  272. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  273. }
  274. on client ticketCreated(row) { place(row) }
  275. on dropConnection(id) {
  276. r = emit server disconnectApp(projectId, id)
  277. if (r == null || r.error != null) {
  278. connectionMessage = r != null ? r.error : 'could not disconnect'
  279. return null
  280. }
  281. connectionMessage = ''
  282. connections = r.connections
  283. hasConnections = r.connections.length > 0
  284. }
  285. on client connectionsChanged(slug) {
  286. r = emit server connectionsOfProject(projectId)
  287. if (r != null && r.connections != null) {
  288. connections = r.connections
  289. hasConnections = r.connections.length > 0
  290. }
  291. }
  292. on client signedIn(tag, info) {
  293. r = emit server whatICanOpen(projectName != null ? projectName : '')
  294. if (r != null && r.projects != null) {
  295. myProjects = r.projects
  296. canWrite = r.projects.length > 0
  297. noRole = r.projects.length == 0 && info.named
  298. canCreateProject = info.named
  299. mustLogIn = false
  300. isAdmin = r.admin == true
  301. if (newProject == '' && r.projects.length > 0) { newProject = r.projects[0].slug }
  302. }
  303. }
  304. on client signedOut(tag) {
  305. canWrite = false
  306. canCreateProject = false
  307. isAdmin = false
  308. noRole = false
  309. mustLogIn = true
  310. myProjects = []
  311. }
  312. on client ticketEvent(ticketId, ev, row) { place(row) }
  313. // THE FACE: a ticket opened from the web by the session's user (#31: only a real session).
  314. // The same push the API sends.
  315. on server openTicket(project, subject, summary, session) {
  316. w = writerOfSession(session)
  317. if (w.error != null) { return { error = w.error } }
  318. r = createTicket(project, subject, summary, w.user, null, null)
  319. if (r.error != null) { return { error = r.error } }
  320. emit client ticketCreated(r.ticket)
  321. return r.ticket
  322. }
  323. // what this session's user may do here after a login without a reload: the projects they may open tickets in,
  324. // and whether they are an admin of THIS page's project (`slug` null = the all-projects page)
  325. on server whatICanOpen(slug, session) {
  326. u = userOfSession(session)
  327. if (u == null) { return { error = 'log in first' } }
  328. p = slug != null && slug != '' ? projectByAnySlug(slug) : null
  329. return { projects = editableProjects(u) admin = p != null && isAdminOf(p.id, u) }
  330. }
  331. // ticket #21: an admin ends a connection — the key is dead at once (connections.hl)
  332. on server disconnectApp(projectId, connectionId, session) {
  333. w = writerOfSession(session)
  334. if (w.error != null) { return { error = w.error } }
  335. r = disconnect('' + projectId, w.user, '' + connectionId)
  336. if (r.error != null) { return { error = r.error } }
  337. emit client connectionsChanged('')
  338. return { connections = r.connections }
  339. }
  340. on server connectionsOfProject(projectId, session) {
  341. return { connections = connectionRows('' + projectId) }
  342. }

Branches

Latest commits

  • f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
  • 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre
  • 090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre
  • d395763ftickets: ident-access gate ports 8769/8768 (8797 is taken on loreana)mre
  • afb9a403tickets: an ident access key (Authorization: Bearer idt_…) works in the API (ident#27 app side): lib/ident-access.hl copied from components, read keys GET only, ident down 503; gate tests/ident-access-tickets.mjsmre
  • 48c1ba79tickets: md-paste-files gate with the file manager casesmre
  • f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mre
  • 06599fa0tickets: MdEditor from components b0f1ec2 (a clipboard with text always pastes the text, tickets#49); real Ctrl+V gatemre
  • 2e1b116ftickets: re-vendor Hybriel master acaceaf3 (framework ec8d6c1d): plugins/web patch queue while a page is built, anonymous session cookies refresh; gate waits for the comment editors to draw (W174) and clicks the form editor when it stands still; security gate: main's code runs on its own binary, lazy-session cookie checksmre
  • 361bc0fetickets: re-vendor Hybriel 7a684920 (WIP, not deployed); on Error exits 1 at startup; migrate passes its log by reference; gate checks follow lazy sessions and the 413 refusalmre
  • 8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre
  • 337e9b21tickets#37: a comment's files are open to everyone who can read the commentmre
  • 1800600ftickets: write the standby service out in full so the boot gate can read the main servicemre
  • 8179d287tickets: standby service on its port plus 10 and a deploy that hands over through it without a gapmre
  • 0398145ctickets: the table grid rule is marked functional for check-thememre
  • 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