gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitbd76cfa6bd76cfa6connect: format Style with nested language rulesmrebd76cfa6/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. 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. pNotice = noticeLook + { }
  74. ticketBoard { display = 'grid' gap = '1rem'
  75. // the windows (Modal's element, quoted: it is not in this View): phone first, a full-screen sheet; from 60rem the centred window (below, in the media block; fit-content is the browser's own dialog height)
  76. 'modal-dialog > dialog' { width = '100vw' height = '100dvh' maxHeight = 'none' borderRadius = '0' }
  77. // the empty message line of the board (a disconnect refusal) takes no room (it left a 3 rem hole under the filters)
  78. '> p.message:empty' { display = 'none' }
  79. }
  80. ticketFilters { display = 'grid' gap = '.5rem'
  81. // phone: ONE row each that scrolls sideways inside itself (14 project chips + 8 state chips filled half a screen before the first ticket)
  82. nav { display = 'flex' flexWrap = 'nowrap' gap = '.35rem' overflowX = 'auto' scrollbarWidth = 'none' }
  83. 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)' }
  84. // the chip classes sit on the same <a> (set from a string): compound selectors, nothing else can say them
  85. 'a.selected' { color = 'var(--color-accent-text)' background = 'var(--color-accent)' }
  86. 'a.selected.open' { color = 'var(--color-accent-text)' }
  87. 'a.selected.progress' { color = 'var(--color-accent-text)' }
  88. 'a.selected.pending' { color = 'var(--color-accent-text)' }
  89. 'a.selected.review' { color = 'var(--color-accent-text)' }
  90. 'a.selected.reopened' { color = 'var(--color-accent-text)' }
  91. 'a.selected.done' { color = 'var(--color-accent-text)' }
  92. 'a.selected.canceled' { color = 'var(--color-accent-text)' }
  93. }
  94. // the ticket rows (this list and /inbox): the class comes from a string in the View
  95. olTickets = ticketsLook + { }
  96. aSubject = subjectLook + { }
  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. // the links of a row (the project) are a tap target too
  100. a { display = 'inline-flex' alignItems = 'center' minWidth = 'var(--layout-tap)' minHeight = 'var(--layout-tap)' }
  101. }
  102. assignee { color = 'var(--color-text-muted)' }
  103. 'assignee::before' { content = '"→ "' }
  104. // the new-ticket form and the new-project form stand in the theme's modal window (components/modal/, not in this View)
  105. 'modal-dialog form' { display = 'grid' gap = '.7rem' }
  106. // the heading row of the ticket list: the title at the left, "New project" (quiet) and "New ticket" (the accent) at the right
  107. headingRow { display = 'flex' flexWrap = 'wrap' alignItems = 'center' justifyContent = 'space-between' gap = '.5rem 1rem'
  108. h1 { margin = '0' }
  109. }
  110. headingActions { display = 'flex' flexWrap = 'wrap' gap = '.5rem' }
  111. // the state badge: one colour per state (also used by /inbox and the ticket page)
  112. 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)' }
  113. 'ticket-state.open' { color = 'var(--color-action)' }
  114. 'ticket-state.progress' { color = 'var(--color-warning)' }
  115. 'ticket-state.pending' { color = 'var(--color-text-muted)' }
  116. 'ticket-state.review' { color = 'var(--color-accent)' }
  117. 'ticket-state.reopened' { color = 'var(--color-danger)' }
  118. 'ticket-state.done' { color = 'var(--color-success)' }
  119. 'ticket-state.canceled' { color = 'var(--color-text-muted)' }
  120. // ticket #20/#21: the project's actions, the apps connected to it, its description
  121. projectActions { display = 'flex' flexWrap = 'wrap' gap = '.5rem'
  122. 'a.button' { background = 'var(--color-surface)' }
  123. }
  124. ulConnections { listStyle = 'none' margin = '0' padding = '0' display = 'grid' gap = '.4rem'
  125. li { display = 'flex' flexWrap = 'wrap' alignItems = 'center' gap = '.2rem .6rem' padding = '.4rem .8rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)' fontSize = '.9rem' }
  126. }
  127. projectDescription { display = 'block' padding = '.8rem' overflowWrap = 'anywhere' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)' }
  128. '@media (min-width: 60rem)' {
  129. olTickets { li { gridTemplateColumns = '8.5rem minmax(0, 1fr) auto' alignItems = 'center' gap = '1rem' } }
  130. ticketFilters { nav { flexWrap = 'wrap' overflowX = 'visible' } }
  131. ticketBoard { 'modal-dialog > dialog' { width = 'min(34rem, calc(100vw - 2rem))' height = 'fit-content' maxHeight = 'calc(100dvh - 2rem)' borderRadius = 'var(--radius-large)' } }
  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" Style.ulConnections
  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" Style.pMessage connectionMessage }
  162. if (isAdmin) { projectActions { a { id = "settingslink" class = "button" href = settingsHref "Project settings" } } }
  163. if (mustLogIn) { p { id = "loginhint" Style.pHint "Reading is open to everyone. To open a ticket, log in with ident (top right)." } }
  164. 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." } }
  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" Style.pMessage newMessage }
  185. }
  186. } }
  187. if (canCreateProject) { Modal { id = "newprojectmodal" title = "New project"
  188. ProjectForm { onCreated = projectCreated }
  189. } }
  190. if (hasNotice) { p { id = "notice" Style.pNotice notice " " a { id = "noticelink" href = noticeHref noticeLink } } }
  191. if (isEmpty) { p { id = "empty" class = "empty" "No tickets here." } }
  192. ol { id = "tickets" Style.olTickets
  193. for (row of rows) {
  194. li {
  195. ticketState { class = row.stateSlug row.state }
  196. a { Style.aSubject 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. 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

  • bd76cfa6connect: format Style with nested language rulesmre
  • 01fad593inbox: format Style with nested language rulesmre
  • 79dc9392you: format Style with nested language rulesmre
  • 78073baamain: format Style with nested language rulesmre
  • 5499c290Sync theme unchanged from layouts 17e0f03mre
  • fd33ee21Sync reviewed components from 8176eb1mre
  • 93348453Re-vendor tickets to Hybriel set day35mre
  • a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
  • cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
  • 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
  • b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre
  • f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
  • 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre
  • 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