gitoria
All repositories: gitoria
9.9 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 { class = "dir" href = e.href e.name } }if (e.isFile) { a { class = "file" href = e.href e.name } }if (e.isOther) { span { class = "file" 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" class = "message" 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''> *' {margin = '0'}}codeBrowser {display = 'grid'gap = '1rem'minWidth = '0''> *' {margin = '0'}}codeHead {display = 'grid'gap = '.3rem'minWidth = '0''> *' {margin = '0'}}codeFile {display = 'grid'gap = '.5rem'minWidth = '0''> *' {margin = '0'}}codeSide {display = 'grid'gap = '1rem'minWidth = '0'section {display = 'grid'gap = '.4rem'minWidth = '0''> *' {margin = '0'}}li {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '0 .8rem'margin = '0'padding = '0 .5rem'overflowWrap = 'anywhere'borderRadius = 'var(--radius-small)''> a:first-child' {font = '.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'}'> a' {display = 'inline-flex'alignItems = 'center'minWidth = '2.75rem'minHeight = '2.75rem'}'> 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'}'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' {display = 'inline-flex'alignItems = 'center'minHeight = '2.75rem'}a {font = '.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'}'> a:first-child' {order = '1'}'> time' {order = '2'marginLeft = 'auto'}'> span:nth-child(2)' {order = '3'flex = '1 1 100%'minWidth = '0'paddingBlock = '.1rem'}'> span.muted' {order = '4'flex = '1 1 100%'fontSize = '.875rem'}}'path-crumbs:has(> strong:only-child)' {display = 'none'}#commits {li {'> a:first-child' {order = '1'}'> time' {order = '2'marginLeft = 'auto'}'> span:nth-child(2)' {order = '3'flex = '1 1 100%'minWidth = '0'paddingBlock = '.1rem'}'> 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)''> a' {flex = '1 1 auto'display = 'flex'alignItems = 'center'minWidth = '0'minHeight = '2.75rem'padding = '0 .8rem'overflowWrap = 'anywhere'}'> span.file' {flex = '1 1 auto'display = 'flex'alignItems = 'center'minWidth = '0'minHeight = '2.75rem'padding = '0 .8rem'overflowWrap = 'anywhere'}'> span.muted' {flex = 'none'whiteSpace = 'nowrap'fontSize = '.875rem'}}'li:nth-child(odd)' {background = 'var(--color-background-sunken)'}'a.dir' {fontWeight = '700'}'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%'}'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'}}@media {minWidth = '60rem'codeBrowser {gridTemplateColumns = 'minmax(0, 1fr) 18rem'alignItems = 'start'columnGap = '2rem''> *' {gridColumn = '1'}'> code-side' {gridColumn = '2'gridRow = '1 / span 4'}}}}
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
- 2ed09441Use layouts theme 17e0f03 for W61 compatibilitymre
- b8609a91Merge branch 'main' into w61-stylemre
- 4639caf7Report W61 theme startup blocker and day39 Style probemre
- 81f0a0bbREADME: two caches were restored by 90b4f72; log W62mre
- 4a3f557eImport layouts theme ebd00b6 for W61 (startup blocked)mre
- ab12a257Merge W62: #25 commit page measurements and proc repromre
- 41323e49gitoria#25: measure commit request costs and reproduce blocking process waitsmre
- 53ca42b2log: W60 merged, W61 W62 startedmre
- 80870a33mission W61: style passmre
- 560fd208Merge W60: helpers, bound forms, login in topics, two form fixes (gitoria#28 #32 #33)mre
- ac5ba6a4log: W60, #25 measuredmre
- 220f6342W60: record corrected form proof, full AE and remaining gapsmre
- 7e31cac5gitoria#28: restrict reply form layout to reply formsmre
- ae373cfdgitoria#28: keep each reply draft in its thread componentmre
- eeeebd5agitoria: insert a newly created organization oncemre
- 34d2d5cagitoria: clear the bound public-key textarea after creationmre
- 119e54c0W60: restore conductor-owned tracking filesmre
- 24b479e7W60: record final gates, Chrome failures and AE evidencemre
- 5e11184cW60: record partial validation, framework gaps and cleanupmre
- 20fe13fagitoria#33: centralize login and tickets connection statemre