tickets
All repositories: gitoria
9.8 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, and the form that// opens a new ticket. 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, 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'projectName = nullstateSlug = nullfilterState = stateOfSlug(stateSlug)rows = ticketRows(projectName, filterState)projects = 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 == 0heading = (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 = ''// 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 = ''hasNotice = falseView {ticketBoard {h1 { id = "heading" heading }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 }projectActions {if (canCreateProject) { a { id = "newprojectlink" class = "button" href = "/new-project" "New project" } }if (isAdmin) { 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) { details { id = "newticket"summary { "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" }}} }if (hasNotice) { p { id = "notice" class = "notice" notice " " a { id = "noticelink" href = noticeHref "open it" } } }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 }}}}}}}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.hrefhasNotice = truenewSubject = ''newSummary = ''summarySeq = summarySeq + 1summaryForms = [{ id = 'summary-' + summarySeq }]} else {notice = r != null ? r.error : 'could not open the ticket'noticeHref = ''hasNotice = true}}// 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) => {next = []if (belongs(row)) { next.push(row) }for (r of rows) { if (r.id != row.id) { next.push(r) } }rows = nextisEmpty = next.length == 0}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
- 6f503cfctests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
- e17e2855re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- a6ddccd2re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
- 81e036b7docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
- 5d8d2cf6deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
- 58e8c02cmission 024: report, LOG, STATUS, e2e fixmre
- 50778073tests/e2e-route-marker.mjs: first paint marker, comments post/edit redrawmre
- c5203298mission 024: MainMenu marks the page from the route (layouts 0bcc629 main-menu.hl); browser-side marker removed; gate: marker in the server HTMLmre
- b1a4c270re-vendor Hybriel master f9614007: bin/ (git-ignored) and plugins wholemre
- 866397a0mission 023: theme from layouts 76f99f6 (current marker, menu count badge), components from 3794c59 (MdEditor keys); Inbox count as badge, current by address; gates and E2E; reportmre
- 7ed2e5e5deploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the script silently (grep under pipefail), as gitoria/layoutsmre
- bf9064a3mission 022: tickets on the layouts theme (step 1): shell, styles, gates, audit, E2E; reportmre
- f3d61711mission 022 WIP: tickets on the layouts theme (dbe3de7): AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst shell, styles reduced to the app's own, check-theme in the gates, 390 audit + real-Chrome walk scriptmre
- 31cabfccmission 021: E2E script, report, LOG, STATUSmre
- 6aea8683editor look: .empty rule only for p.empty, files off where tickets has no upload, state note one line, events test scrolls the editor into view; synced md-editor (components d702d76+6f27ad3); gate 377/0, events 52/0mre
- dce6ffa6Merge branch 'w28-deflake'mre
- 536092a1tickets (mission 019): de-flake the m016 comment clicks (B: unliked) — calmClick waits until the button stops moving; test only, no app changemre
- 9c5fd42amission 020: attachments E2E proof (lisbeth Chrome, real-data copy), reportmre
- 1206404fREADME attachments, report 018, LOG/STATUSmre
- 3d9e7f3ctests: m017 gate fixes (list count, waits before delete clicks); gate 373/0mre