From b9fc1bd60ca2f50107f37cf2c62febfbe421e148 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 22 Oct 2024 20:39:29 +1100 Subject: [PATCH] FEATURE: suppress interested and not going buttons by default (#621) Interested and not going are generally not used. To avoid adding this clutter to the UI we now suppress this. Sites wishing to have these buttons can amend the `event_participation_buttons` site setting Also: - Add a show participants button even if there are no participants (so admins can populate events) - Fix localization for event participation - Allow toggling attendance by pressing the same button - Removes leave event button from the dropdown menu - Refactors outlets to allow maximum flexibility --------- Co-authored-by: Joffrey JAFFEUX --- .../discourse-post-event/creator.gjs | 17 +- .../components/discourse-post-event/dates.gjs | 2 +- .../discourse-post-event/event-status.gjs | 36 ++++ .../components/discourse-post-event/index.gjs | 131 ++++--------- .../discourse-post-event/invitees.gjs | 94 ++++++---- .../discourse-post-event/more-menu.gjs | 59 +++--- .../discourse-post-event/status.gjs | 175 +++++++++++++----- .../components/discourse-post-event/url.gjs | 24 +-- .../common/discourse-post-event.scss | 45 ++++- config/locales/client.en.yml | 13 ++ config/locales/server.en.yml | 1 + config/settings.yml | 10 + 12 files changed, 363 insertions(+), 244 deletions(-) create mode 100644 assets/javascripts/discourse/components/discourse-post-event/event-status.gjs diff --git a/assets/javascripts/discourse/components/discourse-post-event/creator.gjs b/assets/javascripts/discourse/components/discourse-post-event/creator.gjs index 5810e25dd..f115873d1 100644 --- a/assets/javascripts/discourse/components/discourse-post-event/creator.gjs +++ b/assets/javascripts/discourse/components/discourse-post-event/creator.gjs @@ -1,6 +1,7 @@ import Component from "@glimmer/component"; import avatar from "discourse/helpers/avatar"; import { formatUsername } from "discourse/lib/utilities"; +import i18n from "discourse-common/helpers/i18n"; export default class DiscoursePostEventCreator extends Component { get username() { @@ -8,11 +9,17 @@ export default class DiscoursePostEventCreator extends Component { } } diff --git a/assets/javascripts/discourse/components/discourse-post-event/dates.gjs b/assets/javascripts/discourse/components/discourse-post-event/dates.gjs index 7032b0fed..2fde3e7e0 100644 --- a/assets/javascripts/discourse/components/discourse-post-event/dates.gjs +++ b/assets/javascripts/discourse/components/discourse-post-event/dates.gjs @@ -77,7 +77,7 @@ export default class DiscoursePostEventDates extends Component { diff --git a/assets/javascripts/discourse/components/discourse-post-event/event-status.gjs b/assets/javascripts/discourse/components/discourse-post-event/event-status.gjs new file mode 100644 index 000000000..86d95899b --- /dev/null +++ b/assets/javascripts/discourse/components/discourse-post-event/event-status.gjs @@ -0,0 +1,36 @@ +import Component from "@glimmer/component"; +import i18n from "discourse-common/helpers/i18n"; + +export default class EventStatus extends Component { + get eventStatusLabel() { + return i18n( + `discourse_calendar.discourse_post_event.models.event.status.${this.args.event.status}.title` + ); + } + + get eventStatusDescription() { + return i18n( + `discourse_calendar.discourse_post_event.models.event.status.${this.args.event.status}.description` + ); + } + + get statusClass() { + return `status ${this.args.event.status}`; + } + + +} diff --git a/assets/javascripts/discourse/components/discourse-post-event/index.gjs b/assets/javascripts/discourse/components/discourse-post-event/index.gjs index 63cfbb7c9..9c0c9c768 100644 --- a/assets/javascripts/discourse/components/discourse-post-event/index.gjs +++ b/assets/javascripts/discourse/components/discourse-post-event/index.gjs @@ -1,22 +1,32 @@ import Component from "@glimmer/component"; import { hash } from "@ember/helper"; import { service } from "@ember/service"; -import { htmlSafe } from "@ember/template"; import { modifier } from "ember-modifier"; import PluginOutlet from "discourse/components/plugin-outlet"; import concatClass from "discourse/helpers/concat-class"; import routeAction from "discourse/helpers/route-action"; import { emojiUnescape } from "discourse/lib/text"; import { escapeExpression } from "discourse/lib/utilities"; -import i18n from "discourse-common/helpers/i18n"; +import icon from "discourse-common/helpers/d-icon"; import Creator from "./creator"; import Dates from "./dates"; +import EventStatus from "./event-status"; import Invitees from "./invitees"; import MoreMenu from "./more-menu"; import Status from "./status"; import Url from "./url"; -const Separator = ; +const StatusSeparator = ; + +const InfoSection = ; export default class DiscoursePostEvent extends Component { @service currentUser; @@ -34,18 +44,6 @@ export default class DiscoursePostEvent extends Component { return () => this.messageBus.unsubscribe(path); }); - get eventStatusLabel() { - return i18n( - `discourse_calendar.discourse_post_event.models.event.status.${this.args.event.status}.title` - ); - } - - get eventStatusDescription() { - return i18n( - `discourse_calendar.discourse_post_event.models.event.status.${this.args.event.status}.description` - ); - } - get startsAtMonth() { return moment(this.args.event.startsAt).format("MMM"); } @@ -60,10 +58,6 @@ export default class DiscoursePostEvent extends Component { ); } - get statusClass() { - return `status ${this.args.event.status}`; - } - get isPublicEvent() { return this.args.event.status === "public"; } @@ -76,39 +70,12 @@ export default class DiscoursePostEvent extends Component { return this.currentUser && this.args.event.can_act_on_discourse_post_event; } - get containerHeight() { - const datesHeight = 50; - const urlHeight = 50; - const headerHeight = 75; - const bordersHeight = 10; - const separatorsHeight = 4; - const margins = 10; - - let widgetHeight = - datesHeight + headerHeight + bordersHeight + separatorsHeight + margins; - - if (this.args.event.shouldDisplayInvitees && !this.args.event.minimal) { - widgetHeight += 110; - } - - if (this.args.event.canUpdateAttendance) { - widgetHeight += 60; - } - - if (this.args.event.url) { - widgetHeight += urlHeight; - } - - return htmlSafe(`height: ${widgetHeight}px`); - } - diff --git a/assets/javascripts/discourse/components/discourse-post-event/url.gjs b/assets/javascripts/discourse/components/discourse-post-event/url.gjs index 278e88873..0ce02faaa 100644 --- a/assets/javascripts/discourse/components/discourse-post-event/url.gjs +++ b/assets/javascripts/discourse/components/discourse-post-event/url.gjs @@ -9,16 +9,18 @@ export default class DiscoursePostEventUrl extends Component { } } diff --git a/assets/stylesheets/common/discourse-post-event.scss b/assets/stylesheets/common/discourse-post-event.scss index aed0181dd..4bdee323e 100644 --- a/assets/stylesheets/common/discourse-post-event.scss +++ b/assets/stylesheets/common/discourse-post-event.scss @@ -3,6 +3,30 @@ $interested: #fb985d; .discourse-post-event { display: flex; + .event__section { + padding: 0.5em 1em; + + &:not(:last-child) { + border-bottom: 1px solid var(--primary-low); + } + + &:first-child { + border-top: 1px solid var(--primary-low); + } + + p { + margin: 0; + } + + > .d-icon { + padding-right: 0.25em; + } + + .discourse-local-date .d-icon { + padding-right: 0.25em; + } + } + .discourse-post-event-widget { border: 5px solid var(--primary-low); display: flex; @@ -175,8 +199,6 @@ $interested: #fb985d; .event-invitees { display: flex; - height: 110px; - padding: 0 1em; align-items: flex-start; justify-content: center; overflow-y: auto; @@ -195,9 +217,14 @@ $interested: #fb985d; .event-invitees-status { font-weight: 700; - - .invited { - font-weight: 500; + display: flex; + span:not(:last-child)::after { + content: "-"; + font-weight: 400; + margin: 0 0.3em; + } + .event-status-invited { + font-weight: 600; color: var(--primary-medium); } } @@ -269,9 +296,6 @@ $interested: #fb985d; .event-dates { display: flex; align-items: center; - padding: 0 1em; - height: 50px; - flex: 1; .d-icon { color: var(--primary-high); @@ -280,13 +304,16 @@ $interested: #fb985d; .event-url { .url { - margin-left: 1em; max-width: 80%; @include ellipsis; } } .event-dates { + // hardcoded as cooking date is async and will change height after initial rendering otherwise + // not ideal but a decent low tech solution + height: 24px; + .participants { margin-left: 0.5em; color: var(--primary-medium); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 85152b8bd..aeb448f3f 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -336,6 +336,18 @@ en: going: "Going" not_going: "Not Going" interested: "Interested" + going_count: + one: "%{count} going" + other: "%{count} going" + not_going_count: + one: "%{count} not going" + other: "%{count} not going" + interested_count: + one: "%{count} interested" + other: "%{count} interested" + invited_count: + one: "%{count} user invited" + other: "%{count} users invited" event: expired: "Expired" closed: "Closed" @@ -351,6 +363,7 @@ en: description: "A private event can only be joined by invited users." event_ui: show_all: "Show all" + show_participants: "Show participants" participants: one: "%{count} user participated." other: "%{count} users participated." diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 9e7424004..dee98cd61 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -55,6 +55,7 @@ en: sort_categories_by_event_start_date_enabled: "Enable the sorting of category topics by event start date." disable_resorting_on_categories_enabled: "Allow categories to disable the ability for users to sort on the event category." 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'." include_expired_events_on_calendar: "Include past/expired events on Category Calendar and Upcoming Events views." discourse_calendar: diff --git a/config/settings.yml b/config/settings.yml index 4fd08a67b..9ded4eede 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -59,6 +59,16 @@ discourse_calendar: default: false client: true hidden: true + event_participation_buttons: + default: "going" + client: true + type: list + list_type: simple + allow_any: false + choices: + - going + - interested + - not going discourse_post_event_enabled: default: false client: true