gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitebda0fd1ebda0fd1calendar mission 008 (A7): server-side reminder plan on hl:time (push-plan.hl; hl:time fromLocal in a browser static is refused: repro .scratch/hltime-client), push gate 9/9mreebda0fd1/lib/events-helpers.hl

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

Branches

Latest commits

  • ebda0fd1calendar mission 008 (A7): server-side reminder plan on hl:time (push-plan.hl; hl:time fromLocal in a browser static is refused: repro .scratch/hltime-client), push gate 9/9mre
  • d063dad3calendar mission 008 (A7): Web Push (WIP): lib/push.hl subscriptions + sender clock, faces calPushSave/calPushOff, button subscribes, VAPID tool, tests/push.mjs; instantOf on hl:timemre
  • cf175c80calendar mission 008 (A7): re-vendor Hybriel master 0e3c9830 (bin 9d957fed, plugins whole: hl:crypto Web Push primitives, hl:web sendPush)mre
  • 9bf3c38bcalendar mission 008: re-vendor Hybriel f9833544 (gates old = new); Web Push stopped: hl:crypto half missing on mastermre
  • 186f969bcalendar mission 007: signed-in gate for the first-pointer race (fails on 3c5604f), README theme section, reportmre
  • ba9b4955calendar mission 006: first pointer event no longer re-runs the month (stale overwrite race), gate check, e2e settings cleanup, reportmre
  • bd730759calendar mission 006: theme move (WIP): brief, report, LOG, STATUSmre
  • b117b153calendar mission 006 WIP: reminder row fields keep 44 px; e2e script flagsmre
  • 53e3b0debrowser gate: Log out through the user menu, theme colour rgb(15, 20, 25)mre
  • 90bf9e2ecalendar mission 006 WIP: theme dbe3de7, theme shell (AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst), styles cut to the app's own rules, check-theme gate, e2e toolsmre
  • 3c5604f9identkit: refuse a taken ident port, cold-start deadline, abort on dead ident, clear no-code error (as notes)mre
  • 4996bbe7paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • f5bf0803calendar mission 004: re-vendor Hybriel to the shared static build 0f396652; compose cache volume + tmpfs; notify-paths gate in deploy.sh; gate start waits 150 s; reportmre
  • eb86526fmission brief 004mre
  • 2f953b16deploy.sh: wait up to DEPLOY_URL_WAIT (120 s) for 200 after the restart, as the other apps (cold compile, hybriel#148)mre
  • 9078e1b7calendar mission 003 (2/2): report, LOG, STATUS (cause: timers only in an open, front, touched page; gate old 5/2 new 7/0; Hybriel gaps Web Push + page-shown hook, STOP)mre
  • 31ffe910calendar mission 003 (1/2): calendar#9 — missed reminders shown when the app is back, timers set again when it is shownmre
  • 26c997d3mission brief 003mre
  • c6809c76calendar mission 002: report, LOG, STATUS (test bug; fixed gate 78/0 at 00:30 05:40 12:00 19:59 20:01; 23:30 not run, quota stop)mre
  • 00f72783calendar mission 002 (2/2): TEST bug — the reminder steps get their own identity (carol): alice's all-day Vacation (20th-22nd) from the events steps added 2 reminders from the 12th 20:00 to the 19th 23:00; Tokyo check no longer skipped in the Tokyo eveningmre