gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitaef32f3baef32f3b|||PR Drive offline note from framework connection statemreaef32f3b/components/ticket_list.hl

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

Branches

Latest commits

  • aef32f3b|||PR Drive offline note from framework connection statemre
  • 6dea1c60Merge branch 'r35-day72' into mainTickets
  • 7bcfdc22|||PR drop worker edits to conductor recordsmre
  • 2617b6ee|||PR dialogs: host flag cleared on close, dialog gate (tickets#40)mre
  • 6e701371|||PR record partial day72 dialog validationmre
  • b9fb9a91|||PR bind ticket dialog visibility to member flagsmre
  • 0788e65f|||PR re-vendor Hybriel day72mre
  • e2a6bdcfMerge branch 'records-t35' into mainTickets
  • d8d54df1|||PR records: R35 day72 + #40mre
  • 8a7f475aMerge branch 'records-t33' into mainTickets
  • e685d0c2|||PR records: PROCEDURES merge callmre
  • b42aff2b|||PR records: GO 2026-11-23, workers L33 O34, PROCEDURES.mdmre
  • ed091d44Merge branch 'records' into mainTickets
  • 180c0cdb|||PR records: ticket move live (M32), hybriel#439mre
  • 497cae7bMerge branch 'm32-move' into mainTickets
  • 772e0696|||PR Allow project admins to move tickets between their projectsmre
  • be92a560Merge branch 'records' into mainTickets
  • 0daf2ea8|||PR records: PR-only workflow, #50 donemre
  • 0185d0b6Log PR 1 deploymre
  • f5bf16e2Mission 031: deploy PR 1mre