From f7ee0b64d828522a343ad2799a7e6222ec7d506c Mon Sep 17 00:00:00 2001 From: Isabella Zauner Date: Thu, 19 Nov 2026 12:44:12 +0100 Subject: [PATCH 01/22] Add a cross-project calendar API and saved calendars Server side of a Calendar page beside My Tasks, outside any project. - GET /api/calendar?from&to&tags&people&projects&statuses: cards due in the window (at most 62 days) from every project the caller is a member of (not admin-elevated), passing the filters, plus each filter's choices. Tags and statuses match by name, ignoring case, since each project has its own; sub-tasks only with their own tag; expired done cards left out. With a tag chosen, tagged cards without a due date come back as `undated`. Each card names its parent and the first board showing its status. - The filter rule is shared/utils/calendar-filter.ts, so the page applies the same test to live updates. - calendars table and /api/calendars CRUD: a person's own named filter sets (migration 0021). Another person's calendar is a 404. - /api/events?scope=mine streams every project the caller is a member of, re-checking membership per event. Co-Authored-By: Claude Opus 5.5 --- server/api/calendar.get.ts | 36 + server/api/calendars/[id].delete.ts | 8 + server/api/calendars/[id].put.ts | 13 + server/api/calendars/index.get.ts | 11 + server/api/calendars/index.post.ts | 19 + server/api/events.get.ts | 14 +- server/database/migrations/0021_calendars.sql | 11 + .../migrations/meta/0021_snapshot.json | 2646 +++++++++++++++++ server/database/migrations/meta/_journal.json | 7 + server/database/schema.ts | 19 + server/utils/calendar-cards.ts | 106 + server/utils/calendars.ts | 19 + shared/schemas/calendar.ts | 32 + shared/utils/calendar-filter.ts | 50 + tests/integration/calendar.test.ts | 169 ++ tests/unit/calendar-days.test.ts | 99 + tests/unit/calendar-filter.test.ts | 28 + 17 files changed, 3286 insertions(+), 1 deletion(-) create mode 100644 server/api/calendar.get.ts create mode 100644 server/api/calendars/[id].delete.ts create mode 100644 server/api/calendars/[id].put.ts create mode 100644 server/api/calendars/index.get.ts create mode 100644 server/api/calendars/index.post.ts create mode 100644 server/database/migrations/0021_calendars.sql create mode 100644 server/database/migrations/meta/0021_snapshot.json create mode 100644 server/utils/calendar-cards.ts create mode 100644 server/utils/calendars.ts create mode 100644 shared/schemas/calendar.ts create mode 100644 shared/utils/calendar-filter.ts create mode 100644 tests/integration/calendar.test.ts create mode 100644 tests/unit/calendar-days.test.ts create mode 100644 tests/unit/calendar-filter.test.ts diff --git a/server/api/calendar.get.ts b/server/api/calendar.get.ts new file mode 100644 index 0000000..c74bee3 --- /dev/null +++ b/server/api/calendar.get.ts @@ -0,0 +1,36 @@ +import { calendarFiltersSchema } from '#shared/schemas/calendar' + +const DAY = /^\d{4}-\d{2}-\d{2}$/ +/** Six weeks covers any month grid; a little more for a week either side. */ +const MAX_DAYS = 62 + +const list = (value: unknown): string[] => (Array.isArray(value) ? value : value == null || value === '' ? [] : [value]).map(String) + +/** + * `GET /api/calendar?from=YYYY-MM-DD&to=YYYY-MM-DD&tags=…&people=…&projects=…&statuses=…` + * + * The Calendar page: cards due in the window from every project the caller is a + * member of, passing the filters (`server/utils/calendar-cards.ts`), and the + * choices for each filter. Repeat a parameter for several values. + */ +export default defineEventHandler(async (event) => { + const { user } = await resolveAuth(event) + const q = getQuery(event) + const from = String(q.from ?? '') + const to = String(q.to ?? '') + const span = (Date.parse(to) - Date.parse(from)) / 86_400_000 + if (!DAY.test(from) || !DAY.test(to) || Number.isNaN(span) || span < 0 || span > MAX_DAYS) { + throw createError({ statusCode: 400, message: `from and to must be days (YYYY-MM-DD), from before to, at most ${MAX_DAYS} days apart` }) + } + const parsed = calendarFiltersSchema.safeParse({ + mode: q.mode || undefined, + tags: list(q.tags), + people: list(q.people), + projects: list(q.projects), + statuses: list(q.statuses) + }) + if (!parsed.success) { + throw createError({ statusCode: 400, message: parsed.error.issues[0]?.message ?? 'Invalid filters' }) + } + return calendarCards(user.id, { from, to }, parsed.data) +}) diff --git a/server/api/calendars/[id].delete.ts b/server/api/calendars/[id].delete.ts new file mode 100644 index 0000000..2ee3f81 --- /dev/null +++ b/server/api/calendars/[id].delete.ts @@ -0,0 +1,8 @@ +import { eq } from 'drizzle-orm' + +/** `DELETE /api/calendars/:id`. Only the saved filters go; no card is touched. */ +export default defineEventHandler(async (event) => { + const { calendar } = await resolveCalendar(event) + db.delete(schema.calendars).where(eq(schema.calendars.id, calendar.id)).run() + return { ok: true } +}) diff --git a/server/api/calendars/[id].put.ts b/server/api/calendars/[id].put.ts new file mode 100644 index 0000000..a659de1 --- /dev/null +++ b/server/api/calendars/[id].put.ts @@ -0,0 +1,13 @@ +import { eq } from 'drizzle-orm' +import { calendarUpdateSchema } from '#shared/schemas/calendar' + +/** `PUT /api/calendars/:id`: rename it, or store the filters it now shows. */ +export default defineEventHandler(async (event) => { + const { calendar } = await resolveCalendar(event) + const body = await readBodyAs(event, calendarUpdateSchema) + const row = db.update(schema.calendars).set({ + ...(body.name !== undefined && { name: body.name }), + ...(body.filters !== undefined && { filters: JSON.stringify(body.filters) }) + }).where(eq(schema.calendars.id, calendar.id)).returning().get() + return calendarView(row!) +}) diff --git a/server/api/calendars/index.get.ts b/server/api/calendars/index.get.ts new file mode 100644 index 0000000..8a5864a --- /dev/null +++ b/server/api/calendars/index.get.ts @@ -0,0 +1,11 @@ +import { asc, eq } from 'drizzle-orm' + +/** `GET /api/calendars`: the caller's saved calendars, for the sidebar. */ +export default defineEventHandler(async (event) => { + const { user } = await resolveAuth(event) + return db.select().from(schema.calendars) + .where(eq(schema.calendars.userId, user.id)) + .orderBy(asc(schema.calendars.position), asc(schema.calendars.createdAt)) + .all() + .map(calendarView) +}) diff --git a/server/api/calendars/index.post.ts b/server/api/calendars/index.post.ts new file mode 100644 index 0000000..714caa5 --- /dev/null +++ b/server/api/calendars/index.post.ts @@ -0,0 +1,19 @@ +import { eq } from 'drizzle-orm' +import { calendarCreateSchema } from '#shared/schemas/calendar' + +/** `POST /api/calendars`: save the Calendar page's filters under a name. */ +export default defineEventHandler(async (event) => { + const { user } = await resolveAuth(event) + const body = await readBodyAs(event, calendarCreateSchema) + const existing = db.select({ position: schema.calendars.position }).from(schema.calendars) + .where(eq(schema.calendars.userId, user.id)).all() + const row = db.insert(schema.calendars).values({ + userId: user.id, + name: body.name, + filters: JSON.stringify(body.filters), + // max + 1, never a count: after a delete a count ties with an existing row. + position: existing.reduce((max, c) => Math.max(max, c.position), -1) + 1 + }).returning().get() + setResponseStatus(event, 201) + return calendarView(row) +}) diff --git a/server/api/events.get.ts b/server/api/events.get.ts index ac748c9..882f735 100644 --- a/server/api/events.get.ts +++ b/server/api/events.get.ts @@ -13,7 +13,19 @@ */ export default defineEventHandler(async (event) => { const { user } = await resolveAuth(event) - const { projectId } = getQuery(event) as { projectId?: string } + const { projectId, scope } = getQuery(event) as { projectId?: string, scope?: string } + + // Every project the caller is a member of, for a timeline board, which shows + // cards from all of them. Membership is read again for each event rather than + // once at connect, so a project left or joined meanwhile is honoured. + if (scope === 'mine') { + return streamAppEvents(event, { + select: evt => evt.projectId && memberProjectIds(user.id).has(evt.projectId) + ? { event: evt.type, data: JSON.stringify(evt.payload ?? null) } + : null, + allowed: () => isStillAuthorized(event) + }) + } if (!projectId) { throw createError({ statusCode: 400, message: 'projectId is required' }) diff --git a/server/database/migrations/0021_calendars.sql b/server/database/migrations/0021_calendars.sql new file mode 100644 index 0000000..9b39fcb --- /dev/null +++ b/server/database/migrations/0021_calendars.sql @@ -0,0 +1,11 @@ +CREATE TABLE `calendars` ( + `id` text PRIMARY KEY NOT NULL, + `user_id` text NOT NULL, + `name` text NOT NULL, + `filters` text NOT NULL, + `position` integer DEFAULT 0 NOT NULL, + `created_at` integer NOT NULL, + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE INDEX `calendars_user_idx` ON `calendars` (`user_id`); \ No newline at end of file diff --git a/server/database/migrations/meta/0021_snapshot.json b/server/database/migrations/meta/0021_snapshot.json new file mode 100644 index 0000000..6dcafcf --- /dev/null +++ b/server/database/migrations/meta/0021_snapshot.json @@ -0,0 +1,2646 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "0c8cce85-e4c0-4b54-afd1-05442c778073", + "prevId": "b920d19d-b862-41ac-8f21-552549f6cee8", + "tables": { + "ai_skills": { + "name": "ai_skills", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'card'" + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "api_tokens": { + "name": "api_tokens", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_used_at": { + "name": "last_used_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "api_tokens_token_hash_unique": { + "name": "api_tokens_token_hash_unique", + "columns": [ + "token_hash" + ], + "isUnique": true + } + }, + "foreignKeys": { + "api_tokens_user_id_users_id_fk": { + "name": "api_tokens_user_id_users_id_fk", + "tableFrom": "api_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "attachments": { + "name": "attachments", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "card_id": { + "name": "card_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "storage_key": { + "name": "storage_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "original_name": { + "name": "original_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mime_type": { + "name": "mime_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "uploaded_by_id": { + "name": "uploaded_by_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "attachments_card_idx": { + "name": "attachments_card_idx", + "columns": [ + "card_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "attachments_card_id_cards_id_fk": { + "name": "attachments_card_id_cards_id_fk", + "tableFrom": "attachments", + "tableTo": "cards", + "columnsFrom": [ + "card_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "attachments_project_id_projects_id_fk": { + "name": "attachments_project_id_projects_id_fk", + "tableFrom": "attachments", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "attachments_uploaded_by_id_users_id_fk": { + "name": "attachments_uploaded_by_id_users_id_fk", + "tableFrom": "attachments", + "tableTo": "users", + "columnsFrom": [ + "uploaded_by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "board_columns": { + "name": "board_columns", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "board_id": { + "name": "board_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status_id": { + "name": "status_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "board_columns_board_status_unique": { + "name": "board_columns_board_status_unique", + "columns": [ + "board_id", + "status_id" + ], + "isUnique": true + }, + "board_columns_status_idx": { + "name": "board_columns_status_idx", + "columns": [ + "status_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "board_columns_board_id_boards_id_fk": { + "name": "board_columns_board_id_boards_id_fk", + "tableFrom": "board_columns", + "tableTo": "boards", + "columnsFrom": [ + "board_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "board_columns_status_id_statuses_id_fk": { + "name": "board_columns_status_id_statuses_id_fk", + "tableFrom": "board_columns", + "tableTo": "statuses", + "columnsFrom": [ + "status_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "boards": { + "name": "boards", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "''" + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "tag_filters": { + "name": "tag_filters", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status_filters": { + "name": "status_filters", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "assignee_filters": { + "name": "assignee_filters", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "priority_filters": { + "name": "priority_filters", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hidden_card_fields": { + "name": "hidden_card_fields", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "show_subtasks": { + "name": "show_subtasks", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "created_by_id": { + "name": "created_by_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "boards_project_idx": { + "name": "boards_project_idx", + "columns": [ + "project_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "boards_project_id_projects_id_fk": { + "name": "boards_project_id_projects_id_fk", + "tableFrom": "boards", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "boards_created_by_id_users_id_fk": { + "name": "boards_created_by_id_users_id_fk", + "tableFrom": "boards", + "tableTo": "users", + "columnsFrom": [ + "created_by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "calendars": { + "name": "calendars", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "filters": { + "name": "filters", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "calendars_user_idx": { + "name": "calendars_user_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "calendars_user_id_users_id_fk": { + "name": "calendars_user_id_users_id_fk", + "tableFrom": "calendars", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "card_events": { + "name": "card_events", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "card_id": { + "name": "card_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "actor_name": { + "name": "actor_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "field": { + "name": "field", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "from_id": { + "name": "from_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "from_value": { + "name": "from_value", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "to_id": { + "name": "to_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "to_value": { + "name": "to_value", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "card_events_card_id_idx": { + "name": "card_events_card_id_idx", + "columns": [ + "card_id", + "id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "card_events_card_id_cards_id_fk": { + "name": "card_events_card_id_cards_id_fk", + "tableFrom": "card_events", + "tableTo": "cards", + "columnsFrom": [ + "card_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "card_events_actor_id_users_id_fk": { + "name": "card_events_actor_id_users_id_fk", + "tableFrom": "card_events", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "card_reads": { + "name": "card_reads", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "card_id": { + "name": "card_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_read_at": { + "name": "last_read_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "card_reads_user_card_unique": { + "name": "card_reads_user_card_unique", + "columns": [ + "user_id", + "card_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "card_reads_user_id_users_id_fk": { + "name": "card_reads_user_id_users_id_fk", + "tableFrom": "card_reads", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "card_reads_card_id_cards_id_fk": { + "name": "card_reads_card_id_cards_id_fk", + "tableFrom": "card_reads", + "tableTo": "cards", + "columnsFrom": [ + "card_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "card_tags": { + "name": "card_tags", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "card_id": { + "name": "card_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "card_tags_card_tag_unique": { + "name": "card_tags_card_tag_unique", + "columns": [ + "card_id", + "tag_id" + ], + "isUnique": true + }, + "card_tags_tag_idx": { + "name": "card_tags_tag_idx", + "columns": [ + "tag_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "card_tags_card_id_cards_id_fk": { + "name": "card_tags_card_id_cards_id_fk", + "tableFrom": "card_tags", + "tableTo": "cards", + "columnsFrom": [ + "card_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "card_tags_tag_id_tags_id_fk": { + "name": "card_tags_tag_id_tags_id_fk", + "tableFrom": "card_tags", + "tableTo": "tags", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "cards": { + "name": "cards", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "status_id": { + "name": "status_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "assignee_id": { + "name": "assignee_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "priority": { + "name": "priority", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'medium'" + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "due_date": { + "name": "due_date", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "parent_id": { + "name": "parent_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_by_id": { + "name": "created_by_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "cards_parent_idx": { + "name": "cards_parent_idx", + "columns": [ + "parent_id" + ], + "isUnique": false + }, + "cards_project_status_idx": { + "name": "cards_project_status_idx", + "columns": [ + "project_id", + "status_id" + ], + "isUnique": false + }, + "cards_status_idx": { + "name": "cards_status_idx", + "columns": [ + "status_id" + ], + "isUnique": false + }, + "cards_assignee_idx": { + "name": "cards_assignee_idx", + "columns": [ + "assignee_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "cards_status_id_statuses_id_fk": { + "name": "cards_status_id_statuses_id_fk", + "tableFrom": "cards", + "tableTo": "statuses", + "columnsFrom": [ + "status_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cards_project_id_projects_id_fk": { + "name": "cards_project_id_projects_id_fk", + "tableFrom": "cards", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cards_assignee_id_users_id_fk": { + "name": "cards_assignee_id_users_id_fk", + "tableFrom": "cards", + "tableTo": "users", + "columnsFrom": [ + "assignee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "cards_parent_id_cards_id_fk": { + "name": "cards_parent_id_cards_id_fk", + "tableFrom": "cards", + "tableTo": "cards", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "cards_created_by_id_users_id_fk": { + "name": "cards_created_by_id_users_id_fk", + "tableFrom": "cards", + "tableTo": "users", + "columnsFrom": [ + "created_by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "comments": { + "name": "comments", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "card_id": { + "name": "card_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "author_id": { + "name": "author_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "comments_card_idx": { + "name": "comments_card_idx", + "columns": [ + "card_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "comments_card_id_cards_id_fk": { + "name": "comments_card_id_cards_id_fk", + "tableFrom": "comments", + "tableTo": "cards", + "columnsFrom": [ + "card_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "comments_author_id_users_id_fk": { + "name": "comments_author_id_users_id_fk", + "tableFrom": "comments", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "email_verification_tokens": { + "name": "email_verification_tokens", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "purpose": { + "name": "purpose", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "email_verification_tokens_token_unique": { + "name": "email_verification_tokens_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "email_verification_tokens_user_id_users_id_fk": { + "name": "email_verification_tokens_user_id_users_id_fk", + "tableFrom": "email_verification_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "global_settings": { + "name": "global_settings", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "list_columns": { + "name": "list_columns", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "list_id": { + "name": "list_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "field": { + "name": "field", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "list_columns_list_idx": { + "name": "list_columns_list_idx", + "columns": [ + "list_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "list_columns_list_id_lists_id_fk": { + "name": "list_columns_list_id_lists_id_fk", + "tableFrom": "list_columns", + "tableTo": "lists", + "columnsFrom": [ + "list_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "lists": { + "name": "lists", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "''" + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "sort_field": { + "name": "sort_field", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sort_direction": { + "name": "sort_direction", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tag_filters": { + "name": "tag_filters", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status_filters": { + "name": "status_filters", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "assignee_filters": { + "name": "assignee_filters", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "priority_filters": { + "name": "priority_filters", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "show_subtasks": { + "name": "show_subtasks", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "created_by_id": { + "name": "created_by_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "lists_project_idx": { + "name": "lists_project_idx", + "columns": [ + "project_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "lists_project_id_projects_id_fk": { + "name": "lists_project_id_projects_id_fk", + "tableFrom": "lists", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "lists_created_by_id_users_id_fk": { + "name": "lists_created_by_id_users_id_fk", + "tableFrom": "lists", + "tableTo": "users", + "columnsFrom": [ + "created_by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "my_tasks_collapsed": { + "name": "my_tasks_collapsed", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "my_tasks_collapsed_user_id_users_id_fk": { + "name": "my_tasks_collapsed_user_id_users_id_fk", + "tableFrom": "my_tasks_collapsed", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "my_tasks_collapsed_project_id_projects_id_fk": { + "name": "my_tasks_collapsed_project_id_projects_id_fk", + "tableFrom": "my_tasks_collapsed", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "my_tasks_columns": { + "name": "my_tasks_columns", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "field": { + "name": "field", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "my_tasks_columns_user_id_users_id_fk": { + "name": "my_tasks_columns_user_id_users_id_fk", + "tableFrom": "my_tasks_columns", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "notifications": { + "name": "notifications", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "link_url": { + "name": "link_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "card_id": { + "name": "card_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "read_at": { + "name": "read_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "notifications_user_read_idx": { + "name": "notifications_user_read_idx", + "columns": [ + "user_id", + "read_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "notifications_user_id_users_id_fk": { + "name": "notifications_user_id_users_id_fk", + "tableFrom": "notifications", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notifications_project_id_projects_id_fk": { + "name": "notifications_project_id_projects_id_fk", + "tableFrom": "notifications", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notifications_card_id_cards_id_fk": { + "name": "notifications_card_id_cards_id_fk", + "tableFrom": "notifications", + "tableTo": "cards", + "columnsFrom": [ + "card_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notifications_actor_id_users_id_fk": { + "name": "notifications_actor_id_users_id_fk", + "tableFrom": "notifications", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "oauth_clients": { + "name": "oauth_clients", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "redirect_uris": { + "name": "redirect_uris", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_endpoint_auth_method": { + "name": "token_endpoint_auth_method", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'none'" + }, + "client_secret_hash": { + "name": "client_secret_hash", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "oauth_codes": { + "name": "oauth_codes", + "columns": { + "code_hash": { + "name": "code_hash", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "redirect_uri": { + "name": "redirect_uri", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "code_challenge": { + "name": "code_challenge", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "resource": { + "name": "resource", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "oauth_codes_user_id_users_id_fk": { + "name": "oauth_codes_user_id_users_id_fk", + "tableFrom": "oauth_codes", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "oauth_grants": { + "name": "oauth_grants", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "client_name": { + "name": "client_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "access_token_hash": { + "name": "access_token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "access_expires_at": { + "name": "access_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "refresh_token_hash": { + "name": "refresh_token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "refresh_expires_at": { + "name": "refresh_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "previous_refresh_token_hash": { + "name": "previous_refresh_token_hash", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "resource": { + "name": "resource", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_used_at": { + "name": "last_used_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "oauth_grants_access_token_hash_unique": { + "name": "oauth_grants_access_token_hash_unique", + "columns": [ + "access_token_hash" + ], + "isUnique": true + }, + "oauth_grants_refresh_token_hash_unique": { + "name": "oauth_grants_refresh_token_hash_unique", + "columns": [ + "refresh_token_hash" + ], + "isUnique": true + }, + "oauth_grants_previous_refresh_token_hash_unique": { + "name": "oauth_grants_previous_refresh_token_hash_unique", + "columns": [ + "previous_refresh_token_hash" + ], + "isUnique": true + } + }, + "foreignKeys": { + "oauth_grants_user_id_users_id_fk": { + "name": "oauth_grants_user_id_users_id_fk", + "tableFrom": "oauth_grants", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "project_invitations": { + "name": "project_invitations", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "invited_by_id": { + "name": "invited_by_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'member'" + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "project_invitations_token_unique": { + "name": "project_invitations_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "project_invitations_project_id_projects_id_fk": { + "name": "project_invitations_project_id_projects_id_fk", + "tableFrom": "project_invitations", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "project_invitations_invited_by_id_users_id_fk": { + "name": "project_invitations_invited_by_id_users_id_fk", + "tableFrom": "project_invitations", + "tableTo": "users", + "columnsFrom": [ + "invited_by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "project_members": { + "name": "project_members", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'member'" + } + }, + "indexes": { + "project_members_project_user_unique": { + "name": "project_members_project_user_unique", + "columns": [ + "project_id", + "user_id" + ], + "isUnique": true + }, + "project_members_user_idx": { + "name": "project_members_user_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "project_members_project_id_projects_id_fk": { + "name": "project_members_project_id_projects_id_fk", + "tableFrom": "project_members", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "project_members_user_id_users_id_fk": { + "name": "project_members_user_id_users_id_fk", + "tableFrom": "project_members", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "project_stars": { + "name": "project_stars", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "project_stars_user_project_unique": { + "name": "project_stars_user_project_unique", + "columns": [ + "user_id", + "project_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "project_stars_user_id_users_id_fk": { + "name": "project_stars_user_id_users_id_fk", + "tableFrom": "project_stars", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "project_stars_project_id_projects_id_fk": { + "name": "project_stars_project_id_projects_id_fk", + "tableFrom": "project_stars", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "projects": { + "name": "projects", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "briefing": { + "name": "briefing", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "done_status_id": { + "name": "done_status_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "done_retention_days": { + "name": "done_retention_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "projects_slug_unique": { + "name": "projects_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + }, + "projects_key_unique": { + "name": "projects_key_unique", + "columns": [ + "key" + ], + "isUnique": true + } + }, + "foreignKeys": { + "projects_done_status_id_statuses_id_fk": { + "name": "projects_done_status_id_statuses_id_fk", + "tableFrom": "projects", + "tableTo": "statuses", + "columnsFrom": [ + "done_status_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "statuses": { + "name": "statuses", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "statuses_project_idx": { + "name": "statuses_project_idx", + "columns": [ + "project_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "statuses_project_id_projects_id_fk": { + "name": "statuses_project_id_projects_id_fk", + "tableFrom": "statuses", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tags": { + "name": "tags", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'#6366f1'" + } + }, + "indexes": { + "tags_project_idx": { + "name": "tags_project_idx", + "columns": [ + "project_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "tags_project_id_projects_id_fk": { + "name": "tags_project_id_projects_id_fk", + "tableFrom": "tags", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "color_mode": { + "name": "color_mode", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_admin": { + "name": "is_admin", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "suspended_at": { + "name": "suspended_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "session_version": { + "name": "session_version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "email_verified_at": { + "name": "email_verified_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email_notifications": { + "name": "email_notifications", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'human'" + }, + "managed_by_id": { + "name": "managed_by_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "can_create_agents": { + "name": "can_create_agents", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "users_email_unique": { + "name": "users_email_unique", + "columns": [ + "email" + ], + "isUnique": true + }, + "users_email_lower_unique": { + "name": "users_email_lower_unique", + "columns": [ + "lower(\"email\")" + ], + "isUnique": true + }, + "users_agent_name_lower_unique": { + "name": "users_agent_name_lower_unique", + "columns": [ + "lower(\"name\")" + ], + "isUnique": true, + "where": "\"users\".\"kind\" = 'agent'" + } + }, + "foreignKeys": { + "users_managed_by_id_users_id_fk": { + "name": "users_managed_by_id_users_id_fk", + "tableFrom": "users", + "tableTo": "users", + "columnsFrom": [ + "managed_by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": { + "users_email_lower_unique": { + "columns": { + "lower(\"email\")": { + "isExpression": true + } + } + }, + "users_agent_name_lower_unique": { + "columns": { + "lower(\"name\")": { + "isExpression": true + } + } + } + } + } +} \ No newline at end of file diff --git a/server/database/migrations/meta/_journal.json b/server/database/migrations/meta/_journal.json index b0fea9c..8d39696 100644 --- a/server/database/migrations/meta/_journal.json +++ b/server/database/migrations/meta/_journal.json @@ -148,6 +148,13 @@ "when": 1794877818346, "tag": "0020_curly_dreadnoughts", "breakpoints": true + }, + { + "idx": 21, + "version": "6", + "when": 1795088455911, + "tag": "0021_calendars", + "breakpoints": true } ] } \ No newline at end of file diff --git a/server/database/schema.ts b/server/database/schema.ts index 54b40e5..30216a8 100644 --- a/server/database/schema.ts +++ b/server/database/schema.ts @@ -368,6 +368,25 @@ export const cardReads = sqliteTable('card_reads', { // (`/api/projects`, `/api/projects/[id]`), so a person removed from a project, or // no longer an admin, loses it from the sidebar without every removal path — // member delete, agent pruning, transfers, a demotion — having to remember this table. +/** + * A calendar someone saved: a name and the filters of the Calendar page + * (`shared/schemas/calendar.ts`), such as "cards tagged Redaktionsplan, by + * week". Personal, like stars: it belongs to no project, and what it shows is + * always the owner's own projects. Sharing is a link, which the receiver saves + * as their own. + */ +export const calendars = sqliteTable('calendars', { + id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()), + userId: text('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }), + name: text('name').notNull(), + // JSON `CalendarFilters`. + filters: text('filters').notNull(), + position: integer('position').notNull().default(0), + createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()) +}, table => [ + index('calendars_user_idx').on(table.userId) +]) + export const projectStars = sqliteTable('project_stars', { id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()), userId: text('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }), diff --git a/server/utils/calendar-cards.ts b/server/utils/calendar-cards.ts new file mode 100644 index 0000000..5ed0569 --- /dev/null +++ b/server/utils/calendar-cards.ts @@ -0,0 +1,106 @@ +import { and, asc, eq, gte, inArray, isNull, lt, or } from 'drizzle-orm' +import { matchesCalendar, normalizeName, type CalendarFilters } from '#shared/utils/calendar-filter' + +/** + * What the Calendar page shows: cards due between `from` and `to` (inclusive + * `YYYY-MM-DD` days) from every project `userId` is a member of, passing the + * filters, plus the pickers the filters choose from. + * + * - **Membership, not admin.** The calendar lives outside projects, like My + * Tasks, so "every project" means the user's own. An admin is not shown every + * project on the instance, and a project you cannot open contributes nothing. + * - **Tags by name, on the card itself.** A sub-task appears when it carries the + * tag, not because its parent does. + * - **No expired done cards,** the retention every view applies. + * - **Cards without a due date** come back only when a tag is chosen: across + * every project they would be most of the database, while for "cards tagged + * Redaktionsplan" they are exactly the ones still to be scheduled. + * + * With a tag, the path is tags by project (`tags_project_idx`), `card_tags` by + * tag (`card_tags_tag_idx`), cards by key. Without one, cards by project and + * due date, within a window of at most a few weeks. + */ +export function calendarCards(userId: string, range: { from: string, to: string }, filters: CalendarFilters) { + const projectIds = [...memberProjectIds(userId)] + const projects = projectIds.length + ? db.select().from(schema.projects).where(inArray(schema.projects.id, projectIds)).orderBy(asc(schema.projects.name)).all() + : [] + const statuses = projectIds.length + ? db.select({ id: schema.statuses.id, projectId: schema.statuses.projectId, name: schema.statuses.name, color: schema.statuses.color }) + .from(schema.statuses).where(inArray(schema.statuses.projectId, projectIds)).all() + : [] + const tagRows = projectIds.length + ? db.select({ id: schema.tags.id, name: schema.tags.name, color: schema.tags.color }).from(schema.tags).where(inArray(schema.tags.projectId, projectIds)).all() + : [] + const memberRows = projectIds.length + ? db.selectDistinct(memberRefColumns()).from(schema.projectMembers) + .innerJoin(schema.users, eq(schema.projectMembers.userId, schema.users.id)) + .where(inArray(schema.projectMembers.projectId, projectIds)).all() + : [] + + const pickers = { + projects: projects.map(p => ({ id: p.id, name: p.name, slug: p.slug, key: p.key, doneStatusId: p.doneStatusId })), + statuses, + // One entry per name, in its first spelling, with that tag's colour. + tags: [...new Map(tagRows.map(t => [normalizeName(t.name), { name: t.name.trim(), color: t.color }])).values()] + .sort((a, b) => a.name.localeCompare(b.name)), + people: (() => { + const { member } = createUserRefs(memberRows) + return memberRows.map(member).sort((a, b) => a.name.localeCompare(b.name)) + })() + } + if (!projectIds.length) return { ...pickers, cards: [], undated: [] } + + const start = new Date(`${range.from}T00:00:00.000Z`) + const end = new Date(Date.parse(`${range.to}T00:00:00.000Z`) + 86_400_000) + const inRange = and(gte(schema.cards.dueDate, start), lt(schema.cards.dueDate, end)) + + let where + if (filters.tags.length) { + const wanted = new Set(filters.tags.map(normalizeName)) + const tagIds = tagRows.filter(t => wanted.has(normalizeName(t.name))).map(t => t.id) + if (!tagIds.length) return { ...pickers, cards: [], undated: [] } + const cardIds = db.selectDistinct({ id: schema.cardTags.cardId }).from(schema.cardTags) + .where(inArray(schema.cardTags.tagId, tagIds)).all().map(r => r.id) + if (!cardIds.length) return { ...pickers, cards: [], undated: [] } + where = and(inArray(schema.cards.id, cardIds), inArray(schema.cards.projectId, projectIds), or(inRange, isNull(schema.cards.dueDate))) + } else { + where = and(inArray(schema.cards.projectId, projectIds), inRange) + } + + const rows = db.select().from(schema.cards) + .leftJoin(schema.users, eq(schema.cards.assigneeId, schema.users.id)) + .where(where) + .orderBy(asc(schema.cards.dueDate), asc(schema.cards.id)) + .all() + + const projectById = new Map(projects.map(p => [p.id, p])) + const live = rows.filter(r => !isExpiredDone(r.cards, projectById.get(r.cards.projectId)!)) + const { ref } = createUserRefs(live.map(r => r.users)) + const statusName = new Map(statuses.map(s => [s.id, s.name])) + const enriched = enrichCardsWithMetadata(live.map(r => ({ ...r.cards, assignee: ref(r.users) })), { userId }) + .filter(c => matchesCalendar(c, statusName.get(c.statusId), filters)) + + // Where a card "lives": the first board of its project, in board order, that + // shows its status. A card is on every board whose columns include its + // status, or on none, so this names the likeliest one rather than the only one. + const usedProjects = [...new Set(enriched.map(c => c.projectId))] + const boards = usedProjects.length + ? db.select({ id: schema.boards.id, projectId: schema.boards.projectId, name: schema.boards.name, slug: schema.boards.slug, statusId: schema.boardColumns.statusId }) + .from(schema.boards) + .innerJoin(schema.boardColumns, eq(schema.boardColumns.boardId, schema.boards.id)) + .where(inArray(schema.boards.projectId, usedProjects)) + .orderBy(asc(schema.boards.position)) + .all() + : [] + const withBoard = enriched.map((c) => { + const b = boards.find(x => x.projectId === c.projectId && x.statusId === c.statusId) + return { ...c, board: b ? { id: b.id, name: b.name, slug: b.slug } : null } + }) + + return { + ...pickers, + cards: withBoard.filter(c => c.dueDate), + undated: withBoard.filter(c => !c.dueDate) + } +} diff --git a/server/utils/calendars.ts b/server/utils/calendars.ts new file mode 100644 index 0000000..c044005 --- /dev/null +++ b/server/utils/calendars.ts @@ -0,0 +1,19 @@ +import { and, eq } from 'drizzle-orm' +import type { H3Event } from 'h3' +import type { CalendarFilters } from '#shared/utils/calendar-filter' + +/** A saved calendar as the API hands it out, with its filters parsed. */ +export function calendarView(row: typeof schema.calendars.$inferSelect) { + return { id: row.id, name: row.name, position: row.position, filters: safeParseJson(row.filters, { mode: 'week', tags: [], people: [], projects: [], statuses: [] }) } +} + +/** The caller's own saved calendar, or 404: another person's is not theirs to see or change. */ +export async function resolveCalendar(event: H3Event) { + const { user } = await resolveAuth(event) + const id = getRouterParam(event, 'id')! + const row = db.select().from(schema.calendars) + .where(and(eq(schema.calendars.id, id), eq(schema.calendars.userId, user.id))) + .get() + if (!row) throw createError({ statusCode: 404, message: 'Calendar not found' }) + return { user, calendar: row } +} diff --git a/shared/schemas/calendar.ts b/shared/schemas/calendar.ts new file mode 100644 index 0000000..d129fa7 --- /dev/null +++ b/shared/schemas/calendar.ts @@ -0,0 +1,32 @@ +import { z } from 'zod' +import { CALENDAR_MODES } from '../utils/calendar-filter' +import { NOTHING_TO_UPDATE, requiredText, somethingToUpdate } from './common' + +const names = (field: string, max: number) => + z.array(z.string({ error: `${field} must be a list of names` }).trim().min(1).max(50), { error: `${field} must be a list of names` }) + .max(max, { error: `At most ${max} ${field}` }) + +const ids = (field: string, max: number) => + z.array(z.string({ error: `${field} must be a list of ids` }).min(1), { error: `${field} must be a list of ids` }) + .max(max, { error: `At most ${max} ${field}` }) + +/** The Calendar page's filters, as a saved calendar stores them. */ +export const calendarFiltersSchema = z.object({ + mode: z.enum(CALENDAR_MODES, { error: 'mode must be week or month' }).default('week'), + tags: names('tags', 20).default([]), + people: ids('people', 50).default([]), + projects: ids('projects', 100).default([]), + statuses: names('statuses', 50).default([]) +}) + +/** `POST /api/calendars` */ +export const calendarCreateSchema = z.object({ + name: requiredText('Name').pipe(z.string().max(80, { error: 'Name is at most 80 characters' })), + filters: calendarFiltersSchema +}) + +/** `PUT /api/calendars/:id` */ +export const calendarUpdateSchema = z.object({ + name: requiredText('Name').pipe(z.string().max(80, { error: 'Name is at most 80 characters' })).optional(), + filters: calendarFiltersSchema.optional() +}).refine(somethingToUpdate, NOTHING_TO_UPDATE) diff --git a/shared/utils/calendar-filter.ts b/shared/utils/calendar-filter.ts new file mode 100644 index 0000000..237548d --- /dev/null +++ b/shared/utils/calendar-filter.ts @@ -0,0 +1,50 @@ +/** + * What the Calendar page shows, and the one test of whether a card belongs. + * + * Shared by the server, which answers the page's request with it, and the page, + * which runs the same test on every live update to decide whether a changed card + * enters, stays or leaves. Two copies of this rule would be the drift that makes + * a card appear on reload but not live, or the other way round. + * + * Tags and statuses are matched by **name**, ignoring case and outer spaces: + * each project has its own, so "Redaktionsplan" in two projects is two tags and + * "In Progress" two statuses, and picking one name has to mean all of them. + */ +export const CALENDAR_MODES = ['week', 'month'] as const +export type CalendarMode = typeof CALENDAR_MODES[number] + +/** The "Nobody" choice of the people filter. */ +export const UNASSIGNED = '__none__' + +export interface CalendarFilters { + mode: CalendarMode + tags: string[] + people: string[] + projects: string[] + statuses: string[] +} + +export const EMPTY_FILTERS: CalendarFilters = { mode: 'week', tags: [], people: [], projects: [], statuses: [] } + +export const normalizeName = (name: string) => name.trim().toLowerCase() + +export interface CalendarCardFacts { + projectId: string + assigneeId: string | null + tags?: Array<{ name: string }> +} + +/** Whether a card passes every filter that is set; an empty filter lets everything through. */ +export function matchesCalendar(card: CalendarCardFacts, statusName: string | null | undefined, f: CalendarFilters): boolean { + if (f.tags.length) { + const wanted = new Set(f.tags.map(normalizeName)) + if (!(card.tags ?? []).some(t => wanted.has(normalizeName(t.name)))) return false + } + if (f.people.length && !f.people.includes(card.assigneeId ?? UNASSIGNED)) return false + if (f.projects.length && !f.projects.includes(card.projectId)) return false + if (f.statuses.length) { + const wanted = new Set(f.statuses.map(normalizeName)) + if (!statusName || !wanted.has(normalizeName(statusName))) return false + } + return true +} diff --git a/tests/integration/calendar.test.ts b/tests/integration/calendar.test.ts new file mode 100644 index 0000000..e076c95 --- /dev/null +++ b/tests/integration/calendar.test.ts @@ -0,0 +1,169 @@ +import { describe, it, expect, beforeAll } from 'vitest' +import { $fetch, url } from '../setup/server' +import { registerTestUser, type TestUser } from '../setup/auth' +import { addProjectMember, createTestCard, createTestProject, createTestTag, setCardTags } from '../setup/fixtures' + +interface Project { id: string, slug: string, statuses: Array<{ id: string, name: string }> } +interface CalCard { id: number, title: string, projectId: string, dueDate: string | null, parent: { title: string } | null, board: { name: string } | null } +interface Calendar { + cards: CalCard[] + undated: CalCard[] + projects: Array<{ id: string }> + tags: Array<{ name: string }> + people: Array<{ id: string }> + statuses: Array<{ projectId: string, name: string }> +} + +describe('Calendar', () => { + let owner: TestUser // member of A and B + let colleague: TestUser // member of A only + let stranger: TestUser // owns C + let a: Project + let b: Project + let c: Project + let postA: number + let subtaskB: number + let quietSubtask: number + let plainA: number + let undatedA: number + + const project = async (user: TestUser) => { + const created = await createTestProject(user) as { slug: string } + return await $fetch(`/api/projects/${created.slug}`, { headers: user.headers }) as Project + } + const status = (p: Project, name: string) => p.statuses.find(s => s.name === name)!.id + const send = (user: TestUser, path: string, method: string, body?: Record) => + fetch(url(path), { method, headers: { ...user.headers, 'Content-Type': 'application/json' }, body: body && JSON.stringify(body) }) + const calendar = (user: TestUser, query: Record) => + $fetch('/api/calendar', { headers: user.headers, query: { from: '2026-11-23', to: '2026-11-29', ...query } }) as Promise + const ids = (cards: CalCard[]) => cards.map(card => card.id).sort((x, y) => x - y) + + beforeAll(async () => { + owner = await registerTestUser() + colleague = await registerTestUser() + stranger = await registerTestUser() + a = await project(owner) + b = await project(owner) + c = await project(stranger) + await addProjectMember(owner, a.id, { userId: colleague.id }) + + // The same tag name in three projects, spelled three ways. + const tagA = await createTestTag(owner, a.id, { name: 'Redaktionsplan' }) + const tagB = await createTestTag(owner, b.id, { name: 'redaktionsplan' }) + const tagC = await createTestTag(stranger, c.id, { name: 'Redaktionsplan' }) + + postA = (await createTestCard(owner, a.id, status(a, 'To Do'), { title: 'LinkedIn post', dueDate: '2026-11-23', assigneeId: owner.id })).id + await setCardTags(owner, postA, [tagA.id]) + plainA = (await createTestCard(owner, a.id, status(a, 'Backlog'), { title: 'Untagged task', dueDate: '2026-11-24' })).id + undatedA = (await createTestCard(owner, a.id, status(a, 'Backlog'), { title: 'Blog idea' })).id + await setCardTags(owner, undatedA, [tagA.id]) + const later = await createTestCard(owner, a.id, status(a, 'Backlog'), { title: 'Next month', dueDate: '2026-12-15' }) + await setCardTags(owner, later.id, [tagA.id]) + + // A tagged parent, a tagged sub-task and an untagged one. + const campaign = await createTestCard(owner, b.id, status(b, 'Backlog'), { title: 'Spring campaign' }) + await setCardTags(owner, campaign.id, [tagB.id]) + subtaskB = (await (await send(owner, `/api/projects/${b.id}/cards`, 'POST', { title: 'Newsletter', statusId: status(b, 'In Progress'), parentId: campaign.id, dueDate: '2026-11-25' })).json() as { id: number }).id + await setCardTags(owner, subtaskB, [tagB.id]) + quietSubtask = (await (await send(owner, `/api/projects/${b.id}/cards`, 'POST', { title: 'Internal prep', statusId: status(b, 'Backlog'), parentId: campaign.id, dueDate: '2026-11-26' })).json() as { id: number }).id + + const foreign = await createTestCard(stranger, c.id, status(c, 'Backlog'), { title: 'Someone else\'s post', dueDate: '2026-11-23' }) + await setCardTags(stranger, foreign.id, [tagC.id]) + }) + + describe('cards', () => { + it('collects tagged cards and sub-tasks from all the caller\'s projects, by tag name', async () => { + const cal = await calendar(owner, { tags: 'Redaktionsplan' }) + expect(ids(cal.cards)).toEqual([postA, subtaskB].sort((x, y) => x - y)) + const sub = cal.cards.find(card => card.id === subtaskB)! + expect(sub.projectId).toBe(b.id) + expect(sub.parent?.title).toBe('Spring campaign') + expect(sub.dueDate?.slice(0, 10)).toBe('2026-11-25') + }) + + it('leaves out a sub-task whose only tag is on its parent, and cards outside the window', async () => { + const cal = await calendar(owner, { tags: 'Redaktionsplan' }) + expect(ids(cal.cards)).not.toContain(quietSubtask) + expect(cal.cards.map(card => card.title)).not.toContain('Next month') + }) + + it('lists tagged cards without a due date separately, and only when a tag is chosen', async () => { + expect(ids((await calendar(owner, { tags: 'Redaktionsplan' })).undated)).toContain(undatedA) + expect((await calendar(owner, {})).undated).toEqual([]) + }) + + it('shows every card due in the window when no tag is chosen', async () => { + const cal = await calendar(owner, {}) + expect(ids(cal.cards)).toEqual(expect.arrayContaining([postA, plainA, subtaskB, quietSubtask])) + }) + + it('filters by person, project and status name', async () => { + expect(ids((await calendar(owner, { people: owner.id })).cards)).toEqual([postA]) + expect(ids((await calendar(owner, { projects: b.id })).cards)).toEqual([subtaskB, quietSubtask].sort((x, y) => x - y)) + expect(ids((await calendar(owner, { statuses: 'in progress' })).cards)).toEqual([subtaskB]) + }) + + it('shows nobody cards from projects they are not a member of', async () => { + expect((await calendar(owner, { tags: 'Redaktionsplan' })).cards.map(card => card.title)).not.toContain('Someone else\'s post') + const theirs = await calendar(colleague, { tags: 'Redaktionsplan' }) + expect(ids(theirs.cards)).toEqual([postA]) + expect(theirs.projects.map(p => p.id)).toEqual([a.id]) + // A stranger's calendar holds only their own project. + expect((await calendar(stranger, { tags: 'Redaktionsplan' })).cards.map(card => card.title)).toEqual(['Someone else\'s post']) + }) + + it('offers each tag name once, whatever its spelling in each project', async () => { + const names = (await calendar(owner, {})).tags.map(t => t.name.toLowerCase()) + expect(names.filter(n => n === 'redaktionsplan')).toHaveLength(1) + }) + + it('moves a card to its new day, and drops it when the tag goes', async () => { + await send(owner, `/api/cards/${subtaskB}`, 'PUT', { dueDate: '2026-11-28' }) + expect((await calendar(owner, { tags: 'Redaktionsplan' })).cards.find(card => card.id === subtaskB)!.dueDate?.slice(0, 10)).toBe('2026-11-28') + await setCardTags(owner, postA, []) + expect(ids((await calendar(owner, { tags: 'Redaktionsplan' })).cards)).not.toContain(postA) + }) + + it('needs a window of real days, at most 62 days long', async () => { + const get = (query: string) => fetch(url(`/api/calendar?${query}`), { headers: owner.headers }) + expect((await get('from=2026-11-23')).status).toBe(400) + expect((await get('from=2026-11-29&to=2026-11-23')).status).toBe(400) + expect((await get('from=2026-01-01&to=2026-06-01')).status).toBe(400) + expect((await get('from=23.11.2026&to=29.11.2026')).status).toBe(400) + }) + }) + + describe('saved calendars', () => { + const filters = { mode: 'week', tags: ['Redaktionsplan'], people: [], projects: [], statuses: [] } + + it('saves, lists, renames and deletes the caller\'s own calendars', async () => { + const res = await send(owner, '/api/calendars', 'POST', { name: 'Redaktionskalender', filters }) + expect(res.status).toBe(201) + const saved = await res.json() as { id: string, name: string, filters: typeof filters } + expect(saved.filters).toEqual(filters) + + const list = await $fetch('/api/calendars', { headers: owner.headers }) as Array<{ id: string }> + expect(list.map(cal => cal.id)).toContain(saved.id) + + const renamed = await (await send(owner, `/api/calendars/${saved.id}`, 'PUT', { name: 'Content', filters: { ...filters, mode: 'month' } })).json() as { name: string, filters: { mode: string } } + expect(renamed.name).toBe('Content') + expect(renamed.filters.mode).toBe('month') + + expect((await send(owner, `/api/calendars/${saved.id}`, 'DELETE')).status).toBe(200) + expect(((await $fetch('/api/calendars', { headers: owner.headers })) as Array<{ id: string }>).map(cal => cal.id)).not.toContain(saved.id) + }) + + it('keeps each person\'s calendars their own', async () => { + const saved = await (await send(owner, '/api/calendars', 'POST', { name: 'Mine', filters })).json() as { id: string } + expect((await $fetch('/api/calendars', { headers: colleague.headers }) as Array<{ id: string }>).map(cal => cal.id)).not.toContain(saved.id) + expect((await send(colleague, `/api/calendars/${saved.id}`, 'PUT', { name: 'Taken' })).status).toBe(404) + expect((await send(colleague, `/api/calendars/${saved.id}`, 'DELETE')).status).toBe(404) + }) + + it('refuses a calendar without a name, or with filters of the wrong shape', async () => { + expect((await send(owner, '/api/calendars', 'POST', { name: ' ', filters })).status).toBe(400) + expect((await send(owner, '/api/calendars', 'POST', { name: 'Bad', filters: { ...filters, mode: 'year' } })).status).toBe(400) + expect((await send(owner, '/api/calendars', 'POST', { name: 'Bad', filters: { ...filters, tags: 'Redaktionsplan' } })).status).toBe(400) + }) + }) +}) diff --git a/tests/unit/calendar-days.test.ts b/tests/unit/calendar-days.test.ts new file mode 100644 index 0000000..8aad882 --- /dev/null +++ b/tests/unit/calendar-days.test.ts @@ -0,0 +1,99 @@ +import { describe, it, expect, afterEach } from 'vitest' +import { addDays, calendarDays, cardDay, cardsByDay, isDayKey, localDay, periodTitle, shiftAnchor, weekStart } from '../../app/utils/calendar-days' + +const stored = (day: string) => `${day}T00:00:00.000Z` + +describe('time zones', () => { + const original = process.env.TZ + afterEach(() => { + process.env.TZ = original + }) + + it('reads a stored due date as its calendar day in any time zone', () => { + // Midnight UTC is the evening before in New York and morning in Tokyo. + for (const tz of ['America/New_York', 'Europe/Berlin', 'Asia/Tokyo', 'Pacific/Kiritimati', 'Pacific/Pago_Pago']) { + process.env.TZ = tz + expect(cardDay(stored('2026-11-23'))).toBe('2026-11-23') + } + }) + + it('takes today from the viewer\'s clock, not from UTC', () => { + process.env.TZ = 'Europe/Berlin' + // 23:30 UTC on the 22nd is already 00:30 on the 23rd in Berlin. + expect(localDay(new Date('2026-11-22T23:30:00Z'))).toBe('2026-11-23') + process.env.TZ = 'America/Los_Angeles' + // 05:00 UTC on the 23rd is still the evening of the 22nd in Los Angeles. + expect(localDay(new Date('2026-11-23T05:00:00Z'))).toBe('2026-11-22') + }) + + it('steps over the clock change by calendar day', () => { + process.env.TZ = 'Europe/Berlin' + // 25 October 2026 has 25 hours in Berlin. + expect(addDays('2026-10-24', 1)).toBe('2026-10-25') + expect(addDays('2026-10-25', 1)).toBe('2026-10-26') + expect(calendarDays('week', '2026-10-25').map(d => d.key)).toEqual(['2026-10-19', '2026-10-20', '2026-10-21', '2026-10-22', '2026-10-23', '2026-10-24', '2026-10-25']) + }) +}) + +describe('weeks', () => { + it('start on Monday', () => { + expect(weekStart('2026-11-23')).toBe('2026-11-23') + expect(weekStart('2026-11-29')).toBe('2026-11-23') + expect(weekStart('2026-11-30')).toBe('2026-11-30') + }) + + it('show seven labelled days with the weekend marked', () => { + const days = calendarDays('week', '2026-11-25') + expect(days.map(d => d.label)).toEqual(['Mon 23', 'Tue 24', 'Wed 25', 'Thu 26', 'Fri 27', 'Sat 28', 'Sun 29']) + expect(days.filter(d => d.isWeekend).map(d => d.key)).toEqual(['2026-11-28', '2026-11-29']) + expect(days.every(d => d.inPeriod)).toBe(true) + }) + + it('step by seven days and name their span, across months and years', () => { + expect(shiftAnchor('week', '2026-11-25', 1)).toBe('2026-11-30') + expect(shiftAnchor('week', '2026-11-25', -1)).toBe('2026-11-16') + expect(periodTitle('week', '2026-11-25')).toBe('Nov 23 – 29, 2026') + expect(periodTitle('week', '2026-12-01')).toBe('Nov 30 – Dec 6, 2026') + expect(periodTitle('week', '2026-12-30')).toBe('Dec 28, 2026 – Jan 3, 2027') + }) +}) + +describe('months', () => { + it('cover the month in whole weeks, and mark the days outside it', () => { + const days = calendarDays('month', '2026-11-18') + // November 2026 starts on a Sunday: the grid opens on Monday 26 October. + expect(days[0]!.key).toBe('2026-10-26') + expect(days.at(-1)!.key).toBe('2026-12-06') + expect(days).toHaveLength(42) + expect(days.filter(d => d.inPeriod)).toHaveLength(30) + }) + + it('take five weeks when that is enough', () => { + expect(calendarDays('month', '2027-02-10')).toHaveLength(28) + expect(calendarDays('month', '2026-12-10')).toHaveLength(35) + }) + + it('step by month, from any day in it, and are named in full', () => { + expect(shiftAnchor('month', '2026-11-30', 1)).toBe('2026-12-01') + expect(shiftAnchor('month', '2026-01-31', -1)).toBe('2025-12-01') + expect(periodTitle('month', '2026-11-18')).toBe('November 2026') + }) +}) + +describe('cards by day', () => { + it('groups cards by due date and skips those without one', () => { + const byDay = cardsByDay([ + { id: 3, dueDate: stored('2026-11-24') }, + { id: 1, dueDate: stored('2026-11-24') }, + { id: 2, dueDate: null } + ]) + expect([...byDay.keys()]).toEqual(['2026-11-24']) + expect(byDay.get('2026-11-24')!.map(c => c.id)).toEqual([1, 3]) + }) + + it('accepts only real calendar days in the address', () => { + expect(isDayKey('2026-11-23')).toBe(true) + expect(isDayKey('2026-02-30')).toBe(false) + expect(isDayKey('23.11.2026')).toBe(false) + }) +}) diff --git a/tests/unit/calendar-filter.test.ts b/tests/unit/calendar-filter.test.ts new file mode 100644 index 0000000..27d0313 --- /dev/null +++ b/tests/unit/calendar-filter.test.ts @@ -0,0 +1,28 @@ +import { describe, it, expect } from 'vitest' +import { EMPTY_FILTERS, matchesCalendar, UNASSIGNED } from '../../shared/utils/calendar-filter' + +const card = { projectId: 'p1', assigneeId: 'u1', tags: [{ name: 'Redaktionsplan' }, { name: 'LinkedIn' }] } + +describe('matchesCalendar', () => { + it('lets everything through with no filter set', () => { + expect(matchesCalendar(card, 'To Do', EMPTY_FILTERS)).toBe(true) + }) + + it('matches tags and statuses by name, ignoring case and spaces', () => { + expect(matchesCalendar(card, 'To Do', { ...EMPTY_FILTERS, tags: [' redaktionsplan '] })).toBe(true) + expect(matchesCalendar(card, 'To Do', { ...EMPTY_FILTERS, tags: ['Newsletter'] })).toBe(false) + expect(matchesCalendar(card, 'In Progress', { ...EMPTY_FILTERS, statuses: ['in progress'] })).toBe(true) + expect(matchesCalendar(card, 'To Do', { ...EMPTY_FILTERS, statuses: ['Done'] })).toBe(false) + }) + + it('takes any of several values within a filter, and needs every filter that is set', () => { + expect(matchesCalendar(card, 'To Do', { ...EMPTY_FILTERS, tags: ['Newsletter', 'LinkedIn'] })).toBe(true) + expect(matchesCalendar(card, 'To Do', { ...EMPTY_FILTERS, tags: ['LinkedIn'], projects: ['p2'] })).toBe(false) + }) + + it('filters by person, with a choice for cards nobody is assigned to', () => { + expect(matchesCalendar(card, 'To Do', { ...EMPTY_FILTERS, people: ['u1'] })).toBe(true) + expect(matchesCalendar({ ...card, assigneeId: null }, 'To Do', { ...EMPTY_FILTERS, people: [UNASSIGNED] })).toBe(true) + expect(matchesCalendar({ ...card, assigneeId: null }, 'To Do', { ...EMPTY_FILTERS, people: ['u1'] })).toBe(false) + }) +}) From 03ec746775027eae2ed712fa5dbcc1f74a99261d Mon Sep 17 00:00:00 2001 From: Isabella Zauner Date: Thu, 19 Nov 2026 12:52:35 +0100 Subject: [PATCH 02/22] Add a Calendar page beside My Tasks, with saved calendars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What is due when, across your projects: a week or a month, outside any project, as discussed on #9. - /calendar: seven columns, a week (tall days, ticket, project, assignee) or a month (weeks as rows, chips, "+N more" opens that week). Today, previous and next, Week / Month. Filters by tag, person, project and status, kept in the address so a set-up can be linked as it is. - A card is a chip in its due day, in its own project's status colour, done cards faded, with a tooltip; drag it to another day to set its due date; click it to open the ordinary card panel with that project's statuses, people and tags. - With a tag chosen, its undated cards fold out under "No date". - Save as… stores the filters as a named calendar listed in the sidebar under Calendars (/calendar/:id). Changing a saved calendar's filters saves them, with no Save button. Copy link shares the filters, Rename, Delete. - Live: one stream over your projects; a changed card is tested with the same rule as the server (matchesCalendar) and enters, moves or leaves on its own. Only a structural change re-reads the page. - The page says how many of your projects it covers, so two people can tell why they see different cards. Day arithmetic (Monday weeks, month grids, the card's UTC day against the viewer's local today) is app/utils/calendar-days.ts, unit-tested across time zones and the DST change. API documented in openapi.json. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 + app/components/CalendarGrid.vue | 194 +++++++++ app/components/CalendarPage.vue | 682 +++++++++++++++++++++++++++++++ app/components/ui/Page.vue | 1 + app/composables/useCalendars.ts | 53 +++ app/composables/useNavigation.ts | 12 + app/pages/calendar/[id].vue | 8 + app/pages/calendar/index.vue | 7 + app/types/calendar.ts | 28 ++ app/utils/calendar-days.ts | 134 ++++++ server/assets/openapi.json | 358 ++++++++++++++++ 11 files changed, 1483 insertions(+) create mode 100644 app/components/CalendarGrid.vue create mode 100644 app/components/CalendarPage.vue create mode 100644 app/composables/useCalendars.ts create mode 100644 app/pages/calendar/[id].vue create mode 100644 app/pages/calendar/index.vue create mode 100644 app/types/calendar.ts create mode 100644 app/utils/calendar-days.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index d083d48..0912f23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### App + +- **A calendar of what is due, across your projects.** Calendar sits beside My Tasks and shows every card with a due date from the projects you are a member of, by week or by month. Filter by tag, person, project or status; tags and statuses match by name, so "Redaktionsplan" collects that tag from every project, sub-tasks included when they carry it themselves. Drag a card to another day to change its due date, click it to open it. With a tag chosen, its cards without a due date wait under "No date". Save a set of filters as a named calendar, such as "Redaktionskalender", to find it in the sidebar; it is yours alone, and Copy link shares it so others can save it too. Everyone sees the cards of their own projects, and the page says how many that is. + ## v0.20.1 ### App diff --git a/app/components/CalendarGrid.vue b/app/components/CalendarGrid.vue new file mode 100644 index 0000000..1c4c35f --- /dev/null +++ b/app/components/CalendarGrid.vue @@ -0,0 +1,194 @@ + + + diff --git a/app/components/CalendarPage.vue b/app/components/CalendarPage.vue new file mode 100644 index 0000000..a83ec31 --- /dev/null +++ b/app/components/CalendarPage.vue @@ -0,0 +1,682 @@ + + + diff --git a/app/components/ui/Page.vue b/app/components/ui/Page.vue index 86be6a5..768f103 100644 --- a/app/components/ui/Page.vue +++ b/app/components/ui/Page.vue @@ -56,6 +56,7 @@ const WIDTHS = { const SECTIONS: Record = { 'projects': { label: 'All Projects', to: '/projects' }, 'my-tasks': { label: 'My Tasks', to: '/my-tasks' }, + 'calendar': { label: 'Calendar', to: '/calendar' }, 'notifications': { label: 'Notifications', to: '/notifications' }, 'agents': { label: 'Agents', to: '/agents' }, 'admin': { label: 'Admin' }, diff --git a/app/composables/useCalendars.ts b/app/composables/useCalendars.ts new file mode 100644 index 0000000..75d7c54 --- /dev/null +++ b/app/composables/useCalendars.ts @@ -0,0 +1,53 @@ +import type { CalendarFilters } from '#shared/utils/calendar-filter' + +export interface SavedCalendar { + id: string + name: string + position: number + filters: CalendarFilters +} + +/** + * The caller's saved calendars, under one key so the sidebar and the Calendar + * page share one list: saving, renaming or deleting on the page shows in the + * sidebar at once. + */ +export function useCalendars() { + const { data: calendars, refresh } = useFetch('/api/calendars', { key: 'calendars', default: () => [] }) + const toast = useToast() + + async function create(name: string, filters: CalendarFilters): Promise { + try { + const saved = await $fetch('/api/calendars', { method: 'POST', body: { name, filters } }) + calendars.value = [...(calendars.value ?? []), saved] + return saved + } catch (e) { + toast.add({ title: 'Could not save the calendar', description: getErrorMessage(e, 'Unknown error'), color: 'error' }) + return null + } + } + + async function update(id: string, changes: { name?: string, filters?: CalendarFilters }): Promise { + try { + const saved = await $fetch(`/api/calendars/${id}` as string, { method: 'PUT' as const, body: changes }) + calendars.value = (calendars.value ?? []).map(c => c.id === id ? saved : c) + return true + } catch (e) { + toast.add({ title: 'Could not update the calendar', description: getErrorMessage(e, 'Unknown error'), color: 'error' }) + return false + } + } + + async function remove(id: string): Promise { + try { + await $fetch(`/api/calendars/${id}` as string, { method: 'DELETE' as const }) + calendars.value = (calendars.value ?? []).filter(c => c.id !== id) + return true + } catch (e) { + toast.add({ title: 'Could not delete the calendar', description: getErrorMessage(e, 'Unknown error'), color: 'error' }) + return false + } + } + + return { calendars, refresh, create, update, remove } +} diff --git a/app/composables/useNavigation.ts b/app/composables/useNavigation.ts index aeef2ca..0dd8b17 100644 --- a/app/composables/useNavigation.ts +++ b/app/composables/useNavigation.ts @@ -52,12 +52,16 @@ export function useNavigation() { } = useFetch('/api/projects', { key: 'projects' }) const { user } = useUserSession() const toast = useToast() + // Saved calendars sit in the sidebar under their own heading, like starred + // projects: one click back to "Redaktionskalender". + const { calendars } = useCalendars() const topItems = computed(() => [ // Notifications are not here: the sidebar holds areas you work in, and // notifications are a signal, so they are the topbar bell beside the // account (handoff `03` › Topbar), at every width. { label: 'My Tasks', icon: 'i-lucide-check-square', to: '/my-tasks' }, + { label: 'Calendar', icon: 'i-lucide-calendar-days', to: '/calendar' }, { label: 'All Projects', icon: 'i-lucide-layout-grid', to: '/projects' }, // In the top group rather than under Admin: people an admin allows // manage their own agents here too, and they have no Admin section. @@ -89,6 +93,13 @@ export function useNavigation() { const navSections = computed(() => { const sections: NavSection[] = [{ items: topItems.value }] + if (calendars.value?.length) { + sections.push({ + label: 'Calendars', + items: calendars.value.map(c => ({ label: c.name, icon: 'i-lucide-calendar-heart', to: `/calendar/${c.id}` })) + }) + } + // Not before the first response: an empty-state flash on every load would // tell people with stars that they have none. if (projects.value) { @@ -115,6 +126,7 @@ export function useNavigation() { // Not a sidebar row any more, but still a place ⌘K can take you. { label: 'Notifications', icon: 'i-lucide-bell', to: '/notifications' }, ...topItems.value, + ...(calendars.value ?? []).map(c => ({ label: c.name, icon: 'i-lucide-calendar-heart', to: `/calendar/${c.id}` })), ...(projects.value || []).map(projectItem), ...adminItems.value ]) diff --git a/app/pages/calendar/[id].vue b/app/pages/calendar/[id].vue new file mode 100644 index 0000000..ed4742e --- /dev/null +++ b/app/pages/calendar/[id].vue @@ -0,0 +1,8 @@ + + + diff --git a/app/pages/calendar/index.vue b/app/pages/calendar/index.vue new file mode 100644 index 0000000..28dfdc2 --- /dev/null +++ b/app/pages/calendar/index.vue @@ -0,0 +1,7 @@ + + + diff --git a/app/types/calendar.ts b/app/types/calendar.ts new file mode 100644 index 0000000..4ed02e7 --- /dev/null +++ b/app/types/calendar.ts @@ -0,0 +1,28 @@ +import type { BaseCard, Member, Tag } from '~/types/card' + +/** A card as `GET /api/calendar` returns it. */ +export type CalendarApiCard = BaseCard & { + tags: Tag[] + board?: { id: string, name: string, slug: string } | null +} + +/** `GET /api/calendar` */ +export interface CalendarResponse { + cards: CalendarApiCard[] + undated: CalendarApiCard[] + projects: Array<{ id: string, name: string, slug: string, key: string, doneStatusId: string | null }> + statuses: Array<{ id: string, projectId: string, name: string, color: string | null }> + tags: Array<{ name: string, color: string }> + people: Member[] +} + +/** A card as the grid draws it: with what it needs from its project and status. */ +export type CalendarCard = CalendarApiCard & { + projectName: string + projectSlug: string + projectKey: string + ticket: string + statusName: string + statusColor: string | null + isDone: boolean +} diff --git a/app/utils/calendar-days.ts b/app/utils/calendar-days.ts new file mode 100644 index 0000000..d584310 --- /dev/null +++ b/app/utils/calendar-days.ts @@ -0,0 +1,134 @@ +/** + * The Calendar page's days: which ones a week or month shows, how they are + * labelled, and which day a card falls on. Pure, so the rules, time zones above + * all, are unit-tested (`tests/unit/calendar-days.test.ts`). + * + * Two kinds of "day" meet here, and keeping them apart is the whole trick: + * + * - **A card's day is its stored calendar date.** A picked due date is stored + * as midnight UTC of that day (`DueDatePicker`), so it is read back in UTC. + * Read in local time, "due 23 Nov" became the 22nd for anyone west of + * Greenwich, and would for anyone east of it if it were stored as local midnight. + * - **Today is the viewer's local date.** At 00:30 in Berlin it is already the + * next day there, while UTC still says the previous one. + * + * Both are compared as `YYYY-MM-DD` keys, so neither passes through a time-zone + * conversion again. Weeks start on Monday. + */ +import type { CalendarMode } from '#shared/utils/calendar-filter' + +export interface CalendarDay { + /** `YYYY-MM-DD` */ + key: string + /** 0 Sunday … 6 Saturday */ + weekday: number + dayOfMonth: number + /** "Mon 23" */ + label: string + isWeekend: boolean + /** In the month a month view is showing; always true in a week view. */ + inPeriod: boolean +} + +const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] +const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] +const MONTHS_LONG = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] +const pad = (n: number) => String(n).padStart(2, '0') + +const parts = (key: string) => key.split('-').map(Number) as [number, number, number] +const utc = (key: string) => new Date(`${key}T00:00:00Z`) + +/** A stored card date as its calendar day, read in UTC (see above). */ +export function cardDay(value: string | null | undefined): string | null { + if (!value) return null + const d = new Date(value) + if (Number.isNaN(d.getTime())) return null + return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}` +} + +/** The viewer's own calendar day. */ +export function localDay(now = new Date()): string { + return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}` +} + +/** A day key `n` days later (or earlier), by calendar, so a clock change cannot skip one. */ +export function addDays(key: string, n: number): string { + const [y, m, d] = parts(key) + return cardDay(new Date(Date.UTC(y, m - 1, d + n)).toISOString())! +} + +export function isDayKey(value: unknown): value is string { + return typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value) && cardDay(`${value}T00:00:00Z`) === value +} + +/** The Monday of the week a day is in. */ +export function weekStart(key: string): string { + return addDays(key, -((utc(key).getUTCDay() + 6) % 7)) +} + +/** The first and last day of the month a day is in. */ +function monthBounds(key: string): { first: string, last: string } { + const [y, m] = parts(key) + const first = `${y}-${pad(m)}-01` + const last = cardDay(new Date(Date.UTC(y, m, 0)).toISOString())! + return { first, last } +} + +/** + * The days a view shows around `anchor`: the week it is in, or the whole weeks + * that cover its month (five or six of them), Monday first. + */ +export function calendarDays(mode: CalendarMode, anchor: string): CalendarDay[] { + const { first, last } = monthBounds(anchor) + const start = mode === 'week' ? weekStart(anchor) : weekStart(first) + const end = mode === 'week' ? addDays(start, 6) : addDays(weekStart(last), 6) + const days: CalendarDay[] = [] + for (let key = start; key <= end; key = addDays(key, 1)) { + const weekday = utc(key).getUTCDay() + const dayOfMonth = parts(key)[2] + days.push({ + key, + weekday, + dayOfMonth, + label: `${WEEKDAYS[weekday]} ${dayOfMonth}`, + isWeekend: weekday === 0 || weekday === 6, + inPeriod: mode === 'week' || (key >= first && key <= last) + }) + } + return days +} + +/** The anchor one week or month earlier (`-1`) or later (`1`). */ +export function shiftAnchor(mode: CalendarMode, anchor: string, step: -1 | 1): string { + if (mode === 'week') return addDays(weekStart(anchor), 7 * step) + const [y, m] = parts(anchor) + return cardDay(new Date(Date.UTC(y, m - 1 + step, 1)).toISOString())! +} + +/** "Nov 23 – 29, 2026", "Nov 30 – Dec 6, 2026", or "November 2026". */ +export function periodTitle(mode: CalendarMode, anchor: string): string { + if (mode === 'month') { + const [y, m] = parts(anchor) + return `${MONTHS_LONG[m - 1]} ${y}` + } + const start = weekStart(anchor) + const end = addDays(start, 6) + const [sy, sm, sd] = parts(start) + const [ey, em, ed] = parts(end) + if (sy !== ey) return `${MONTHS[sm - 1]} ${sd}, ${sy} – ${MONTHS[em - 1]} ${ed}, ${ey}` + if (sm !== em) return `${MONTHS[sm - 1]} ${sd} – ${MONTHS[em - 1]} ${ed}, ${ey}` + return `${MONTHS[sm - 1]} ${sd} – ${ed}, ${ey}` +} + +/** Cards by the day they are due, each day earliest-created first. */ +export function cardsByDay(cards: T[]): Map { + const byDay = new Map() + for (const card of [...cards].sort((a, b) => a.id - b.id)) { + const day = cardDay(card.dueDate) + if (!day) continue + const list = byDay.get(day) + if (list) list.push(card) + else byDay.set(day, [card]) + } + return byDay +} diff --git a/server/assets/openapi.json b/server/assets/openapi.json index d7b2bb7..c893e63 100644 --- a/server/assets/openapi.json +++ b/server/assets/openapi.json @@ -90,6 +90,10 @@ { "name": "OAuth", "description": "OAuth 2.1 authorization server for the MCP endpoint: authorization code with PKCE (S256), refresh token rotation, dynamic client registration (RFC 7591), client ID metadata documents, and discovery (RFC 8414, RFC 9728). The consent page is /oauth/authorize in the app." + }, + { + "name": "Calendar", + "description": "Cards by due date across the caller's projects, and saved filter sets" } ], "paths": { @@ -8085,6 +8089,303 @@ } } } + }, + "/api/calendar": { + "get": { + "tags": [ + "Calendar" + ], + "summary": "Cards due in a window, across your projects", + "description": "Cards due between `from` and `to` from every project the caller is a member of (not admin-elevated), passing the filters. Tags and statuses match by name, case-insensitively. Sub-tasks appear only with their own tag; expired done cards are left out. With a tag chosen, tagged cards without a due date come back as `undated`. Also returns each filter's choices.", + "parameters": [ + { + "name": "from", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "date" + }, + "description": "First day, YYYY-MM-DD" + }, + { + "name": "to", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "date" + }, + "description": "Last day, inclusive; at most 62 days after `from`" + }, + { + "name": "tags", + "in": "query", + "schema": { + "type": "array", + "items": { + "type": "string" + } + }, + "style": "form", + "explode": true, + "description": "Tag names; repeat for several" + }, + { + "name": "people", + "in": "query", + "schema": { + "type": "array", + "items": { + "type": "string" + } + }, + "style": "form", + "explode": true, + "description": "User ids, or `__none__`" + }, + { + "name": "projects", + "in": "query", + "schema": { + "type": "array", + "items": { + "type": "string" + } + }, + "style": "form", + "explode": true, + "description": "Project ids" + }, + { + "name": "statuses", + "in": "query", + "schema": { + "type": "array", + "items": { + "type": "string" + } + }, + "style": "form", + "explode": true, + "description": "Status names" + } + ], + "responses": { + "200": { + "description": "Cards, undated cards, and the projects, statuses, tag names and people to filter by", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "cards": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Card" + } + }, + "undated": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Card" + } + }, + "projects": { + "type": "array", + "items": { + "type": "object" + } + }, + "statuses": { + "type": "array", + "items": { + "type": "object" + } + }, + "tags": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "color": { + "type": "string" + } + } + } + }, + "people": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MemberSummary" + } + } + } + } + } + } + }, + "400": { + "description": "Invalid window or filters", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + } + }, + "/api/calendars": { + "get": { + "tags": [ + "Calendar" + ], + "summary": "Your saved calendars", + "responses": { + "200": { + "description": "Saved calendars, in sidebar order", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Calendar" + } + } + } + } + } + } + }, + "post": { + "tags": [ + "Calendar" + ], + "summary": "Save calendar filters under a name", + "description": "Personal: only the caller sees it. Share a calendar as a /calendar link with its filters.", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "name", + "filters" + ], + "properties": { + "name": { + "type": "string", + "maxLength": 80 + }, + "filters": { + "$ref": "#/components/schemas/CalendarFilters" + } + } + } + } + } + }, + "responses": { + "201": { + "description": "Saved", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Calendar" + } + } + } + }, + "400": { + "description": "Invalid name or filters" + } + } + } + }, + "/api/calendars/{id}": { + "put": { + "tags": [ + "Calendar" + ], + "summary": "Rename a saved calendar or store its filters", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [], + "properties": { + "name": { + "type": "string", + "maxLength": 80 + }, + "filters": { + "$ref": "#/components/schemas/CalendarFilters" + } + } + } + } + } + }, + "responses": { + "200": { + "description": "Updated", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Calendar" + } + } + } + }, + "404": { + "description": "Not found, or another person's" + } + } + }, + "delete": { + "tags": [ + "Calendar" + ], + "summary": "Delete a saved calendar", + "description": "Only the saved filters go; no card is touched.", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Deleted" + }, + "404": { + "description": "Not found, or another person's" + } + } + } } }, "components": { @@ -9110,6 +9411,63 @@ "description": "For an agent actor, its manager" } } + }, + "CalendarFilters": { + "type": "object", + "properties": { + "mode": { + "type": "string", + "enum": [ + "week", + "month" + ], + "default": "week" + }, + "tags": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Tag names, matched case-insensitively across projects" + }, + "people": { + "type": "array", + "items": { + "type": "string" + }, + "description": "User ids; `__none__` for unassigned" + }, + "projects": { + "type": "array", + "items": { + "type": "string" + } + }, + "statuses": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Status names, matched case-insensitively" + } + } + }, + "Calendar": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "position": { + "type": "integer" + }, + "filters": { + "$ref": "#/components/schemas/CalendarFilters" + } + } } }, "responses": { From 5e89a37c53abcb2d3e528ff193ef6e24e12cb7aa Mon Sep 17 00:00:00 2001 From: Isabella Zauner Date: Thu, 19 Nov 2026 14:05:22 +0100 Subject: [PATCH 03/22] Harden the calendar: reconnects, navigation, saved mode, query size - Re-read the page after the event stream reconnects; events sent while it was down are not replayed. - A saved calendar waits for the list before saying it does not exist, and says when the list failed to load. - Ad hoc, the filters follow the address on Back, Forward and the sidebar link, not only on first load. - A filter change made just before leaving a saved calendar is stored, not dropped with the debounce. - "+N more" opens that week without rewriting a saved calendar's mode. - scope=mine checks one membership per event instead of reading them all. - The tag path selects tagged cards in a subquery rather than an id list that grows with the tag's history. - from/to must be real days: 2026-02-30 is a 400, not 2 March. - Week titles read "Nov 23 to 29, 2026": UI copy has no en dashes. - The tag picker keeps each name's first spelling; boards by status come from a map; scope=mine is in openapi.json; comments fixed. Co-Authored-By: Claude Opus 5.5 --- app/components/CalendarPage.vue | 83 ++++++++++++++++++++++++------ app/composables/useCalendars.ts | 4 +- app/utils/calendar-days.ts | 8 +-- server/api/calendar.get.ts | 5 +- server/api/events.get.ts | 8 +-- server/assets/openapi.json | 16 +++++- server/database/schema.ts | 18 +++---- server/utils/calendar-cards.ts | 27 ++++++---- server/utils/calendars.ts | 4 +- tests/integration/calendar.test.ts | 2 + tests/unit/calendar-days.test.ts | 6 +-- 11 files changed, 127 insertions(+), 54 deletions(-) diff --git a/app/components/CalendarPage.vue b/app/components/CalendarPage.vue index a83ec31..68f695f 100644 --- a/app/components/CalendarPage.vue +++ b/app/components/CalendarPage.vue @@ -33,7 +33,7 @@ const props = defineProps<{ const route = useRoute() const router = useRouter() const toast = useToast() -const { calendars, create, update, remove } = useCalendars() +const { calendars, status: calendarsStatus, refresh: refreshCalendars, create, update, remove } = useCalendars() // ─── Filters and window ────────────────────────────────────────────────────── @@ -46,7 +46,9 @@ function filtersFromQuery(): CalendarFilters { } const saved = computed(() => props.calendarId ? calendars.value?.find(c => c.id === props.calendarId) ?? null : null) -const missing = computed(() => !!props.calendarId && !!calendars.value && !saved.value) +// Only once the list has arrived: it defaults to empty, which is not "not yours". +const missing = computed(() => !!props.calendarId && calendarsStatus.value === 'success' && !saved.value) +const listFailed = computed(() => !!props.calendarId && calendarsStatus.value === 'error') const filters = ref(props.calendarId ? { ...EMPTY_FILTERS } : filtersFromQuery()) @@ -59,21 +61,41 @@ watch(saved, (cal) => { } }, { immediate: true }) +// Ad hoc, the address is the source: Back, Forward or the sidebar's Calendar +// link change it without remounting the page, and the filters follow. +if (!props.calendarId) { + watch(() => route.query, () => { + const next = filtersFromQuery() + if (JSON.stringify(next) !== JSON.stringify(filters.value)) filters.value = next + }) +} + const today = ref(localDay()) const anchor = computed(() => isDayKey(route.query.date) ? route.query.date : today.value) -const days = computed(() => calendarDays(filters.value.mode, anchor.value)) +/** + * The mode on screen. "+N more" on a busy day opens that day's week without + * touching a saved calendar's stored mode, which only the Week / Month switch + * changes. + */ +const modeOverride = ref(null) +const mode = computed(() => modeOverride.value ?? filters.value.mode) +watch(() => props.calendarId, () => { + modeOverride.value = null +}) + +const days = computed(() => calendarDays(mode.value, anchor.value)) const range = computed(() => ({ from: days.value[0]!.key, to: days.value.at(-1)!.key })) -const title = computed(() => periodTitle(filters.value.mode, anchor.value)) +const title = computed(() => periodTitle(mode.value, anchor.value)) function setDate(day: string) { router.replace({ query: { ...route.query, date: day === today.value ? undefined : day } }) } function step(direction: -1 | 1) { - setDate(shiftAnchor(filters.value.mode, anchor.value, direction)) + setDate(shiftAnchor(mode.value, anchor.value, direction)) } -const isCurrent = computed(() => filters.value.mode === 'week' +const isCurrent = computed(() => mode.value === 'week' ? weekStart(anchor.value) === weekStart(today.value) : anchor.value.slice(0, 7) === today.value.slice(0, 7)) @@ -90,6 +112,7 @@ function filterQuery(f: CalendarFilters) { // Ad hoc: the address follows the filters. Saved: the calendar stores them. let saveTimer: ReturnType | null = null +let pendingSave: (() => void) | null = null watch(filters, (f) => { if (!props.calendarId) { router.replace({ query: { date: route.query.date, ...filterQuery(f) } }) @@ -98,17 +121,26 @@ watch(filters, (f) => { const cal = saved.value if (!cal || JSON.stringify(cal.filters) === JSON.stringify(f)) return if (saveTimer) clearTimeout(saveTimer) - saveTimer = setTimeout(() => { + pendingSave = () => { + pendingSave = null void update(cal.id, { filters: f }) - }, 400) + } + saveTimer = setTimeout(() => pendingSave?.(), 400) }, { deep: true }) const modeModel = computed({ - get: () => filters.value.mode, - set: (mode: CalendarMode) => { - filters.value = { ...filters.value, mode } + get: () => mode.value, + set: (next: CalendarMode) => { + modeOverride.value = null + filters.value = { ...filters.value, mode: next } } }) + +function openDay(day: string) { + if (props.calendarId) modeOverride.value = 'week' + else filters.value = { ...filters.value, mode: 'week' } + setDate(day) +} const MODE_ITEMS = [ { value: 'week', label: 'Week' }, { value: 'month', label: 'Month' } @@ -237,6 +269,18 @@ function applyCard(card: CalendarApiCard) { onMounted(() => { source = new EventSource('/api/events?scope=mine') + // Events sent while the connection was down are gone (the bus keeps no + // backlog), so a reconnect re-reads the page once, as project views do. + let reconnecting = false + source.onerror = () => { + reconnecting = true + } + source.onopen = () => { + if (reconnecting) { + reconnecting = false + void refresh() + } + } source.addEventListener('card.upsert', (e) => { try { applyCard(JSON.parse((e as MessageEvent).data) as CalendarApiCard) @@ -266,7 +310,9 @@ onMounted(() => { onBeforeUnmount(() => { source?.close() if (refreshTimer) clearTimeout(refreshTimer) + // A filter changed in the last moment is stored, not dropped with the page. if (saveTimer) clearTimeout(saveTimer) + pendingSave?.() if (dayTimer) clearInterval(dayTimer) }) @@ -451,8 +497,13 @@ useSeoMeta({ title: () => saved.value?.name ?? 'Calendar' })
+ saved.value?.name ?? 'Calendar' }) icon="i-lucide-chevron-left" color="neutral" variant="outline" - :aria-label="filters.mode === 'week' ? 'Previous week' : 'Previous month'" + :aria-label="mode === 'week' ? 'Previous week' : 'Previous month'" @click="step(-1)" /> @@ -571,13 +622,13 @@ useSeoMeta({ title: () => saved.value?.name ?? 'Calendar' }) /> diff --git a/app/composables/useCalendars.ts b/app/composables/useCalendars.ts index 75d7c54..6ceec3c 100644 --- a/app/composables/useCalendars.ts +++ b/app/composables/useCalendars.ts @@ -13,7 +13,7 @@ export interface SavedCalendar { * sidebar at once. */ export function useCalendars() { - const { data: calendars, refresh } = useFetch('/api/calendars', { key: 'calendars', default: () => [] }) + const { data: calendars, refresh, status } = useFetch('/api/calendars', { key: 'calendars', default: () => [] }) const toast = useToast() async function create(name: string, filters: CalendarFilters): Promise { @@ -49,5 +49,5 @@ export function useCalendars() { } } - return { calendars, refresh, create, update, remove } + return { calendars, status, refresh, create, update, remove } } diff --git a/app/utils/calendar-days.ts b/app/utils/calendar-days.ts index d584310..cc01484 100644 --- a/app/utils/calendar-days.ts +++ b/app/utils/calendar-days.ts @@ -105,7 +105,7 @@ export function shiftAnchor(mode: CalendarMode, anchor: string, step: -1 | 1): s return cardDay(new Date(Date.UTC(y, m - 1 + step, 1)).toISOString())! } -/** "Nov 23 – 29, 2026", "Nov 30 – Dec 6, 2026", or "November 2026". */ +/** "Nov 23 to 29, 2026", "Nov 30 to Dec 6, 2026", or "November 2026". UI copy has no en dashes. */ export function periodTitle(mode: CalendarMode, anchor: string): string { if (mode === 'month') { const [y, m] = parts(anchor) @@ -115,9 +115,9 @@ export function periodTitle(mode: CalendarMode, anchor: string): string { const end = addDays(start, 6) const [sy, sm, sd] = parts(start) const [ey, em, ed] = parts(end) - if (sy !== ey) return `${MONTHS[sm - 1]} ${sd}, ${sy} – ${MONTHS[em - 1]} ${ed}, ${ey}` - if (sm !== em) return `${MONTHS[sm - 1]} ${sd} – ${MONTHS[em - 1]} ${ed}, ${ey}` - return `${MONTHS[sm - 1]} ${sd} – ${ed}, ${ey}` + if (sy !== ey) return `${MONTHS[sm - 1]} ${sd}, ${sy} to ${MONTHS[em - 1]} ${ed}, ${ey}` + if (sm !== em) return `${MONTHS[sm - 1]} ${sd} to ${MONTHS[em - 1]} ${ed}, ${ey}` + return `${MONTHS[sm - 1]} ${sd} to ${ed}, ${ey}` } /** Cards by the day they are due, each day earliest-created first. */ diff --git a/server/api/calendar.get.ts b/server/api/calendar.get.ts index c74bee3..e063425 100644 --- a/server/api/calendar.get.ts +++ b/server/api/calendar.get.ts @@ -1,6 +1,7 @@ import { calendarFiltersSchema } from '#shared/schemas/calendar' -const DAY = /^\d{4}-\d{2}-\d{2}$/ +/** A real calendar day as `YYYY-MM-DD`: 2026-02-30 is not one, though `Date.parse` rolls it into March. */ +const isDay = (value: string) => /^\d{4}-\d{2}-\d{2}$/.test(value) && !Number.isNaN(Date.parse(`${value}T00:00:00Z`)) && new Date(`${value}T00:00:00Z`).toISOString().slice(0, 10) === value /** Six weeks covers any month grid; a little more for a week either side. */ const MAX_DAYS = 62 @@ -19,7 +20,7 @@ export default defineEventHandler(async (event) => { const from = String(q.from ?? '') const to = String(q.to ?? '') const span = (Date.parse(to) - Date.parse(from)) / 86_400_000 - if (!DAY.test(from) || !DAY.test(to) || Number.isNaN(span) || span < 0 || span > MAX_DAYS) { + if (!isDay(from) || !isDay(to) || Number.isNaN(span) || span < 0 || span > MAX_DAYS) { throw createError({ statusCode: 400, message: `from and to must be days (YYYY-MM-DD), from before to, at most ${MAX_DAYS} days apart` }) } const parsed = calendarFiltersSchema.safeParse({ diff --git a/server/api/events.get.ts b/server/api/events.get.ts index 882f735..a6b51b6 100644 --- a/server/api/events.get.ts +++ b/server/api/events.get.ts @@ -15,12 +15,12 @@ export default defineEventHandler(async (event) => { const { user } = await resolveAuth(event) const { projectId, scope } = getQuery(event) as { projectId?: string, scope?: string } - // Every project the caller is a member of, for a timeline board, which shows - // cards from all of them. Membership is read again for each event rather than - // once at connect, so a project left or joined meanwhile is honoured. + // Every project the caller is a member of, for the Calendar page, which shows + // cards from all of them. Membership is checked per event (one indexed lookup) + // rather than once at connect, so a project left or joined meanwhile is honoured. if (scope === 'mine') { return streamAppEvents(event, { - select: evt => evt.projectId && memberProjectIds(user.id).has(evt.projectId) + select: evt => evt.projectId && isProjectMember(evt.projectId, user.id) ? { event: evt.type, data: JSON.stringify(evt.payload ?? null) } : null, allowed: () => isStillAuthorized(event) diff --git a/server/assets/openapi.json b/server/assets/openapi.json index c893e63..96954c1 100644 --- a/server/assets/openapi.json +++ b/server/assets/openapi.json @@ -7829,11 +7829,23 @@ { "name": "projectId", "in": "query", - "required": true, - "description": "Project ID", + "required": false, + "description": "Project ID Required unless scope=mine.", "schema": { "type": "string" } + }, + { + "name": "scope", + "in": "query", + "required": false, + "schema": { + "type": "string", + "enum": [ + "mine" + ] + }, + "description": "`mine` streams every project the caller is a member of (the Calendar page), checking membership per event, instead of one projectId." } ], "responses": { diff --git a/server/database/schema.ts b/server/database/schema.ts index 30216a8..c0b2fc9 100644 --- a/server/database/schema.ts +++ b/server/database/schema.ts @@ -368,6 +368,15 @@ export const cardReads = sqliteTable('card_reads', { // (`/api/projects`, `/api/projects/[id]`), so a person removed from a project, or // no longer an admin, loses it from the sidebar without every removal path — // member delete, agent pruning, transfers, a demotion — having to remember this table. +export const projectStars = sqliteTable('project_stars', { + id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()), + userId: text('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }), + projectId: text('project_id').notNull().references(() => projects.id, { onDelete: 'cascade' }), + createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()) +}, table => [ + uniqueIndex('project_stars_user_project_unique').on(table.userId, table.projectId) +]) + /** * A calendar someone saved: a name and the filters of the Calendar page * (`shared/schemas/calendar.ts`), such as "cards tagged Redaktionsplan, by @@ -387,15 +396,6 @@ export const calendars = sqliteTable('calendars', { index('calendars_user_idx').on(table.userId) ]) -export const projectStars = sqliteTable('project_stars', { - id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()), - userId: text('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }), - projectId: text('project_id').notNull().references(() => projects.id, { onDelete: 'cascade' }), - createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()) -}, table => [ - uniqueIndex('project_stars_user_project_unique').on(table.userId, table.projectId) -]) - // ─── OAuth for MCP clients ─────────────────────────────────────────────────── // // Completo is an OAuth 2.1 authorization server for exactly one resource: its diff --git a/server/utils/calendar-cards.ts b/server/utils/calendar-cards.ts index 5ed0569..5ee473e 100644 --- a/server/utils/calendar-cards.ts +++ b/server/utils/calendar-cards.ts @@ -42,8 +42,13 @@ export function calendarCards(userId: string, range: { from: string, to: string projects: projects.map(p => ({ id: p.id, name: p.name, slug: p.slug, key: p.key, doneStatusId: p.doneStatusId })), statuses, // One entry per name, in its first spelling, with that tag's colour. - tags: [...new Map(tagRows.map(t => [normalizeName(t.name), { name: t.name.trim(), color: t.color }])).values()] - .sort((a, b) => a.name.localeCompare(b.name)), + tags: (() => { + const byName = new Map() + for (const t of tagRows) { + if (!byName.has(normalizeName(t.name))) byName.set(normalizeName(t.name), { name: t.name.trim(), color: t.color }) + } + return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name)) + })(), people: (() => { const { member } = createUserRefs(memberRows) return memberRows.map(member).sort((a, b) => a.name.localeCompare(b.name)) @@ -60,10 +65,10 @@ export function calendarCards(userId: string, range: { from: string, to: string const wanted = new Set(filters.tags.map(normalizeName)) const tagIds = tagRows.filter(t => wanted.has(normalizeName(t.name))).map(t => t.id) if (!tagIds.length) return { ...pickers, cards: [], undated: [] } - const cardIds = db.selectDistinct({ id: schema.cardTags.cardId }).from(schema.cardTags) - .where(inArray(schema.cardTags.tagId, tagIds)).all().map(r => r.id) - if (!cardIds.length) return { ...pickers, cards: [], undated: [] } - where = and(inArray(schema.cards.id, cardIds), inArray(schema.cards.projectId, projectIds), or(inRange, isNull(schema.cards.dueDate))) + // A subquery, not a list of ids read into JS: a tag in use for years has + // thousands of cards, and only the window's (and the undated) are wanted. + const tagged = db.select({ id: schema.cardTags.cardId }).from(schema.cardTags).where(inArray(schema.cardTags.tagId, tagIds)) + where = and(inArray(schema.cards.id, tagged), inArray(schema.cards.projectId, projectIds), or(inRange, isNull(schema.cards.dueDate))) } else { where = and(inArray(schema.cards.projectId, projectIds), inRange) } @@ -93,10 +98,12 @@ export function calendarCards(userId: string, range: { from: string, to: string .orderBy(asc(schema.boards.position)) .all() : [] - const withBoard = enriched.map((c) => { - const b = boards.find(x => x.projectId === c.projectId && x.statusId === c.statusId) - return { ...c, board: b ? { id: b.id, name: b.name, slug: b.slug } : null } - }) + const boardByStatus = new Map() + for (const b of boards) { + const key = `${b.projectId}:${b.statusId}` + if (!boardByStatus.has(key)) boardByStatus.set(key, { id: b.id, name: b.name, slug: b.slug }) + } + const withBoard = enriched.map(c => ({ ...c, board: boardByStatus.get(`${c.projectId}:${c.statusId}`) ?? null })) return { ...pickers, diff --git a/server/utils/calendars.ts b/server/utils/calendars.ts index c044005..4692416 100644 --- a/server/utils/calendars.ts +++ b/server/utils/calendars.ts @@ -1,10 +1,10 @@ import { and, eq } from 'drizzle-orm' import type { H3Event } from 'h3' -import type { CalendarFilters } from '#shared/utils/calendar-filter' +import { EMPTY_FILTERS, type CalendarFilters } from '#shared/utils/calendar-filter' /** A saved calendar as the API hands it out, with its filters parsed. */ export function calendarView(row: typeof schema.calendars.$inferSelect) { - return { id: row.id, name: row.name, position: row.position, filters: safeParseJson(row.filters, { mode: 'week', tags: [], people: [], projects: [], statuses: [] }) } + return { id: row.id, name: row.name, position: row.position, filters: { ...EMPTY_FILTERS, ...safeParseJson>(row.filters, {}) } } } /** The caller's own saved calendar, or 404: another person's is not theirs to see or change. */ diff --git a/tests/integration/calendar.test.ts b/tests/integration/calendar.test.ts index e076c95..3c16384 100644 --- a/tests/integration/calendar.test.ts +++ b/tests/integration/calendar.test.ts @@ -130,6 +130,8 @@ describe('Calendar', () => { expect((await get('from=2026-11-29&to=2026-11-23')).status).toBe(400) expect((await get('from=2026-01-01&to=2026-06-01')).status).toBe(400) expect((await get('from=23.11.2026&to=29.11.2026')).status).toBe(400) + // Not a day at all, though Date.parse would roll it into March. + expect((await get('from=2026-02-30&to=2026-03-02')).status).toBe(400) }) }) diff --git a/tests/unit/calendar-days.test.ts b/tests/unit/calendar-days.test.ts index 8aad882..b399ad5 100644 --- a/tests/unit/calendar-days.test.ts +++ b/tests/unit/calendar-days.test.ts @@ -52,9 +52,9 @@ describe('weeks', () => { it('step by seven days and name their span, across months and years', () => { expect(shiftAnchor('week', '2026-11-25', 1)).toBe('2026-11-30') expect(shiftAnchor('week', '2026-11-25', -1)).toBe('2026-11-16') - expect(periodTitle('week', '2026-11-25')).toBe('Nov 23 – 29, 2026') - expect(periodTitle('week', '2026-12-01')).toBe('Nov 30 – Dec 6, 2026') - expect(periodTitle('week', '2026-12-30')).toBe('Dec 28, 2026 – Jan 3, 2027') + expect(periodTitle('week', '2026-11-25')).toBe('Nov 23 to 29, 2026') + expect(periodTitle('week', '2026-12-01')).toBe('Nov 30 to Dec 6, 2026') + expect(periodTitle('week', '2026-12-30')).toBe('Dec 28, 2026 to Jan 3, 2027') }) }) From 456036ee690375ac01f4105cbd6e445e2c9a915f Mon Sep 17 00:00:00 2001 From: Thomas Lohner Date: Thu, 19 Nov 2026 16:07:36 +0100 Subject: [PATCH 04/22] Calendar chips: board's priority bar, no tooltip, no status dot The tooltip repeated the chip, did not exist on touch, and its fixed one-line height let three lines spill over the neighbouring days. The status dot is replaced by the priority edge bar the board uses, so the bar means the same in both places. Week chips wrap the title to two lines. --- app/components/CalendarGrid.vue | 98 ++++++++++++++------------------- 1 file changed, 42 insertions(+), 56 deletions(-) diff --git a/app/components/CalendarGrid.vue b/app/components/CalendarGrid.vue index 1c4c35f..47d46bf 100644 --- a/app/components/CalendarGrid.vue +++ b/app/components/CalendarGrid.vue @@ -8,8 +8,8 @@ import { cardsByDay, type CalendarDay } from '~/utils/calendar-days' * post's project) or a whole month (weeks as rows, compact chips, the rest of * a full day behind "+N more"). * - * A card is a chip in the day it is due, in its status colour (`.swatch-dot`, - * from its own project), done cards faded. A chip can be dragged to another + * A card is a chip in the day it is due, with the board's priority edge bar + * for high and urgent, done cards faded. A chip can be dragged to another * day, which sets that day as its due date; the page saves it. * * Wider than the screen, the grid scrolls sideways inside its own container, @@ -69,10 +69,6 @@ function onDragEnd() { dropTarget.value = null } -function origin(card: CalendarCard) { - return [card.projectName, card.board?.name].filter(Boolean).join(' / ') -} - const minWidth = computed(() => props.mode === 'week' ? '980px' : '770px') @@ -124,60 +120,50 @@ const minWidth = computed(() => props.mode === 'week' ? '980px' : '770px')
- + - + {{ card.ticket }} + {{ card.projectName }} + + + + + {{ card.title }} + + {{ card.ticket }} + {{ card.projectName }} + + + + + +