gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit07ab845b07ab845bvendor: Hybriel set-day50 (run() leak fix #335)mre07ab845b/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; prepend this slug only once.
  132. next = [{ slug = r.org.slug isPrivate = r.org.isPrivate isPublic = !r.org.isPrivate address = r.address }]
  133. for (x of orgs) { if (x.slug != r.org.slug) { next.push(x) } }
  134. orgs = next
  135. hasOrgs = true
  136. }
  137. // this session's tabs follow a login / name / logout (the shell's faces push them)
  138. on client gitoriaSignedIn(tag, info) {
  139. canCreate = info.named
  140. needsLogin = false
  141. }
  142. on client gitoriaSignedOut(tag) {
  143. canCreate = false
  144. needsLogin = true
  145. }
  146. // a new repo, from any session: the list follows live
  147. on client repoCreated(row) {
  148. next = [row]
  149. for (x of repos) { if (x.id != row.id) { next.push(x) } }
  150. repos = next
  151. noRepos = false
  152. }
  153. on server gitoriaCreate(slug, description, session) {
  154. return makeRepo(slug, description, '', false, session)
  155. }
  156. on server gitoriaCreateRepo(slug, description, org, priv, session) {
  157. return makeRepo(slug, description, org, priv, session)
  158. }
  159. on server gitoriaCreateOrg(slug, priv, session) {
  160. u = userOfSession(session)
  161. if (u == null) { return { error = 'log in with ident (top right) first' } }
  162. r = createOrg(u.id, slug, priv)
  163. if (r.error != null) { return { error = r.error } }
  164. return { org = r.org address = repoOrigin(r.org.slug) + '/' }
  165. }
  166. makeRepo = (slug, description, org, priv, session) => {
  167. u = userOfSession(session)
  168. if (u == null) { return { error = 'log in with ident (top right) to create a repository' } }
  169. r = createRepoIn(u.id, org, slug, description, priv)
  170. if (r.error != null) { return { error = r.error } }
  171. return r
  172. }
  173. Style {
  174. repoList {
  175. display = 'grid'
  176. gap = '1rem'
  177. minWidth = '0'
  178. // Direct-child and sibling combinators have no bare language form.
  179. '> *' {
  180. margin = '0'
  181. }
  182. }
  183. #createform {
  184. display = 'grid'
  185. gap = '.75rem'
  186. padding = '1rem'
  187. background = 'var(--color-surface)'
  188. borderRadius = 'var(--radius-large)'
  189. // Direct-child and sibling combinators have no bare language form.
  190. '> *' {
  191. margin = '0'
  192. }
  193. }
  194. #repos {
  195. display = 'grid'
  196. gap = '.5rem'
  197. margin = '0'
  198. padding = '0'
  199. listStyle = 'none'
  200. li {
  201. display = 'grid'
  202. gap = '.1rem'
  203. margin = '0'
  204. padding = '.25rem 1rem .6rem'
  205. background = 'var(--color-surface)'
  206. borderRadius = 'var(--radius-large)'
  207. @media {
  208. minWidth = '60rem'
  209. gridTemplateColumns = 'minmax(10rem, 16rem) 1fr auto'
  210. alignItems = 'center'
  211. gap = '.15rem 1rem'
  212. padding = '.25rem 1rem'
  213. }
  214. }
  215. }
  216. repoMeta {
  217. display = 'flex'
  218. flexWrap = 'wrap'
  219. gap = '.2rem 1rem'
  220. fontSize = '.875rem'
  221. color = 'var(--color-text-muted)'
  222. }
  223. #orgform {
  224. display = 'grid'
  225. gap = '.75rem'
  226. padding = '1rem'
  227. margin = '1rem 0'
  228. background = 'var(--color-surface)'
  229. borderRadius = 'var(--radius-large)'
  230. }
  231. #orgs {
  232. listStyle = 'none'
  233. margin = '0'
  234. padding = '0'
  235. display = 'grid'
  236. gap = '.1rem'
  237. li {
  238. display = 'flex'
  239. alignItems = 'center'
  240. gap = '.75rem'
  241. minHeight = '2.75rem'
  242. }
  243. }
  244. aRepoSlug {
  245. display = 'flex'
  246. alignItems = 'center'
  247. minHeight = '2.75rem'
  248. fontWeight = '700'
  249. fontSize = '1.05rem'
  250. overflowWrap = 'anywhere'
  251. }
  252. spanRepoAbout {
  253. color = 'var(--color-text)'
  254. }
  255. #createerror {
  256. margin = '0'
  257. color = 'var(--color-danger)'
  258. empty { display = 'none' }
  259. }
  260. #orgerror {
  261. margin = '0'
  262. color = 'var(--color-danger)'
  263. empty { display = 'none' }
  264. }
  265. #created {
  266. margin = '0'
  267. color = 'var(--color-success)'
  268. }
  269. }

Branches

Latest commits

  • 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
  • 5e25e816log: W61 mergedmre
  • aafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmre
  • aca1fda1Merge W61: theme from layouts 17e0f03, Views refer to Style rules (gitoria#37 #27)mre
  • 03cb650blog: W61 theme decisionmre