gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9eff66279eff6627Merge branch 'f2-api-bugs' into mainGitoria9eff6627/components/codebrowser.hl

11.6 KB

  1. // components/codebrowser.hl — THE CODE BROWSER (ticket #9, gitoria#16), composed into the three code pages:
  2. // code.hl (/code, /code/<path>: the main branch), branch.hl (/branch/<name>[/<path>]), commit.hl
  3. // (/commit/<id>[/<path>]); `kind` ('code' | 'branch' | 'commit') and `rest` (the part after /<kind>/) come from the
  4. // page. Rendered on the SERVER with its content: the repo from the request's host, the tree / file / branches /
  5. // commits from git (lib/code.hl browseNow — hl:proc run() waits, hybriel#80) — in the first HTML and in every hl:web navigation.
  6. import { slugOfRequest } from '../lib/orgs.hl'
  7. import { userOfSession } from '../lib/users.hl'
  8. import { repoAt, ownsRepo } from '../lib/repos.hl'
  9. import { browseNow, makeMain } from '../lib/code.hl'
  10. import { withRefParts } from '../lib/tickets-helpers.hl'
  11. host = null
  12. orepo = ''
  13. session = null
  14. kind = 'code'
  15. rest = ''
  16. slug = slugOfRequest(host, orepo)
  17. repo = repoAt(slug, session)
  18. hasRepo = repo != null
  19. codeData = repo != null ? withRefParts(browseNow(slug, kind, rest, repo.branch, ownsRepo(slug, session)), repo.ticketsProject) : null
  20. codeShown = codeData != null && !codeData.isMessage
  21. codeMessage = codeData != null && codeData.isMessage
  22. codeText = codeData != null && codeData.isMessage ? codeData.message : ''
  23. codeError = ''
  24. View {
  25. codeView {
  26. if (hasRepo) {
  27. if (codeMessage) { p { id = "codemessage" class = "empty" codeText } }
  28. if (codeShown) {
  29. codeBrowser {
  30. codeHead {
  31. span { id = "codekind" class = "muted" codeData.kindLabel }
  32. strong { id = "coderef" codeData.refLabel }
  33. latestCommit {
  34. a { id = "commitlink" href = codeData.commitHref codeData.short }
  35. 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 } } } }
  36. span { class = "muted" codeData.author }
  37. time { codeData.date }
  38. }
  39. }
  40. pathCrumbs { id = "crumbs" class = "crumbs"
  41. for (c of codeData.crumbs) {
  42. if (c.linked) { a { href = c.href c.name } span { class = "muted" "/" } }
  43. if (c.last) { strong { c.name } }
  44. }
  45. }
  46. if (codeData.isTree) {
  47. if (codeData.noEntries) { p { id = "noentries" class = "empty" "This folder is empty." } }
  48. ul { id = "entries"
  49. for (e of codeData.entries) {
  50. li {
  51. if (e.isDir) { a { Style.aDir href = e.href e.name } }
  52. if (e.isFile) { a { class = "file" href = e.href e.name } }
  53. if (e.isOther) { span { Style.spanFile e.name } }
  54. span { class = "muted" e.size }
  55. }
  56. }
  57. }
  58. }
  59. if (codeData.isFile) {
  60. codeFile { id = "codefile"
  61. p { class = "muted" codeData.fileSize }
  62. if (codeData.binary) { p { id = "binary" class = "empty" "This file is not text (or not UTF-8) — not shown." } }
  63. if (codeData.tooBig) { p { id = "toobig" class = "empty" "This file is too large to show here." } }
  64. ol { id = "lines"
  65. for (ln of codeData.lines) { li { code { ln.text } } }
  66. }
  67. if (codeData.truncated) { p { id = "linestruncated" class = "muted" "Only the first lines are shown." } }
  68. }
  69. }
  70. codeSide {
  71. section { id = "branches"
  72. h2 { "Branches" }
  73. ul {
  74. for (b of codeData.branches) {
  75. li {
  76. if (b.isCurrent) { strong { b.name } }
  77. if (b.notCurrent) { a { href = b.href b.name } }
  78. if (b.isDefault) { span { class = "muted" "main branch" } }
  79. if (b.canSet) { button { class = "quiet setmain" type = "button" value = b.name "Make main" on click(e) { emit setMain(e.target.value) } } }
  80. }
  81. }
  82. }
  83. p { id = "codeerror" codeError }
  84. }
  85. section { id = "commits"
  86. h2 { "Latest commits" }
  87. ul {
  88. for (c of codeData.commits) {
  89. li {
  90. a { href = c.href c.short }
  91. span { for (pt of c.parts) { if (pt.isText) { span { pt.text } } if (pt.isLink) { a { class = "ticketref" href = pt.href pt.text } } } }
  92. span { class = "muted" c.author }
  93. time { c.date }
  94. }
  95. }
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }
  102. }
  103. }
  104. // "Make main" (the owner): the face answers with the same view, read again with the new main branch
  105. on setMain(name) {
  106. codeError = ''
  107. r = emit server gitoriaSetBranch(slug, name, kind, rest)
  108. if (r == null || r.error != null) {
  109. codeError = r != null ? r.error : 'could not change the main branch'
  110. return null
  111. }
  112. codeData = r.result
  113. codeShown = !r.result.isMessage
  114. codeMessage = r.result.isMessage
  115. codeText = r.result.isMessage ? r.result.message : ''
  116. }
  117. on server gitoriaSetBranch(slugOf, name, kindOf, restOf, session) {
  118. if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not change the main branch' } }
  119. if (kindOf != 'code' && kindOf != 'branch' && kindOf != 'commit') { return { error = 'could not change the main branch' } }
  120. if (restOf == null || hlTypeName(restOf) != 'String' || restOf.length > 500 || name == null || hlTypeName(name) != 'String') { return { error = 'could not change the main branch' } }
  121. u = userOfSession(session)
  122. if (u == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can change the main branch' } }
  123. return makeMain(u.id, slugOf, name, kindOf, restOf)
  124. }
  125. Style {
  126. codeView {
  127. display = 'grid'
  128. gap = '1rem'
  129. minWidth = '0'
  130. // Direct-child and sibling combinators have no bare language form.
  131. '> *' {
  132. margin = '0'
  133. }
  134. }
  135. codeBrowser {
  136. display = 'grid'
  137. gap = '1rem'
  138. minWidth = '0'
  139. // Direct-child and sibling combinators have no bare language form.
  140. '> *' {
  141. margin = '0'
  142. }
  143. @media {
  144. minWidth = '60rem'
  145. gridTemplateColumns = 'minmax(0, 1fr) 18rem'
  146. alignItems = 'start'
  147. columnGap = '2rem'
  148. // Direct-child and sibling combinators have no bare language form.
  149. '> *' {
  150. gridColumn = '1'
  151. }
  152. // Direct-child and sibling combinators have no bare language form.
  153. '> code-side' {
  154. gridColumn = '2'
  155. gridRow = '1 / span 4'
  156. }
  157. }
  158. }
  159. codeHead {
  160. display = 'grid'
  161. gap = '.3rem'
  162. minWidth = '0'
  163. // Direct-child and sibling combinators have no bare language form.
  164. '> *' {
  165. margin = '0'
  166. }
  167. }
  168. codeFile {
  169. display = 'grid'
  170. gap = '.5rem'
  171. minWidth = '0'
  172. // Direct-child and sibling combinators have no bare language form.
  173. '> *' {
  174. margin = '0'
  175. }
  176. }
  177. codeSide {
  178. display = 'grid'
  179. gap = '1rem'
  180. minWidth = '0'
  181. section {
  182. display = 'grid'
  183. gap = '.4rem'
  184. minWidth = '0'
  185. // Direct-child and sibling combinators have no bare language form.
  186. '> *' {
  187. margin = '0'
  188. }
  189. }
  190. li {
  191. display = 'flex'
  192. flexWrap = 'wrap'
  193. alignItems = 'center'
  194. gap = '0 .8rem'
  195. margin = '0'
  196. padding = '0 .5rem'
  197. overflowWrap = 'anywhere'
  198. borderRadius = 'var(--radius-small)'
  199. // Direct-child and sibling combinators have no bare language form.
  200. '> a' {
  201. display = 'inline-flex'
  202. alignItems = 'center'
  203. minWidth = '2.75rem'
  204. minHeight = '2.75rem'
  205. firstChild {
  206. font = '.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'
  207. }
  208. }
  209. // Direct-child and sibling combinators have no bare language form.
  210. '> strong' {
  211. display = 'inline-flex'
  212. alignItems = 'center'
  213. minWidth = '2.75rem'
  214. minHeight = '2.75rem'
  215. }
  216. }
  217. ul {
  218. display = 'grid'
  219. margin = '0'
  220. padding = '0'
  221. listStyle = 'none'
  222. }
  223. h2 {
  224. fontSize = '1.05rem'
  225. }
  226. // This selector condition takes arguments and has no bare form.
  227. 'li:nth-child(odd)' {
  228. background = 'var(--color-background-sunken)'
  229. }
  230. }
  231. latestCommit {
  232. display = 'flex'
  233. flexWrap = 'wrap'
  234. gap = '0 .8rem'
  235. alignItems = 'center'
  236. minWidth = '0'
  237. padding = '.1rem .8rem .4rem'
  238. background = 'var(--color-surface)'
  239. borderRadius = 'var(--radius-large)'
  240. a {
  241. font = '.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'
  242. }
  243. // Direct-child and sibling combinators have no bare language form.
  244. '> a' {
  245. firstChild {
  246. order = '1'
  247. }
  248. display = 'inline-flex'
  249. alignItems = 'center'
  250. minHeight = '2.75rem'
  251. }
  252. // Direct-child and sibling combinators have no bare language form.
  253. '> time' {
  254. order = '2'
  255. marginLeft = 'auto'
  256. }
  257. // This selector condition takes arguments and has no bare form.
  258. '> span:nth-child(2)' {
  259. order = '3'
  260. flex = '1 1 100%'
  261. minWidth = '0'
  262. paddingBlock = '.1rem'
  263. }
  264. // Direct-child and sibling combinators have no bare language form.
  265. '> span.muted' {
  266. order = '4'
  267. flex = '1 1 100%'
  268. fontSize = '.875rem'
  269. }
  270. }
  271. // This selector condition takes arguments and has no bare form.
  272. 'path-crumbs:has(> strong:only-child)' {
  273. display = 'none'
  274. }
  275. #commits {
  276. li {
  277. // Direct-child and sibling combinators have no bare language form.
  278. '> a' {
  279. firstChild {
  280. order = '1'
  281. }
  282. }
  283. // Direct-child and sibling combinators have no bare language form.
  284. '> time' {
  285. order = '2'
  286. marginLeft = 'auto'
  287. }
  288. // This selector condition takes arguments and has no bare form.
  289. '> span:nth-child(2)' {
  290. order = '3'
  291. flex = '1 1 100%'
  292. minWidth = '0'
  293. paddingBlock = '.1rem'
  294. }
  295. // Direct-child and sibling combinators have no bare language form.
  296. '> span.muted' {
  297. order = '4'
  298. flex = '1 1 100%'
  299. fontSize = '.875rem'
  300. }
  301. }
  302. }
  303. pathCrumbs {
  304. display = 'flex'
  305. flexWrap = 'wrap'
  306. alignItems = 'center'
  307. gap = '0 .1rem'
  308. minWidth = '0'
  309. overflowWrap = 'anywhere'
  310. a {
  311. display = 'inline-flex'
  312. alignItems = 'center'
  313. justifyContent = 'center'
  314. minWidth = '2.75rem'
  315. minHeight = '2.75rem'
  316. padding = '0 .4rem'
  317. borderRadius = 'var(--radius-small)'
  318. hover {
  319. background = 'var(--color-surface)'
  320. }
  321. }
  322. }
  323. #entries {
  324. display = 'grid'
  325. margin = '0'
  326. padding = '0'
  327. listStyle = 'none'
  328. li {
  329. display = 'flex'
  330. alignItems = 'center'
  331. justifyContent = 'space-between'
  332. gap = '1rem'
  333. margin = '0'
  334. paddingRight = '.8rem'
  335. borderRadius = 'var(--radius-small)'
  336. // Direct-child and sibling combinators have no bare language form.
  337. '> a' {
  338. flex = '1 1 auto'
  339. display = 'flex'
  340. alignItems = 'center'
  341. minWidth = '0'
  342. minHeight = '2.75rem'
  343. padding = '0 .8rem'
  344. overflowWrap = 'anywhere'
  345. }
  346. // Direct-child and sibling combinators have no bare language form.
  347. '> span.muted' {
  348. flex = 'none'
  349. whiteSpace = 'nowrap'
  350. fontSize = '.875rem'
  351. }
  352. }
  353. // This selector condition takes arguments and has no bare form.
  354. 'li:nth-child(odd)' {
  355. background = 'var(--color-background-sunken)'
  356. }
  357. // Pseudo-elements and parts have no bare language form.
  358. 'a.dir::after' {
  359. content = '"/"'
  360. }
  361. }
  362. #lines {
  363. margin = '0'
  364. padding = '.5rem 0'
  365. overflowX = 'auto'
  366. listStyle = 'none'
  367. counterReset = 'line'
  368. background = 'var(--color-background-sunken)'
  369. borderRadius = 'var(--radius-large)'
  370. font = '.875rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'
  371. li {
  372. counterIncrement = 'line'
  373. whiteSpace = 'pre'
  374. minHeight = '1.5em'
  375. margin = '0'
  376. padding = '0 .8rem 0 0'
  377. width = 'max-content'
  378. minWidth = '100%'
  379. }
  380. // Pseudo-elements and parts have no bare language form.
  381. 'li::before' {
  382. content = 'counter(line)'
  383. display = 'inline-block'
  384. width = '4ch'
  385. marginRight = '.8rem'
  386. paddingLeft = '.5rem'
  387. boxSizing = 'content-box'
  388. textAlign = 'right'
  389. color = 'var(--color-text-muted)'
  390. userSelect = 'none'
  391. }
  392. code {
  393. padding = '0'
  394. font = 'inherit'
  395. color = 'var(--color-text-strong)'
  396. background = 'transparent'
  397. }
  398. }
  399. aDir {
  400. fontWeight = '700'
  401. }
  402. spanFile {
  403. flex = '1 1 auto'
  404. display = 'flex'
  405. alignItems = 'center'
  406. minWidth = '0'
  407. minHeight = '2.75rem'
  408. padding = '0 .8rem'
  409. overflowWrap = 'anywhere'
  410. }
  411. #codeerror {
  412. margin = '0'
  413. color = 'var(--color-danger)'
  414. empty { display = 'none' }
  415. }
  416. }

Branches

Latest commits

  • 9eff6627Merge branch 'f2-api-bugs' into mainGitoria
  • 26117255|||PR apps API: review comments on files with spaces in their namemre
  • b8796cecMerge branch 'f1-broken-json' into mainGitoria
  • 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
  • f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
  • 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
  • 16a3530fMerge branch 'heap-revert' into mainGitoria
  • 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
  • 13f0c342Merge branch 'hl25-records' into mainGitoria
  • a002ecb7|||PR records: HL25 report, heap helper, logmre
  • 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
  • fefaedd2log: tracker PR-only, HL25 startedmre
  • 21aa57calog: parkmre
  • e9f950a8reports: G25c soakmre
  • a7783686log: deploy 9f41ffcmre
  • 9f41ffc1log: W30b mergedmre
  • bef635c1Merge branch 'w30b'mre
  • 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
  • c4f6d9e3reports: G25c growth huntmre
  • b88e39f1log: privacy cleanup donemre