gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit090ee809090ee809tickets: 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)mre090ee809/components/ticket_list.hl

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

Branches

Latest commits

  • 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
  • 4348dbabident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 66ef3005Merge branch 'iw-ident-widget'mre