gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit97f77b0797f77b07ident mission 012 (WIP): onto the layouts theme dbe3de7, shell on AppHeader/MainMenu/UserMenu/Sidebar + ContentFirst, styles cut, check-theme gatemre97f77b07/components/appsettings.hl

8.1 KB

  1. // components/appsettings.hl — `/inbox/<connection id>`: THE PER-APP PAGE (piece 4 of 6,
  2. // ticket ident#6; CONCEPT.md "Per-app page": "for each app and identity the user has a page
  3. // showing when they registered in that app and all its notifications (by name), each with
  4. // push and email switches, and on top one override for all").
  5. // A connection = one identity in one app (lib/apps.hl connectionsTable); its `created` is
  6. // "when they registered". The switches show the EFFECTIVE setting (the app's preset
  7. // unless the user switched it; lib/notify.hl effectiveOf). THE OVERRIDE: when it is on, its
  8. // push / email switches count for every notification of the app and the per-kind
  9. // switches are locked. Push is impossible for a name the app has not registered.
  10. // Every flip is saved at once (a face) and the server's new state is shown.
  11. //
  12. // Faces are named `inbox…` (a face is found by its EVENT NAME across all files).
  13. parent './main.hl'
  14. import { accountOfSession } from '../lib/accounts.hl'
  15. import { settingsPage, setSwitch, setOverride } from '../lib/notify.hl'
  16. import { disconnectConnection } from '../lib/apps.hl'
  17. import { siteName } from '../project.hl'
  18. session = null
  19. cid = null
  20. me = accountOfSession(session)
  21. signedIn = me != null
  22. signedOut = me == null
  23. page = me != null && cid != null ? settingsPage(me.id, cid) : null
  24. found = page != null
  25. notFound = me != null && page == null
  26. meEmail = me != null ? me.email : ''
  27. appName = page != null ? page.app : ''
  28. identityName = page != null ? page.identity : ''
  29. since = page != null ? page.since : ''
  30. overrideActive = page != null ? page.overrideActive : 'off'
  31. overridePush = page != null ? page.overridePush : 'off'
  32. overrideEmail = page != null ? page.overrideEmail : 'off'
  33. overrideOn = overrideActive == 'on'
  34. overrideActiveChecked = page != null ? page.overrideActiveChecked : 'false'
  35. overridePushChecked = page != null ? page.overridePushChecked : 'false'
  36. overrideEmailChecked = page != null ? page.overrideEmailChecked : 'false'
  37. kinds = page != null ? page.kinds : []
  38. hasKinds = kinds.length > 0
  39. noKinds = kinds.length == 0
  40. current = '/inbox'
  41. __title = siteName + (page != null ? ' | ' + page.app + ' notifications' : ' | notifications')
  42. message = ''
  43. notice = ''
  44. View {
  45. identCard { class = "wide"
  46. if (signedOut) {
  47. h1 { "Notification settings" }
  48. p { id = "signinfirst" class = "lead" "Sign in to ident first: " a { href = "/" "sign in" } "." }
  49. }
  50. if (notFound) {
  51. h1 { "Notification settings" }
  52. p { id = "notfound" class = "message" "This app connection does not exist or is not yours." }
  53. p { class = "links" a { href = "/inbox" "Back to the inbox" } }
  54. }
  55. if (found) {
  56. accountBar {
  57. userEmail { id = "meemail" meEmail }
  58. a { id = "toinbox" href = "/inbox" "Inbox" }
  59. }
  60. section { id = "connhead"
  61. h1 { id = "connapp" appName }
  62. p { class = "lead" "Identity " strong { id = "connidentity" identityName } " — registered in this app since " strong { id = "connsince" since } "." }
  63. button { id = "disconnect" type = "button" class = "quiet small danger" "Sign out of this app" on click(e) { emit doDisconnect(e) } }
  64. }
  65. section { id = "overridesection"
  66. h2 { "All notifications" }
  67. p { class = "lead" "One setting for every notification of this app. While it is on, the switches below are locked." }
  68. switchRow {
  69. switchLabel { "Override all" }
  70. button { id = "ovactive" type = "button" class = "switch" role = "switch" "aria-checked" = overrideActiveChecked overrideActive on click(e) { emit flipOverride('active') } }
  71. }
  72. switchRow {
  73. switchLabel { "Push" }
  74. button { id = "ovpush" type = "button" class = "switch" role = "switch" "aria-checked" = overridePushChecked overridePush on click(e) { emit flipOverride('push') } }
  75. }
  76. switchRow {
  77. switchLabel { "Email" }
  78. button { id = "ovemail" type = "button" class = "switch" role = "switch" "aria-checked" = overrideEmailChecked overrideEmail on click(e) { emit flipOverride('email') } }
  79. }
  80. }
  81. section { id = "kindssection"
  82. h2 { "Notifications" }
  83. if (noKinds) { p { id = "nokinds" class = "lead" "This app has not registered or sent any notifications yet." } }
  84. ul { id = "kinds"
  85. for (k of kinds) {
  86. li { class = "kind"
  87. kindMain {
  88. kindName { k.name }
  89. kindPreset { k.preset }
  90. }
  91. kindSwitches {
  92. switchRow {
  93. switchLabel { "Push" }
  94. if (k.canPush) { button { type = "button" class = "switch push" role = "switch" "aria-checked" = k.pushChecked value = k.name k.push on click(e) { emit flipKind(e.target.value, 'push') } } }
  95. if (k.lockedPush) { button { type = "button" class = "switch push locked" role = "switch" "aria-checked" = k.pushChecked "aria-disabled" = "true" value = k.name k.push } }
  96. if (k.noPush) { switchOff { class = "push" "—" } }
  97. }
  98. switchRow {
  99. switchLabel { "Email" }
  100. if (k.canEmail) { button { type = "button" class = "switch email" role = "switch" "aria-checked" = k.emailChecked value = k.name k.email on click(e) { emit flipKind(e.target.value, 'email') } } }
  101. if (k.lockedEmail) { button { type = "button" class = "switch email locked" role = "switch" "aria-checked" = k.emailChecked "aria-disabled" = "true" value = k.name k.email } }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. p { id = "notice" class = "notice" notice }
  110. p { id = "message" class = "message" message }
  111. }
  112. }
  113. show = (p) => {
  114. overrideActive = p.overrideActive
  115. overridePush = p.overridePush
  116. overrideEmail = p.overrideEmail
  117. overrideOn = p.overrideActive == 'on'
  118. overrideActiveChecked = p.overrideActiveChecked
  119. overridePushChecked = p.overridePushChecked
  120. overrideEmailChecked = p.overrideEmailChecked
  121. kinds = p.kinds
  122. hasKinds = p.kinds.length > 0
  123. noKinds = p.kinds.length == 0
  124. return null
  125. }
  126. answer = (r) => {
  127. if (r == null) {
  128. message = 'the server did not answer — try again'
  129. return null
  130. }
  131. if (r.error != null) {
  132. message = r.error
  133. return null
  134. }
  135. show(r.page)
  136. notice = 'Saved.'
  137. return null
  138. }
  139. on flipOverride(field) {
  140. message = ''
  141. notice = ''
  142. cur = field == 'active' ? overrideActive : (field == 'push' ? overridePush : overrideEmail)
  143. answer(emit server inboxOverride('' + cid, field, cur != 'on'))
  144. }
  145. kindRow = (name) => {
  146. for (k of kinds) { if (k.name == name) { return k } }
  147. return null
  148. }
  149. on flipKind(name, channel) {
  150. message = ''
  151. notice = ''
  152. k = kindRow(name)
  153. if (k == null) { return null }
  154. cur = channel == 'push' ? k.push : k.email
  155. answer(emit server inboxSwitch('' + cid, name, channel, cur != 'on'))
  156. }
  157. // FORGETS this connection: the app gets a fresh, unrelated id on a later login
  158. on doDisconnect(e) {
  159. message = ''
  160. notice = ''
  161. if (!confirm('Sign out of ' + appName + '? It will no longer recognize this identity.')) { return null }
  162. r = emit server inboxDisconnect('' + cid)
  163. if (r == null) {
  164. message = 'the server did not answer — try again'
  165. return null
  166. }
  167. if (r.error != null) {
  168. message = r.error
  169. return null
  170. }
  171. found = false
  172. notFound = true
  173. notice = 'Signed out of ' + appName + '.'
  174. }
  175. // ---- the faces ------------------------------------------------------------------------
  176. // The LAST parameter is the session; accountOfSession only accepts the framework's own
  177. // Session (hl:web never takes it from the peer, hybriel#16/#31).
  178. on server inboxSwitch(cid, kind, channel, value, session) {
  179. let me = accountOfSession(session)
  180. if (me == null) { return { error = 'you are not signed in' } }
  181. if (cid == null || hlTypeName(cid) != 'String') { return { error = 'field connection must be a string' } }
  182. return setSwitch(me.id, cid, kind, channel, value)
  183. }
  184. on server inboxOverride(cid, field, value, session) {
  185. let me = accountOfSession(session)
  186. if (me == null) { return { error = 'you are not signed in' } }
  187. if (cid == null || hlTypeName(cid) != 'String') { return { error = 'field connection must be a string' } }
  188. return setOverride(me.id, cid, field, value)
  189. }
  190. on server inboxDisconnect(cid, session) {
  191. let me = accountOfSession(session)
  192. if (me == null) { return { error = 'you are not signed in' } }
  193. if (cid == null || hlTypeName(cid) != 'String') { return { error = 'field connection must be a string' } }
  194. return disconnectConnection(me.id, cid)
  195. }

Branches

Latest commits

  • 97f77b07ident mission 012 (WIP): onto the layouts theme dbe3de7, shell on AppHeader/MainMenu/UserMenu/Sidebar + ContentFirst, styles cut, check-theme gatemre
  • 8e4f435bpaths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • fa288f63ident mission 011: report wording (Intl zone names)mre
  • 961fae01ident mission 011: report, LOG, STATUSmre
  • 65348039ident#7: delivery gate — console check split at the gate's own server restart (49 checks)mre
  • dfa7b783ident#7: README (Delivery, env, gate, files, data), deploy.sh runs tests/delivery.mjsmre
  • ab6331f4ident#7: tests/delivery.mjs — fake clock gate: Vienna/New York/Tokyo/UTC 17:00, urgent, mail off, restart, DST days, zone changemre
  • 7869f57bident#7: delivery — the daily mail at 17:00 in the user's zone (digests table, once per local day, test clock IDENT_TEST_CLOCK), urgent mailed at once, push hookmre
  • 371ef1b5ident#7: lib/mail.hl sendNotificationMail (sink: <sink>.mail, one JSON line per mail)mre
  • 39749e0bident#7: time zones through hl:time — server checks isZone, an account without a known zone reads as UTC, allAccountsmre
  • 7a54fe72mission brief 011mre
  • a6a874cdident mission 010: vendor hybriel 0f396652 (plugins + compose cache volume/tmpfs + deploy URL wait + report)mre
  • 4e7cf78emission brief 010mre
  • e8b2b0f7docker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • 5fdbb6b2ident mission 009: report — scratch folder notemre
  • 74235815ident mission 009 (4/4): docs (README files map + same-output test, STATUS, LOG), report, tests/letcount.py + realdata-baseline/comparemre
  • fe183516ident mission 009 (3/4): let only where reassigned — 293 never-reassigned lets are plain declarations; kept: reassigned, loop bodies, names of a file member, a name declared twice in one function; same outputmre
  • d2e7f91bident mission 009 (2/4): one lib file per topic (login, accounts, identities, apps, invites, selector, notify + helpers, util), function routes as thin wrappers in lib/api.hl, project.hl = the map; same outputmre
  • 91017164ident mission 009 (1/4): file moves — the root .hl files into lib/ (api.hl → lib/api-helpers.hl), styles.hl → components/styles.hl; imports adjusted, no other changemre
  • f8bdcbc2ident: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); all gates greenmre