tickets
All repositories: gitoria
33.8 KB
// components/ticket.hl — `/:projectSlug/:ticketNumber` (ticket #25; was /projects/…): one ticket, its// append-only event history, a comment form and the state change. (Old URLs `/tickets/<n>`,// `/projects/<slug>/<n>`, `/projects/<slug>/tickets/<n>` are 301-redirected here by lib/api.hl.) Live: an event on THIS ticket (from any browser or// the API) is appended here and the state badge follows, without a reload.// Ticket #6 (mission 014): the summary, comments and state notes are MARKDOWN, rendered by the// child component Markdown (components/markdown.hl) from markdown.hl's blocks — safe: no HTML// string, links checked. Ticket #8: the ticket's AUTHOR (a ticket from before the login: the// creator) gets "Edit" — subject + summary; the edit is a history event that keeps the previous// values ("edited the ticket", the previous summary folded under it), pushed live like a comment.// Ticket #4 (mission 017): RELATIONS — "Part of <parent>", the children with their states and// "all children confirmed" / "n of m children confirmed", "Blocked by" and "Blocks" (each with// states); logged-in users get the forms "Parent" (set / remove) and "Blocked by" (add / remove per// row) — the store decides who may (the author of either ticket, or the creator). Live: the// `ticketsRelated` push carries the relation view of every ticket involved in a write.// Ticket #12 (mission 024): the Markdown fields are edited visually; since mission 016 with the Hybriel MdEditor (below).// Ctrl/Cmd+Enter in an editor sends its form.// Ticket #20 (roles): a member of the project may comment; `use` also moves the ticket between open and// review; `edit` / `admin` edit it, assign it (a member; "Assigned to …" is shown) and set any state; a// visitor without a role only reads. The server decides in every case; the page only shows what it may.// A ticket opened through a FORMER slug of its project shows a note with the current address.// Mission 016 (layouts#2): THE COMMENTS are drawn by the shared Comments block (components/comments/, copied verbatim from// components.hybriel.worldapi.org — tools/sync-components.sh): in the history every run of comments that follow each other is// one block, in place between the state changes etc. (`entries`, entriesOf); "write a comment" is a last block under// "Respond". The block shows Edit / Delete on the user's own comments (it asks before a delete) and a like; it tells this// page through the four functions it is handed (posted / edited / deleted / liked), the faces below write (lib/comments.hl// decides who may: the author edits and deletes, any member likes), and the push `commentChanged` swaps the row in every// open page. A deleted comment stays one line in the history ("commented (deleted …)"). Signed out / no member: user ''// (read only). The block's count line and its form are hidden inside the history (styles.hl): it has no switch for them.// The Markdown fields (edit summary, state note) are the Hybriel MdEditor (components/md-editor/, the block's editor); the// old <md-editor> of shared/md-editor.js is gone — it would have taken over the block's own <md-editor> elements.// tickets#27 (mission 017): ATTACHMENTS. The "Respond" block has attach = "true": its form sits in the shared FilesUpload (pick// mode; components/files-upload/, copied verbatim) — files chosen, photographed, dropped or pasted (Ctrl+V, also into the editor)// wait under it and go with the post (face commentWithFiles; lib/attachments.hl checks and stores them). Each comment shows its// files: pictures as thumbnails that open the full picture, other files as rows. Only members may fetch them, so for anybody else// the block gets the files without `url` (names and sizes, no link).parent './main.hl'import { ticketRowAt, ticketRecord, eventRows, stateChoices, addComment, changeComment, changeState, assignTicket, editTicket, mayEditId, ticketRights, relatedViews, setParent, changeBlocker } from '../lib/tickets.hl'import { assignChoices, isMember } from '../lib/projects.hl'import { relationViewOf, noRef } from '../lib/tickets-helpers.hl'import { pageEventsOf, pageEventOf } from '../lib/events.hl'import { markdownBlocks } from '../lib/markdown.hl'import { siteName } from '../project.hl'import { canWriteSession, writerOfSession, userOfSession } from '../lib/users.hl'import Markdown from './markdown.hl'import Comments from './comments/comments.hl'import MdEditor from './md-editor/md-editor.hl'import { hintLook, messageLook } from '../lib/looks.hl'projectSlug = nullticketNumber = nullrow = ticketRowAt(projectSlug, ticketNumber)present = row != nullgone = row == nullticketId = row != null ? row.id : ''ref = row != null ? row.ref : ''movedNote = row != null && projectSlug != row.projectcurrentHref = row != null ? row.href : ''assignee = row != null ? row.assignee : ''hasAssignee = row != null && row.hasAssigneecreatedBy = row != null ? row.createdBy : ''hasOld = row != null && row.hasOldoldRef = row != null ? row.oldRef : ''subject = row != null ? row.subject : 'No such ticket'summary = row != null ? row.summary : ''hasSummary = row != null && row.summary != ''summaryMd = row != null ? markdownBlocks(row.summary) : []project = row != null ? row.project : ''projectHref = row != null ? row.projectHref : '/'state = row != null ? row.state : ''stateSlug = row != null ? row.stateSlug : ''created = row != null ? row.created : ''updated = row != null ? row.updated : ''events = row != null ? pageEventsOf(eventRows(row.id)) : []__title = siteName + ' | ' + (row != null ? row.project + ' ' + row.ref + ' ' + row.subject : 'no such ticket')// the forms: only for a logged-in user with a display name (ticket #7); the author is that// user (the faces read the session). Confirm / reject: the server refuses a non-creator.session = nullme = userOfSession(session)canWrite = row != null && me != null && isMember(row.projectId, me)mustLogIn = me == nullnotMember = me != null && !canWriteoptions = row != null ? stateChoices(ticketRecord(row.id), me) : []memberOptions = row != null ? assignChoices(row.projectId) : []// the comments (mission 016): the user the blocks compare authors with ('' = read only) and the history as entriesmeName = me != null ? me.name : ''meId = me != null ? me.id : ''writer = canWrite ? meName : ''entries = entriesOf(events, meId)noComments = []message = ''// editing (ticket #8): only the author (the server decides; the face checks again)canEdit = row != null && mayEditId(row.id, me)assignDraft = row != null ? row.assigneeId : ''assignMessage = ''editing = falseshowEdit = canEditshowEdit2 = canEditeditSubject = ''editSummary = ''editStart = ''editMessage = ''// relations (ticket #4): the view of lib/tickets-helpers.hl relationViewOf, flat members for the Viewrel = row != null ? relationViewOf(row) : nullhasRelations = rel != null && rel.hasRelationshasParent = rel != null && rel.hasParentparentRef = rel != null ? rel.parent : noRefhasChildren = rel != null && rel.hasChildrenchildren = rel != null ? rel.children : []childNote = rel != null ? rel.childNote : ''childClass = rel != null ? rel.childClass : ''hasBlockedBy = rel != null && rel.hasBlockedByblockedBy = rel != null ? rel.blockedBy : []hasBlocks = rel != null && rel.hasBlocksblocks = rel != null ? rel.blocks : []parentDraft = ''blockerDraft = ''linkMessage = ''Style {pHint = hintLook + { }pMessage = messageLook + { }ticketView {display = 'grid'gridTemplateColumns = 'minmax(0, 1fr)'gap = '1.2rem'header {display = 'grid'gap = '.4rem'p {margin = '0'}ticketState {justifySelf = 'start'}button {justifySelf = 'start'}}section {display = 'grid'gap = '.7rem'}form {display = 'grid'gap = '.5rem'}}'#dates' {color = 'var(--color-text-muted)'fontSize = '.875rem'}'#people' {margin = '0'color = 'var(--color-text-muted)'fontSize = '.9rem'strong {color = 'var(--color-text)'}}formerRef {marginLeft = '.2rem'fontSize = '.875rem'color = 'var(--color-text-muted)'}ticketSummary {display = 'block'padding = '.8rem'overflowWrap = 'anywhere'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}'#events' {listStyle = 'none'margin = '0'padding = '0'display = 'grid'gap = '.5rem'// Keep the combinator as a quoted nested key.'> li' {marginLeft = '.8rem'padding = '.5rem .7rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-small)'}// Keep the combinator as a quoted nested key.'> li.state' {background = 'transparent'padding = '.2rem .7rem'}// Keep the combinator as a quoted nested key.'> li.link' {background = 'transparent'padding = '.2rem .7rem'}// Keep the combinator as a quoted nested key.'> li.comments' {padding = '.3rem 0'background = 'transparent'contain = 'inline-size'}// Keep the combinator as a quoted nested key.'> li.comment.deleted' {background = 'transparent'padding = '.2rem .7rem'fontStyle = 'italic'color = 'var(--color-text-muted)'}}// Keep the selector into a composed component; this View does not own its elements.'#events comments-block h2.comments-count' {display = 'none'}// Keep the selector into a composed component; this View does not own its elements.'#events comments-block .comments-empty' {display = 'none'}// Keep the selector into a composed component; this View does not own its elements.'#events comments-block form.comment-form' {display = 'none'}// Keep the selector into a composed component; this View does not own its elements.'#events comments-block ol.comment-list' {margin = '0'}// Keep the selector into a composed component; this View does not own its elements.'#commentform h2.comments-count' {display = 'none'}// Keep the selector into a composed component; this View does not own its elements.'#commentform .comments-empty' {display = 'none'}// Keep the selector into a composed component; this View does not own its elements.'#commentform ol.comment-list' {display = 'none'}commentForm {display = 'block'}eventHead {display = 'block'fontSize = '.9rem'strong {color = 'var(--color-text-strong)'}}eventText {display = 'block'marginTop = '.3rem'overflowWrap = 'anywhere'}// Keep the compound class selector; there is no same-element bare form.'event-text.edit' {fontSize = '.9rem'color = 'var(--color-text-muted)'p {margin = '0'}s {color = 'var(--color-text)'}details {marginTop = '.3rem'background = 'var(--color-background-sunken)'}summary {padding = '.3rem .6rem'fontWeight = '400'fontSize = '.875rem'}}// Keep the selector into a composed component; this View does not own its elements.'event-text.edit markdown-text' {padding = '0 .6rem .5rem'color = 'var(--color-text)'}'#editform' {padding = '.8rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}formButtons {display = 'grid'gridTemplateColumns = 'repeat(auto-fit, minmax(9rem, 1fr))'gap = '.5rem'@media {minWidth = '60rem'display = 'flex'flexWrap = 'wrap'}}mdField {display = 'grid'gap = '.25rem'// Keep the combinator as a quoted nested key.'> span' {fontSize = '.9rem'color = 'var(--color-text-muted)'}}ticketRelations {display = 'grid'gap = '.8rem'padding = '.8rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'h2 {margin = '0 0 .4rem'fontSize = '1rem'}p {margin = '0'}}'#parent' {a {display = 'inline-flex'alignItems = 'center'minHeight = 'var(--layout-tap)'fontWeight = '600'whiteSpace = 'nowrap'}}spanRefsubject {color = 'var(--color-text-strong)'overflowWrap = 'anywhere'}'#childnote' {margin = '0 0 .4rem'fontSize = '.9rem'color = 'var(--color-text-muted)'}// Keep the compound class selector; there is no same-element bare form.'#childnote.done' {fontWeight = '600'color = 'var(--color-success)'}ulRefs {listStyle = 'none'margin = '0'padding = '0'display = 'grid'gap = '.35rem'a {display = 'inline-flex'alignItems = 'center'minHeight = 'var(--layout-tap)'fontWeight = '600'whiteSpace = 'nowrap'}li {display = 'flex'flexWrap = 'wrap'alignItems = 'baseline'gap = '.2rem .6rem'}}buttonUnblock {padding = '.1rem .6rem'fontSize = '.875rem'marginLeft = 'auto'}'#parentform' {@media {minWidth = '60rem'gridTemplateColumns = 'minmax(0, 1fr) auto'alignItems = 'end'}}'#blockerform' {@media {minWidth = '60rem'gridTemplateColumns = 'minmax(0, 1fr) auto'alignItems = 'end'}}}View {ticketView {if (gone) { p { id = "gone" class = "empty" "There is no such ticket." } }if (present) {header {p { a { id = "project" href = projectHref project } " " ticketRef { id = "ref" ref }if (hasOld) { formerRef { id = "oldref" "formerly " oldRef } }}h1 { id = "subject" subject }ticketState { id = "state" class = stateSlug state }p { id = "people" "opened by " strong { id = "createdby" createdBy }if (hasAssignee) { " · assigned to " strong { id = "assignee" assignee } }}if (movedNote) { p { id = "movednote" Style.pHint "This project has a new address: " a { id = "movedlink" href = currentHref currentHref } } }p { id = "dates" "opened " time { created } " · updated " time { id = "updated" updated } }if (showEdit) { button { id = "editbutton" type = "button" class = "quiet" "Edit" on click(e) { emit startEdit(e) } } }}if (editing) {form { id = "editform"on submit(e) {e.preventDefault()emit saveEdit(e)}label { "Subject"input { id = "editsubject" name = "subject" required = "required" maxlength = "200" value = editSubject on input(e) { emit setEditSubject(e.target.value) } }}mdField { id = "editsummary" on input(e) { emit setEditSummary(e.target.name, e.target.value) }span { "Summary" }MdEditor { name = "summary" value = editStart rows = 8 files = "off" }}formButtons {button { id = "editsave" type = "submit" "Save" }button { id = "editcancel" type = "button" class = "quiet" "Cancel" on click(e) { emit cancelEdit(e) } }}p { id = "editmessage" Style.pMessage editMessage }}}if (hasSummary) { ticketSummary { id = "summary" Markdown { blocks = summaryMd } } }if (hasRelations) { ticketRelations { id = "relations"if (hasParent) { p { id = "parent" "Part of "a { href = parentRef.href parentRef.project " " parentRef.ref }" " span { Style.spanRefsubject parentRef.subject }" " ticketState { class = parentRef.stateSlug parentRef.state }} }if (hasChildren) { div { id = "childrenbox"h2 { "Children" }p { id = "childnote" class = childClass childNote }ul { id = "children" Style.ulRefsfor (c of children) { li {ticketState { class = c.stateSlug c.state }a { href = c.href c.project " " c.ref }span { Style.spanRefsubject c.subject }} }}} }if (hasBlockedBy) { div { id = "blockedbybox"h2 { "Blocked by" }ul { id = "blockedby" Style.ulRefsfor (c of blockedBy) { li {ticketState { class = c.stateSlug c.state }a { href = c.href c.project " " c.ref }span { Style.spanRefsubject c.subject }if (showEdit2) { button { type = "button" class = "quiet" Style.buttonUnblock value = c.key "Remove" on click(e) { emit removeBlocker(e.target.value) } } }} }}} }if (hasBlocks) { div { id = "blocksbox"h2 { "Blocks" }ul { id = "blocks" Style.ulRefsfor (c of blocks) { li {ticketState { class = c.stateSlug c.state }a { href = c.href c.project " " c.ref }span { Style.spanRefsubject c.subject }} }}} }} }section {h2 { "History" }ol { id = "events"for (en of entries) {if (en.isGroup) { li { class = "comments"Comments { comments = en.comments user = writer onPost = posted onEdit = edited onDelete = deleted onLike = liked }} }if (en.isEvent) { li { class = en.clseventHead {strong { en.ev.author }" " en.ev.labelif (en.ev.isState) { " " ticketState { class = en.ev.toSlug en.ev.to } }" " time { en.ev.when }}if (en.ev.isEdit) { eventText { class = "edit"if (en.ev.subjectChanged) { p { class = "was" "Subject before: " s { en.ev.oldSubject } } }if (en.ev.summaryChanged) { details { class = "was"summary { "Summary before" }Markdown { blocks = en.ev.oldSummaryMd }} }} }if (en.ev.hasText) { eventText { Markdown { blocks = en.ev.md } } }} }}}}if (mustLogIn) {p { id = "loginhint" Style.pHint "Reading is open to everyone. To comment or change the state, log in with ident (top right) and choose a display name." }}if (notMember) {p { id = "memberhint" Style.pHint "You are not a member of this project — ask an admin to invite you to comment." }}if (canWrite) { section {h2 { "Respond" }commentForm { id = "commentform"Comments { comments = noComments user = writer onPost = respond states = options emptyText = "" placeholder = "Write a comment (Markdown; Ctrl+Enter sends)" attach = "true" maxFileSize = 10485760 attachText = "Choose pictures or files — or drop or paste them anywhere in the box" }}p { id = "message" Style.pMessage message }} }if (showEdit2) { section {h2 { "Manage" }form { id = "assignform"on submit(e) {e.preventDefault()emit sendAssign(e)}label { "Assigned to"select { id = "assignselect" name = "assignee" value = assignDraft on change(e) { emit setAssignDraft(e.target.value) }option { value = "" "nobody" }for (o of memberOptions) { option { value = o.value o.label } }}}button { id = "assignsave" type = "submit" "Assign" }}p { id = "assignmessage" Style.pMessage assignMessage }form { id = "parentform"on submit(e) {e.preventDefault()emit sendParent(e)}label { "Parent ticket (project#number)"input { id = "parentkey" name = "parent" placeholder = "e.g. ident.worldapi.org#1" autocomplete = "off" value = parentDraft on input(e) { emit setParentDraft(e.target.value) } }}formButtons {button { id = "parentsave" type = "submit" "Set parent" }if (hasParent) { button { id = "parentremove" type = "button" class = "quiet" "Remove parent" on click(e) { emit removeParent(e) } } }}}form { id = "blockerform"on submit(e) {e.preventDefault()emit sendBlocker(e)}label { "Blocked by (project#number)"input { id = "blockerkey" name = "blocker" placeholder = "e.g. hybriel#12" autocomplete = "off" value = blockerDraft on input(e) { emit setBlockerDraft(e.target.value) } }}button { id = "blockeradd" type = "submit" "Add blocker" }}p { id = "linkmessage" Style.pMessage linkMessage }} }}}}on setEditSubject(v) { editSubject = v }// the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not iton setEditSummary(name, v) { if (name == 'summary') { editSummary = v } }on startEdit(e) {editSubject = subjecteditSummary = summaryeditStart = summaryeditMessage = ''editing = trueshowEdit = false}on cancelEdit(e) {editing = falseshowEdit = canEditeditMessage = ''}on saveEdit(e) {r = emit server ticketEdit(ticketId, editSubject, editSummary)if (r != null && r.error != null) {editMessage = r.errorreturn null}editing = falseshowEdit = canEditeditMessage = ''}on setAssignDraft(v) { assignDraft = v }on sendAssign(e) {r = emit server ticketAssign(ticketId, assignDraft)if (r != null && r.error != null) { assignMessage = r.error } else { assignMessage = '' }}on setParentDraft(v) { parentDraft = v }on setBlockerDraft(v) { blockerDraft = v }// relations (ticket #4): the answer is only ok / error — the page follows the pushon sendParent(e) {if (parentDraft.trim() == '') {linkMessage = 'name the parent as project#number'return null}r = emit server ticketSetParent(ticketId, parentDraft)if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' parentDraft = '' }}on removeParent(e) {r = emit server ticketSetParent(ticketId, '')if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }}on sendBlocker(e) {if (blockerDraft.trim() == '') {linkMessage = 'name the blocking ticket as project#number'return null}r = emit server ticketAddBlocker(ticketId, blockerDraft)if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' blockerDraft = '' }}on removeBlocker(key) {r = emit server ticketRemoveBlocker(ticketId, key)if (r != null && r.error != null) { linkMessage = r.error } else { linkMessage = '' }}// ---- the comments (mission 016): the history as entries — a run of comments is one block, every other event one line.// A comment entry is the block's record { id, author, when, text, likes, liked, history, files }; a deleted comment is a line.// every viewer who sees a comment gets its files' url (tickets#37): reading is public, so the thumbnail and the file are too.entriesOf(list, uid) {out = []let run = []for (ev of list) {if (ev.kind == 'comment' && ev.deleted != true) {run.push(commentOf(ev, uid))} else {let shown = ev// tickets#33: a state change that carries a note is a comment card (put into the feed like any comment) followed by the state line aloneif (ev.kind == 'state' && ev.hasText == true) {run.push(commentOf(ev, uid))shown = { id = ev.id kind = ev.kind author = ev.author label = ev.label isState = true isEdit = false to = ev.to toSlug = ev.toSlug when = ev.when hasText = false deleted = false }}if (run.length > 0) {out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} })run = []}out.push({ id = '' + ev.id isGroup = false isEvent = true comments = [] cls = ev.deleted == true ? 'comment deleted' : ev.kind ev = shown })}}if (run.length > 0) { out.push({ id = 'c-' + run[0].id isGroup = true isEvent = false comments = run cls = 'comments' ev = {} }) }return out}// the block's record of a comment (or of the note of a state change)commentOf(ev, uid) {return { id = '' + ev.id author = ev.author when = ev.when text = ev.text likes = ev.likes != null ? ev.likes : 0 liked = uid != '' && ev.likedBy != null && ev.likedBy.includes(uid) history = ev.earlier != null ? ev.earlier : [] files = filesOf(ev.attachments) }}// a comment's attachments as the block shows them: { name, url, image, size }filesOf(list) {out = []if (list == null) { return out }for (a of list) { out.push({ name = a.name url = a.url image = a.image size = a.size }) }return out}// what the blocks tell this page: the faces write; every open page (this one too) follows the push. A refusal shows in// #message; a refused post answers false, so the block keeps the typed text (and the files). With files (tickets#27) the post is// the face commentWithFiles: the framework uploads them first; a file it refuses (over uploadMax) ends the emit with null.posted = (text, files) => {let r = nullif (files != null && files.length > 0) {r = emit server commentWithFiles(ticketId, text, files)if (r == null) {message = 'the comment was not sent: a file could not be uploaded (at most 10 MB each)'return false}} else {r = emit server commentOn(ticketId, text)}if (r != null && r.error != null) {message = r.errorreturn false}message = ''return true}// THE ONE COMPOSER of "Respond": a comment (with its files), a state change, or both — one request each, the comment first. The block// tells what is there: the text, the files and the state chosen ('' = no change). A comment that is refused keeps everything in the form// (false); a comment that went through and a state change that is refused clears the form and shows the refusal; a state change// alone that is refused keeps the form.respond = (text, files, state) => {words = text.trim() != '' || (files != null && files.length > 0)if (words) {ok = posted(text, files)if (ok == false) { return false }}if (state != '') {r = emit server setTicketState(ticketId, state, '')if (r != null && r.error != null) {message = r.errorreturn words}message = ''}return true}edited = (id, text) => {r = emit server ticketCommentEdit(ticketId, id, text)message = r != null && r.error != null ? r.error : ''}deleted = (id) => {r = emit server ticketCommentDelete(ticketId, id)message = r != null && r.error != null ? r.error : ''}liked = (id) => {r = emit server ticketCommentLike(ticketId, id)message = r != null && r.error != null ? r.error : ''}// ---- what the server pushes: an event on some ticket -----------------------------------on client ticketEvent(evTicket, ev, changed, count) {if ('' + evTicket == '' + ticketId) {next = []for (x of events) { next.push(x) }next.push(ev)events = nextentries = entriesOf(next, meId)state = changed.statestateSlug = changed.stateSlugupdated = changed.updatedassignee = changed.assigneehasAssignee = changed.hasAssigneeassignDraft = changed.assigneeIdrights = emit server ticketRights(ticketId)takeRights(rights)if (ev.isEdit == true) {subject = changed.subjectsummary = changed.summaryhasSummary = changed.summary != ''summaryMd = ev.summaryMd}}}// mission 016: a comment of THIS ticket was edited, deleted or (un)liked — its row is swappedon client commentChanged(evTicket, ev) {if ('' + evTicket == '' + ticketId) {next = []for (x of events) {if ('' + x.id == '' + ev.id) { next.push(ev) } else { next.push(x) }}events = nextentries = entriesOf(next, meId)}}// relations changed (a write on this ticket or on a related one): take over this ticket's viewon client ticketsRelated(views) {for (v of views) {if ('' + v.id == '' + ticketId) {hasRelations = v.hasRelationshasParent = v.hasParentparentRef = v.parenthasChildren = v.hasChildrenchildren = v.childrenchildNote = v.childNotechildClass = v.childClasshasBlockedBy = v.hasBlockedByblockedBy = v.blockedByhasBlocks = v.hasBlocksblocks = v.blocks}}}// login / logout in the shell (this session's tabs): the forms come and go without a reload// what this session's user may do on this ticket now (the face answers from their role)takeRights = (r) => {if (r == null || r.error != null) { return null }canWrite = r.comment == truemeName = r.namemeId = r.userIdwriter = r.comment == true ? r.name : ''entries = entriesOf(events, r.userId)mustLogIn = falsenotMember = !canWritecanEdit = r.edit == trueshowEdit = canEdit && !editingshowEdit2 = canEdit// the Respond block is rebuilt (and loses a draft) when a value bound into it changes: the choices only when they really changedif (!sameChoices(options, r.options)) { options = r.options }memberOptions = r.members}on client signedIn(tag, info) {r = emit server ticketRights(ticketId)takeRights(r)}on client signedOut(tag) {canWrite = falsewriter = ''meName = ''meId = ''entries = entriesOf(events, '')mustLogIn = truenotMember = falsecanEdit = falseshowEdit = falseshowEdit2 = falseediting = false}sameChoices(a, b) {if (a.length != b.length) { return false }let i = 0while (i < a.length) {if (a[i].value != b[i].value) { return false }i = i + 1}return true}// ---- the faces: the writer is the session's user (#31: a forged trailing argument is not// a real session → refused) ---------------------------------------------------------------on server commentOn(ticketId, text, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }r = addComment('' + ticketId, w.user, text, null)if (r.error != null) { return { error = r.error } }emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)return { ok = true }}// tickets#27: a comment with files — `files` arrive as [{ bytes, name, type, size }] (the framework took them from /__hl/upload);// lib/attachments.hl checks the limits and the content, a refusal comes back as the messageon server commentWithFiles(ticketId, text, files, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }if (hlTypeName(text) != 'String') { return { error = 'the comment must be text' } }r = addComment('' + ticketId, w.user, text, files)if (r.error != null) { return { error = r.error } }emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)return { ok = true }}on server setTicketState(ticketId, state, note, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }r = changeState('' + ticketId, state, w.user, note)if (r.error != null) { return { error = r.error } }emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)if (r.assignEvent != null) { emit client ticketEvent(r.ticket.id, pageEventOf(r.assignEvent), r.ticket) }emit client ticketsRelated(relatedViews(r.ticket.id, []))return { ok = true }}// mission 016: the comment's author edits / deletes it, a member likes it (again = takes it back) — lib/comments.hl decideson server ticketCommentEdit(ticketId, commentId, text, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }if (hlTypeName(text) != 'String') { return { error = 'the comment must be text' } }r = changeComment('' + ticketId, '' + commentId, w.user, 'edit', text)if (r.error != null) { return { error = r.error } }emit client commentChanged(r.ticket.id, pageEventOf(r.event))return { ok = true }}on server ticketCommentDelete(ticketId, commentId, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }r = changeComment('' + ticketId, '' + commentId, w.user, 'delete', '')if (r.error != null) { return { error = r.error } }emit client commentChanged(r.ticket.id, pageEventOf(r.event))return { ok = true }}on server ticketCommentLike(ticketId, commentId, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }r = changeComment('' + ticketId, '' + commentId, w.user, 'like', '')if (r.error != null) { return { error = r.error } }emit client commentChanged(r.ticket.id, pageEventOf(r.event))return { ok = true }}// ticket #20: assign the ticket to a member ('' = nobody); the store wants the role edit or adminon server ticketAssign(ticketId, userId, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }if (hlTypeName(userId) != 'String') { return { error = 'the assignee must be text' } }r = assignTicket('' + ticketId, w.user, userId)if (r.error != null) { return { error = r.error } }emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)return { ok = true }}// ticket #8: the author edits subject + summary (the store refuses anyone else)on server ticketEdit(ticketId, subject, summary, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }if (hlTypeName(subject) != 'String' || hlTypeName(summary) != 'String') { return { error = 'subject and summary must be text' } }r = editTicket('' + ticketId, w.user, subject, summary)if (r.error != null) { return { error = r.error } }emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)emit client ticketsRelated(relatedViews(r.ticket.id, []))return { ok = true }}// ticket #4: relations — the store refuses a user who may not (edit / admin in this ticket's project)on server ticketSetParent(ticketId, key, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }if (hlTypeName(key) != 'String') { return { error = 'the parent must be text' } }r = setParent('' + ticketId, w.user, key)if (r.error != null) { return { error = r.error } }emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)emit client ticketsRelated(r.related)return { ok = true }}on server ticketAddBlocker(ticketId, key, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }r = changeBlocker('' + ticketId, w.user, key, true, 'add')if (r.error != null) { return { error = r.error } }emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)emit client ticketsRelated(r.related)return { ok = true }}on server ticketRemoveBlocker(ticketId, key, session) {w = writerOfSession(session)if (w.error != null) { return { error = w.error } }if (hlTypeName(key) != 'String') { return { error = 'the blocker must be text' } }r = changeBlocker('' + ticketId, w.user, key, false, 'remove')if (r.error != null) { return { error = r.error } }emit client ticketEvent(r.ticket.id, pageEventOf(r.event), r.ticket)emit client ticketsRelated(r.related)return { ok = true }}// what the session's user may do on this ticket: comment (a member), edit / assign (edit, admin), the states// they may move it to, and the members it can be assigned toon server ticketRights(ticketId, session) {u = userOfSession(session)if (u == null) { return { error = 'log in first' } }t = ticketRecord('' + ticketId)if (t == null) { return { error = 'no such ticket' } }r = ticketRights(t, u)// mission 016: who the comment blocks compare authors with, and whose likes count as "liked"r.name = u.namer.userId = u.idreturn r}
Branches
Latest commits
- 7c8e6d83Limit edited state note fix to Markdown renderingmre
- 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
- f8e42a85Re-vendor tickets to Hybriel set day38b (1e554d7)mre
- 51645016Merge purge-94 (#94, identity rule)mre
- 94d6ca2arecords: D38 startedmre
- 9df09aacmission 029: day38b re-vendor + deploymre
- d2834f65records: #94 backup planmre
- 4467d8cbrecords: #94 purge readymre
- aa2d124eREADME: the #94 purge gatemre
- e843ff7cOne-time purge of miserit-anthar#94 (#94, identity rule): idempotent step in lib/migrate.hl, fixture gate tests/purge94.mjsmre
- 506a4efdmission 028: #94, identity rulemre
- 78c7f48eRefine mpackdb holdmre