gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchv595803cf4f|||PR vendor: Hybriel set-day59 and GC budget 32 MiBmrev59/components/list.hl

8.6 KB

  1. // components/list.hl — THE REPO LIST of the main address (ticket #6, gitoria#16): every repository, newest
  2. // first, and "Create a repository" (slug = its address, unique in the whole system) for a named user.
  3. // Composed into components/index.hl (route `/`) when the request's host is the main address. Rendered on
  4. // the server with its rows; a new repo from any session reaches every open list (push `repoCreated`).
  5. import { repoOrigin } from '../lib/util.hl'
  6. import Tokens from './tokens.hl'
  7. import SshKeys from './sshkeys.hl'
  8. import { repoRows, orgRows, createRepoIn, createOrg } from '../lib/repos.hl'
  9. import { infoOfSession, userOfSession, userIdOfSession } from '../lib/users.hl'
  10. session = null
  11. me = infoOfSession(session)
  12. canCreate = me != null && me.named
  13. needsLogin = me == null
  14. repos = repoRows(userIdOfSession(session))
  15. orgs = orgRows(userIdOfSession(session))
  16. hasOrgs = orgs.length > 0
  17. noRepos = repos.length == 0
  18. repoSlug = ''
  19. repoDescription = ''
  20. repoOrg = ''
  21. repoVisibility = 'public'
  22. orgSlug = ''
  23. orgVisibility = 'public'
  24. createError = ''
  25. orgError = ''
  26. createdText = ''
  27. createdHref = ''
  28. hasCreated = false
  29. // THE LIST COMES FIRST (mobile first): the repositories are what this page is for; the create form, tokens and keys follow it.
  30. // (Before, a phone scrolled past three forms — 5 000 px — to reach the first repository.)
  31. View {
  32. repoList {
  33. h1 { id = "heading" "Repositories" }
  34. if (needsLogin) { p { id = "loginhint" class = "muted" "Log in with ident (top right) to create a repository." } }
  35. if (noRepos) { p { id = "empty" class = "empty" "No repository yet." } }
  36. ol { id = "repos"
  37. for (r of repos) {
  38. li {
  39. a { Style.aRepoSlug href = r.address r.slug }
  40. if (r.isPrivate) { span { class = "muted" "Private" } }
  41. if (r.described) { span { Style.spanRepoAbout r.description } }
  42. repoMeta { span { r.owner } time { r.created } }
  43. }
  44. }
  45. }
  46. if (hasOrgs) {
  47. h2 { "Organizations" }
  48. ul { id = "orgs"
  49. for (o of orgs) {
  50. li { a { class = "slug" href = o.address o.slug } if (o.isPrivate) { span { class = "muted" "Private" } } }
  51. }
  52. }
  53. }
  54. if (canCreate) {
  55. form { id = "createform"
  56. on submit(e) {
  57. e.preventDefault()
  58. emit createIt(e)
  59. }
  60. h2 { "Create a repository" }
  61. label { "Address — its name is unique in the whole system and becomes NAME.gitoria.worldapi.org"
  62. input { id = "slug" name = "slug" required = "required" minlength = "2" maxlength = "40" autocomplete = "off" autocapitalize = "none" spellcheck = "false" value = repoSlug on input(e) { repoSlug = e.target.value } }
  63. }
  64. label { "Description (optional)"
  65. input { id = "description" name = "description" maxlength = "200" autocomplete = "off" value = repoDescription on input(e) { repoDescription = e.target.value } }
  66. }
  67. label { "Organization (optional) — put the repository inside one of yours: ORG.gitoria.worldapi.org/NAME"
  68. input { id = "org" name = "org" maxlength = "40" autocomplete = "off" autocapitalize = "none" spellcheck = "false" value = repoOrg on input(e) { repoOrg = e.target.value } }
  69. }
  70. label { "Visibility — a private repository is seen only by you and the members you add"
  71. select { id = "priv" name = "priv" value = repoVisibility on change(e) { repoVisibility = e.target.value }
  72. option { value = "public" "Public" }
  73. option { value = "private" "Private" }
  74. }
  75. }
  76. button { id = "createsave" type = "submit" "Create repository" }
  77. p { id = "createerror" createError }
  78. }
  79. }
  80. if (canCreate) {
  81. form { id = "orgform"
  82. on submit(e) {
  83. e.preventDefault()
  84. emit createOrgIt(e)
  85. }
  86. h2 { "Create an organization" }
  87. label { "Name — becomes NAME.gitoria.worldapi.org, its repositories live at NAME.gitoria.worldapi.org/REPO"
  88. input { id = "orgslug" name = "orgslug" required = "required" minlength = "2" maxlength = "40" autocomplete = "off" autocapitalize = "none" spellcheck = "false" value = orgSlug on input(e) { orgSlug = e.target.value } }
  89. }
  90. label { "Visibility — a private organization makes every repository of it private, also new ones"
  91. select { id = "orgpriv" name = "orgpriv" value = orgVisibility on change(e) { orgVisibility = e.target.value }
  92. option { value = "public" "Public" }
  93. option { value = "private" "Private" }
  94. }
  95. }
  96. button { id = "orgsave" type = "submit" "Create organization" }
  97. p { id = "orgerror" orgError }
  98. }
  99. }
  100. if (hasCreated) { p { id = "created" createdText " " a { id = "createdlink" href = createdHref "Open it" } } }
  101. Tokens { }
  102. SshKeys { }
  103. }
  104. }
  105. on createIt(e) {
  106. r = emit server gitoriaCreateRepo(repoSlug, repoDescription, repoOrg, repoVisibility == 'private')
  107. if (r == null || r.error != null) {
  108. createError = r != null ? r.error : 'could not create the repository'
  109. return null
  110. }
  111. createError = ''
  112. repoSlug = ''
  113. repoDescription = ''
  114. repoVisibility = 'public'
  115. createdText = "Created '" + r.repo.slug + "': "
  116. createdHref = r.repo.address
  117. hasCreated = true
  118. }
  119. on createOrgIt(e) {
  120. r = emit server gitoriaCreateOrg(orgSlug, orgVisibility == 'private')
  121. if (r == null || r.error != null) {
  122. orgError = r != null ? r.error : 'could not create the organization'
  123. return null
  124. }
  125. orgError = ''
  126. orgSlug = ''
  127. orgVisibility = 'public'
  128. createdText = "Created the organization '" + r.org.slug + "': "
  129. createdHref = r.address
  130. hasCreated = true
  131. // The ack may already sync orgs from session: remove by key, then the new row goes on top once.
  132. orgs.remove(r.org.id)
  133. orgs = [{ @id = r.org.id slug = r.org.slug isPrivate = r.org.isPrivate isPublic = !r.org.isPrivate createdMs = r.org.createdMs address = r.address }].concat(orgs)
  134. hasOrgs = true
  135. }
  136. // this session's tabs follow a login / name / logout (the shell's faces push them)
  137. on client gitoriaSignedIn(tag, info) {
  138. canCreate = info.named
  139. needsLogin = false
  140. }
  141. on client gitoriaSignedOut(tag) {
  142. canCreate = false
  143. needsLogin = true
  144. }
  145. // a new repo, from any session: the list follows live
  146. on client repoCreated(row) {
  147. repos.remove(row.@id)
  148. repos = [row].concat(repos)
  149. noRepos = false
  150. }
  151. on server gitoriaCreate(slug, description, session) {
  152. return makeRepo(slug, description, '', false, session)
  153. }
  154. on server gitoriaCreateRepo(slug, description, org, priv, session) {
  155. return makeRepo(slug, description, org, priv, session)
  156. }
  157. on server gitoriaCreateOrg(slug, priv, session) {
  158. u = userOfSession(session)
  159. if (u == null) { return { error = 'log in with ident (top right) first' } }
  160. r = createOrg(u.id, slug, priv)
  161. if (r.error != null) { return { error = r.error } }
  162. return { org = r.org address = repoOrigin(r.org.slug) + '/' }
  163. }
  164. makeRepo = (slug, description, org, priv, session) => {
  165. u = userOfSession(session)
  166. if (u == null) { return { error = 'log in with ident (top right) to create a repository' } }
  167. r = createRepoIn(u.id, org, slug, description, priv)
  168. if (r.error != null) { return { error = r.error } }
  169. return r
  170. }
  171. Style {
  172. repoList {
  173. display = 'grid'
  174. gap = '1rem'
  175. minWidth = '0'
  176. // Direct-child and sibling combinators have no bare language form.
  177. '> *' {
  178. margin = '0'
  179. }
  180. }
  181. #createform {
  182. display = 'grid'
  183. gap = '.75rem'
  184. padding = '1rem'
  185. background = 'var(--color-surface)'
  186. borderRadius = 'var(--radius-large)'
  187. // Direct-child and sibling combinators have no bare language form.
  188. '> *' {
  189. margin = '0'
  190. }
  191. }
  192. #repos {
  193. display = 'grid'
  194. gap = '.5rem'
  195. margin = '0'
  196. padding = '0'
  197. listStyle = 'none'
  198. li {
  199. display = 'grid'
  200. gap = '.1rem'
  201. margin = '0'
  202. padding = '.25rem 1rem .6rem'
  203. background = 'var(--color-surface)'
  204. borderRadius = 'var(--radius-large)'
  205. @media {
  206. minWidth = '60rem'
  207. gridTemplateColumns = 'minmax(10rem, 16rem) 1fr auto'
  208. alignItems = 'center'
  209. gap = '.15rem 1rem'
  210. padding = '.25rem 1rem'
  211. }
  212. }
  213. }
  214. repoMeta {
  215. display = 'flex'
  216. flexWrap = 'wrap'
  217. gap = '.2rem 1rem'
  218. fontSize = '.875rem'
  219. color = 'var(--color-text-muted)'
  220. }
  221. #orgform {
  222. display = 'grid'
  223. gap = '.75rem'
  224. padding = '1rem'
  225. margin = '1rem 0'
  226. background = 'var(--color-surface)'
  227. borderRadius = 'var(--radius-large)'
  228. }
  229. #orgs {
  230. listStyle = 'none'
  231. margin = '0'
  232. padding = '0'
  233. display = 'grid'
  234. gap = '.1rem'
  235. li {
  236. display = 'flex'
  237. alignItems = 'center'
  238. gap = '.75rem'
  239. minHeight = '2.75rem'
  240. }
  241. }
  242. aRepoSlug {
  243. display = 'flex'
  244. alignItems = 'center'
  245. minHeight = '2.75rem'
  246. fontWeight = '700'
  247. fontSize = '1.05rem'
  248. overflowWrap = 'anywhere'
  249. }
  250. spanRepoAbout {
  251. color = 'var(--color-text)'
  252. }
  253. #createerror {
  254. margin = '0'
  255. color = 'var(--color-danger)'
  256. empty { display = 'none' }
  257. }
  258. #orgerror {
  259. margin = '0'
  260. color = 'var(--color-danger)'
  261. empty { display = 'none' }
  262. }
  263. #created {
  264. margin = '0'
  265. color = 'var(--color-success)'
  266. }
  267. }

Branches

Latest commits

  • 5803cf4f|||PR vendor: Hybriel set-day59 and GC budget 32 MiBmre
  • 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