WIP: Add calendar settings and a nested modal stack

Add a 'days with events' preference (default 3, range 1-7) that drives the upcoming events widget, and extend the fetch window to 8 days so the largest window can populate.

Add a Calendar settings pane (moved under Integrations) that lists the connected CalDAV/ICS sources in a two-column grid with add/edit/remove, and remove calendars from Manage Integrations.

Turn the modal service into a stack so add/edit forms open on top of the settings dialog, with one dialog per level, per-entry title ids, and a softened stacked backdrop.

Move CALENDAR_ACTOR into its own config module to break the calendar/caldav/ics import cycle.
This commit is contained in:
raucao committed 2026-11-06 15:48:08 +04:00
1 parent 23e5aeb6ca
commit 11f8d3f049
34 files changed
+894 -137

No files matched your search

+124
View File
@@ -0,0 +1,124 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { modifier } from 'ember-modifier';
const WIDTHS = {
sm: 'sm:max-w-sm',
md: 'sm:max-w-md',
lg: 'sm:max-w-lg',
xl: 'sm:max-w-xl',
'2xl': 'sm:max-w-2xl',
'3xl': 'sm:max-w-3xl',
settings: 'sm:max-w-4xl',
};
const BACKDROP_BASE =
'fixed inset-0 transition-opacity data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in';
// Each stacked dialog needs its own title id. Descriptors are plain objects and
// are kept identity-stable by the modal service, so key the ids off the object.
const TITLE_IDS = new WeakMap();
let nextTitleId = 0;
function titleIdFor(descriptor) {
if (!descriptor) {
return 'modal-title';
}
if (!TITLE_IDS.has(descriptor)) {
nextTitleId += 1;
TITLE_IDS.set(descriptor, `modal-title-${nextTitleId}`);
}
return TITLE_IDS.get(descriptor);
}
// One entry in the modal stack. Renders a native <dialog> so each level gets
// its own focus trap and Esc handling; stacked dialogs sit above the ones
// below in the top layer.
export default class ModalEntryComponent extends Component {
dialogElement = null;
get currentComponent() {
return this.args.descriptor?.component;
}
get maxWidthClass() {
const size = this.args.descriptor?.size ?? 'md';
return WIDTHS[size] || WIDTHS.md;
}
// A unique title id per entry so stacked dialogs do not share `#modal-title`.
get titleId() {
return titleIdFor(this.args.descriptor);
}
// The base entry keeps the full scrim; stacked entries use a lighter one so
// the two backdrops do not read as near-black.
get backdropClass() {
return this.args.depth === 0
? `${BACKDROP_BASE} bg-neutral-950/75`
: `${BACKDROP_BASE} bg-neutral-950/50`;
}
trackDialog = modifier((element) => {
this.dialogElement = element;
queueMicrotask(() => {
if (element.isConnected && !element.open) {
element.showModal();
}
});
const handleClose = () => {
this.dialogElement = null;
this.args.onFinished?.();
};
element.addEventListener('close', handleClose);
return () => {
element.removeEventListener('close', handleClose);
this.dialogElement = null;
};
});
@action
close() {
this.dialogElement?.close();
}
@action
replace(descriptor) {
this.args.onReplace?.(descriptor);
}
<template>
<el-dialog>
<dialog
aria-labelledby={{this.titleId}}
class="fixed inset-0 size-auto max-h-none max-w-none overflow-y-auto bg-transparent backdrop:bg-transparent"
{{this.trackDialog}}
>
<el-dialog-backdrop class={{this.backdropClass}}></el-dialog-backdrop>
<div
tabindex="0"
class="flex min-h-full items-end justify-center p-4 text-center focus:outline-none sm:items-center sm:p-0"
>
<el-dialog-panel
class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all data-closed:translate-y-4 data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in sm:my-8 sm:w-full
{{this.maxWidthClass}}
data-closed:sm:translate-y-0 data-closed:sm:scale-95"
>
<this.currentComponent
@props={{@descriptor.props}}
@titleId={{this.titleId}}
@close={{this.close}}
@replace={{this.replace}}
/>
</el-dialog-panel>
</div>
</dialog>
</el-dialog>
</template>
}
+14 -76
View File
@@ -1,57 +1,17 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { fn } from '@ember/helper';
import { service } from '@ember/service';
import { modifier } from 'ember-modifier';
const WIDTHS = {
sm: 'sm:max-w-sm',
md: 'sm:max-w-md',
lg: 'sm:max-w-lg',
xl: 'sm:max-w-xl',
'2xl': 'sm:max-w-2xl',
'3xl': 'sm:max-w-3xl',
settings: 'sm:max-w-4xl',
};
import ModalEntry from './modal-entry.gjs';
// Renders the modal stack: one <dialog> per entry, so a form can open on top of
// the settings dialog without replacing it.
export default class ModalHostComponent extends Component {
@service modal;
dialogElement = null;
get currentComponent() {
return this.modal.current?.component;
}
get maxWidthClass() {
const size = this.modal.current?.size ?? 'md';
return WIDTHS[size] || WIDTHS.md;
}
trackDialog = modifier((element) => {
this.dialogElement = element;
queueMicrotask(() => {
if (element.isConnected && !element.open) {
element.showModal();
}
});
const handleClose = () => {
this.dialogElement = null;
this.modal.finished();
};
element.addEventListener('close', handleClose);
return () => {
element.removeEventListener('close', handleClose);
this.dialogElement = null;
};
});
@action
close() {
this.dialogElement?.close();
finished(descriptor) {
this.modal.finished(descriptor);
}
@action
@@ -60,35 +20,13 @@ export default class ModalHostComponent extends Component {
}
<template>
{{#if this.modal.current}}
<el-dialog>
<dialog
id="app-modal"
aria-labelledby="modal-title"
class="fixed inset-0 size-auto max-h-none max-w-none overflow-y-auto bg-transparent backdrop:bg-transparent"
{{this.trackDialog}}
>
<el-dialog-backdrop
class="fixed inset-0 bg-neutral-950/75 transition-opacity data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in"
></el-dialog-backdrop>
<div
tabindex="0"
class="flex min-h-full items-end justify-center p-4 text-center focus:outline-none sm:items-center sm:p-0"
>
<el-dialog-panel
class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all data-closed:translate-y-4 data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in sm:my-8 sm:w-full
{{this.maxWidthClass}}
data-closed:sm:translate-y-0 data-closed:sm:scale-95"
>
<this.currentComponent
@props={{this.modal.current.props}}
@close={{this.close}}
@replace={{this.replace}}
/>
</el-dialog-panel>
</div>
</dialog>
</el-dialog>
{{/if}}
{{#each this.modal.stack as |descriptor index|}}
<ModalEntry
@descriptor={{descriptor}}
@depth={{index}}
@onFinished={{fn this.finished descriptor}}
@onReplace={{this.replace}}
/>
{{/each}}
</template>
}
+1 -1
View File
@@ -36,7 +36,7 @@ export default class SettingsClockForm extends Component {
<template>
<div class="p-6">
<h3
id="modal-title"
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>Clock</h3>
<div class="mt-2">
+4 -1
View File
@@ -52,7 +52,10 @@ export default class SettingsGlobalSettings extends Component {
<header
class="flex items-center justify-between gap-4 border-b border-gray-200 px-6 py-4"
>
<h3 id="modal-title" class="text-base font-semibold text-gray-900">
<h3
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold text-gray-900"
>
{{this.activeLabel}}
</h3>
<button
@@ -0,0 +1,172 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { fn } from '@ember/helper';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
import { formFor } from '../../../../config/integration-forms';
import { CALENDAR_TYPES } from '../../../../config/calendar';
import { CALDAV_TYPE } from '../../../../config/caldav';
import { ICS_TYPE } from '../../../../config/ics';
import Avatar from '../../integrations/avatar.gjs';
// Feather icons (https://feathericons.com), one path per element.
const SETTINGS_ICON = [
'M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z',
'M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z',
];
const REMOVE_ICON = [
'M12 2a10 10 0 1 0 0 20a10 10 0 1 0 0-20z',
'M15 9l-6 6',
'M9 9l6 6',
];
// The connected calendars, moved out of Manage Integrations. Add/edit open the
// calendar wizards on top of the settings dialog via the modal stack.
export default class SettingsCalendarList extends Component {
@service integrations;
@service modal;
get rows() {
return this.integrations.rows.filter((row) =>
CALENDAR_TYPES.includes(row.type)
);
}
@action
edit(row) {
const component = formFor(row.type);
if (!component) {
return;
}
this.modal.open({
component,
props: { mode: 'edit', integration: row },
size: 'md',
});
}
@action
async remove(row) {
await this.integrations.remove(row);
}
@action
add(type) {
const component = formFor(type);
if (!component) {
return;
}
this.modal.open({ component, props: { mode: 'add' }, size: 'md' });
}
<template>
<div>
{{#if this.rows.length}}
<ul class="grid grid-cols-1 gap-3 sm:grid-cols-2">
{{#each this.rows as |row|}}
<li
data-instance={{row.id}}
data-integration={{row.type}}
class="flex items-center gap-3 rounded-lg border border-gray-200 p-3"
>
<Avatar @integration={{row}} />
<div class="min-w-0 flex-auto">
<p class="truncate text-sm font-medium text-gray-700">
{{row.label}}
</p>
<p class="truncate text-sm text-gray-500">{{row.byline}}</p>
{{#if row.error}}
<p class="truncate text-sm text-red-600">{{row.error}}</p>
{{/if}}
</div>
<div class="flex shrink-0 items-center">
{{#if row.hasSettings}}
<button
type="button"
data-test-settings
aria-label="Settings"
title="Settings"
{{on "click" (fn this.edit row)}}
class="rounded-md p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
aria-hidden="true"
class="size-5"
>
{{#each SETTINGS_ICON as |d|}}
<path
d={{d}}
stroke-linecap="round"
stroke-linejoin="round"
/>
{{/each}}
</svg>
</button>
{{/if}}
<button
type="button"
data-test-remove
aria-label="Remove"
title="Remove"
{{on "click" (fn this.remove row)}}
class="rounded-md p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
aria-hidden="true"
class="size-5"
>
{{#each REMOVE_ICON as |d|}}
<path
d={{d}}
stroke-linecap="round"
stroke-linejoin="round"
/>
{{/each}}
</svg>
</button>
</div>
</li>
{{/each}}
</ul>
{{else}}
<p class="rounded-xl bg-gray-50 p-6 text-center text-sm text-gray-500">
No calendars connected yet.
</p>
{{/if}}
<div class="mt-6 flex flex-wrap gap-2">
<button
type="button"
data-add={{CALDAV_TYPE}}
{{on "click" (fn this.add CALDAV_TYPE)}}
class="rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
>
Add CalDAV account
</button>
<button
type="button"
data-add={{ICS_TYPE}}
{{on "click" (fn this.add ICS_TYPE)}}
class="rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
>
Subscribe via link
</button>
</div>
</div>
</template>
}
@@ -0,0 +1,56 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { CALENDAR_VISIBLE_DAYS_OPTIONS } from '../../../../config/calendar';
import SettingsSelect from '../../integrations/select.gjs';
import CalendarList from './calendar-list.gjs';
// The Events settings section: how many days of events to show, and the
// calendars that feed the upcoming events widget.
export default class SettingsEventsSection extends Component {
@service calendar;
get dayOptions() {
return CALENDAR_VISIBLE_DAYS_OPTIONS;
}
@action
updateVisibleDays(value) {
this.calendar.setVisibleDays(Number(value));
}
<template>
<div class="min-h-0 flex-1 overflow-y-auto px-6 py-6">
<div class="max-w-prose">
<p class="text-sm text-gray-500">
Control the upcoming events widget and the calendars that feed it.
</p>
</div>
<div class="mt-5 max-w-xs">
<SettingsSelect
@id="calendar-visible-days"
@name="calendar-visible-days"
@label="Days with events"
@options={{this.dayOptions}}
@value={{this.calendar.visibleDays}}
@onChange={{this.updateVisibleDays}}
/>
<p class="mt-2 text-sm text-gray-500">
How many days of upcoming events to show on the dashboard.
</p>
</div>
<div class="mt-8 border-t border-gray-200 pt-6">
<h4 class="text-sm font-semibold text-gray-900">Calendars</h4>
<p class="mt-1 max-w-prose text-sm text-gray-500">
The calendars whose events appear on your dashboard.
</p>
<div class="mt-4">
<CalendarList />
</div>
</div>
</div>
</template>
}
@@ -105,8 +105,8 @@ export default class SettingsProtocolGateway extends Component {
saved.
</p>
<p>
Self-hosters can point it at their own instance for maximum
privacy and security.
Self-hosters can point it at their own instance for maximum privacy
and security.
</p>
<p>
<a
@@ -35,7 +35,7 @@ export default class SettingsIntegrationsAddList extends Component {
<template>
<div class="p-6">
<h3
id="modal-title"
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>Add Integration</h3>
<div class="mt-2">
@@ -108,7 +108,7 @@ export default class SettingsIntegrationsBitcoinForm extends Component {
<template>
<div class="p-6" {{this.resetOnClose}}>
<h3
id="modal-title"
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>{{this.title}}</h3>
<div class="mt-2">
@@ -258,7 +258,7 @@ export default class SettingsIntegrationsCalendarCaldavForm extends Component {
<template>
<div class="p-6">
<h3
id="modal-title"
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>{{this.title}}</h3>
<div class="mt-2">
@@ -128,7 +128,7 @@ export default class SettingsIntegrationsCalendarIcsForm extends Component {
<template>
<div class="p-6">
<h3
id="modal-title"
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>{{this.title}}</h3>
<div class="mt-2">
@@ -50,7 +50,7 @@ export default class SettingsIntegrationsDiscourseForm extends Component {
<template>
<div class="p-6">
<h3
id="modal-title"
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>Add Discourse Integration</h3>
<div class="mt-2">
@@ -144,7 +144,7 @@ export default class SettingsIntegrationsFeedbinForm extends Component {
<template>
<div class="p-6">
<h3
id="modal-title"
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>{{this.title}}</h3>
<div class="mt-2">
@@ -134,7 +134,7 @@ export default class SettingsIntegrationsGiteaForm extends Component {
<template>
<div class="p-6">
<h3
id="modal-title"
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>{{this.title}}</h3>
<div class="mt-2">
@@ -129,7 +129,7 @@ export default class SettingsIntegrationsGithubForm extends Component {
<template>
<div class="p-6">
<h3
id="modal-title"
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>{{this.title}}</h3>
<div class="mt-2">
@@ -141,7 +141,7 @@ export default class SettingsIntegrationsHomeAssistantForm extends Component {
<template>
<div class="p-6">
<h3
id="modal-title"
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>{{this.title}}</h3>
<div class="mt-2">
@@ -4,6 +4,7 @@ import { fn } from '@ember/helper';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
import { formFor } from '../../../config/integration-forms';
import { CALENDAR_TYPES } from '../../../config/calendar';
import Avatar from './avatar.gjs';
export default class SettingsIntegrationsManageList extends Component {
@@ -14,7 +15,16 @@ export default class SettingsIntegrationsManageList extends Component {
@service modal;
get rows() {
return this.integrations.rows;
// Calendars are managed from the Events settings section, not here.
return this.integrations.rows.filter(
(row) => !CALENDAR_TYPES.includes(row.type)
);
}
get hasCalendars() {
return this.integrations.rows.some((row) =>
CALENDAR_TYPES.includes(row.type)
);
}
@action
@@ -57,7 +67,7 @@ export default class SettingsIntegrationsManageList extends Component {
<template>
<div class="p-6">
<h3
id="modal-title"
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold leading-6 text-gray-900"
>Manage Integrations</h3>
<div class="mt-2">
@@ -118,10 +128,14 @@ export default class SettingsIntegrationsManageList extends Component {
{{else}}
<div class="mt-6 rounded-xl bg-gray-50 p-6 text-center">
<p class="text-sm text-gray-500">
You don't have any integrations connected yet.
You don't have any other integrations connected yet.
</p>
<p class="mt-1 text-sm text-gray-400">
Use "Add Integration" to connect one.
{{#if this.hasCalendars}}
Your calendars are managed in Settings → Calendar.
{{else}}
Use "Add Integration" to connect one.
{{/if}}
</p>
</div>
{{/if}}
@@ -28,7 +28,10 @@ export default class IntegrationResult extends Component {
</svg>
</div>
<div class="mt-3 text-center sm:mt-5">
<h3 id="modal-title" class="text-base font-semibold text-gray-900">
<h3
id={{if @titleId @titleId "modal-title"}}
class="text-base font-semibold text-gray-900"
>
Integration Failed
</h3>
<div class="mt-2">
+1 -1
View File
@@ -1,4 +1,4 @@
import { CALENDAR_ACTOR } from './calendar';
import { CALENDAR_ACTOR } from './calendar-actor';
export const CALDAV_TYPE = 'calendar-caldav';
+6
View File
@@ -0,0 +1,6 @@
// The Sockethub actor used for calendar sessions. It must stay stable across
// the credentials, fetch, and query messages so they share one session.
//
// Kept in its own module so `caldav.js`/`ics.js` can import it without creating
// a cycle with `calendar.js` (which imports their type constants).
export const CALENDAR_ACTOR = { id: 'caldav:dashtab', type: 'person' };
+43 -8
View File
@@ -1,18 +1,53 @@
// Shared configuration for the calendar integrations and their event cache.
import { CALDAV_TYPE } from './caldav';
import { ICS_TYPE } from './ics';
// Persistent cache namespace for fetched events.
export const CALENDAR_EVENTS_NAMESPACE = 'events';
// The Sockethub actor used for calendar sessions. It must stay stable across
// the credentials, fetch, and query messages so they share one session.
export const CALENDAR_ACTOR = { id: 'caldav:dashtab', type: 'person' };
// Re-exported for callers that read it from the calendar config.
export { CALENDAR_ACTOR } from './calendar-actor';
// Fetch a week ahead; the dashboard shows three day groups in total: today
// plus the next two days that have events when today itself has events, or the
// next three days that have events when today is empty (empty days are
// skipped).
export const CALENDAR_FETCH_DAYS = 7;
// Fetch a week-plus ahead; the dashboard shows a configurable number of day
// groups in total: today plus the next days that have events when today itself
// has events, or that many days when today is empty (empty days are skipped).
// The fetch window reaches one day past the largest visible window so the last
// day group can always be populated.
export const CALENDAR_FETCH_DAYS = 8;
export const CALENDAR_VISIBLE_DAYS = 3;
export const CALENDAR_VISIBLE_DAYS_MIN = 1;
export const CALENDAR_VISIBLE_DAYS_MAX = 7;
// Storage namespace/key for the user's chosen day count.
export const CALENDAR_VISIBLE_DAYS_KEY = 'calendar-visible-days';
// Select options for the "days with events" setting.
export const CALENDAR_VISIBLE_DAYS_OPTIONS = Array.from(
{ length: CALENDAR_VISIBLE_DAYS_MAX - CALENDAR_VISIBLE_DAYS_MIN + 1 },
(_, index) => {
const value = CALENDAR_VISIBLE_DAYS_MIN + index;
return { value, label: `${value} day${value === 1 ? '' : 's'}` };
}
);
// The integration type ids that make up a calendar source.
export const CALENDAR_TYPES = [CALDAV_TYPE, ICS_TYPE];
// Clamps a stored or selected value to a usable day count, falling back to the
// default for anything out of range.
export function normalizeVisibleDays(value) {
const days = Number(value);
if (
Number.isInteger(days) &&
days >= CALENDAR_VISIBLE_DAYS_MIN &&
days <= CALENDAR_VISIBLE_DAYS_MAX
) {
return days;
}
return CALENDAR_VISIBLE_DAYS;
}
// Background refresh interval for the events cache.
export const CALENDAR_REFRESH_INTERVAL = 900000;
+1 -1
View File
@@ -1,4 +1,4 @@
import { CALENDAR_ACTOR } from './calendar';
import { CALENDAR_ACTOR } from './calendar-actor';
export const ICS_TYPE = 'calendar-ics';
+2
View File
@@ -1,9 +1,11 @@
import Events from '../components/settings/global-settings/sections/events.gjs';
import ProtocolGateway from '../components/settings/global-settings/sections/protocol-gateway.gjs';
// Maps a settings section id to its content component. Sections without an
// entry fall back to the generic placeholder, so this grows one section at a
// time. Mirrors the integration form registry in `integration-forms.js`.
const CONTENT = {
events: Events,
'protocol-gateway': ProtocolGateway,
};
+10 -15
View File
@@ -48,23 +48,9 @@ export const SETTINGS_GROUPS = [
'M14.25 6.087c0-.355.186-.676.401-.959.221-.29.349-.634.349-1.003 0-1.036-1.007-1.875-2.25-1.875s-2.25.84-2.25 1.875c0 .369.128.713.349 1.003.215.283.401.604.401.959v0a.64.64 0 0 1-.657.643 48.39 48.39 0 0 1-4.163-.3c.186 1.613.293 3.25.315 4.907a.656.656 0 0 1-.658.663v0c-.355 0-.676-.186-.959-.401a1.647 1.647 0 0 0-1.003-.349c-1.036 0-1.875 1.007-1.875 2.25s.84 2.25 1.875 2.25c.369 0 .713-.128 1.003-.349.283-.215.604-.401.959-.401v0c.31 0 .555.26.532.57a48.039 48.039 0 0 1-.642 5.056c1.518.19 3.058.309 4.616.354a.64.64 0 0 0 .657-.643v0c0-.355-.186-.676-.401-.959a1.647 1.647 0 0 1-.349-1.003c0-1.035 1.008-1.875 2.25-1.875 1.243 0 2.25.84 2.25 1.875 0 .369-.128.713-.349 1.003-.215.283-.4.604-.4.959v0c0 .333.277.599.61.58a48.1 48.1 0 0 0 5.427-.63 48.05 48.05 0 0 0 .582-4.717.532.532 0 0 0-.533-.57v0c-.355 0-.676.186-.959.401-.29.221-.634.349-1.003.349-1.035 0-1.875-1.007-1.875-2.25s.84-2.25 1.875-2.25c.37 0 .713.128 1.003.349.283.215.604.401.96.401v0a.656.656 0 0 0 .658-.663 48.422 48.422 0 0 0-.37-5.36c-1.886.342-3.81.574-5.766.689a.578.578 0 0 1-.61-.58v0Z',
],
},
{
id: 'notifications',
label: 'Notifications',
description: 'Decide which events should notify you.',
icon: [
'M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9',
'M13.73 21a2 2 0 0 1-3.46 0',
],
},
],
},
{
label: 'Calendar',
items: [
{
id: 'events',
label: 'Events',
label: 'Calendar',
description: 'Control the upcoming events widget and its sources.',
icon: [
'M5 4h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z',
@@ -73,6 +59,15 @@ export const SETTINGS_GROUPS = [
'M3 10h18',
],
},
{
id: 'notifications',
label: 'Notifications',
description: 'Decide which events should notify you.',
icon: [
'M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9',
'M13.73 21a2 2 0 0 1-3.46 0',
],
},
],
},
{
+33 -3
View File
@@ -3,10 +3,14 @@ import { tracked } from '@glimmer/tracking';
import {
CALDAV_PLATFORM,
CALENDAR_REFRESH_INTERVAL,
CALENDAR_TYPES,
CALENDAR_VISIBLE_DAYS,
CALENDAR_VISIBLE_DAYS_KEY,
classifyCalendarError,
fetchWindow,
groupEvents,
normalizeEvent,
normalizeVisibleDays,
} from '../config/calendar';
import {
CALDAV_TYPE,
@@ -20,7 +24,6 @@ import { ICS_TYPE, feedName, icsInstanceKey, readMessage } from '../config/ics';
import { isCancellation } from './http';
const CALENDAR_CONSUMER = 'calendar';
const CALENDAR_TYPES = [CALDAV_TYPE, ICS_TYPE];
function hostOf(url) {
try {
@@ -44,6 +47,7 @@ export default class CalendarService extends Service {
@tracked instances = [];
@tracked error = null;
@tracked visibleDays = CALENDAR_VISIBLE_DAYS;
intervalId = null;
refreshPromise = null;
@@ -53,7 +57,7 @@ export default class CalendarService extends Service {
constructor() {
super(...arguments);
this.ready = this.load();
this.ready = Promise.all([this.load(), this.loadVisibleDays()]);
this.removeRestoreHandler = this.pageLifecycle.onRestore(() =>
this.handleRestore()
);
@@ -111,6 +115,32 @@ export default class CalendarService extends Service {
}
}
// The visible day count is a preference, loaded separately so a storage
// failure here does not fail the calendar load itself.
async loadVisibleDays() {
try {
const stored = await this.storage.get(
'preferences',
CALENDAR_VISIBLE_DAYS_KEY
);
if (stored != null) {
this.visibleDays = normalizeVisibleDays(stored);
}
} catch (err) {
console.error('Error loading the calendar visible days:', err);
}
}
async setVisibleDays(days) {
this.visibleDays = normalizeVisibleDays(days);
await this.storage.set(
'preferences',
CALENDAR_VISIBLE_DAYS_KEY,
this.visibleDays
);
}
buildInstance(key, data) {
return {
id: key,
@@ -412,7 +442,7 @@ export default class CalendarService extends Service {
entry.events.map((event) => ({ ...event, source: entry.source }))
);
return groupEvents(events);
return groupEvents(events, new Date(), this.visibleDays);
}
isEntryVisible(entry, instancesById) {
+25 -6
View File
@@ -1,22 +1,41 @@
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
// Holds the open modals as a stack. `open` pushes (so a form can sit on top of
// the settings dialog), `replace` swaps the top, and `close`/`finished` pop.
// Descriptors keep their identity so callers can compare them.
export default class ModalService extends Service {
@tracked current = null;
@tracked stack = [];
get current() {
return this.stack.at(-1) ?? null;
}
open(descriptor) {
this.current = descriptor;
this.stack = [...this.stack, descriptor];
}
replace(descriptor) {
this.current = descriptor;
if (this.stack.length === 0) {
this.open(descriptor);
return;
}
this.stack = [...this.stack.slice(0, -1), descriptor];
}
close() {
this.current = null;
this.stack = this.stack.slice(0, -1);
}
finished() {
this.current = null;
// Called when a dialog fires its `close` event. Removes that exact entry so
// closing a lower dialog does not pop a higher one. Idempotent.
finished(descriptor) {
if (!descriptor) {
this.stack = [];
return;
}
this.stack = this.stack.filter((entry) => entry !== descriptor);
}
}
@@ -1,24 +1,26 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, click, settled } from '@ember/test-helpers';
import { render, click, settled, waitUntil } from '@ember/test-helpers';
import { fn, hash } from '@ember/helper';
import { on } from '@ember/modifier';
import ModalHost from 'dashtab/components/modal-host';
const BodyB = <template>
<div data-body="b">
<h3 id="modal-title">B</h3>
<h3 id={{if @titleId @titleId "modal-title"}}>B</h3>
<button type="button" data-close {{on "click" @close}}>Close</button>
</div>
</template>;
const BodyA = <template>
<div data-body="a">
<h3 id="modal-title">A</h3>
<h3 id={{if @titleId @titleId "modal-title"}}>A</h3>
<button
type="button"
data-replace
{{on "click" (fn @replace (hash component=BodyB props=(hash) size="md"))}}
>Replace</button>
<button type="button" data-close {{on "click" @close}}>Close</button>
</div>
</template>;
@@ -42,7 +44,7 @@ module('Integration | Component | modal-host', function (hooks) {
assert.dom('[data-body="a"]').exists();
assert.dom('el-dialog-panel').hasClass('sm:max-w-sm');
assert.true(document.getElementById('app-modal').open);
assert.dom('dialog[open]').exists();
});
test('replace swaps the body while the dialog stays open', async function (assert) {
@@ -57,7 +59,7 @@ module('Integration | Component | modal-host', function (hooks) {
assert.dom('[data-body="a"]').doesNotExist();
assert.dom('[data-body="b"]').exists();
assert.true(document.getElementById('app-modal').open);
assert.dom('dialog[open]').exists();
});
test('finishing the modal unmounts it', async function (assert) {
@@ -74,4 +76,40 @@ module('Integration | Component | modal-host', function (hooks) {
assert.dom('[data-body]').doesNotExist();
assert.dom('dialog').doesNotExist();
});
test('opening a second modal keeps the first mounted', async function (assert) {
const modal = this.owner.lookup('service:modal');
await render(<template><ModalHost /></template>);
modal.open({ component: BodyA, props: {}, size: 'sm' });
await settled();
modal.open({ component: BodyB, props: {}, size: 'md' });
await settled();
assert.dom('[data-body="a"]').exists();
assert.dom('[data-body="b"]').exists();
assert.dom('dialog[open]').exists({ count: 2 });
});
test('closing the top modal reveals the one below', async function (assert) {
const modal = this.owner.lookup('service:modal');
await render(<template><ModalHost /></template>);
modal.open({ component: BodyA, props: {}, size: 'sm' });
await settled();
modal.open({ component: BodyB, props: {}, size: 'md' });
await settled();
await click('[data-body="b"] [data-close]');
// The native `close` event is queued as a task, so wait for the entry to
// unmount before asserting.
await waitUntil(() => !document.querySelector('[data-body="b"]'));
assert.dom('[data-body="a"]').exists();
assert.dom('[data-body="b"]').doesNotExist();
assert.dom('dialog[open]').exists({ count: 1 });
});
});
@@ -23,6 +23,6 @@ module('Integration | Component | settings-button', function (hooks) {
await click('[aria-label="Open settings"]');
assert.dom('el-dialog-panel').hasClass('sm:max-w-4xl');
assert.dom('#modal-title').exists({ count: 1 });
assert.dom('el-dialog-panel h3').hasText('Appearance');
});
});
@@ -0,0 +1,119 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, click } from '@ember/test-helpers';
import CalendarList from 'dashtab/components/settings/global-settings/sections/calendar-list';
class FakeIntegrations {
constructor(rows = []) {
this.rows = rows;
this.removed = [];
}
async remove(instance) {
this.removed.push(instance);
}
}
class FakeModal {
opened = null;
open(descriptor) {
this.opened = descriptor;
}
}
const CALENDAR_ICON_PATH =
'M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5';
const ROWS = [
{
id: 'caldav-1',
type: 'calendar-caldav',
label: 'CalDAV',
byline: 'cal.example.com',
hasSettings: true,
colorClass: 'bg-rose-500',
iconPath: CALENDAR_ICON_PATH,
},
{
id: 'ics-1',
type: 'calendar-ics',
label: 'ICS / WebCal',
byline: 'example.org',
hasSettings: true,
colorClass: 'bg-rose-500',
iconPath: CALENDAR_ICON_PATH,
},
{
id: 'discourse-1',
type: 'discourse',
label: 'Discourse',
byline: 'forum.example.com',
hasSettings: false,
},
];
function register(owner, { rows = ROWS } = {}) {
const integrations = new FakeIntegrations(rows);
const modal = new FakeModal();
owner.register('service:integrations', integrations, { instantiate: false });
owner.register('service:modal', modal, { instantiate: false });
return { integrations, modal };
}
module(
'Integration | Component | settings/global-settings/sections/calendar-list',
function (hooks) {
setupRenderingTest(hooks);
test('it lists only the calendar sources', async function (assert) {
register(this.owner);
await render(<template><CalendarList /></template>);
assert.dom('[data-instance="caldav-1"]').exists();
assert.dom('[data-instance="ics-1"]').exists();
assert.dom('[data-instance="discourse-1"]').doesNotExist();
});
test('editing a calendar opens its form', async function (assert) {
const { modal } = register(this.owner);
await render(<template><CalendarList /></template>);
await click('[data-instance="caldav-1"] [data-test-settings]');
assert.ok(modal.opened.component);
assert.strictEqual(modal.opened.props.mode, 'edit');
assert.strictEqual(modal.opened.props.integration.id, 'caldav-1');
});
test('removing a calendar removes the source', async function (assert) {
const { integrations } = register(this.owner);
await render(<template><CalendarList /></template>);
await click('[data-instance="ics-1"] [data-test-remove]');
assert.deepEqual(
integrations.removed.map((row) => row.id),
['ics-1']
);
});
test('adding a calendar opens the matching form', async function (assert) {
const { modal } = register(this.owner, { rows: [] });
await render(<template><CalendarList /></template>);
await click('[data-add="calendar-caldav"]');
assert.ok(modal.opened.component);
assert.strictEqual(modal.opened.props.mode, 'add');
await click('[data-add="calendar-ics"]');
assert.ok(modal.opened.component);
assert.strictEqual(modal.opened.props.mode, 'add');
});
}
);
@@ -0,0 +1,67 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render } from '@ember/test-helpers';
import Events from 'dashtab/components/settings/global-settings/sections/events';
class FakeCalendar {
visibleDays = 3;
calls = [];
setVisibleDays(days) {
this.calls.push(days);
this.visibleDays = days;
}
}
class FakeIntegrations {
rows = [];
}
class FakeModal {
open() {}
}
function register(owner, { calendar = new FakeCalendar() } = {}) {
owner.register('service:calendar', calendar, { instantiate: false });
owner.register('service:integrations', new FakeIntegrations(), {
instantiate: false,
});
owner.register('service:modal', new FakeModal(), { instantiate: false });
return { calendar };
}
function chooseOption(value) {
const select = document.querySelector('el-select');
const event = new Event('change', { bubbles: true });
Object.defineProperty(event, 'target', { value: { value } });
select.dispatchEvent(event);
}
module(
'Integration | Component | settings/global-settings/sections/events',
function (hooks) {
setupRenderingTest(hooks);
test('shows the current day count and saves the chosen one', async function (assert) {
const { calendar } = register(this.owner);
await render(<template><Events /></template>);
assert.dom('el-selectedcontent').hasText('3 days');
chooseOption('5');
assert.deepEqual(calendar.calls, [5]);
});
test('renders the calendar list', async function (assert) {
register(this.owner);
await render(<template><Events /></template>);
assert.dom('[data-add="calendar-caldav"]').exists();
assert.dom('[data-add="calendar-ics"]').exists();
});
}
);
@@ -124,7 +124,35 @@ module(
assert.dom('[data-instance]').doesNotExist();
assert
.dom()
.containsText("You don't have any integrations connected yet");
.containsText("You don't have any other integrations connected yet");
});
test('it hides calendars, which are managed in Settings', async function (assert) {
this.owner.register(
'service:calendar',
{
instancesFor(type) {
return type === 'calendar-caldav'
? [
{
id: 'cal-1',
type: 'calendar-caldav',
label: 'Work',
url: 'https://cal.example.com',
},
]
: [];
},
},
{ instantiate: false }
);
register(this.owner);
await render(<template><List /></template>);
assert.dom('[data-integration="calendar-caldav"]').doesNotExist();
assert.dom().containsText('managed in Settings');
});
test('it lists one row per connected integration', async function (assert) {
+20 -2
View File
@@ -1,26 +1,44 @@
import { module, test } from 'qunit';
import {
CALENDAR_TYPES,
CALENDAR_VISIBLE_DAYS,
classifyCalendarError,
fetchWindow,
groupEvents,
normalizeEvent,
normalizeVisibleDays,
parseEventDate,
} from 'dashtab/config/calendar';
module('Unit | Config | calendar', function () {
test('fetchWindow spans from now to local midnight plus the fetch days', function (assert) {
test('fetchWindow reaches the midnight after the largest visible window', function (assert) {
const now = new Date(2026, 9, 27, 15, 30);
const { startTime, endTime } = fetchWindow(now);
assert.strictEqual(startTime, now.toISOString());
const end = new Date(endTime);
// Oct 27 + CALENDAR_FETCH_DAYS (8) = Nov 4 local midnight, one day past the
// largest visible window (today + 7) so its last day can always populate.
assert.strictEqual(end.getFullYear(), 2026);
assert.strictEqual(end.getMonth(), 10);
assert.strictEqual(end.getDate(), 3);
assert.strictEqual(end.getDate(), 4);
assert.strictEqual(end.getHours(), 0);
});
test('normalizeVisibleDays clamps to the supported range', function (assert) {
assert.strictEqual(normalizeVisibleDays(5), 5);
assert.strictEqual(normalizeVisibleDays('5'), 5);
assert.strictEqual(normalizeVisibleDays(0), CALENDAR_VISIBLE_DAYS);
assert.strictEqual(normalizeVisibleDays(99), CALENDAR_VISIBLE_DAYS);
assert.strictEqual(normalizeVisibleDays('nope'), CALENDAR_VISIBLE_DAYS);
assert.strictEqual(normalizeVisibleDays(null), CALENDAR_VISIBLE_DAYS);
});
test('CALENDAR_TYPES lists the calendar integration ids', function (assert) {
assert.deepEqual(CALENDAR_TYPES, ['calendar-caldav', 'calendar-ics']);
});
test('parseEventDate reads date-only values as local dates', function (assert) {
const date = parseEventDate('2026-08-03', true);
+51
View File
@@ -2,6 +2,7 @@ import { module, test } from 'qunit';
import { setupTest } from 'dashtab/tests/helpers';
import { caldavInstanceKey } from 'dashtab/config/caldav';
import { icsInstanceKey } from 'dashtab/config/ics';
import { CALENDAR_VISIBLE_DAYS_KEY } from 'dashtab/config/calendar';
class FakeSockethub {
constructor(overrides = {}) {
@@ -55,6 +56,7 @@ module('Unit | Service | calendar', function (hooks) {
async function setup(context, overrides = {}) {
const storage = context.owner.lookup('service:storage');
await storage.clear('integrations');
await storage.remove('preferences', CALENDAR_VISIBLE_DAYS_KEY);
const cache = context.owner.lookup('service:calendar-cache');
await cache.ready;
@@ -482,4 +484,53 @@ module('Unit | Service | calendar', function (hooks) {
assert.strictEqual(grouped.days.length, 1);
assert.strictEqual(grouped.days[0].events[0].id, 'future');
});
test('setVisibleDays persists a normalized value', async function (assert) {
const { service, storage } = await setup(this);
await service.setVisibleDays('5');
assert.strictEqual(service.visibleDays, 5);
assert.strictEqual(
await storage.get('preferences', CALENDAR_VISIBLE_DAYS_KEY),
5
);
await service.setVisibleDays(99);
assert.strictEqual(service.visibleDays, 3);
});
test('events honors the configured visible day count', async function (assert) {
const { service, cache } = await setup(this);
const now = new Date();
const iso = (offset) => {
const day = new Date(now);
day.setDate(day.getDate() + offset);
return day.toISOString();
};
service.instances = [{ id: 'x', type: 'calendar-ics' }];
await cache.put({
key: 'calendar-ics:x:feed',
source: {
type: 'calendar-ics',
instanceKey: 'x',
calendarId: 'feed',
name: 'Feed',
},
fetchedAt: Date.now(),
events: [1, 2, 3].map((offset) => ({
id: `d${offset}`,
name: `Day ${offset}`,
startTime: iso(offset),
allDay: false,
})),
});
service.visibleDays = 2;
assert.strictEqual(service.events.days.length, 2);
});
});
+39
View File
@@ -24,4 +24,43 @@ module('Unit | Service | modal', function (hooks) {
service.close();
assert.strictEqual(service.current, null);
});
test('it stacks modals and pops them one at a time', function (assert) {
const service = this.owner.lookup('service:modal');
const first = { component: 'first' };
const second = { component: 'second' };
service.open(first);
service.open(second);
assert.strictEqual(service.stack.length, 2);
assert.strictEqual(service.current, second);
service.close();
assert.strictEqual(service.stack.length, 1);
assert.strictEqual(service.current, first);
});
test('finished removes the matching descriptor and is idempotent', function (assert) {
const service = this.owner.lookup('service:modal');
const first = { component: 'first' };
const second = { component: 'second' };
service.open(first);
service.open(second);
service.finished(second);
assert.strictEqual(service.stack.length, 1);
assert.strictEqual(service.current, first);
// Removing an already-removed descriptor is a no-op.
service.finished(second);
assert.strictEqual(service.stack.length, 1);
assert.strictEqual(service.current, first);
});
});