tickets
All repositories: gitoria
17.4 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 + { }pNotice = noticeLook + { }ticketBoard { display = 'grid' gap = '1rem'// 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)'modal-dialog > dialog' { width = '100vw' height = '100dvh' maxHeight = 'none' borderRadius = '0' }// the empty message line of the board (a disconnect refusal) takes no room (it left a 3 rem hole under the filters)'> p.message:empty' { display = 'none' }}ticketFilters { display = 'grid' gap = '.5rem'// phone: ONE row each that scrolls sideways inside itself (14 project chips + 8 state chips filled half a screen before the first ticket)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)' }// the chip classes sit on the same <a> (set from a string): compound selectors, nothing else can say them'a.selected' { color = 'var(--color-accent-text)' background = 'var(--color-accent)' }'a.selected.open' { color = 'var(--color-accent-text)' }'a.selected.progress' { color = 'var(--color-accent-text)' }'a.selected.pending' { color = 'var(--color-accent-text)' }'a.selected.review' { color = 'var(--color-accent-text)' }'a.selected.reopened' { color = 'var(--color-accent-text)' }'a.selected.done' { color = 'var(--color-accent-text)' }'a.selected.canceled' { color = 'var(--color-accent-text)' }}// the ticket rows (this list and /inbox): the class comes from a string in the ViewolTickets = ticketsLook + { }aSubject = subjectLook + { }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'// the links of a row (the project) are a tap target tooa { display = 'inline-flex' alignItems = 'center' minWidth = 'var(--layout-tap)' minHeight = 'var(--layout-tap)' }}assignee { color = 'var(--color-text-muted)' }'assignee::before' { content = '"→ "' }// the new-ticket form and the new-project form stand in the theme's modal window (components/modal/, not in this View)'modal-dialog form' { display = 'grid' gap = '.7rem' }// the heading row of the ticket list: the title at the left, "New project" (quiet) and "New ticket" (the accent) at the rightheadingRow { display = 'flex' flexWrap = 'wrap' alignItems = 'center' justifyContent = 'space-between' gap = '.5rem 1rem'h1 { margin = '0' }}headingActions { display = 'flex' flexWrap = 'wrap' gap = '.5rem' }// the state badge: one colour per state (also used by /inbox and the ticket page)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)' }'ticket-state.open' { color = 'var(--color-action)' }'ticket-state.progress' { color = 'var(--color-warning)' }'ticket-state.pending' { color = 'var(--color-text-muted)' }'ticket-state.review' { color = 'var(--color-accent)' }'ticket-state.reopened' { color = 'var(--color-danger)' }'ticket-state.done' { color = 'var(--color-success)' }'ticket-state.canceled' { color = 'var(--color-text-muted)' }// ticket #20/#21: the project's actions, the apps connected to it, its descriptionprojectActions { display = 'flex' flexWrap = 'wrap' gap = '.5rem''a.button' { background = 'var(--color-surface)' }}ulConnections { 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)' }'@media (min-width: 60rem)' {olTickets { li { gridTemplateColumns = '8.5rem minmax(0, 1fr) auto' alignItems = 'center' gap = '1rem' } }ticketFilters { nav { flexWrap = 'wrap' overflowX = 'visible' } }ticketBoard { '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" Style.ulConnectionsfor (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" Style.pNotice notice " " a { id = "noticelink" href = noticeHref noticeLink } } }if (isEmpty) { p { id = "empty" class = "empty" "No tickets here." } }ol { id = "tickets" Style.olTicketsfor (row of rows) {li {ticketState { class = row.stateSlug row.state }a { Style.aSubject 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
- 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