gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commite9fec7bbe9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlase9fec7bb/lib/events-helpers.hl

5.2 KB

  1. // lib/events-helpers.hl — what lib/events.hl looks up (calendar mission 001, code order): the size limits, what the
  2. // page sends → a WorldAPI Event record (build), a stored event → what the page shows (viewOf), the temporary ids of
  3. // events made offline, the window check of the faces and the order by start.
  4. import { isText, isDate, isTime, isZone, nextDay, prevDay, before } from '../components/month-view/dates.hl'
  5. import { envOr } from './util.hl'
  6. import { toReminders, toRows } from '../components/month-view/reminders.hl'
  7. static maxTitle = 200
  8. static maxPlace = 200
  9. static maxNotes = 5000
  10. // events per user (security mission SC: a signed-in user could fill the disk): CALENDAR_MAX_EVENTS
  11. static maxEvents = toNumber(envOr('CALENDAR_MAX_EVENTS', '20000'))
  12. // what the page sends: { id?, custom, reminders (rows), title, allDay, startDate, startTime, endDate, endTime, place, notes, zone }
  13. // → { error } or { record } (a WorldAPI Event without owner/id). endDate/endTime may be empty (no end); all-day: the
  14. // last day, inclusive ('' = one day).
  15. static build = (b) => {
  16. if (b == null || hlTypeName(b) != 'Hybrid') { return { error = 'the event must be an object' } }
  17. if (!isText(b.title) || b.title.trim() == '') { return { error = 'the event needs a title' } }
  18. if (b.title.length > maxTitle) { return { error = 'the title is too long (at most ' + maxTitle + ' characters)' } }
  19. if (!isText(b.place) || b.place.length > maxPlace) { return { error = 'the place is too long (at most ' + maxPlace + ' characters)' } }
  20. if (!isText(b.notes) || b.notes.length > maxNotes) { return { error = 'the notes are too long (at most ' + maxNotes + ' characters)' } }
  21. if (b.allDay != true && b.allDay != false) { return { error = 'allDay must be true or false' } }
  22. if (!isDate(b.startDate)) { return { error = 'the start date is not a date' } }
  23. if (!isZone(b.zone)) { return { error = 'the time zone is missing' } }
  24. r = {}
  25. r['$type'] = 'event'
  26. r['$version'] = 1
  27. r['$title'] = b.title.trim()
  28. if (b.notes.trim() != '') { r['$description'] = b.notes }
  29. if (b.place.trim() != '') { r['$location'] = b.place.trim() }
  30. r['$status'] = 'confirmed'
  31. r['$visibility'] = 'private'
  32. // no own reminders: `$reminders` stays out and the calendar's apply; own ones (also none at all) are written
  33. if (b.custom == true) {
  34. rem = toReminders(b.reminders)
  35. if (rem.error != null) { return { error = rem.error } }
  36. r['$reminders'] = rem.reminders
  37. }
  38. if (b.allDay) {
  39. r['$kind'] = 'allday'
  40. r['$start'] = b.startDate
  41. if (isText(b.endDate) && b.endDate != '') {
  42. if (!isDate(b.endDate)) { return { error = 'the end date is not a date' } }
  43. if (before(b.endDate, b.startDate)) { return { error = 'the end is before the start' } }
  44. if (b.endDate != b.startDate) { r['$end'] = nextDay(b.endDate) }
  45. }
  46. return { record = r }
  47. }
  48. if (!isTime(b.startTime)) { return { error = 'the start time is not a time' } }
  49. r['$kind'] = 'appointment'
  50. r['$timezone'] = b.zone
  51. r['$start'] = b.startDate + 'T' + b.startTime + ':00'
  52. hasEnd = (isText(b.endDate) && b.endDate != '') || (isText(b.endTime) && b.endTime != '')
  53. if (hasEnd) {
  54. ed = isText(b.endDate) && b.endDate != '' ? b.endDate : b.startDate
  55. if (!isDate(ed)) { return { error = 'the end date is not a date' } }
  56. if (!isTime(b.endTime)) { return { error = 'the end time is not a time' } }
  57. end = ed + 'T' + b.endTime + ':00'
  58. if (before(end, r['$start'])) { return { error = 'the end is before the start' } }
  59. r['$end'] = end
  60. }
  61. return { record = r }
  62. }
  63. // what the page shows of a stored event: first / last day (inclusive), times, texts
  64. static viewOf = (Hybrid e) => {
  65. allDay = e['$kind'] == 'allday'
  66. start = e['$start']
  67. end = e['$end']
  68. first = start.slice(0, 10)
  69. let last = first
  70. if (allDay) {
  71. if (end != null) { last = prevDay(end) }
  72. } else if (end != null) {
  73. last = end.slice(0, 10)
  74. }
  75. v = { id = e.id title = e['$title'] allDay = allDay first = first last = last
  76. startDate = first startTime = allDay ? '' : start.slice(11, 16)
  77. endDate = end == null ? '' : last endTime = allDay || end == null ? '' : end.slice(11, 16)
  78. place = e['$location'] == null ? '' : e['$location'] notes = e['$description'] == null ? '' : e['$description']
  79. start = start zone = e['$timezone'] == null ? '' : e['$timezone']
  80. custom = e['$reminders'] != null rows = e['$reminders'] == null ? [] : toRows(e['$reminders']) }
  81. return v
  82. }
  83. // an event made offline carries a temporary id `local-…` until the page reloads; the server keeps it as `ref`, so an edit
  84. // (or delete) sent with that id reaches the same event instead of making a second one
  85. static isLocalId = (id) => { return isText(id) && id.length > 6 && id.length <= 60 && id.slice(0, 6) == 'local-' }
  86. // the window is two dates the page shows; anything else is refused
  87. static validWindow = (first, last) => { return isDate(first) && isDate(last) }
  88. // the views ordered by start (a hand-written selection sort)
  89. static byStart = (Hybrid views) => {
  90. m = views.length
  91. out = []
  92. used = []
  93. let i = 0
  94. while (i < m) { used.push(false) i = i + 1 }
  95. let round = 0
  96. while (round < m) {
  97. let best = -1
  98. let j = 0
  99. while (j < m) {
  100. if (!used[j] && (best < 0 || before(views[j].start, views[best].start))) { best = j }
  101. j = j + 1
  102. }
  103. used[best] = true
  104. out.push(views[best])
  105. round = round + 1
  106. }
  107. return out
  108. }

