tickets
All repositories: gitoria
12.5 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'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 = falseView {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" class = "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" class = "message" connectionMessage }if (isAdmin) { projectActions { a { id = "settingslink" class = "button" href = settingsHref "Project settings" } } }if (mustLogIn) { p { id = "loginhint" class = "hint" "Reading is open to everyone. To open a ticket, log in with ident (top right)." } }if (noRole) { p { id = "rolehint" class = "hint" "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" class = "message" newMessage }}} }if (canCreateProject) { Modal { id = "newprojectmodal" title = "New project"ProjectForm { onCreated = projectCreated }} }if (hasNotice) { p { id = "notice" class = "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 } }let 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
- 4348dbabident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
- 66ef3005Merge branch 'iw-ident-widget'mre
- bc0ad663tickets: a gap between your name and Log out in the phone header (they touched); gate checks itmre
- 2f818d46UX2: report, LOG line, e2e fixes, gate pause after loadmre
- af3ef7c4gate: the legacy state line says progressmre
- 62480a00tickets#33: a state change with a note is a comment card in the feed (same framework rendering, can be liked, edited, deleted), its state line stands alone; gate checks for a new comment with and without a state change, at once and after a reloadmre
- 4ae80007UX: Respond is one composer (state in its footer, button says what happens); New ticket / New project windows in the list heading row; project form shared; theme copied from layouts; gates and a lisbeth e2emre
- f03b438atickets header: the selector alone top right plus your name and Log out as before the theme missions; the user icon is gonemre
- 81f10e4eident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
- e9f428e7tools: reown-authors (tracker#36: every author that is not Caramboleyo or Apollo becomes the project's conductor; antcolony, miserit-anthar, hybrilior, termuplex stay) and a read-only author surveymre
- f51029abMerge branch 'sy-sync'mre
- eae6e8c7sync components.hybriel 4922f9c: comments like / Edit / Delete / 'edited' are 44 px targets; gate: 'edited' hit-area padding, thread targets check (SY)mre
- 0de4750btheme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
- 4eeb7bfeST2 report wordingmre
- 2558f56cst2-sec: keep the hlsid session cookie name (no one is signed out), Secure flag only; gate: a cookie issued by main stays signed in; ident stub serves selector.js; security.mjs in deploy GATESmre
- ea2e440esecurity audit (ST): JSON body cap, relation rights, login session rotation, __Host- Secure cookie, API security headers, CSP+referrer meta, /connect cap, one-line subjects, tests/security.mjs, reportmre
- 7c8c2282sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- b6277497report MT-mobile, LOGmre
- 6709398blist paging: the newest rows come first (the sorted array was not used); filter rows hide their scrollbar; gate checks the ordermre
- 31736a80gate: member-name check fails on the old row layout toomre