gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchm32-move772e0696|||PR Allow project admins to move tickets between their projectsmrem32-move/components/ticket_list.hl

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

Branches

Latest commits

  • 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
  • c69cd5f3Merge branch 'pr-flow' into mainTickets
  • cc56798cLog gitoria PR-only requestmre
  • d876d0b2|||PR README: changes land as PRsmre
  • fd83ac1fconductor: caramboleyo is the user, not owner/creatorApollo
  • 3b858c91Log backup hard-link fixmre
  • 7f6b37a0deploy.sh backup: tar --hard-dereference (hard links broke mpackdb sidecars on restore)mre
  • e93711d9Log E30 livemre
  • 59c02e4dMerge e30: preserve edited state note labels in Markdownmre
  • 30970796Log E30 deploy GOmre
  • 7c8e6d83Limit edited state note fix to Markdown renderingmre
  • 910536d0Log E30 reviewmre
  • 36984386Preserve state transitions when their notes are editedmre
  • d75cb946Log E30 startmre
  • 0bf3fefaMission 030: edited state note labelmre
  • 691565c6Log neutral-ticket rule checkmre