gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchl33-thinecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mrel33-thin/components/ticket_list.hl

18.3 KB

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

Branches

Latest commits

  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre
  • 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