gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit6f6e57976f6e5797Tickets conductor: STATUS wordingmre6f6e5797/components/ticket_list.hl

17.6 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. import { hintLook, messageLook, noticeLook, subjectLook, ticketsLook } from '../lib/looks.hl'
  23. projectName = null
  24. stateSlug = null
  25. filterState = stateOfSlug(stateSlug)
  26. // 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
  27. // paint and a 90 000 px page on a phone. `total` = how many tickets the filters match
  28. pageSize = 50
  29. limit = pageSize
  30. first = firstRows(projectName, filterState, limit)
  31. rows = first.rows
  32. total = first.total
  33. projects = projectLinks(projectName, filterState)
  34. stateFilters = stateLinks(projectName, filterState)
  35. session = null
  36. project = projectName != null ? projectByAnySlug(projectName) : null
  37. noSuchProject = projectName != null && project == null
  38. projectId = project != null ? project.id : ''
  39. hasDescription = project != null && project.description != null && project.description != ''
  40. descriptionMd = hasDescription ? markdownBlocks(project.description) : []
  41. isAdmin = project != null && isAdminOf(project.id, userOfSession(session))
  42. // ticket #21: the apps connected to this project (connections.hl), shown to everybody; an admin can disconnect
  43. connections = project != null ? connectionRows(project.id) : []
  44. hasConnections = connections.length > 0
  45. connectionMessage = ''
  46. settingsHref = project != null ? '/projects/' + project.slug + '/settings' : ''
  47. isEmpty = rows.length == 0
  48. hasMore = rows.length < total
  49. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  50. heading = (projectName != null ? (project != null ? project.title : projectName) : 'All projects') + (filterState != null ? ' · ' + filterState : '')
  51. __title = siteName + ' | ' + heading
  52. // the new-ticket form
  53. myProjects = editableProjects(userOfSession(session))
  54. newProject = projectName != null && project != null ? project.slug : (myProjects.length > 0 ? myProjects[0].slug : '')
  55. newSubject = ''
  56. newSummary = ''
  57. newMessage = ''
  58. // the MdEditor is built once per element: a new key gives the next ticket an empty editor
  59. summarySeq = 0
  60. summaryForms = [{ id = 'summary-0' }]
  61. // only for a member with the role edit or admin (ticket #20): the author is that user
  62. canWrite = myProjects.length > 0
  63. canCreateProject = canWriteSession(session)
  64. mustLogIn = userOfSession(session) == null
  65. noRole = userOfSession(session) != null && myProjects.length == 0
  66. notice = ''
  67. noticeHref = ''
  68. noticeLink = 'open it'
  69. hasNotice = false
  70. Style {
  71. pMessage = messageLook + { }
  72. pHint = hintLook + { }
  73. '#notice' = noticeLook + { }
  74. ticketBoard {
  75. display = 'grid'
  76. gap = '1rem'
  77. // Keep the selector into a composed component; this View does not own its elements.
  78. 'modal-dialog > dialog' {
  79. width = '100vw'
  80. height = '100dvh'
  81. maxHeight = 'none'
  82. borderRadius = '0'
  83. }
  84. }
  85. ticketFilters {
  86. display = 'grid'
  87. gap = '.5rem'
  88. nav {
  89. display = 'flex'
  90. flexWrap = 'nowrap'
  91. gap = '.35rem'
  92. overflowX = 'auto'
  93. scrollbarWidth = 'none'
  94. a {
  95. flex = 'none'
  96. whiteSpace = 'nowrap'
  97. display = 'inline-flex'
  98. alignItems = 'center'
  99. minHeight = 'var(--layout-tap)'
  100. padding = '.2rem .8rem'
  101. background = 'var(--color-surface)'
  102. fontSize = '.875rem'
  103. color = 'var(--color-text)'
  104. borderRadius = 'var(--radius-small)'
  105. }
  106. // Keep the compound class selector; there is no same-element bare form.
  107. 'a.selected' {
  108. color = 'var(--color-accent-text)'
  109. background = 'var(--color-accent)'
  110. }
  111. @media {
  112. minWidth = '60rem'
  113. flexWrap = 'wrap'
  114. overflowX = 'visible'
  115. }
  116. }
  117. }
  118. '#tickets' {
  119. listStyle = 'none'
  120. margin = '0'
  121. padding = '0'
  122. display = 'grid'
  123. gap = '.5rem'
  124. li {
  125. display = 'grid'
  126. gridTemplateColumns = 'minmax(0, 1fr)'
  127. gap = '.3rem'
  128. padding = '.7rem .8rem'
  129. background = 'var(--color-surface)'
  130. borderRadius = 'var(--radius-large)'
  131. ticketState {
  132. justifySelf = 'start'
  133. }
  134. // Keep the combinator as a quoted nested key.
  135. '> a' {
  136. minWidth = 'var(--layout-tap)'
  137. minHeight = 'var(--layout-tap)'
  138. display = 'flex'
  139. alignItems = 'baseline'
  140. paddingBlock = '.5rem'
  141. color = 'var(--color-text-strong)'
  142. fontWeight = '600'
  143. overflowWrap = 'anywhere'
  144. }
  145. @media {
  146. minWidth = '60rem'
  147. gridTemplateColumns = '8.5rem minmax(0, 1fr) auto'
  148. alignItems = 'center'
  149. gap = '1rem'
  150. }
  151. }
  152. }
  153. ticketRef {
  154. flex = 'none'
  155. marginRight = '.4rem'
  156. color = 'var(--color-text-muted)'
  157. fontWeight = '400'
  158. whiteSpace = 'nowrap'
  159. }
  160. ticketMeta {
  161. display = 'flex'
  162. flexWrap = 'wrap'
  163. alignItems = 'center'
  164. gap = '.2rem .8rem'
  165. fontSize = '.875rem'
  166. a {
  167. display = 'inline-flex'
  168. alignItems = 'center'
  169. minWidth = 'var(--layout-tap)'
  170. minHeight = 'var(--layout-tap)'
  171. }
  172. }
  173. assignee {
  174. color = 'var(--color-text-muted)'
  175. }
  176. // Keep the selector into a composed component; this View does not own its elements.
  177. 'modal-dialog form' {
  178. display = 'grid'
  179. gap = '.7rem'
  180. }
  181. headingRow {
  182. display = 'flex'
  183. flexWrap = 'wrap'
  184. alignItems = 'center'
  185. justifyContent = 'space-between'
  186. gap = '.5rem 1rem'
  187. h1 {
  188. margin = '0'
  189. }
  190. }
  191. headingActions {
  192. display = 'flex'
  193. flexWrap = 'wrap'
  194. gap = '.5rem'
  195. }
  196. ticketState {
  197. display = 'inline-block'
  198. background = 'var(--color-background-sunken)'
  199. padding = '.05rem .55rem'
  200. fontSize = '.875rem'
  201. fontWeight = '600'
  202. whiteSpace = 'nowrap'
  203. borderRadius = 'var(--radius-small)'
  204. color = 'var(--color-text-muted)'
  205. }
  206. // Keep the compound class selector; there is no same-element bare form.
  207. 'ticket-state.open' {
  208. color = 'var(--color-action)'
  209. }
  210. // Keep the compound class selector; there is no same-element bare form.
  211. 'ticket-state.progress' {
  212. color = 'var(--color-warning)'
  213. }
  214. // Keep the compound class selector; there is no same-element bare form.
  215. 'ticket-state.pending' {
  216. color = 'var(--color-text-muted)'
  217. }
  218. // Keep the compound class selector; there is no same-element bare form.
  219. 'ticket-state.review' {
  220. color = 'var(--color-accent)'
  221. }
  222. // Keep the compound class selector; there is no same-element bare form.
  223. 'ticket-state.reopened' {
  224. color = 'var(--color-danger)'
  225. }
  226. // Keep the compound class selector; there is no same-element bare form.
  227. 'ticket-state.done' {
  228. color = 'var(--color-success)'
  229. }
  230. // Keep the compound class selector; there is no same-element bare form.
  231. 'ticket-state.canceled' {
  232. color = 'var(--color-text-muted)'
  233. }
  234. projectActions {
  235. display = 'flex'
  236. flexWrap = 'wrap'
  237. gap = '.5rem'
  238. // Keep the compound class selector; there is no same-element bare form.
  239. 'a.button' {
  240. background = 'var(--color-surface)'
  241. }
  242. }
  243. '#connections' {
  244. listStyle = 'none'
  245. margin = '0'
  246. padding = '0'
  247. display = 'grid'
  248. gap = '.4rem'
  249. li {
  250. display = 'flex'
  251. flexWrap = 'wrap'
  252. alignItems = 'center'
  253. gap = '.2rem .6rem'
  254. padding = '.4rem .8rem'
  255. background = 'var(--color-surface)'
  256. borderRadius = 'var(--radius-large)'
  257. fontSize = '.9rem'
  258. }
  259. }
  260. projectDescription {
  261. display = 'block'
  262. padding = '.8rem'
  263. overflowWrap = 'anywhere'
  264. background = 'var(--color-surface)'
  265. borderRadius = 'var(--radius-large)'
  266. }
  267. '#connectionmessage' {
  268. empty {
  269. display = 'none'
  270. }
  271. }
  272. // Keep the query at Style root so size declarations stay declarations.
  273. @media {
  274. minWidth = '60rem'
  275. ticketBoard {
  276. // Keep the selector into a composed component; this View does not own its elements.
  277. 'modal-dialog > dialog' {
  278. width = 'min(34rem, calc(100vw - 2rem))'
  279. height = 'fit-content'
  280. maxHeight = 'calc(100dvh - 2rem)'
  281. borderRadius = 'var(--radius-large)'
  282. }
  283. }
  284. }
  285. }
  286. View {
  287. ticketBoard {
  288. headingRow {
  289. h1 { id = "heading" heading }
  290. headingActions {
  291. if (canCreateProject) { button { id = "newprojectlink" type = "button" "New project" on click(e) { emit openWindow('newprojectmodal') } } }
  292. if (canWrite) { button { id = "newticketbutton" type = "button" class = "primary" "New ticket" on click(e) { emit openWindow('newticketmodal') } } }
  293. }
  294. }
  295. ticketFilters {
  296. nav { id = "projectfilter"
  297. for (f of projects) { a { href = f.href class = f.cls f.label } }
  298. }
  299. nav { id = "statefilter"
  300. for (f of stateFilters) { a { href = f.href class = f.cls f.label } }
  301. }
  302. }
  303. if (noSuchProject) { p { id = "noproject" class = "empty" "There is no such project." } }
  304. if (hasDescription) { projectDescription { id = "description" Markdown { blocks = descriptionMd } } }
  305. if (hasConnections) { ul { id = "connections"
  306. for (c of connections) {
  307. li { class = "connection"
  308. "Connected to " strong { c.text }
  309. if (isAdmin) { button { type = "button" class = "quiet danger disconnect" "Disconnect" on click(e) { emit dropConnection(c.id) } } }
  310. }
  311. }
  312. } }
  313. p { id = "connectionmessage" Style.pMessage connectionMessage }
  314. if (isAdmin) { projectActions { a { id = "settingslink" class = "button" href = settingsHref "Project settings" } } }
  315. if (mustLogIn) { p { id = "loginhint" Style.pHint "Reading is open to everyone. To open a ticket, log in with ident (top right)." } }
  316. if (noRole) { p { id = "rolehint" Style.pHint "To open a ticket you need the role edit or admin in a project — ask an admin of the project to invite you." } }
  317. if (canWrite) { Modal { id = "newticketmodal" title = "New ticket"
  318. form { id = "newticketform"
  319. on submit(e) {
  320. e.preventDefault()
  321. emit create(e)
  322. }
  323. label { "Project"
  324. select { id = "newproject" name = "project" value = newProject on change(e) { emit setProject(e.target.value) }
  325. for (p of myProjects) { option { value = p.slug p.title } }
  326. }
  327. }
  328. label { "Subject"
  329. input { id = "newsubject" name = "subject" required = "required" maxlength = "200" value = newSubject on input(e) { emit setSubject(e.target.value) } }
  330. }
  331. mdField { id = "newsummary" on input(e) { emit setSummary(e.target.name, e.target.value) }
  332. span { "Summary" }
  333. for (f of summaryForms) { MdEditor { name = "summary" value = "" rows = 4 placeholder = "" files = "off" } }
  334. }
  335. button { id = "newsubmit" type = "submit" "Open ticket" }
  336. p { id = "newmessage" Style.pMessage newMessage }
  337. }
  338. } }
  339. if (canCreateProject) { Modal { id = "newprojectmodal" title = "New project"
  340. ProjectForm { onCreated = projectCreated }
  341. } }
  342. if (hasNotice) { p { id = "notice" notice " " a { id = "noticelink" href = noticeHref noticeLink } } }
  343. if (isEmpty) { p { id = "empty" class = "empty" "No tickets here." } }
  344. ol { id = "tickets" class = "tickets"
  345. for (row of rows) {
  346. li {
  347. ticketState { class = row.stateSlug row.state }
  348. a { class = "subject" href = row.href ticketRef { row.ref } row.subject }
  349. ticketMeta {
  350. a { href = row.projectHref row.projectTitle }
  351. if (row.hasAssignee) { assignee { "→ " row.assignee } }
  352. time { row.updated }
  353. }
  354. }
  355. }
  356. }
  357. if (hasMore) { button { id = "moretickets" type = "button" class = "quiet" moreLabel on click(e) { emit showMore(e) } } }
  358. }
  359. }
  360. on showMore(e) {
  361. limit = limit + pageSize
  362. r = emit server moreRows(projectName != null ? projectName : '', filterState != null ? filterState : '', limit)
  363. if (r != null && r.rows != null) {
  364. rows = r.rows
  365. total = r.total
  366. isEmpty = rows.length == 0
  367. hasMore = rows.length < total
  368. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  369. }
  370. }
  371. on server moreRows(project, state, n, session) {
  372. return firstRows(project != '' ? project : null, state != '' ? state : null, n)
  373. }
  374. // the window of a form (Esc, the × and a tap beside it close it)
  375. on openWindow(id) { document.getElementById(id).showModal() }
  376. on setProject(v) { newProject = v }
  377. on setSubject(v) { newSubject = v }
  378. // the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not it
  379. on setSummary(name, v) { if (name == 'summary') { newSummary = v } }
  380. on create(e) {
  381. if (newProject.trim() == '' || newSubject.trim() == '') { return null }
  382. r = emit server openTicket(newProject, newSubject, newSummary)
  383. if (r != null && r.error == null) {
  384. notice = 'Opened ' + r.project + ' ' + r.ref + '.'
  385. noticeHref = r.href
  386. noticeLink = 'open it'
  387. hasNotice = true
  388. newMessage = ''
  389. document.getElementById('newticketmodal').close('opened')
  390. newSubject = ''
  391. newSummary = ''
  392. summarySeq = summarySeq + 1
  393. summaryForms = [{ id = 'summary-' + summarySeq }]
  394. } else {
  395. newMessage = r != null ? r.error : 'could not open the ticket'
  396. }
  397. }
  398. // the project form (components/project-form.hl) tells the page: the window closes, the page says it and links the settings
  399. projectCreated = (title, settingsHref) => {
  400. notice = 'Created ' + title + '.'
  401. noticeHref = settingsHref
  402. noticeLink = 'open its settings'
  403. hasNotice = true
  404. document.getElementById('newprojectmodal').close('created')
  405. }
  406. // does a row belong in THIS list (its filters)?
  407. belongs = (row) => {
  408. return (projectName == null || row.projectId == projectId) && (filterState == null || row.state == filterState)
  409. }
  410. // the row goes to the top (newest update first) if it belongs, and out if not
  411. place = (row) => {
  412. let wasIn = false
  413. for (r of rows) { if (r.id == row.id) { wasIn = true } }
  414. allShown = rows.length >= total
  415. next = []
  416. if (belongs(row)) { next.push(row) }
  417. for (r of rows) { if (r.id != row.id) { next.push(r) } }
  418. // a new ticket joins the count when everything was on the page; one that left the filter leaves it
  419. if (belongs(row) && !wasIn && allShown) { total = total + 1 }
  420. if (!belongs(row) && wasIn) { total = total - 1 }
  421. if (allShown && next.length > limit) { limit = next.length }
  422. rows = next.length > limit ? next.slice(0, limit) : next
  423. isEmpty = rows.length == 0
  424. hasMore = rows.length < total
  425. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  426. }
  427. on client ticketCreated(row) { place(row) }
  428. on dropConnection(id) {
  429. r = emit server disconnectApp(projectId, id)
  430. if (r == null || r.error != null) {
  431. connectionMessage = r != null ? r.error : 'could not disconnect'
  432. return null
  433. }
  434. connectionMessage = ''
  435. connections = r.connections
  436. hasConnections = r.connections.length > 0
  437. }
  438. on client connectionsChanged(slug) {
  439. r = emit server connectionsOfProject(projectId)
  440. if (r != null && r.connections != null) {
  441. connections = r.connections
  442. hasConnections = r.connections.length > 0
  443. }
  444. }
  445. on client signedIn(tag, info) {
  446. r = emit server whatICanOpen(projectName != null ? projectName : '')
  447. if (r != null && r.projects != null) {
  448. myProjects = r.projects
  449. canWrite = r.projects.length > 0
  450. noRole = r.projects.length == 0 && info.named
  451. canCreateProject = info.named
  452. mustLogIn = false
  453. isAdmin = r.admin == true
  454. if (newProject == '' && r.projects.length > 0) { newProject = r.projects[0].slug }
  455. }
  456. }
  457. on client signedOut(tag) {
  458. canWrite = false
  459. canCreateProject = false
  460. isAdmin = false
  461. noRole = false
  462. mustLogIn = true
  463. myProjects = []
  464. }
  465. on client ticketEvent(ticketId, ev, row) { place(row) }
  466. // THE FACE: a ticket opened from the web by the session's user (#31: only a real session).
  467. // The same push the API sends.
  468. on server openTicket(project, subject, summary, session) {
  469. w = writerOfSession(session)
  470. if (w.error != null) { return { error = w.error } }
  471. r = createTicket(project, subject, summary, w.user, null, null)
  472. if (r.error != null) { return { error = r.error } }
  473. emit client ticketCreated(r.ticket)
  474. return r.ticket
  475. }
  476. // what this session's user may do here after a login without a reload: the projects they may open tickets in,
  477. // and whether they are an admin of THIS page's project (`slug` null = the all-projects page)
  478. on server whatICanOpen(slug, session) {
  479. u = userOfSession(session)
  480. if (u == null) { return { error = 'log in first' } }
  481. p = slug != null && slug != '' ? projectByAnySlug(slug) : null
  482. return { projects = editableProjects(u) admin = p != null && isAdminOf(p.id, u) }
  483. }
  484. // ticket #21: an admin ends a connection — the key is dead at once (connections.hl)
  485. on server disconnectApp(projectId, connectionId, session) {
  486. w = writerOfSession(session)
  487. if (w.error != null) { return { error = w.error } }
  488. r = disconnect('' + projectId, w.user, '' + connectionId)
  489. if (r.error != null) { return { error = r.error } }
  490. emit client connectionsChanged('')
  491. return { connections = r.connections }
  492. }
  493. on server connectionsOfProject(projectId, session) {
  494. return { connections = connectionRows('' + projectId) }
  495. }

