gitoria
All repositories: gitoria
7.8 KB
// components/list.hl — THE REPO LIST of the main address (ticket #6, gitoria#16): every repository, newest// first, and "Create a repository" (slug = its address, unique in the whole system) for a named user.// Composed into components/index.hl (route `/`) when the request's host is the main address. Rendered on// the server with its rows; a new repo from any session reaches every open list (push `repoCreated`).import { repoOrigin } from '../lib/util.hl'import Tokens from './tokens.hl'import SshKeys from './sshkeys.hl'import { repoRows, orgRows, createRepoIn, createOrg } from '../lib/repos.hl'import { infoOfSession, userOfSession, userIdOfSession } from '../lib/users.hl'session = nullme = infoOfSession(session)canCreate = me != null && me.namedneedsLogin = me == nullrepos = repoRows(userIdOfSession(session))orgs = orgRows(userIdOfSession(session))hasOrgs = orgs.length > 0noRepos = repos.length == 0createError = ''orgError = ''createdText = ''createdHref = ''hasCreated = false// THE LIST COMES FIRST (mobile first): the repositories are what this page is for; the create form, tokens and keys follow it.// (Before, a phone scrolled past three forms — 5 000 px — to reach the first repository.)View {repoList {h1 { id = "heading" "Repositories" }if (needsLogin) { p { id = "loginhint" class = "muted" "Log in with ident (top right) to create a repository." } }if (noRepos) { p { id = "empty" class = "empty" "No repository yet." } }ol { id = "repos"for (r of repos) {li {a { class = "slug" href = r.address r.slug }if (r.isPrivate) { span { class = "muted" "Private" } }if (r.described) { span { class = "about" r.description } }repoMeta { span { r.owner } time { r.created } }}}}if (hasOrgs) {h2 { "Organizations" }ul { id = "orgs"for (o of orgs) {li { a { class = "slug" href = o.address o.slug } if (o.isPrivate) { span { class = "muted" "Private" } } }}}}if (canCreate) {form { id = "createform"on submit(e) {e.preventDefault()emit createIt(e)}h2 { "Create a repository" }label { "Address — its name is unique in the whole system and becomes NAME.gitoria.worldapi.org"input { id = "slug" name = "slug" required = "required" minlength = "2" maxlength = "40" autocomplete = "off" autocapitalize = "none" spellcheck = "false" }}label { "Description (optional)"input { id = "description" name = "description" maxlength = "200" autocomplete = "off" }}label { "Organization (optional) — put the repository inside one of yours: ORG.gitoria.worldapi.org/NAME"input { id = "org" name = "org" maxlength = "40" autocomplete = "off" autocapitalize = "none" spellcheck = "false" }}label { "Visibility — a private repository is seen only by you and the members you add"select { id = "priv" name = "priv"option { value = "public" "Public" }option { value = "private" "Private" }}}button { id = "createsave" type = "submit" "Create repository" }p { id = "createerror" class = "message" createError }}}if (canCreate) {form { id = "orgform"on submit(e) {e.preventDefault()emit createOrgIt(e)}h2 { "Create an organization" }label { "Name — becomes NAME.gitoria.worldapi.org, its repositories live at NAME.gitoria.worldapi.org/REPO"input { id = "orgslug" name = "orgslug" required = "required" minlength = "2" maxlength = "40" autocomplete = "off" autocapitalize = "none" spellcheck = "false" }}label { "Visibility — a private organization makes every repository of it private, also new ones"select { id = "orgpriv" name = "orgpriv"option { value = "public" "Public" }option { value = "private" "Private" }}}button { id = "orgsave" type = "submit" "Create organization" }p { id = "orgerror" class = "message" orgError }}}if (hasCreated) { p { id = "created" class = "notice" createdText " " a { id = "createdlink" href = createdHref "Open it" } } }Tokens { }SshKeys { }}}on createIt(e) {f = e.target.elementsr = emit server gitoriaCreateRepo(f.slug.value, f.description.value, f.org.value, f.priv.value == 'private')if (r == null || r.error != null) {createError = r != null ? r.error : 'could not create the repository'return null}createError = ''f.slug.value = ''f.description.value = ''f.priv.value = 'public'createdText = "Created '" + r.repo.slug + "': "createdHref = r.repo.addresshasCreated = true}on createOrgIt(e) {f = e.target.elementsr = emit server gitoriaCreateOrg(f.orgslug.value, f.orgpriv.value == 'private')if (r == null || r.error != null) {orgError = r != null ? r.error : 'could not create the organization'return null}orgError = ''f.orgslug.value = ''f.orgpriv.value = 'public'createdText = "Created the organization '" + r.org.slug + "': "createdHref = r.addresshasCreated = trueorgs = [{ slug = r.org.slug isPrivate = r.org.isPrivate isPublic = !r.org.isPrivate address = r.address }].concat(orgs)hasOrgs = true}// this session's tabs follow a login / name / logout (the shell's faces push them)on client gitoriaSignedIn(tag, info) {canCreate = info.namedneedsLogin = false}on client gitoriaSignedOut(tag) {canCreate = falseneedsLogin = true}// a new repo, from any session: the list follows liveon client repoCreated(row) {next = [row]for (x of repos) { if (x.id != row.id) { next.push(x) } }repos = nextnoRepos = false}on server gitoriaCreate(slug, description, session) {return makeRepo(slug, description, '', false, session)}on server gitoriaCreateRepo(slug, description, org, priv, session) {return makeRepo(slug, description, org, priv, session)}on server gitoriaCreateOrg(slug, priv, session) {u = userOfSession(session)if (u == null) { return { error = 'log in with ident (top right) first' } }r = createOrg(u.id, slug, priv)if (r.error != null) { return { error = r.error } }return { org = r.org address = repoOrigin(r.org.slug) + '/' }}makeRepo = (slug, description, org, priv, session) => {u = userOfSession(session)if (u == null) { return { error = 'log in with ident (top right) to create a repository' } }r = createRepoIn(u.id, org, slug, description, priv)if (r.error != null) { return { error = r.error } }return r}Style {repoList {display = 'grid'gap = '1rem'minWidth = '0''> *' {margin = '0'}}#createform {display = 'grid'gap = '.75rem'padding = '1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)''> *' {margin = '0'}}#repos {display = 'grid'gap = '.5rem'margin = '0'padding = '0'listStyle = 'none'li {display = 'grid'gap = '.1rem'margin = '0'padding = '.25rem 1rem .6rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}'.slug' {display = 'flex'alignItems = 'center'minHeight = '2.75rem'fontWeight = '700'fontSize = '1.05rem'overflowWrap = 'anywhere'}'.about' {color = 'var(--color-text)'}}repoMeta {display = 'flex'flexWrap = 'wrap'gap = '.2rem 1rem'fontSize = '.875rem'color = 'var(--color-text-muted)'}@media {minWidth = '60rem'#repos {li {gridTemplateColumns = 'minmax(10rem, 16rem) 1fr auto'alignItems = 'center'gap = '.15rem 1rem'padding = '.25rem 1rem'}}}#orgform {display = 'grid'gap = '.75rem'padding = '1rem'margin = '1rem 0'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}#orgs {listStyle = 'none'margin = '0'padding = '0'display = 'grid'gap = '.1rem'li {display = 'flex'alignItems = 'center'gap = '.75rem'minHeight = '2.75rem'}}}
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