tickets
All repositories: gitoria
17.6 KB
// components/ticket_list.hl — `/`, `/project/:projectName` (also `/:projectName`, ticket #25),// `/state/:stateSlug` and both:// the tickets, newest update first, filtered by project and state. At the right of the heading: "New ticket" (the accent button) and// "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,// moves within or leaves this list without a reload. Ticket #12: the summary is edited visually — since mission 016 in the// Hybriel MdEditor (components/md-editor/; its hidden field keeps the Markdown and fires `input`).// Ticket #20: a project's page (`/<slug>`, also `/project/<slug>`; `/projects/<slug>` answers 301) shows its title, description// (Markdown), its tickets and — for an admin — the link to its settings page. The new-ticket form needs the// role edit or admin: its project choice holds only the projects the user may open tickets in.parent './main.hl'import { ticketRows, firstRows, createTicket } from '../lib/tickets.hl'import { projectLinks, stateLinks, stateOfSlug } from '../lib/tickets-helpers.hl'import { projectByAnySlug, editableProjects, isAdminOf } from '../lib/projects.hl'import { markdownBlocks } from '../lib/markdown.hl'import { siteName } from '../project.hl'import { canWriteSession, writerOfSession, userOfSession } from '../lib/users.hl'import { connectionRows, disconnect } from '../lib/connections.hl'import Markdown from './markdown.hl'import MdEditor from './md-editor/md-editor.hl'import Modal from './modal/modal.hl'import ProjectForm from './project-form.hl'import { hintLook, messageLook, noticeLook, subjectLook, ticketsLook } from '../lib/looks.hl'projectName = nullstateSlug = nullfilterState = stateOfSlug(stateSlug)// 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// paint and a 90 000 px page on a phone. `total` = how many tickets the filters matchpageSize = 50limit = pageSizefirst = firstRows(projectName, filterState, limit)rows = first.rowstotal = first.totalprojects = projectLinks(projectName, filterState)stateFilters = stateLinks(projectName, filterState)session = nullproject = projectName != null ? projectByAnySlug(projectName) : nullnoSuchProject = projectName != null && project == nullprojectId = project != null ? project.id : ''hasDescription = project != null && project.description != null && project.description != ''descriptionMd = hasDescription ? markdownBlocks(project.description) : []isAdmin = project != null && isAdminOf(project.id, userOfSession(session))// ticket #21: the apps connected to this project (connections.hl), shown to everybody; an admin can disconnectconnections = project != null ? connectionRows(project.id) : []hasConnections = connections.length > 0connectionMessage = ''settingsHref = project != null ? '/projects/' + project.slug + '/settings' : ''isEmpty = rows.length == 0hasMore = rows.length < totalmoreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'heading = (projectName != null ? (project != null ? project.title : projectName) : 'All projects') + (filterState != null ? ' · ' + filterState : '')__title = siteName + ' | ' + heading// the new-ticket formmyProjects = editableProjects(userOfSession(session))newProject = projectName != null && project != null ? project.slug : (myProjects.length > 0 ? myProjects[0].slug : '')newSubject = ''newSummary = ''newMessage = ''// the MdEditor is built once per element: a new key gives the next ticket an empty editorsummarySeq = 0summaryForms = [{ id = 'summary-0' }]// only for a member with the role edit or admin (ticket #20): the author is that usercanWrite = myProjects.length > 0canCreateProject = canWriteSession(session)mustLogIn = userOfSession(session) == nullnoRole = userOfSession(session) != null && myProjects.length == 0notice = ''noticeHref = ''noticeLink = 'open it'hasNotice = falseStyle {pMessage = messageLook + { }pHint = hintLook + { }'#notice' = noticeLook + { }ticketBoard {display = 'grid'gap = '1rem'// Keep the selector into a composed component; this View does not own its elements.'modal-dialog > dialog' {width = '100vw'height = '100dvh'maxHeight = 'none'borderRadius = '0'}}ticketFilters {display = 'grid'gap = '.5rem'nav {display = 'flex'flexWrap = 'nowrap'gap = '.35rem'overflowX = 'auto'scrollbarWidth = 'none'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)'}// Keep the compound class selector; there is no same-element bare form.'a.selected' {color = 'var(--color-accent-text)'background = 'var(--color-accent)'}@media {minWidth = '60rem'flexWrap = 'wrap'overflowX = 'visible'}}}'#tickets' {listStyle = 'none'margin = '0'padding = '0'display = 'grid'gap = '.5rem'li {display = 'grid'gridTemplateColumns = 'minmax(0, 1fr)'gap = '.3rem'padding = '.7rem .8rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'ticketState {justifySelf = 'start'}// Keep the combinator as a quoted nested key.'> a' {minWidth = 'var(--layout-tap)'minHeight = 'var(--layout-tap)'display = 'flex'alignItems = 'baseline'paddingBlock = '.5rem'color = 'var(--color-text-strong)'fontWeight = '600'overflowWrap = 'anywhere'}@media {minWidth = '60rem'gridTemplateColumns = '8.5rem minmax(0, 1fr) auto'alignItems = 'center'gap = '1rem'}}}ticketRef {flex = 'none'marginRight = '.4rem'color = 'var(--color-text-muted)'fontWeight = '400'whiteSpace = 'nowrap'}ticketMeta {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '.2rem .8rem'fontSize = '.875rem'a {display = 'inline-flex'alignItems = 'center'minWidth = 'var(--layout-tap)'minHeight = 'var(--layout-tap)'}}assignee {color = 'var(--color-text-muted)'}// Keep the selector into a composed component; this View does not own its elements.'modal-dialog form' {display = 'grid'gap = '.7rem'}headingRow {display = 'flex'flexWrap = 'wrap'alignItems = 'center'justifyContent = 'space-between'gap = '.5rem 1rem'h1 {margin = '0'}}headingActions {display = 'flex'flexWrap = 'wrap'gap = '.5rem'}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)'}// Keep the compound class selector; there is no same-element bare form.'ticket-state.open' {color = 'var(--color-action)'}// Keep the compound class selector; there is no same-element bare form.'ticket-state.progress' {color = 'var(--color-warning)'}// Keep the compound class selector; there is no same-element bare form.'ticket-state.pending' {color = 'var(--color-text-muted)'}// Keep the compound class selector; there is no same-element bare form.'ticket-state.review' {color = 'var(--color-accent)'}// Keep the compound class selector; there is no same-element bare form.'ticket-state.reopened' {color = 'var(--color-danger)'}// Keep the compound class selector; there is no same-element bare form.'ticket-state.done' {color = 'var(--color-success)'}// Keep the compound class selector; there is no same-element bare form.'ticket-state.canceled' {color = 'var(--color-text-muted)'}projectActions {display = 'flex'flexWrap = 'wrap'gap = '.5rem'// Keep the compound class selector; there is no same-element bare form.'a.button' {background = 'var(--color-surface)'}}'#connections' {listStyle = 'none'margin = '0'padding = '0'display = 'grid'gap = '.4rem'li {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '.2rem .6rem'padding = '.4rem .8rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'fontSize = '.9rem'}}projectDescription {display = 'block'padding = '.8rem'overflowWrap = 'anywhere'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}'#connectionmessage' {empty {display = 'none'}}// Keep the query at Style root so size declarations stay declarations.@media {minWidth = '60rem'ticketBoard {// Keep the selector into a composed component; this View does not own its elements.'modal-dialog > dialog' {width = 'min(34rem, calc(100vw - 2rem))'height = 'fit-content'maxHeight = 'calc(100dvh - 2rem)'borderRadius = 'var(--radius-large)'}}}}View {ticketBoard {headingRow {h1 { id = "heading" heading }headingActions {if (canCreateProject) { button { id = "newprojectlink" type = "button" "New project" on click(e) { emit openWindow('newprojectmodal') } } }if (canWrite) { button { id = "newticketbutton" type = "button" class = "primary" "New ticket" on click(e) { emit openWindow('newticketmodal') } } }}}ticketFilters {nav { id = "projectfilter"for (f of projects) { a { href = f.href class = f.cls f.label } }}nav { id = "statefilter"for (f of stateFilters) { a { href = f.href class = f.cls f.label } }}}if (noSuchProject) { p { id = "noproject" class = "empty" "There is no such project." } }if (hasDescription) { projectDescription { id = "description" Markdown { blocks = descriptionMd } } }if (hasConnections) { ul { id = "connections"for (c of connections) {li { class = "connection""Connected to " strong { c.text }if (isAdmin) { button { type = "button" class = "quiet danger disconnect" "Disconnect" on click(e) { emit dropConnection(c.id) } } }}}} }p { id = "connectionmessage" Style.pMessage connectionMessage }if (isAdmin) { projectActions { a { id = "settingslink" class = "button" href = settingsHref "Project settings" } } }if (mustLogIn) { p { id = "loginhint" Style.pHint "Reading is open to everyone. To open a ticket, log in with ident (top right)." } }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." } }if (canWrite) { Modal { id = "newticketmodal" title = "New ticket"form { id = "newticketform"on submit(e) {e.preventDefault()emit create(e)}label { "Project"select { id = "newproject" name = "project" value = newProject on change(e) { emit setProject(e.target.value) }for (p of myProjects) { option { value = p.slug p.title } }}}label { "Subject"input { id = "newsubject" name = "subject" required = "required" maxlength = "200" value = newSubject on input(e) { emit setSubject(e.target.value) } }}mdField { id = "newsummary" on input(e) { emit setSummary(e.target.name, e.target.value) }span { "Summary" }for (f of summaryForms) { MdEditor { name = "summary" value = "" rows = 4 placeholder = "" files = "off" } }}button { id = "newsubmit" type = "submit" "Open ticket" }p { id = "newmessage" Style.pMessage newMessage }}} }if (canCreateProject) { Modal { id = "newprojectmodal" title = "New project"ProjectForm { onCreated = projectCreated }} }if (hasNotice) { p { id = "notice" notice " " a { id = "noticelink" href = noticeHref noticeLink } } }if (isEmpty) { p { id = "empty" class = "empty" "No tickets here." } }ol { id = "tickets" class = "tickets"for (row of rows) {li {ticketState { class = row.stateSlug row.state }a { class = "subject" href = row.href ticketRef { row.ref } row.subject }ticketMeta {a { href = row.projectHref row.projectTitle }if (row.hasAssignee) { assignee { "→ " row.assignee } }time { row.updated }}}}}if (hasMore) { button { id = "moretickets" type = "button" class = "quiet" moreLabel on click(e) { emit showMore(e) } } }}}on showMore(e) {limit = limit + pageSizer = emit server moreRows(projectName != null ? projectName : '', filterState != null ? filterState : '', limit)if (r != null && r.rows != null) {rows = r.rowstotal = r.totalisEmpty = rows.length == 0hasMore = rows.length < totalmoreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'}}on server moreRows(project, state, n, session) {return firstRows(project != '' ? project : null, state != '' ? state : null, n)}// the window of a form (Esc, the × and a tap beside it close it)on openWindow(id) { document.getElementById(id).showModal() }on setProject(v) { newProject = v }on setSubject(v) { newSubject = v }// the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not iton setSummary(name, v) { if (name == 'summary') { newSummary = v } }on create(e) {if (newProject.trim() == '' || newSubject.trim() == '') { return null }r = emit server openTicket(newProject, newSubject, newSummary)if (r != null && r.error == null) {notice = 'Opened ' + r.project + ' ' + r.ref + '.'noticeHref = r.hrefnoticeLink = 'open it'hasNotice = truenewMessage = ''document.getElementById('newticketmodal').close('opened')newSubject = ''newSummary = ''summarySeq = summarySeq + 1summaryForms = [{ id = 'summary-' + summarySeq }]} else {newMessage = r != null ? r.error : 'could not open the ticket'}}// the project form (components/project-form.hl) tells the page: the window closes, the page says it and links the settingsprojectCreated = (title, settingsHref) => {notice = 'Created ' + title + '.'noticeHref = settingsHrefnoticeLink = 'open its settings'hasNotice = truedocument.getElementById('newprojectmodal').close('created')}// does a row belong in THIS list (its filters)?belongs = (row) => {return (projectName == null || row.projectId == projectId) && (filterState == null || row.state == filterState)}// the row goes to the top (newest update first) if it belongs, and out if notplace = (row) => {let wasIn = falsefor (r of rows) { if (r.id == row.id) { wasIn = true } }allShown = rows.length >= totalnext = []if (belongs(row)) { next.push(row) }for (r of rows) { if (r.id != row.id) { next.push(r) } }// a new ticket joins the count when everything was on the page; one that left the filter leaves itif (belongs(row) && !wasIn && allShown) { total = total + 1 }if (!belongs(row) && wasIn) { total = total - 1 }if (allShown && next.length > limit) { limit = next.length }rows = next.length > limit ? next.slice(0, limit) : nextisEmpty = rows.length == 0hasMore = rows.length < totalmoreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'}on client ticketCreated(row) { place(row) }on dropConnection(id) {r = emit server disconnectApp(projectId, id)if (r == null || r.error != null) {connectionMessage = r != null ? r.error : 'could not disconnect'return null}connectionMessage = ''connections = r.connectionshasConnections = r.connections.length > 0}on client connectionsChanged(slug) {r = emit server connectionsOfProject(projectId)if (r != null && r.connections != null) {connections = r.connectionshasConnections = r.connections.length > 0}}on client signedIn(tag, info) {r = emit server whatICanOpen(projectName != null ? projectName : '')if (r != null && r.projects != null) {myProjects = r.projectscanWrite = r.projects.length > 0noRole = r.projects.length == 0 && info.namedcanCreateProject = info.namedmustLogIn = falseisAdmin = r.admin == trueif (newProject == '' && r.projects.length > 0) { newProject = r.projects[0].slug }}}on client signedOut(tag) {canWrite = falsecanCreateProject = falseisAdmin = falsenoRole = falsemustLogIn = truemyProjects = []}on client ticketEvent(ticketId, ev, row) { place(row) }// THE FACE: a ticket opened from the web by the session's user (#31: only a real session).// The same push the API sends.on server openTicket(project, subject, summary, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }r = createTicket(project, subject, summary, w.user, null, null)if (r.error != null) { return { error = r.error } }emit client ticketCreated(r.ticket)return r.ticket}// what this session's user may do here after a login without a reload: the projects they may open tickets in,// and whether they are an admin of THIS page's project (`slug` null = the all-projects page)on server whatICanOpen(slug, session) {u = userOfSession(session)if (u == null) { return { error = 'log in first' } }p = slug != null && slug != '' ? projectByAnySlug(slug) : nullreturn { projects = editableProjects(u) admin = p != null && isAdminOf(p.id, u) }}// ticket #21: an admin ends a connection — the key is dead at once (connections.hl)on server disconnectApp(projectId, connectionId, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }r = disconnect('' + projectId, w.user, '' + connectionId)if (r.error != null) { return { error = r.error } }emit client connectionsChanged('')return { connections = r.connections }}on server connectionsOfProject(projectId, session) {return { connections = connectionRows('' + projectId) }}
Branches
Latest commits
- 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
- bc3bdecerecords: day38b live, #94 purgedmre
- f6c5aa0dMerge main (records)mre
- e23d42acconnect gate: wait for hydration before clicking Disconnectmre
- a5d45d00records: D38 cause, GOmre
- 19eeb938records: D38 gates, two day38b failuresmre