gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit369e4b9c369e4b9cMerge branch 'k40-lists' into mainTickets369e4b9c/components/connect.hl

4.5 KB

  1. import { confirmForSession } from '../lib/connections.hl'
  2. // components/connect.hl — `/connect/:nonce` (ticket #21): another app (first: gitoria) asks to be connected to one
  3. // project. The person — logged in through ident, with a display name — picks a project they are ADMIN of, or makes a
  4. // new one, and confirms. Then the page links back to the app with a one-time code (connections.hl); the app's server
  5. // swaps the code for a key that reaches that one project. Everybody else sees the login hint; a used or expired
  6. // request says so. Everything is checked again by the store in the faces.
  7. parent './main.hl'
  8. import { requestOf, requestView, adminProjects, confirmRequest } from '../lib/connections.hl'
  9. import { siteName } from '../project.hl'
  10. import { userOfSession, writerOfSession, canWriteSession } from '../lib/users.hl'
  11. import { hintLook, messageLook, noticeLook } from '../lib/looks.hl'
  12. nonce = null
  13. session = null
  14. pending = requestOf(nonce)
  15. valid = pending != null
  16. gone = pending == null
  17. info = pending != null ? requestView(pending) : { app = '' label = '' hasLabel = false host = '' }
  18. appName = info.app
  19. appLabel = info.label
  20. hasLabel = info.hasLabel
  21. appHost = info.host
  22. canWrite = valid && canWriteSession(session)
  23. showForm = valid && canWriteSession(session)
  24. mustLogIn = valid && !canWriteSession(session)
  25. choices = adminProjects(userOfSession(session))
  26. choice = choices.length > 0 ? choices[0].id : ''
  27. makeNew = choices.length == 0
  28. newTitle = ''
  29. message = ''
  30. done = false
  31. doneUrl = ''
  32. doneProject = ''
  33. __title = siteName + ' | connect ' + (pending != null ? pending.app : 'an app')
  34. Style {
  35. pHint = hintLook + { }
  36. '#connectmessage' = messageLook + { }
  37. '#connected' = noticeLook + { }
  38. connectPage {
  39. display = 'grid'
  40. gap = '1rem'
  41. maxWidth = '38rem'
  42. form {
  43. display = 'grid'
  44. gap = '.8rem'
  45. }
  46. }
  47. }
  48. View {
  49. connectPage {
  50. if (gone) { p { id = "gone" class = "empty" "This connection request is used up or expired. Start again from the app." } }
  51. if (valid) {
  52. h1 { id = "connecttitle" "Connect " appName " to a project" }
  53. p { id = "connectwho" Style.pHint
  54. strong { appName }
  55. if (hasLabel) { " (" appLabel ")" }
  56. " at "
  57. strong { appHost }
  58. " asks for a key to ONE of your projects. With it the app can open tickets, comment and change their state there — for the people who work in it, within their roles. You can disconnect it on the project's page at any time."
  59. }
  60. }
  61. if (mustLogIn) { p { id = "loginhint" Style.pHint "Log in with ident (top right) and choose a display name to connect." } }
  62. if (showForm) {
  63. form { id = "connectform"
  64. on submit(e) {
  65. e.preventDefault()
  66. emit confirm(e)
  67. }
  68. label { "Project"
  69. select { id = "connectproject" name = "project" value = choice on change(e) { emit setChoice(e.target.value) }
  70. for (c of choices) { option { value = c.id c.title } }
  71. option { value = "" "A new project" }
  72. }
  73. }
  74. if (makeNew) {
  75. label { "Title of the new project"
  76. input { id = "connecttitleinput" name = "title" required = "required" maxlength = "100" autocomplete = "off" value = newTitle on input(e) { emit setNewTitle(e.target.value) } }
  77. }
  78. }
  79. button { id = "connectconfirm" type = "submit" "Connect" }
  80. p { id = "connectmessage" message }
  81. }
  82. }
  83. if (done) {
  84. p { id = "connected" "Connected to " strong { doneProject } ". " }
  85. a { id = "connectcontinue" class = "button" href = doneUrl "Continue to " appName }
  86. }
  87. }
  88. }
  89. on setChoice(v) {
  90. choice = v
  91. makeNew = v == ''
  92. }
  93. on setNewTitle(v) { newTitle = v }
  94. on confirm(e) {
  95. if (makeNew && newTitle.trim() == '') { return null }
  96. r = emit server connectConfirm(nonce, choice, newTitle)
  97. if (r == null || r.error != null) {
  98. message = r != null ? r.error : 'could not connect'
  99. return null
  100. }
  101. message = ''
  102. showForm = false
  103. doneUrl = r.url
  104. doneProject = r.project
  105. done = true
  106. }
  107. on client signedIn(tag, info) {
  108. r = emit server connectChoices()
  109. if (r != null && r.projects != null) {
  110. choices = r.projects
  111. choice = r.projects.length > 0 ? r.projects[0].id : ''
  112. makeNew = r.projects.length == 0
  113. }
  114. canWrite = valid && info.named
  115. showForm = valid && info.named && !done
  116. mustLogIn = valid && !info.named
  117. }
  118. on client signedOut(tag) {
  119. canWrite = false
  120. showForm = false
  121. mustLogIn = valid
  122. choices = []
  123. }
  124. on server connectChoices(session) {
  125. u = userOfSession(session)
  126. if (u == null) { return { error = 'log in first' } }
  127. return { projects = adminProjects(u) }
  128. }
  129. on server connectConfirm(nonce, projectId, title, session) {
  130. return confirmForSession(nonce, projectId, title, session)
  131. }

Branches

Latest commits

  • 369e4b9cMerge branch 'k40-lists' into mainTickets
  • 9af8e780|||PR Use keyed list mutations for live ticket updatesmre
  • 610d8e8aMerge branch 'records-t39' into mainTickets
  • 32bcdf24|||PR records: GO P39 K40mre
  • 4123c6d1Merge branch 'records-t38' into mainTickets
  • cd3641a1|||PR records: day72 deploy live, tickets closedmre
  • 7d44d852Merge branch 'records-t37' into mainTickets
  • 926f7061|||PR records: merges, D36 deploymre
  • bf58534eMerge branch 'l33-final' into mainTickets
  • 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
  • 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
  • 5822cb3aMerge branch 'o34-clean' into mainTickets
  • 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
  • 14cf96b4Merge branch 'records-t36' into mainTickets
  • 07749fa1|||PR records: day72 + #40 mergedmre
  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre
  • 6dea1c60Merge branch 'r35-day72' into mainTickets
  • 7bcfdc22|||PR drop worker edits to conductor recordsmre
  • 2617b6ee|||PR dialogs: host flag cleared on close, dialog gate (tickets#40)mre
  • 6e701371|||PR record partial day72 dialog validationmre