Branches

Latest commits

  • 6f6e5797Tickets conductor: STATUS wordingmre
  • 957de51fTickets conductor: T36 live, #36 review, #50 donemre
  • bc2fde32Merge branch 'main' into t36-stylemre
  • b7ca093atests: wait for the new row and normalize editor marker spacesmre
  • 41da3525Tickets conductor: flake cause, T36 deploy stepmre
  • 64c477e6Tickets conductor: deploy waits for Arachnemre
  • 467d7286Tickets conductor: T36 done, deploy questionmre
  • fed5ca81ticket_list: remove repeated selected-state coloursmre
  • 8542fc8aTickets conductor: T36 proof reviewedmre
  • 35980936inbox: preserve desktop columns after list styles were scopedmre
  • 2a5b8b91Tickets conductor: T36 cap stop, resumed for proofmre
  • c077a5cbstyles: format Style with nested language rulesmre
  • ccdde2beticket: format Style with nested language rulesmre
  • d083535bticket_list: nest Style rules and bare media queriesmre
  • c24608ebmarkdown: format Style with nested language rulesmre
  • de964b3bsettings: format Style with nested language rulesmre
  • 03c1de05new_project: format Style with nested language rulesmre
  • bd76cfa6connect: format Style with nested language rulesmre
  • 01fad593inbox: format Style with nested language rulesmre
  • 79dc9392you: format Style with nested language rulesmre