From 09583aa7dd055d8424b166d3c22f61a505dfb64f Mon Sep 17 00:00:00 2001 From: Renato Atilio Date: Fri, 20 Oct 2023 06:34:06 -0300 Subject: [PATCH] FEATURE: add a "none" option to avoid showing the category calendar on any outlet (#459) --- .../category-calendar.gjs | 13 ++ .../category-calendar.hbs | 1 - .../category-calendar.js | 7 - .../category-calendar.hbs | 0 .../category-calendar.js | 8 - .../category-events-calendar.gjs | 14 ++ .../category-events.hbs | 1 - config/settings.yml | 1 + .../category-events-calendar-outlet-test.js | 145 ++++++++++++++++++ 9 files changed, 173 insertions(+), 17 deletions(-) create mode 100644 assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.gjs delete mode 100644 assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.hbs delete mode 100644 assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.js delete mode 100644 assets/javascripts/discourse/connectors/discovery-list-container-top/category-calendar.hbs delete mode 100644 assets/javascripts/discourse/connectors/discovery-list-container-top/category-calendar.js create mode 100644 assets/javascripts/discourse/connectors/discovery-list-container-top/category-events-calendar.gjs delete mode 100644 assets/javascripts/discourse/connectors/discovery-list-container-top/category-events.hbs create mode 100644 test/javascripts/acceptance/category-events-calendar-outlet-test.js diff --git a/assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.gjs b/assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.gjs new file mode 100644 index 00000000..ff982b81 --- /dev/null +++ b/assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.gjs @@ -0,0 +1,13 @@ +import Component from "@glimmer/component"; + +export default class CategoryCalendar extends Component { + static shouldRender(_, ctx) { + return ( + ctx.siteSettings.calendar_categories_outlet === "before-topic-list-body" + ); + } + + +} diff --git a/assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.hbs b/assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.hbs deleted file mode 100644 index f38bef49..00000000 --- a/assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.hbs +++ /dev/null @@ -1 +0,0 @@ -
\ No newline at end of file diff --git a/assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.js b/assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.js deleted file mode 100644 index bbfa4ccf..00000000 --- a/assets/javascripts/discourse/connectors/before-topic-list-body/category-calendar.js +++ /dev/null @@ -1,7 +0,0 @@ -export default { - shouldRender(_, ctx) { - return ( - ctx.siteSettings.calendar_categories_outlet === "before-topic-list-body" - ); - }, -}; diff --git a/assets/javascripts/discourse/connectors/discovery-list-container-top/category-calendar.hbs b/assets/javascripts/discourse/connectors/discovery-list-container-top/category-calendar.hbs deleted file mode 100644 index e69de29b..00000000 diff --git a/assets/javascripts/discourse/connectors/discovery-list-container-top/category-calendar.js b/assets/javascripts/discourse/connectors/discovery-list-container-top/category-calendar.js deleted file mode 100644 index bce52074..00000000 --- a/assets/javascripts/discourse/connectors/discovery-list-container-top/category-calendar.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - shouldRender(_, ctx) { - return ( - ctx.siteSettings.calendar_categories_outlet === - "discovery-list-container-top" - ); - }, -}; diff --git a/assets/javascripts/discourse/connectors/discovery-list-container-top/category-events-calendar.gjs b/assets/javascripts/discourse/connectors/discovery-list-container-top/category-events-calendar.gjs new file mode 100644 index 00000000..86bb2100 --- /dev/null +++ b/assets/javascripts/discourse/connectors/discovery-list-container-top/category-events-calendar.gjs @@ -0,0 +1,14 @@ +import Component from "@glimmer/component"; + +export default class CategoryEventsCalendar extends Component { + static shouldRender(_, ctx) { + return ( + ctx.siteSettings.calendar_categories_outlet === + "discovery-list-container-top" + ); + } + + +} diff --git a/assets/javascripts/discourse/connectors/discovery-list-container-top/category-events.hbs b/assets/javascripts/discourse/connectors/discovery-list-container-top/category-events.hbs deleted file mode 100644 index e5f9000b..00000000 --- a/assets/javascripts/discourse/connectors/discovery-list-container-top/category-events.hbs +++ /dev/null @@ -1 +0,0 @@ -
\ No newline at end of file diff --git a/config/settings.yml b/config/settings.yml index 05b05dce..f78dd38f 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -29,6 +29,7 @@ discourse_calendar: default: "discovery-list-container-top" type: enum choices: + - none - discovery-list-container-top - before-topic-list-body working_days: diff --git a/test/javascripts/acceptance/category-events-calendar-outlet-test.js b/test/javascripts/acceptance/category-events-calendar-outlet-test.js new file mode 100644 index 00000000..ca7ee40a --- /dev/null +++ b/test/javascripts/acceptance/category-events-calendar-outlet-test.js @@ -0,0 +1,145 @@ +import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers"; +import { test } from "qunit"; +import { visit } from "@ember/test-helpers"; + +const eventsPretender = (server, helper) => { + server.get("/discourse-post-event/events.json", () => { + return helper.response({ + events: [ + { + id: 67501, + creator: { + id: 1500588, + username: "foobar", + name: null, + avatar_template: "/user_avatar/localhost/foobar/{size}/1913_2.png", + assign_icon: "user-plus", + assign_path: "/u/foobar/activity/assigned", + }, + sample_invitees: [], + watching_invitee: null, + starts_at: "2022-04-25T15:14:00.000Z", + ends_at: "2022-04-30T16:14:00.000Z", + timezone: "Asia/Calcutta", + stats: { + going: 0, + interested: 0, + not_going: 0, + invited: 0, + }, + status: "public", + raw_invitees: ["trust_level_0"], + post: { + id: 67501, + post_number: 1, + url: "/t/this-is-an-event/18449/1", + topic: { + id: 18449, + title: "This is an event", + }, + }, + name: "Awesome Event", + can_act_on_discourse_post_event: true, + can_update_attendance: true, + is_expired: false, + is_ongoing: false, + should_display_invitees: false, + url: null, + custom_fields: {}, + is_public: true, + is_private: false, + is_standalone: false, + reminders: [], + recurrence: null, + }, + ], + }); + }); +}; + +acceptance( + "Discourse Calendar - Category Events Calendar Outlet None", + function (needs) { + needs.user(); + needs.settings({ + calendar_enabled: true, + discourse_post_event_enabled: true, + events_calendar_categories: "1", + calendar_categories: "", + calendar_categories_outlet: "none", + }); + + needs.pretender(eventsPretender); + + test("don't display calendars if outlet option is none", async (assert) => { + await visit("/c/bug/1"); + + assert.notOk( + exists("#category-events-calendar"), + "Category Events calendar div does not exist" + ); + + assert.notOk( + exists(".category-calendar"), + "Category calendar div does not exist." + ); + }); + } +); + +acceptance( + "Discourse Calendar - Category Events Calendar Outlet Container Top", + function (needs) { + needs.user(); + needs.settings({ + calendar_enabled: true, + discourse_post_event_enabled: true, + events_calendar_categories: "1", + calendar_categories: "", + calendar_categories_outlet: "discovery-list-container-top", + }); + + needs.pretender(eventsPretender); + + test("display the specific calendar for the discovery-list-container-top outlet", async (assert) => { + await visit("/c/bug/1"); + + assert.ok( + exists("#category-events-calendar"), + "Category Events calendar div exists" + ); + + assert.notOk( + exists(".category-calendar"), + "Category calendar div does not exist." + ); + }); + } +); + +acceptance( + "Discourse Calendar - Category Events Calendar Outlet Container Before Topic List", + function (needs) { + needs.user(); + needs.settings({ + calendar_enabled: true, + discourse_post_event_enabled: true, + events_calendar_categories: "1", + calendar_categories: "", + calendar_categories_outlet: "before-topic-list-body", + }); + + needs.pretender(eventsPretender); + + test("display the specific calendar for before-topic-list-body outlet", async (assert) => { + await visit("/c/bug/1"); + + assert.notOk( + exists("#category-events-calendar"), + "Category Events calendar div does not exist" + ); + + assert.ok(exists(".category-calendar"), "Category calendar div exists."); + }); + } +);