calendar
All repositories: gitoria
5.0 KB
// lib/events.hl — THE EVENTS (ticket calendar#2). One hl:mpackdb table, storage/mpackdb/events.db, pk @id, index owner.// A record IS a WorldAPI Event (https://worldapi.org/standards/event): the `$`-keys `$type $version $kind $title// $description $start $end $timezone $location $status $visibility $created $updated`, plus `owner` (the users @id)// and the @id. Appointment: `$start`/`$end` local wall-clock `YYYY-MM-DDTHH:MM:SS` in `$timezone`. All-day:// `$kind = 'allday'`, `$start` a date, `$end` the EXCLUSIVE end date (left out for one day). Every event is// `$visibility = 'private'`: every function takes the owner's user id and reaches only that user's events.// Every write to the table is here. Looked up in lib/events-helpers.hl: build (page fields → record), viewOf (record →// what the page shows), isLocalId, byStart. The default reminders are lib/settings.hl.import { MPackDB } from 'hl:mpackdb'import { timestamp } from 'hl:time'import { storageDir, countOfList } from './util.hl'import { build, viewOf, isLocalId, byStart } from './events-helpers.hl'import { defaultsOf } from './settings.hl'import { before } from '../components/month-view/dates.hl'import { describe, shift } from '../components/month-view/reminders.hl'import { serverToday } from '../components/month-view/clock.hl'static eventsTable = new MPackDB(file = storageDir + '/events.db', primaryKey = '@id', indexes = ['owner'])static ownEvent = (userId, id) => {if (id == null || hlTypeName(id) != 'String' || id == '') { return null }e = eventsTable.fetch(id)if (e == null || e.owner != userId) { return null }return e}// the owner's events that touch first..last (dates), by startstatic eventsBetween = (userId, first, last) => {found = eventsTable.find('owner', userId)n = countOfList(found)views = []let i = 0while (i < n) {let v = viewOf(found[i])if (!before(v.last, first) && !before(last, v.first)) { views.push(v) }i = i + 1}return byStart(views)}static realId = (userId, id) => {if (!isLocalId(id)) { return id }found = eventsTable.find('owner', userId)n = countOfList(found)let i = 0while (i < n) {if (found[i].ref == id) { return found[i].id }i = i + 1}return null}// create, or change when the fields name an event (real or temporary id)static saveEvent = (userId, b) => {if (b != null && hlTypeName(b) == 'Hybrid' && b.id != null && b.id != '') {id = realId(userId, b.id)if (id != null) { return changeEvent(userId, id, b) }if (!isLocalId(b.id)) { return changeEvent(userId, b.id, b) }}return createEvent(userId, b)}static createEvent = (userId, b) => {x = build(b)if (x.error != null) { return x }r = x.recordt = timestamp()r['$created'] = tr['$updated'] = tr.owner = userIdif (isLocalId(b.id)) { r.ref = b.id }let id = eventsTable.put(r)if (id == null) { return { error = 'could not store the event: ' + eventsTable.lastError() } }return { id = id }}static changeEvent = (userId, id, b) => {old = ownEvent(userId, id)if (old == null) { return { error = 'no such event' } }x = build(b)if (x.error != null) { return x }r = x.recordr['$created'] = old['$created']r['$updated'] = timestamp()r.owner = userIdif (old.ref != null) { r.ref = old.ref }r.id = ideventsTable.update(id, r)return { id = id }}static deleteEvent = (userId, given) => {id = realId(userId, given)old = ownEvent(userId, id)if (old == null) { return { error = 'no such event' } }eventsTable.delete(id)return { ok = true }}// ---- the reminders still to come ------------------------------------------------------------------------// the owner's events starting first..last with the reminders that apply (own, else the defaults); timed and all-daystatic upcoming = (userId, first, last) => {defaults = defaultsOf(userId)found = eventsTable.find('owner', userId)n = countOfList(found)out = []let i = 0while (i < n) {let v = viewOf(found[i])if (!before(v.first, first) && !before(last, v.first)) {let list = { id = v.id title = v.title allDay = v.allDay startDate = v.startDate startTime = v.startTime place = v.place zone = v.zone rows = v.custom ? v.rows : defaults }out.push(list)}i = i + 1}return out}// the events with the reminders that apply, from two days back to nine days ahead (what the browser plans its notifications from)static soonOf = (userId) => {t = serverToday()return upcoming(userId, shift(t, -2), shift(t, 9))}// ---- what the faces answer (components/calendar.hl) -----------------------------------------------------// the events of the six weeks on screen, the defaults (text and rows) and the reminders still to comestatic calendarView = (userId, first, last) => {return { events = eventsBetween(userId, first, last) defaults = describe(defaultsOf(userId)) soon = soonOf(userId) defaultRows = defaultsOf(userId) }}// the settings editor: the default reminders as rows, their text and the reminders still to comestatic settingsView = (userId) => {return { rows = defaultsOf(userId) defaults = describe(defaultsOf(userId)) soon = soonOf(userId) defaultRows = defaultsOf(userId) }}
Branches
Latest commits
- 3af29fc8calendar mission 008 (A8): report, README, LOG, push-shots.mjsmre
- f91f3663calendar mission 008 (A8): push only asked of the browser when the app has the VAPID settings (pushAvailable); real-FCM E2E scripts (push-real-app.mjs, push-real.mjs)mre
- bf571badcalendar mission 008 (A8): Turn off on this device (unsubscribes the browser, server drops the device, choice kept), subscribe/refresh when the app is shown again; push gate part 3mre
- 50985708calendar mission 008 (A7): Web Push report, README, mission, LOGmre
- ee318774calendar mission 008 (A7): push-real.mjs, push sent log linemre
- 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