gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit03b5bb0803b5bb08W39 report to reports/, drop scratch repro, mission + logmre03b5bb08/components/codebrowser.hl

9.9 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 { class = "dir" href = e.href e.name } }
  52. if (e.isFile) { a { class = "file" href = e.href e.name } }
  53. if (e.isOther) { span { class = "file" 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" class = "message" 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. '> *' {
  131. margin = '0'
  132. }
  133. }
  134. codeBrowser {
  135. display = 'grid'
  136. gap = '1rem'
  137. minWidth = '0'
  138. '> *' {
  139. margin = '0'
  140. }
  141. }
  142. codeHead {
  143. display = 'grid'
  144. gap = '.3rem'
  145. minWidth = '0'
  146. '> *' {
  147. margin = '0'
  148. }
  149. }
  150. codeFile {
  151. display = 'grid'
  152. gap = '.5rem'
  153. minWidth = '0'
  154. '> *' {
  155. margin = '0'
  156. }
  157. }
  158. codeSide {
  159. display = 'grid'
  160. gap = '1rem'
  161. minWidth = '0'
  162. section {
  163. display = 'grid'
  164. gap = '.4rem'
  165. minWidth = '0'
  166. '> *' {
  167. margin = '0'
  168. }
  169. }
  170. li {
  171. display = 'flex'
  172. flexWrap = 'wrap'
  173. alignItems = 'center'
  174. gap = '0 .8rem'
  175. margin = '0'
  176. padding = '0 .5rem'
  177. overflowWrap = 'anywhere'
  178. borderRadius = 'var(--radius-small)'
  179. '> a:first-child' {
  180. font = '.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'
  181. }
  182. '> a' {
  183. display = 'inline-flex'
  184. alignItems = 'center'
  185. minWidth = '2.75rem'
  186. minHeight = '2.75rem'
  187. }
  188. '> strong' {
  189. display = 'inline-flex'
  190. alignItems = 'center'
  191. minWidth = '2.75rem'
  192. minHeight = '2.75rem'
  193. }
  194. }
  195. ul {
  196. display = 'grid'
  197. margin = '0'
  198. padding = '0'
  199. listStyle = 'none'
  200. }
  201. h2 {
  202. fontSize = '1.05rem'
  203. }
  204. 'li:nth-child(odd)' {
  205. background = 'var(--color-background-sunken)'
  206. }
  207. }
  208. latestCommit {
  209. display = 'flex'
  210. flexWrap = 'wrap'
  211. gap = '0 .8rem'
  212. alignItems = 'center'
  213. minWidth = '0'
  214. padding = '.1rem .8rem .4rem'
  215. background = 'var(--color-surface)'
  216. borderRadius = 'var(--radius-large)'
  217. '> a' {
  218. display = 'inline-flex'
  219. alignItems = 'center'
  220. minHeight = '2.75rem'
  221. }
  222. a {
  223. font = '.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'
  224. }
  225. '> a:first-child' {
  226. order = '1'
  227. }
  228. '> time' {
  229. order = '2'
  230. marginLeft = 'auto'
  231. }
  232. '> span:nth-child(2)' {
  233. order = '3'
  234. flex = '1 1 100%'
  235. minWidth = '0'
  236. paddingBlock = '.1rem'
  237. }
  238. '> span.muted' {
  239. order = '4'
  240. flex = '1 1 100%'
  241. fontSize = '.875rem'
  242. }
  243. }
  244. 'path-crumbs:has(> strong:only-child)' {
  245. display = 'none'
  246. }
  247. #commits {
  248. li {
  249. '> a:first-child' {
  250. order = '1'
  251. }
  252. '> time' {
  253. order = '2'
  254. marginLeft = 'auto'
  255. }
  256. '> span:nth-child(2)' {
  257. order = '3'
  258. flex = '1 1 100%'
  259. minWidth = '0'
  260. paddingBlock = '.1rem'
  261. }
  262. '> span.muted' {
  263. order = '4'
  264. flex = '1 1 100%'
  265. fontSize = '.875rem'
  266. }
  267. }
  268. }
  269. pathCrumbs {
  270. display = 'flex'
  271. flexWrap = 'wrap'
  272. alignItems = 'center'
  273. gap = '0 .1rem'
  274. minWidth = '0'
  275. overflowWrap = 'anywhere'
  276. a {
  277. display = 'inline-flex'
  278. alignItems = 'center'
  279. justifyContent = 'center'
  280. minWidth = '2.75rem'
  281. minHeight = '2.75rem'
  282. padding = '0 .4rem'
  283. borderRadius = 'var(--radius-small)'
  284. hover {
  285. background = 'var(--color-surface)'
  286. }
  287. }
  288. }
  289. #entries {
  290. display = 'grid'
  291. margin = '0'
  292. padding = '0'
  293. listStyle = 'none'
  294. li {
  295. display = 'flex'
  296. alignItems = 'center'
  297. justifyContent = 'space-between'
  298. gap = '1rem'
  299. margin = '0'
  300. paddingRight = '.8rem'
  301. borderRadius = 'var(--radius-small)'
  302. '> a' {
  303. flex = '1 1 auto'
  304. display = 'flex'
  305. alignItems = 'center'
  306. minWidth = '0'
  307. minHeight = '2.75rem'
  308. padding = '0 .8rem'
  309. overflowWrap = 'anywhere'
  310. }
  311. '> span.file' {
  312. flex = '1 1 auto'
  313. display = 'flex'
  314. alignItems = 'center'
  315. minWidth = '0'
  316. minHeight = '2.75rem'
  317. padding = '0 .8rem'
  318. overflowWrap = 'anywhere'
  319. }
  320. '> span.muted' {
  321. flex = 'none'
  322. whiteSpace = 'nowrap'
  323. fontSize = '.875rem'
  324. }
  325. }
  326. 'li:nth-child(odd)' {
  327. background = 'var(--color-background-sunken)'
  328. }
  329. 'a.dir' {
  330. fontWeight = '700'
  331. }
  332. 'a.dir::after' {
  333. content = '"/"'
  334. }
  335. }
  336. #lines {
  337. margin = '0'
  338. padding = '.5rem 0'
  339. overflowX = 'auto'
  340. listStyle = 'none'
  341. counterReset = 'line'
  342. background = 'var(--color-background-sunken)'
  343. borderRadius = 'var(--radius-large)'
  344. font = '.875rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'
  345. li {
  346. counterIncrement = 'line'
  347. whiteSpace = 'pre'
  348. minHeight = '1.5em'
  349. margin = '0'
  350. padding = '0 .8rem 0 0'
  351. width = 'max-content'
  352. minWidth = '100%'
  353. }
  354. 'li::before' {
  355. content = 'counter(line)'
  356. display = 'inline-block'
  357. width = '4ch'
  358. marginRight = '.8rem'
  359. paddingLeft = '.5rem'
  360. boxSizing = 'content-box'
  361. textAlign = 'right'
  362. color = 'var(--color-text-muted)'
  363. userSelect = 'none'
  364. }
  365. code {
  366. padding = '0'
  367. font = 'inherit'
  368. color = 'var(--color-text-strong)'
  369. background = 'transparent'
  370. }
  371. }
  372. @media {
  373. minWidth = '60rem'
  374. codeBrowser {
  375. gridTemplateColumns = 'minmax(0, 1fr) 18rem'
  376. alignItems = 'start'
  377. columnGap = '2rem'
  378. '> *' {
  379. gridColumn = '1'
  380. }
  381. '> code-side' {
  382. gridColumn = '2'
  383. gridRow = '1 / span 4'
  384. }
  385. }
  386. }
  387. }

Branches

Latest commits

  • 03b5bb08W39 report to reports/, drop scratch repro, mission + logmre
  • 154d333fMerge w39-create-api: POST /api/repos with a user token (#39)mre
  • 149dd512Rewrite W39 reportmre
  • e5385075Expect 401 for POST /api/repos without a tokenmre
  • 1a76055cDocument repository creation APImre
  • 4d779b3bAdd create-api gatemre
  • 88563122Add POST /api/repos for user tokensmre
  • b00860e3Create repositories with member checks in createRepoInmre
  • 0a38f236Report repository creation API blockermre
  • b5f72187Record malformed JSON blocker for repository creationmre
  • a2ae8302logmre
  • 6947cd58logmre
  • 2175e48clogmre
  • 40eb3ca1gitoria#38: review package, logmre
  • 06a5a50egitoria#38: deploy b8252ca, logmre
  • b8252ca0gitoria#46: W46b report, logmre
  • 50093aafgitoria#46: statuses keyed by app + context (merge w46b-keyed)mre
  • dd0267edgitoria#46: fix a label in the keyed gatemre
  • b1dcb580gitoria#46: statuses keyed by app + context, required = app + context, old rows still readmre
  • 2287363egitoria#47: W47 report, logmre