Branches

Latest commits

  • e9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlas
  • eff166a4Re-vendor complete Hybriel plugins and runtime to day44mre
  • cef81394Wait for the DST fixture page instead of an unused socketmre
  • 42434f47Check lazy-session cookies after login with a stored anonymous fixturemre
  • 728e84e3Re-vendor complete Hybriel day41 plugin directoriesmre
  • cbd7ff43Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 59d1da0acalendar: plain declarations instead of needless let in 9 files (calendar#17): 49 declarations that are never reassigned; reassigned ones and the timer closure's p stay letmre
  • f5415cf9calendar: the Style blocks in the language's nested form (calendar#16): rules named after the View's own elements with their children nested, pseudo-classes and @media nested, merged duplicate select rule; same CSS, shots identical in Chrome at 4 sizesmre
  • edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
  • bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre
  • 5d8579d7README: login.js stays by caramboleyo's explicit rulemre
  • cc759328Merge sb3-standby: calendar deploys through its standbymre
  • f2fcdc6dcalendar: a standby container (port 45015, profile standby, reminder clock off) and a /health page; deploy hands over through standby-swap.sh without a gapmre
  • 229643f7Merge branch 'cal-14'mre
  • 1110b26fcalendar#14: the month name no longer breaks into two lines on a phone (Reminder settings drops to its own row when the header is too narrow), gate checks for one-line title and all header controls on screenmre
  • 490c658aident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 18095868calendar: Reminder settings button opens its dialog again (the dialog's open handler still closed the removed user menu and stopped); old e2e and gate scripts use the new headermre
  • 6eee4b5acalendar header: the selector alone top right plus Log out as before the theme missions; Reminder settings back on the month page (WIP: the settings test still fails)mre
  • 0b909decident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • 0c8f9364Merge branch 'sy-sync'mre