gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit499f25f2499f25f2Review fixes for the Settings organization move (#53)mre499f25f2/components/list.hl

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

Branches

Latest commits

  • 499f25f2Review fixes for the Settings organization move (#53)mre
  • ed3b922b|||PR move a repository into an organization in Settings (#53)mre
  • 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
  • 9f7ce8d8Preserve rename compatibility and live page titlesmre
  • c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
  • ce08920dMerge branch 'w52c-header-phone' into mainGitoria
  • 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
  • e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
  • c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
  • 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
  • 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
  • 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
  • 155861f6Merge branch 'w52-person-approval' into mainGitoria
  • b5435de8|||PR person approvals: second Kunibert round (#52)mre
  • 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre
  • 2a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre
  • 83f0c953Report person approval verificationmre
  • 3ae94b86Record browser failures and verify owned tab cleanupmre
  • 54eec687Gate person approvals and merge alternativesmre
  • 12b08829Add person approvals for pull request headsmre