A platform for community discussion. Free, open, simple.
FEATURE: allow picking first day of week in calendar (#34670)
Sam0ccb0c3c8ce9
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjsindex a94e88e7535..5d70970ebd9 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs@@ -1,7 +1,6 @@import Component from "@glimmer/component";import { action } from "@ember/object";import { service } from "@ember/service";-import AsyncContent from "discourse/components/async-content";import { popupAjaxError } from "discourse/lib/ajax-error";import { bind } from "discourse/lib/decorators";import getURL from "discourse/lib/get-url";@@ -26,7 +25,8 @@ export default class CategoryCalendar extends Component {include_subcategories: true,};- return await this.discoursePostEventApi.events(params);+ const events = await this.discoursePostEventApi.events(params);+ return this.formattedEvents(events);} catch (error) {popupAjaxError(error);}@@ -103,7 +103,7 @@ export default class CategoryCalendar extends Component {}@action- formatedEvents(events = []) {+ formattedEvents(events = []) {return events.map((event) => {const { startsAt, endsAt, post, categoryId } = event;@@ -148,16 +148,12 @@ export default class CategoryCalendar extends Component {<template>{{#if this.shouldRender}}- <AsyncContent @asyncData={{this.loadEvents}}>- <:content as |events|>- <FullCalendar- @events={{this.formatedEvents events}}- @height="650px"- @initialView={{this.categorySetting?.defaultView}}- @weekends={{this.renderWeekends}}- />- </:content>- </AsyncContent>+ <FullCalendar+ @onLoadEvents={{this.loadEvents}}+ @height="650px"+ @initialView={{this.categorySetting?.defaultView}}+ @weekends={{this.renderWeekends}}+ />{{/if}}</template>}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjsindex 918b4b335a1..7ecf844ebbb 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjs@@ -30,6 +30,8 @@ export default class FullCalendar extends Component {@service capabilities;@service tooltip;@service menu;+ @service siteSettings;+ @service loadingSlider;@controller topic;@@ -41,6 +43,19 @@ export default class FullCalendar extends Component {super.willDestroy(...arguments);}+ get firstDayOfWeek() {+ const setting = this.siteSettings.calendar_first_day_of_week;+ switch (setting) {+ case "saturday":+ return 6;+ case "sunday":+ return 0;+ case "monday":+ default:+ return 1;+ }+ }+@actionasync setupCalendar(element) {const calendarModule = await loadFullCalendar();@@ -49,12 +64,23 @@ export default class FullCalendar extends Component {locale: getCurrentBcp47Locale(),buttonText: getCalendarButtonsText(),timeZone: this.currentUser?.user_option?.timezone || "local",- firstDay: 1,+ firstDay: this.firstDayOfWeek,displayEventTime: true,weekends: this.args.weekends ?? true,initialDate: this.args.initialDate,height: this.args.height ?? "100%",- events: this.args.events || [],+ events: async (info, successCallback, failureCallback) => {+ if (this.args.onLoadEvents) {+ try {+ this.loadingSlider.transitionStarted();+ const events = await this.args.onLoadEvents(info);+ successCallback(events);+ this.loadingSlider.transitionEnded();+ } catch (error) {+ failureCallback(error);+ }+ }+ },plugins: [calendarModule.DayGrid,calendarModule.TimeGrid,@@ -130,10 +156,6 @@ export default class FullCalendar extends Component {updateCalendar() {if (this.calendar) {this.calendar.setOption("headerToolbar", this.headerToolbar);- this.calendar.setOption("events", this.args.events || []);- if (this.args.initialDate) {- this.calendar.gotoDate(this.args.initialDate);- }}}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/post-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/post-calendar.gjsindex 549bd8c8f65..23fec844e8e 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/post-calendar.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/post-calendar.gjs@@ -37,7 +37,8 @@ export default class PostCalendar extends Component {return this.args.options.calendarFullDay === "true";}- get events() {+ @action+ loadEvents() {const events = [];if (this.isStatic) {@@ -302,7 +303,7 @@ export default class PostCalendar extends Component {@leftHeaderToolbar={{this.leftHeaderToolbar}}@centerHeaderToolbar={{this.centerHeaderToolbar}}@rightHeaderToolbar="timeGridDay,timeGridWeek,dayGridMonth,listYear"- @events={{this.events}}+ @onLoadEvents={{this.loadEvents}}@height={{@height}}/></div>diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjsindex 481a969b3ce..31c5b5cb6c8 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/upcoming-events-calendar.gjs@@ -16,10 +16,7 @@ export default class UpcomingEventsCalendar extends Component {@service router;@service capabilities;@service siteSettings;-- _isInitializing = true;- _isViewChanging = false;- _lastNavigationTime = 0;+ @service discoursePostEventService;get customButtons() {return {@@ -29,10 +26,10 @@ export default class UpcomingEventsCalendar extends Component {const params = this.router.currentRoute.params;this.router.replaceWith("discourse-post-event-upcoming-events.mine",- params.view || "month",- params.year || moment().year(),- params.month || moment().month() + 1,- params.day || moment().date()+ params.view,+ params.year,+ params.month,+ params.day);},},@@ -42,24 +39,27 @@ export default class UpcomingEventsCalendar extends Component {const params = this.router.currentRoute.params;this.router.replaceWith("discourse-post-event-upcoming-events.index",- params.view || "month",- params.year || moment().year(),- params.month || moment().month() + 1,- params.day || moment().date()+ params.view,+ params.year,+ params.month,+ params.day);},},};}- get events() {- if (!this.args.events) {- return [];- }+ @action+ async loadEvents(info) {+ const events = await this.discoursePostEventService.fetchEvents({+ after: info.startStr,+ before: info.endStr,+ attending_user: this.args.mine ? this.currentUser?.username : null,+ });const tagsColorsMap = JSON.parse(this.siteSettings.map_events_to_color);- return this.args.events.map((event) => {+ return events.map((event) => {const { startsAt, endsAt, post, categoryId } = event;let backgroundColor;@@ -141,187 +141,16 @@ export default class UpcomingEventsCalendar extends Component {async onDatesChange(info) {this.applyCustomButtonsState();- const view = normalizeViewForRoute(info.view.type);- const currentParams = this.router.currentRoute.params;- const currentYear = parseInt(currentParams.year, 10);- const currentMonth = parseInt(currentParams.month, 10);- const currentDay = parseInt(currentParams.day, 10);- const isViewChanged = currentParams.view !== view;-- if (isViewChanged) {- this._isViewChanging = true;-- let navYear = currentYear;- let navMonth = currentMonth;- let navDay = currentDay;-- if (view === "month") {- navYear = currentYear;- navMonth = currentMonth;- navDay = 1;- }-- this.router.replaceWith(- this.router.currentRouteName,- view,- navYear,- navMonth,- navDay- );- return;- }-- if (this._isViewChanging) {- this._isViewChanging = false;- return;- }-- const calculatedParams = this.#calculateUrlParams(- view,- info.view,- currentYear,- currentMonth,- currentDay,- isViewChanged- );-- const { year: urlYear, month: urlMonth, day: urlDay } = calculatedParams;-- const isMonthChanged =- view === "month" &&- (currentYear !== urlYear || currentMonth !== urlMonth);- const isDayChanged =- view !== "month" &&- (currentYear !== urlYear ||- currentMonth !== urlMonth ||- currentDay !== urlDay);-- // Prevent URL changes during calendar initialization- if (this._isInitializing) {- this._isInitializing = false;- return;- }-- const shouldNavigate = isViewChanged || isMonthChanged || isDayChanged;-- if (shouldNavigate) {- this.router.replaceWith(- this.router.currentRouteName,- view,- urlYear,- urlMonth,- urlDay- );- }- }-- #calculateUrlParams(- view,- calendarView,- currentYear,- currentMonth,- currentDay,- isViewChanged = false- ) {- const viewStart = moment(calendarView.currentStart);- const viewEnd = moment(calendarView.currentEnd);- const currentParams = this.router.currentRoute.params;-- if (isViewChanged) {- const result = {- year: currentYear,- month: currentMonth,- day: parseInt(currentParams.day, 10),- };- return result;- }-- if (view === "month") {- const viewMiddleForMonth = moment(- (viewStart.valueOf() + viewEnd.valueOf()) / 2- );- const startYear = viewMiddleForMonth.year();- const startMonth = viewMiddleForMonth.month() + 1;- const isSequential = this.#isSequentialMonthNavigation(- currentYear,- currentMonth,- startYear,- startMonth- );- const isTodayNav = this.#isTodayNavigation(- currentParams,- startYear,- startMonth- );-- if (isSequential) {- return { year: startYear, month: startMonth, day: 1 };- } else if (isTodayNav) {- return {- year: startYear,- month: startMonth,- day: moment().date(),- };- } else {- return {- year: viewMiddleForMonth.year(),- month: viewMiddleForMonth.month() + 1,- day: viewMiddleForMonth.date(),- };- }- } else {- let viewDate;- if (view === "week") {- const viewMiddle = moment(- (viewStart.valueOf() + viewEnd.valueOf()) / 2- );- viewDate = moment(viewMiddle).startOf("isoWeek");- } else if (view === "day") {- const viewMiddle = moment(- (viewStart.valueOf() + viewEnd.valueOf()) / 2- );- viewDate = moment(viewMiddle);- } else if (view === "year") {- const viewMiddle = moment(- (viewStart.valueOf() + viewEnd.valueOf()) / 2- );- viewDate = moment(viewMiddle);- } else {- viewDate = moment(viewStart);- }-- const result = {- year: viewDate.year(),- month: viewDate.month() + 1,- day: viewDate.date(),- };- return result;- }- }-- #isSequentialMonthNavigation(currentYear, currentMonth, newYear, newMonth) {- if (newYear === currentYear && newMonth === currentMonth + 1) {- return true;- }- if (newYear === currentYear && newMonth === currentMonth - 1) {- return true;- }- if (newYear === currentYear + 1 && newMonth === 1 && currentMonth === 12) {- return true;- }- if (newYear === currentYear - 1 && newMonth === 12 && currentMonth === 1) {- return true;- }-- return false;- }+ const localDate = moment(info.view.currentStart)+ .clone()+ .tz(this.currentUser?.user_option?.timezone);- #isTodayNavigation(currentParams, newYear, newMonth) {- const today = moment();- return (- newYear === today.year() &&- newMonth === today.month() + 1 &&- (currentParams.year !== newYear || currentParams.month !== newMonth)+ this.router.replaceWith(+ this.router.currentRouteName,+ normalizeViewForRoute(info.view.type),+ localDate.year(),+ localDate.month() + 1,+ localDate.date());}@@ -351,7 +180,7 @@ export default class UpcomingEventsCalendar extends Component {<FullCalendar@initialDate={{@initialDate}}@onDatesChange={{this.onDatesChange}}- @events={{this.events}}+ @onLoadEvents={{this.loadEvents}}@initialView={{@initialView}}@customButtons={{this.customButtons}}@leftHeaderToolbar={{this.leftHeaderToolbar}}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/controllers/discourse-post-event-upcoming-events-index.js b/plugins/discourse-calendar/assets/javascripts/discourse/controllers/discourse-post-event-upcoming-events-index.jsindex 2522d8242f0..471cf031b35 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/controllers/discourse-post-event-upcoming-events-index.js+++ b/plugins/discourse-calendar/assets/javascripts/discourse/controllers/discourse-post-event-upcoming-events-index.js@@ -9,10 +9,8 @@ export default class DiscoursePostEventUpcomingEventsIndexController extends Con}get initialDate() {- return this.model.initialDate;- }-- get events() {- return this.model.events;+ return Date.parse(+ `${this.model.year}/${this.model.month}/${this.model.day}`+ );}}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/controllers/discourse-post-event-upcoming-events-mine.js b/plugins/discourse-calendar/assets/javascripts/discourse/controllers/discourse-post-event-upcoming-events-mine.jsindex 1e2517271b4..324d87f9ce0 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/controllers/discourse-post-event-upcoming-events-mine.js+++ b/plugins/discourse-calendar/assets/javascripts/discourse/controllers/discourse-post-event-upcoming-events-mine.js@@ -9,10 +9,8 @@ export default class DiscoursePostEventUpcomingEventsMineController extends Cont}get initialDate() {- return this.model.initialDate;- }-- get events() {- return this.model.events;+ return Date.parse(+ `${this.model.year}/${this.model.month}/${this.model.day}`+ );}}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/routes/discourse-post-event-upcoming-events-index.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/routes/discourse-post-event-upcoming-events-index.gjsindex ff984b77a66..c93633eb3a5 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/routes/discourse-post-event-upcoming-events-index.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/routes/discourse-post-event-upcoming-events-index.gjs@@ -1,3 +1,13 @@-import UpcomingEventsBaseRoute from "./upcoming-events-base-route";+import { service } from "@ember/service";+import DiscourseURL from "discourse/lib/url";+import DiscourseRoute from "discourse/routes/discourse";-export default class PostEventUpcomingEventsIndexRoute extends UpcomingEventsBaseRoute {}+export default class PostEventUpcomingEventsIndexRoute extends DiscourseRoute {+ @service siteSettings;++ activate() {+ if (!this.siteSettings.discourse_post_event_enabled) {+ DiscourseURL.redirectTo("/404");+ }+ }+}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/routes/discourse-post-event-upcoming-events-mine.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/routes/discourse-post-event-upcoming-events-mine.gjsindex 44c3294aa0d..bbde0d4cc3d 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/routes/discourse-post-event-upcoming-events-mine.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/routes/discourse-post-event-upcoming-events-mine.gjs@@ -1,7 +1,13 @@-import UpcomingEventsBaseRoute from "./upcoming-events-base-route";+import { service } from "@ember/service";+import DiscourseURL from "discourse/lib/url";+import DiscourseRoute from "discourse/routes/discourse";-export default class PostEventUpcomingEventsMineRoute extends UpcomingEventsBaseRoute {- addRouteSpecificParams(fetchParams) {- fetchParams.attending_user = this.currentUser?.username;+export default class PostEventUpcomingEventsMineRoute extends DiscourseRoute {+ @service siteSettings;++ activate() {+ if (!this.siteSettings.discourse_post_event_enabled) {+ DiscourseURL.redirectTo("/404");+ }}}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/routes/upcoming-events-base-route.js b/plugins/discourse-calendar/assets/javascripts/discourse/routes/upcoming-events-base-route.jsdeleted file mode 100644index 155428bdc54..00000000000--- a/plugins/discourse-calendar/assets/javascripts/discourse/routes/upcoming-events-base-route.js+++ /dev/null@@ -1,71 +0,0 @@-import { service } from "@ember/service";-import moment from "moment";-import DiscourseURL from "discourse/lib/url";-import DiscourseRoute from "discourse/routes/discourse";--export default class UpcomingEventsBaseRoute extends DiscourseRoute {- @service discoursePostEventService;- @service currentUser;-- activate() {- if (!this.siteSettings.discourse_post_event_enabled) {- DiscourseURL.redirectTo("/404");- }- }-- async model(params) {- let after, before, initialDate;-- if (params.view === "year") {- const year = parseInt(params.year, 10);- after = moment.utc({ year }).startOf("year").toISOString();- before = moment.utc({ year }).endOf("year").toISOString();- initialDate = moment.utc({ year }).format("YYYY-MM-DD");- } else if (params.view === "month") {- const year = parseInt(params.year, 10);- const month = parseInt(params.month, 10) - 1; // moment months are 0-indexed-- const date = moment.utc({ year, month });- after = date.clone().startOf("month").toISOString();- before = date.clone().endOf("month").toISOString();- initialDate = moment.utc({ year, month }).format("YYYY-MM-DD");- } else if (params.view === "week") {- const year = parseInt(params.year, 10);- const month = parseInt(params.month, 10) - 1; // moment months are 0-indexed- const day = parseInt(params.day, 10);-- const date = moment.utc({ year, month, day });- after = date.clone().startOf("isoWeek").toISOString();- before = date.clone().endOf("isoWeek").toISOString();- initialDate = moment.utc({ year, month, day }).format("YYYY-MM-DD");- } else if (params.view === "day") {- const year = parseInt(params.year, 10);- const month = parseInt(params.month, 10) - 1; // moment months are 0-indexed- const day = parseInt(params.day, 10);-- const date = moment.utc({ year, month, day });- after = date.clone().startOf("day").toISOString();- before = date.clone().endOf("day").toISOString();- initialDate = moment.utc({ year, month, day }).format("YYYY-MM-DD");- }-- const fetchParams = {- after,- before,- };-- this.addRouteSpecificParams(fetchParams);-- const events =- await this.discoursePostEventService.fetchEvents(fetchParams);-- return {- events,- initialDate,- view: params.view,- };- }-- // Override in subclasses to add route-specific parameters- addRouteSpecificParams() {}-}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/templates/discourse-post-event-upcoming-events-index.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/templates/discourse-post-event-upcoming-events-index.gjsindex 05f9322c59a..0bebe1258f7 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/templates/discourse-post-event-upcoming-events-index.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/templates/discourse-post-event-upcoming-events-index.gjs@@ -5,7 +5,6 @@ export default RouteTemplate(<template><div class="discourse-post-event-upcoming-events"><UpcomingEventsCalendar- @events={{@controller.events}}@initialView={{@controller.initialView}}@initialDate={{@controller.initialDate}}/>diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/templates/discourse-post-event-upcoming-events-mine.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/templates/discourse-post-event-upcoming-events-mine.gjsindex 78420a0690a..041b26f319e 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/templates/discourse-post-event-upcoming-events-mine.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/templates/discourse-post-event-upcoming-events-mine.gjs@@ -5,7 +5,6 @@ export default RouteTemplate(<template><div class="discourse-post-event-upcoming-events"><UpcomingEventsCalendar- @events={{@controller.events}}@mine={{true}}@initialView={{@controller.initialView}}@initialDate={{@controller.initialDate}}diff --git a/plugins/discourse-calendar/config/locales/server.en.yml b/plugins/discourse-calendar/config/locales/server.en.ymlindex ad67308e9bb..f4102c58682 100644--- a/plugins/discourse-calendar/config/locales/server.en.yml+++ b/plugins/discourse-calendar/config/locales/server.en.yml@@ -57,6 +57,7 @@ en:calendar_automatic_holidays_enabled: "Automatically set holiday status based on a users region (note: you can disable specific automatic holidays in plugin settings)"event_participation_buttons: "List of event participation buttons users can use."sidebar_show_upcoming_events: "Show upcoming events link in the sidebar under 'More'."+ calendar_first_day_of_week: "Set the first day of the week for calendar display. Options are Saturday, Sunday, or Monday."discourse_calendar:invite_user_notification: "%{username} invited you to: %{description}"diff --git a/plugins/discourse-calendar/config/settings.yml b/plugins/discourse-calendar/config/settings.ymlindex 36e5c5151b7..1f20c0bc193 100644--- a/plugins/discourse-calendar/config/settings.yml+++ b/plugins/discourse-calendar/config/settings.yml@@ -113,3 +113,8 @@ discourse_calendar:client: truedefault: ""json_schema: DiscourseCalendar::SiteSettings::MapEventsTitleJsonSchema+ calendar_first_day_of_week:+ type: enum+ enum: "CalendarFirstDayOfWeek"+ default: monday+ client: truediff --git a/plugins/discourse-calendar/lib/calendar_first_day_of_week.rb b/plugins/discourse-calendar/lib/calendar_first_day_of_week.rbnew file mode 100644index 00000000000..090e0ba863d--- /dev/null+++ b/plugins/discourse-calendar/lib/calendar_first_day_of_week.rb@@ -0,0 +1,21 @@+# frozen_string_literal: true++require_dependency "enum_site_setting"++class CalendarFirstDayOfWeek < EnumSiteSetting+ def self.valid_value?(val)+ values.any? { |v| v[:value].to_s == val.to_s }+ end++ def self.values+ @values ||= [+ { name: "user.notification_schedule.saturday", value: "saturday" },+ { name: "user.notification_schedule.sunday", value: "sunday" },+ { name: "user.notification_schedule.monday", value: "monday" },+ ]+ end++ def self.translate_names?+ true+ end+enddiff --git a/plugins/discourse-calendar/plugin.rb b/plugins/discourse-calendar/plugin.rbindex 4f1e194dce9..a0c4a8eca99 100644--- a/plugins/discourse-calendar/plugin.rb+++ b/plugins/discourse-calendar/plugin.rb@@ -11,6 +11,7 @@ libdir = File.join(File.dirname(__FILE__), "vendor/holidays/lib")$LOAD_PATH.unshift(libdir) if $LOAD_PATH.exclude?(libdir)require_relative "lib/calendar_settings_validator.rb"+require_relative "lib/calendar_first_day_of_week.rb"enabled_site_setting :calendar_enableddiff --git a/plugins/discourse-calendar/spec/lib/calendar_first_day_of_week_spec.rb b/plugins/discourse-calendar/spec/lib/calendar_first_day_of_week_spec.rbnew file mode 100644index 00000000000..176264d7712--- /dev/null+++ b/plugins/discourse-calendar/spec/lib/calendar_first_day_of_week_spec.rb@@ -0,0 +1,29 @@+# frozen_string_literal: true++require "rails_helper"++describe SiteSetting do+ before { SiteSetting.calendar_enabled = true }++ it "has the correct default value" do+ expect(SiteSetting.calendar_first_day_of_week).to eq("monday")+ end++ it "accepts valid enum values" do+ expect { SiteSetting.calendar_first_day_of_week = "saturday" }.not_to raise_error+ expect { SiteSetting.calendar_first_day_of_week = "sunday" }.not_to raise_error+ expect { SiteSetting.calendar_first_day_of_week = "monday" }.not_to raise_error+ end++ it "rejects invalid enum values" do+ expect { SiteSetting.calendar_first_day_of_week = "Tuesday" }.to raise_error(+ Discourse::InvalidParameters,+ )+ expect { SiteSetting.calendar_first_day_of_week = "Friday" }.to raise_error(+ Discourse::InvalidParameters,+ )+ expect { SiteSetting.calendar_first_day_of_week = "Invalid" }.to raise_error(+ Discourse::InvalidParameters,+ )+ end+enddiff --git a/plugins/discourse-calendar/spec/system/calendar_first_day_of_week_spec.rb b/plugins/discourse-calendar/spec/system/calendar_first_day_of_week_spec.rbnew file mode 100644index 00000000000..928af552dba--- /dev/null+++ b/plugins/discourse-calendar/spec/system/calendar_first_day_of_week_spec.rb@@ -0,0 +1,55 @@+# frozen_string_literal: true++describe "Calendar first day of week", type: :system do+ fab!(:admin)++ let(:upcoming_events) { PageObjects::Pages::DiscourseCalendar::UpcomingEvents.new }++ before do+ SiteSetting.calendar_enabled = true+ SiteSetting.discourse_post_event_enabled = true+ sign_in(admin)+ end++ context "when default" do+ it "renders monday as the first day" do+ upcoming_events.visit+ upcoming_events.open_month_view++ expect(upcoming_events).to have_first_column_as_monday+ end+ end++ context "when monday" do+ before { SiteSetting.calendar_first_day_of_week = "monday" }++ it "renders monday as the first day" do+ upcoming_events.visit+ upcoming_events.open_month_view++ expect(upcoming_events).to have_first_column_as_monday+ end+ end++ context "when saturday" do+ before { SiteSetting.calendar_first_day_of_week = "saturday" }++ it "renders saturday as the first day" do+ upcoming_events.visit+ upcoming_events.open_month_view++ expect(upcoming_events).to have_first_column_as_saturday+ end+ end++ context "when sunday" do+ before { SiteSetting.calendar_first_day_of_week = "sunday" }++ it "renders sunday as the first day" do+ upcoming_events.visit+ upcoming_events.open_month_view++ expect(upcoming_events).to have_first_column_as_sunday+ end+ end+enddiff --git a/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/upcoming_events.rb b/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/upcoming_events.rbindex c5e88013afd..90328c53ace 100644--- a/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/upcoming_events.rb+++ b/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/upcoming_events.rb@@ -145,6 +145,22 @@ module PageObjectsheight = get_event_height(title)height >= expected_height - 1 && height <= expected_height + 1end++ def first_weekday_header_text+ find(".fc-col-header .fc-col-header-cell:nth-child(1) .fc-col-header-cell-cushion").text+ end++ def has_first_column_as_sunday?+ has_css?(".fc-daygrid-body tr td:nth-child(1).fc-day-sun", minimum: 1)+ end++ def has_first_column_as_saturday?+ has_css?(".fc-daygrid-body tr td:nth-child(1).fc-day-sat", minimum: 1)+ end++ def has_first_column_as_monday?+ has_css?(".fc-daygrid-body tr td:nth-child(1).fc-day-mon", minimum: 1)+ endendendenddiff --git a/plugins/discourse-calendar/spec/system/post_calendar_spec.rb b/plugins/discourse-calendar/spec/system/post_calendar_spec.rbnew file mode 100644index 00000000000..77fccf1fa78--- /dev/null+++ b/plugins/discourse-calendar/spec/system/post_calendar_spec.rb@@ -0,0 +1,31 @@+# frozen_string_literal: true++describe "Post calendar", type: :system do+ fab!(:admin)++ let(:calendar_post) { create_post(user: admin, raw: "[calendar]\n[/calendar]") }++ before do+ Jobs.run_immediately!+ SiteSetting.calendar_enabled = true+ SiteSetting.discourse_post_event_enabled = true+ SiteSetting.holiday_calendar_topic_id = calendar_post.topic.id+ sign_in(admin)+ end++ it "shows the calendar on the post" do+ away_post =+ create_post(+ user: admin,+ topic: calendar_post.topic,+ raw: "Away [date=#{Time.now.strftime("%Y-%m-%d")}]",+ )++ visit(calendar_post.topic.url)++ expect(page).to have_css(+ ".fc-daygrid-event-harness .fc-event-title",+ text: away_post.user.username,+ )+ end+enddiff --git a/plugins/discourse-calendar/spec/system/upcoming_events_spec.rb b/plugins/discourse-calendar/spec/system/upcoming_events_spec.rbindex a382ef1a58c..2612efcb63d 100644--- a/plugins/discourse-calendar/spec/system/upcoming_events_spec.rb+++ b/plugins/discourse-calendar/spec/system/upcoming_events_spec.rb@@ -16,12 +16,18 @@ describe "Upcoming Events", type: :system doenddescribe "basic functionality" do- fab!(:event)+ it "displays events in the calendar", time: Time.utc(2025, 9, 10, 12, 0) do+ post =+ create_post(+ user: admin,+ category: Fabricate(:category),+ title: "A great event to join",+ raw: "[event start=\"2025-09-11 08:05\" end=\"2025-09-11 10:05\"]\n[/event]",+ )- it "displays events in the calendar" doupcoming_events.visit- expect(upcoming_events).to have_content_in_calendar(event.post.topic.title)+ expect(upcoming_events).to have_content_in_calendar(post.topic.title)endend@@ -33,8 +39,9 @@ describe "Upcoming Events", type: :system doit "displays event time in event timezone with (Local time) suffix",timezone: "Australia/Brisbane",time: Time.utc(2025, 9, 10, 12, 0) do- PostCreator.create!(- admin,+ create_post(+ user: admin,+ category: Fabricate(:category),title: "Local time event",raw:"[event showLocalTime=true timezone=CET start=\"2025-09-11 08:05\" end=\"2025-09-11 10:05\"]\n[/event]",@@ -61,8 +68,9 @@ describe "Upcoming Events", type: :system doit "displays event time converted to user timezone",timezone: "Australia/Brisbane",time: Time.utc(2025, 9, 10, 12, 0) do- PostCreator.create!(- admin,+ create_post(+ user: admin,+ category: Fabricate(:category),title: "Event with UTC time",raw:"[event timezone=CET start=\"2025-09-11 19:00\" end=\"2025-09-11 21:00\"]\n[/event]",@@ -85,8 +93,9 @@ describe "Upcoming Events", type: :system dodescribe "with same timezone as user" doit "displays event time normally when event timezone matches user timezone",time: Time.utc(2025, 9, 10, 12, 0) do- PostCreator.create!(- admin,+ create_post(+ user: admin,+ category: Fabricate(:category),title: "Same timezone event",raw:"[event showLocalTime=true timezone=\"America/New_York\" start=\"2025-09-12 08:05\" end=\"2025-09-12 09:05\"]\n[/event]",@@ -112,8 +121,9 @@ describe "Upcoming Events", type: :system doit "displays multiple occurrences with correct local time",timezone: "Australia/Brisbane",time: Time.utc(2025, 9, 10, 12, 0) do- PostCreator.create!(- admin,+ create_post(+ user: admin,+ category: Fabricate(:category),title: "Recurring local event",raw:"[event recurrence=every_week showLocalTime=true timezone=CET start=\"2025-09-11 08:05\" end=\"2025-09-11 10:05\"]\n[/event]",@@ -153,8 +163,9 @@ describe "Upcoming Events", type: :system doit "displays multiple occurrences converted to user timezone",timezone: "Australia/Brisbane",time: Time.utc(2025, 9, 10, 12, 0) do- PostCreator.create!(- admin,+ create_post(+ user: admin,+ category: Fabricate(:category),title: "Recurring UTC event",raw:"[event recurrence=every_week timezone=CET start=\"2025-09-11 19:00\" end=\"2025-09-11 20:00\"]\n[/event]",@@ -199,8 +210,9 @@ describe "Upcoming Events", type: :system doit "displays multiple occurrences without timezone conversion issues",timezone: "Australia/Brisbane",time: Time.utc(2025, 9, 10, 12, 0) do- PostCreator.create!(- admin,+ create_post(+ user: admin,+ category: Fabricate(:category),title: "Recurring same TZ event",raw:"[event recurrence=every_week showLocalTime=true timezone=\"America/New_York\" start=\"2025-09-12 08:05\" end=\"2025-09-12 10:05\"]\n[/event]",@@ -238,38 +250,37 @@ describe "Upcoming Events", type: :system doenddescribe "recurring events" do- fab!(:event)-- before do- event.update!(- original_starts_at: Time.utc(2025, 3, 18, 13, 00),- timezone: "Australia/Brisbane",- recurrence: "every_week",- recurrence_until: 21.days.from_now,- )- end-it "displays recurring events until the specified end date",time: Time.utc(2025, 6, 2, 19, 00) do+ post =+ create_post(+ user: admin,+ category: Fabricate(:category),+ title: "A recurring post event",+ raw:+ "[event recurrenceUntil=\"#{30.days.from_now.iso8601}\" timezone=\"Australia\/Brisbane\" recurrence=\"every_week\" status=\"public\" start=\"2025-06-11 08:05\"]\n[/event]",+ )+upcoming_events.visitupcoming_events.expect_event_count(4)- upcoming_events.expect_event_at_position(event.post.topic.title, row: 2, col: 2)- upcoming_events.expect_event_at_position(event.post.topic.title, row: 3, col: 2)- upcoming_events.expect_event_at_position(event.post.topic.title, row: 4, col: 2)+ upcoming_events.expect_event_at_position(post.topic.title, row: 3, col: 3)+ upcoming_events.expect_event_at_position(post.topic.title, row: 4, col: 3)+ upcoming_events.expect_event_at_position(post.topic.title, row: 5, col: 3)+ upcoming_events.expect_event_at_position(post.topic.title, row: 6, col: 3)endendenddescribe "event filtering" doit "loads the correct range of dates", time: Time.utc(2025, 9, 1, 12, 0) do- post =- PostCreator.create!(- admin,- title: "going to the zoo",- raw:- "[event start=\"2025-09-07 18:30\" status=\"public\" timezone=\"Europe/Prague\" end=\"2025-09-07 21:00\"]\n[/event]",- )+ create_post(+ user: admin,+ category: Fabricate(:category),+ title: "going to the zoo",+ raw:+ "[event start=\"2025-09-07 18:30\" status=\"public\" timezone=\"Europe/Prague\" end=\"2025-09-07 21:00\"]\n[/event]",+ )visit("/upcoming-events/week/2025/9/1")@@ -279,14 +290,16 @@ describe "Upcoming Events", type: :system doit "shows only events the user is attending when filtered",time: Time.utc(2025, 6, 2, 19, 00) doattending_event =- PostCreator.create!(- admin,- title: "attending post event",+ create_post(+ user: admin,+ category: Fabricate(:category),+ title: "Attending post event",raw: "[event status=\"public\" start=\"2025-06-11 08:05\"]\n[/event]",)- PostCreator.create!(- admin,- title: "non attending post event",+ create_post(+ user: admin,+ category: Fabricate(:category),+ title: "Non attending post event",raw: "[event start=\"2025-06-12 08:05\"]\n[/event]",)DiscoursePostEvent::Event.find(attending_event.id).create_invitees(@@ -313,7 +326,7 @@ describe "Upcoming Events", type: :system doupcoming_events.today- upcoming_events.expect_to_be_on_path("/upcoming-events/month/2025/6/2")+ upcoming_events.expect_to_be_on_path("/upcoming-events/month/2025/6/1")endcontext "in different timezone", timezone: "Europe/London" do@@ -429,52 +442,52 @@ describe "Upcoming Events", type: :system docontext "with recurring event" doit "displays longer events with appropriate visual height in time grid view",time: Time.utc(2025, 6, 2, 19, 00) do- short_event_post =- PostCreator.create!(- admin,- title: "Short meeting",- raw:- "[event recurrence=\"every_week\" start=\"2025-06-03 10:00\" end=\"2025-06-03 11:00\"]\n[/event]",- )-- long_event_post =- PostCreator.create!(- admin,- title: "Long workshop",- raw:- "[event recurrence=\"every_week\" start=\"2025-06-03 14:00\" end=\"2025-06-03 17:00\"]\n[/event]",- )+ create_post(+ user: admin,+ category: Fabricate(:category),+ title: "This is a short meeting",+ raw:+ "[event recurrence=\"every_week\" start=\"2025-06-03 10:00\" end=\"2025-06-03 11:00\"]\n[/event]",+ )++ create_post(+ user: admin,+ category: Fabricate(:category),+ title: "This is a long workshop",+ raw:+ "[event recurrence=\"every_week\" start=\"2025-06-03 14:00\" end=\"2025-06-03 17:00\"]\n[/event]",+ )upcoming_events.visitvisit("/upcoming-events/week/2025/6/2")- expect(upcoming_events).to have_event_height("Short meeting", 47)- expect(upcoming_events).to have_event_height("Long workshop", 143)+ expect(upcoming_events).to have_event_height("This is a short meeting", 47)+ expect(upcoming_events).to have_event_height("This is a long workshop", 143)endendcontext "with non recurring event" doit "displays longer events with appropriate visual height in time grid view",time: Time.utc(2025, 6, 2, 19, 00) do- short_event_post =- PostCreator.create!(- admin,- title: "Short meeting",- raw: "[event start=\"2025-06-03 10:00\" end=\"2025-06-03 11:00\"]\n[/event]",- )-- long_event_post =- PostCreator.create!(- admin,- title: "Long workshop",- raw: "[event start=\"2025-06-03 14:00\" end=\"2025-06-03 17:00\"]\n[/event]",- )+ create_post(+ user: admin,+ category: Fabricate(:category),+ title: "This is a short meeting",+ raw: "[event start=\"2025-06-03 10:00\" end=\"2025-06-03 11:00\"]\n[/event]",+ )++ create_post(+ user: admin,+ category: Fabricate(:category),+ title: "This is a long workshop",+ raw: "[event start=\"2025-06-03 14:00\" end=\"2025-06-03 17:00\"]\n[/event]",+ )upcoming_events.visitvisit("/upcoming-events/week/2025/6/2")- expect(upcoming_events).to have_event_height("Short meeting", 47)- expect(upcoming_events).to have_event_height("Long workshop", 143)+ expect(upcoming_events).to have_event_height("This is a short meeting", 47)+ expect(upcoming_events).to have_event_height("This is a long workshop", 143)endendend@@ -487,7 +500,7 @@ describe "Upcoming Events", type: :system doupcoming_events.open_week_viewupcoming_events.expect_content("Sep 15 – 21, 2025")- upcoming_events.expect_to_be_on_path("/upcoming-events/week/2025/9/16")+ upcoming_events.expect_to_be_on_path("/upcoming-events/week/2025/9/15")endendend