gitoria
All repositories: gitoria
11.6 KB
// components/codebrowser.hl — THE CODE BROWSER (ticket #9, gitoria#16), composed into the three code pages:// code.hl (/code, /code/<path>: the main branch), branch.hl (/branch/<name>[/<path>]), commit.hl// (/commit/<id>[/<path>]); `kind` ('code' | 'branch' | 'commit') and `rest` (the part after /<kind>/) come from the// page. Rendered on the SERVER with its content: the repo from the request's host, the tree / file / branches /// commits from git (lib/code.hl browseNow — hl:proc run() waits, hybriel#80) — in the first HTML and in every hl:web navigation.import { slugOfRequest } from '../lib/orgs.hl'import { userOfSession } from '../lib/users.hl'import { repoAt, ownsRepo } from '../lib/repos.hl'import { browseNow, makeMain } from '../lib/code.hl'import { withRefParts } from '../lib/tickets-helpers.hl'host = nullorepo = ''session = nullkind = 'code'rest = ''slug = slugOfRequest(host, orepo)repo = repoAt(slug, session)hasRepo = repo != nullcodeData = repo != null ? withRefParts(browseNow(slug, kind, rest, repo.branch, ownsRepo(slug, session)), repo.ticketsProject) : nullcodeShown = codeData != null && !codeData.isMessagecodeMessage = codeData != null && codeData.isMessagecodeText = codeData != null && codeData.isMessage ? codeData.message : ''codeError = ''View {codeView {if (hasRepo) {if (codeMessage) { p { id = "codemessage" class = "empty" codeText } }if (codeShown) {codeBrowser {codeHead {span { id = "codekind" class = "muted" codeData.kindLabel }strong { id = "coderef" codeData.refLabel }latestCommit {a { id = "commitlink" href = codeData.commitHref codeData.short }span { id = "commitsubject" for (pt of codeData.subjectParts) { if (pt.isText) { span { pt.text } } if (pt.isLink) { a { class = "ticketref" href = pt.href pt.text } } } }span { class = "muted" codeData.author }time { codeData.date }}}pathCrumbs { id = "crumbs" class = "crumbs"for (c of codeData.crumbs) {if (c.linked) { a { href = c.href c.name } span { class = "muted" "/" } }if (c.last) { strong { c.name } }}}if (codeData.isTree) {if (codeData.noEntries) { p { id = "noentries" class = "empty" "This folder is empty." } }ul { id = "entries"for (e of codeData.entries) {li {if (e.isDir) { a { Style.aDir href = e.href e.name } }if (e.isFile) { a { class = "file" href = e.href e.name } }if (e.isOther) { span { Style.spanFile e.name } }span { class = "muted" e.size }}}}}if (codeData.isFile) {codeFile { id = "codefile"p { class = "muted" codeData.fileSize }if (codeData.binary) { p { id = "binary" class = "empty" "This file is not text (or not UTF-8) — not shown." } }if (codeData.tooBig) { p { id = "toobig" class = "empty" "This file is too large to show here." } }ol { id = "lines"for (ln of codeData.lines) { li { code { ln.text } } }}if (codeData.truncated) { p { id = "linestruncated" class = "muted" "Only the first lines are shown." } }}}codeSide {section { id = "branches"h2 { "Branches" }ul {for (b of codeData.branches) {li {if (b.isCurrent) { strong { b.name } }if (b.notCurrent) { a { href = b.href b.name } }if (b.isDefault) { span { class = "muted" "main branch" } }if (b.canSet) { button { class = "quiet setmain" type = "button" value = b.name "Make main" on click(e) { emit setMain(e.target.value) } } }}}}p { id = "codeerror" codeError }}section { id = "commits"h2 { "Latest commits" }ul {for (c of codeData.commits) {li {a { href = c.href c.short }span { for (pt of c.parts) { if (pt.isText) { span { pt.text } } if (pt.isLink) { a { class = "ticketref" href = pt.href pt.text } } } }span { class = "muted" c.author }time { c.date }}}}}}}}}}}// "Make main" (the owner): the face answers with the same view, read again with the new main branchon setMain(name) {codeError = ''r = emit server gitoriaSetBranch(slug, name, kind, rest)if (r == null || r.error != null) {codeError = r != null ? r.error : 'could not change the main branch'return null}codeData = r.resultcodeShown = !r.result.isMessagecodeMessage = r.result.isMessagecodeText = r.result.isMessage ? r.result.message : ''}on server gitoriaSetBranch(slugOf, name, kindOf, restOf, session) {if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not change the main branch' } }if (kindOf != 'code' && kindOf != 'branch' && kindOf != 'commit') { return { error = 'could not change the main branch' } }if (restOf == null || hlTypeName(restOf) != 'String' || restOf.length > 500 || name == null || hlTypeName(name) != 'String') { return { error = 'could not change the main branch' } }u = userOfSession(session)if (u == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can change the main branch' } }return makeMain(u.id, slugOf, name, kindOf, restOf)}Style {codeView {display = 'grid'gap = '1rem'minWidth = '0'// Direct-child and sibling combinators have no bare language form.'> *' {margin = '0'}}codeBrowser {display = 'grid'gap = '1rem'minWidth = '0'// Direct-child and sibling combinators have no bare language form.'> *' {margin = '0'}@media {minWidth = '60rem'gridTemplateColumns = 'minmax(0, 1fr) 18rem'alignItems = 'start'columnGap = '2rem'// Direct-child and sibling combinators have no bare language form.'> *' {gridColumn = '1'}// Direct-child and sibling combinators have no bare language form.'> code-side' {gridColumn = '2'gridRow = '1 / span 4'}}}codeHead {display = 'grid'gap = '.3rem'minWidth = '0'// Direct-child and sibling combinators have no bare language form.'> *' {margin = '0'}}codeFile {display = 'grid'gap = '.5rem'minWidth = '0'// Direct-child and sibling combinators have no bare language form.'> *' {margin = '0'}}codeSide {display = 'grid'gap = '1rem'minWidth = '0'section {display = 'grid'gap = '.4rem'minWidth = '0'// Direct-child and sibling combinators have no bare language form.'> *' {margin = '0'}}li {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '0 .8rem'margin = '0'padding = '0 .5rem'overflowWrap = 'anywhere'borderRadius = 'var(--radius-small)'// Direct-child and sibling combinators have no bare language form.'> a' {display = 'inline-flex'alignItems = 'center'minWidth = '2.75rem'minHeight = '2.75rem'firstChild {font = '.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'}}// Direct-child and sibling combinators have no bare language form.'> strong' {display = 'inline-flex'alignItems = 'center'minWidth = '2.75rem'minHeight = '2.75rem'}}ul {display = 'grid'margin = '0'padding = '0'listStyle = 'none'}h2 {fontSize = '1.05rem'}// This selector condition takes arguments and has no bare form.'li:nth-child(odd)' {background = 'var(--color-background-sunken)'}}latestCommit {display = 'flex'flexWrap = 'wrap'gap = '0 .8rem'alignItems = 'center'minWidth = '0'padding = '.1rem .8rem .4rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'a {font = '.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'}// Direct-child and sibling combinators have no bare language form.'> a' {firstChild {order = '1'}display = 'inline-flex'alignItems = 'center'minHeight = '2.75rem'}// Direct-child and sibling combinators have no bare language form.'> time' {order = '2'marginLeft = 'auto'}// This selector condition takes arguments and has no bare form.'> span:nth-child(2)' {order = '3'flex = '1 1 100%'minWidth = '0'paddingBlock = '.1rem'}// Direct-child and sibling combinators have no bare language form.'> span.muted' {order = '4'flex = '1 1 100%'fontSize = '.875rem'}}// This selector condition takes arguments and has no bare form.'path-crumbs:has(> strong:only-child)' {display = 'none'}#commits {li {// Direct-child and sibling combinators have no bare language form.'> a' {firstChild {order = '1'}}// Direct-child and sibling combinators have no bare language form.'> time' {order = '2'marginLeft = 'auto'}// This selector condition takes arguments and has no bare form.'> span:nth-child(2)' {order = '3'flex = '1 1 100%'minWidth = '0'paddingBlock = '.1rem'}// Direct-child and sibling combinators have no bare language form.'> span.muted' {order = '4'flex = '1 1 100%'fontSize = '.875rem'}}}pathCrumbs {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '0 .1rem'minWidth = '0'overflowWrap = 'anywhere'a {display = 'inline-flex'alignItems = 'center'justifyContent = 'center'minWidth = '2.75rem'minHeight = '2.75rem'padding = '0 .4rem'borderRadius = 'var(--radius-small)'hover {background = 'var(--color-surface)'}}}#entries {display = 'grid'margin = '0'padding = '0'listStyle = 'none'li {display = 'flex'alignItems = 'center'justifyContent = 'space-between'gap = '1rem'margin = '0'paddingRight = '.8rem'borderRadius = 'var(--radius-small)'// Direct-child and sibling combinators have no bare language form.'> a' {flex = '1 1 auto'display = 'flex'alignItems = 'center'minWidth = '0'minHeight = '2.75rem'padding = '0 .8rem'overflowWrap = 'anywhere'}// Direct-child and sibling combinators have no bare language form.'> span.muted' {flex = 'none'whiteSpace = 'nowrap'fontSize = '.875rem'}}// This selector condition takes arguments and has no bare form.'li:nth-child(odd)' {background = 'var(--color-background-sunken)'}// Pseudo-elements and parts have no bare language form.'a.dir::after' {content = '"/"'}}#lines {margin = '0'padding = '.5rem 0'overflowX = 'auto'listStyle = 'none'counterReset = 'line'background = 'var(--color-background-sunken)'borderRadius = 'var(--radius-large)'font = '.875rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'li {counterIncrement = 'line'whiteSpace = 'pre'minHeight = '1.5em'margin = '0'padding = '0 .8rem 0 0'width = 'max-content'minWidth = '100%'}// Pseudo-elements and parts have no bare language form.'li::before' {content = 'counter(line)'display = 'inline-block'width = '4ch'marginRight = '.8rem'paddingLeft = '.5rem'boxSizing = 'content-box'textAlign = 'right'color = 'var(--color-text-muted)'userSelect = 'none'}code {padding = '0'font = 'inherit'color = 'var(--color-text-strong)'background = 'transparent'}}aDir {fontWeight = '700'}spanFile {flex = '1 1 auto'display = 'flex'alignItems = 'center'minWidth = '0'minHeight = '2.75rem'padding = '0 .8rem'overflowWrap = 'anywhere'}#codeerror {margin = '0'color = 'var(--color-danger)'empty { display = 'none' }}}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 1e8f4f0avendor: Hybriel set-day52 (fault-path leak fix #335, keyed rows #331)mre
- f5f0fb7blog: 2026-11-08 day50/#29 live, H25 correction, V52 startedmre
- dc77fb95main: offline note from __hlOnline, tick removed (#29)mre
- 37a86d93tests/reviews: seeded fake hook's DNS failures are not server errors (flaky gate)mre
- 07ab845bvendor: Hybriel set-day50 (run() leak fix #335)mre
- 71b2fa4blog: hybriel#335mre
- bd94cc7elog: #25 cause found (run() leak)mre
- 565cb508log: H25 round 1mre
- 90a0af84log: H25 startedmre
- 87bd53b8mission H25mre
- 71a746cflog: day48 livemre
- bf568e14log: V48 mergedmre
- 09955dedMerge v48: Hybriel set-day48, theme layouts ce4a0bamre
- f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
- 5d0834e7log: Apollo model rulemre
- fe8e5bd5log: #25 sample, V48 missionmre
- 8580c5d9log: theme fix from Atlasmre
- 46823d93log: Apollo budget correctionmre
- f6d32341log: Apollo on budget and #25 nextmre
- d7184f53log: batch live, #25 evidencemre