From 188270539f02d2504a6b2ac214a10601ba8db8cc Mon Sep 17 00:00:00 2001 From: Jan Cernik <66427541+jancernik@users.noreply.github.com> Date: Fri, 13 Jan 2023 12:12:02 -0300 Subject: [PATCH] FEATURE: Add minimal option to events (#362) It allows hiding the Going/Not going buttons and invitees status --- app/models/discourse_post_event/event.rb | 2 ++ .../discourse_post_event/event_serializer.rb | 1 + .../modal/discourse-post-event-builder.hbs | 9 +++++++++ .../widgets/discourse-post-event-status.js | 8 ++++++-- .../discourse/widgets/discourse-post-event.js | 15 +++++++++------ .../discourse-post-event-decorator.js | 2 +- assets/javascripts/lib/raw-event-helper.js | 4 ++++ .../common/discourse-post-event-builder.scss | 3 ++- config/locales/client.en.yml | 3 +++ ...210225_add_minimal_option_to_calendar_event.rb | 7 +++++++ lib/discourse_post_event/event_parser.rb | 1 + 11 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20221223210225_add_minimal_option_to_calendar_event.rb diff --git a/app/models/discourse_post_event/event.rb b/app/models/discourse_post_event/event.rb index 64e93ef5..73f4bca6 100644 --- a/app/models/discourse_post_event/event.rb +++ b/app/models/discourse_post_event/event.rb @@ -313,6 +313,7 @@ module DiscoursePostEvent reminders: event_params[:reminders], raw_invitees: event_params[:"allowed-groups"] ? event_params[:"allowed-groups"].split(",") : nil, + minimal: event_params[:minimal], } params[:custom_fields] = {} @@ -418,4 +419,5 @@ end # reminders :string # recurrence :string # timezone :string +# minimal :boolean default(FALSE), not null # diff --git a/app/serializers/discourse_post_event/event_serializer.rb b/app/serializers/discourse_post_event/event_serializer.rb index 3e15c07f..0bdca375 100644 --- a/app/serializers/discourse_post_event/event_serializer.rb +++ b/app/serializers/discourse_post_event/event_serializer.rb @@ -26,6 +26,7 @@ module DiscoursePostEvent attributes :is_standalone attributes :reminders attributes :recurrence + attributes :minimal def can_act_on_discourse_post_event scope.can_act_on_discourse_post_event?(object) diff --git a/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs b/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs index 76c77ec5..5e71f5de 100644 --- a/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs +++ b/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs @@ -187,6 +187,15 @@ }} {{/event-field}} + {{#event-field class="minimal-event" label="discourse_post_event.builder_modal.minimal.label"}} + + {{/event-field}} + {{#if allowedCustomFields.length}} {{#event-field label="discourse_post_event.builder_modal.custom_fields.label" diff --git a/assets/javascripts/discourse/widgets/discourse-post-event-status.js b/assets/javascripts/discourse/widgets/discourse-post-event-status.js index cc826237..acebe82e 100644 --- a/assets/javascripts/discourse/widgets/discourse-post-event-status.js +++ b/assets/javascripts/discourse/widgets/discourse-post-event-status.js @@ -13,8 +13,12 @@ export default createWidget("discourse-post-event-status", { }, template: hbs` - {{attach widget="going-button"}} + {{#unless attrs.minimal}} + {{attach widget="going-button"}} + {{/unless}} {{attach widget="interested-button"}} - {{attach widget="not-going-button"}} + {{#unless attrs.minimal}} + {{attach widget="not-going-button"}} + {{/unless}} `, }); diff --git a/assets/javascripts/discourse/widgets/discourse-post-event.js b/assets/javascripts/discourse/widgets/discourse-post-event.js index 9f0af57c..9f9330e9 100644 --- a/assets/javascripts/discourse/widgets/discourse-post-event.js +++ b/assets/javascripts/discourse/widgets/discourse-post-event.js @@ -237,6 +237,7 @@ export default createWidget("discourse-post-event", { widget="discourse-post-event-status" attrs=(hash watchingInvitee=this.state.eventModel.watching_invitee + minimal=this.state.eventModel.minimal ) }} @@ -261,13 +262,15 @@ export default createWidget("discourse-post-event", { ) }} - {{#if state.eventModel.should_display_invitees}} -
+ {{#unless state.eventModel.minimal}} + {{#if state.eventModel.should_display_invitees}} +
- {{attach widget="discourse-post-event-invitees" - attrs=(hash eventModel=state.eventModel) - }} - {{/if}} + {{attach widget="discourse-post-event-invitees" + attrs=(hash eventModel=state.eventModel) + }} + {{/if}} + {{/unless}} {{/if}} `, diff --git a/assets/javascripts/initializers/discourse-post-event-decorator.js b/assets/javascripts/initializers/discourse-post-event-decorator.js index 66fafe01..410ebb71 100644 --- a/assets/javascripts/initializers/discourse-post-event-decorator.js +++ b/assets/javascripts/initializers/discourse-post-event-decorator.js @@ -101,7 +101,7 @@ function _attachWidget(api, cooked, eventModel) { let widgetHeight = datesHeight + headerHeight + bordersHeight + separatorsHeight + margins; - if (eventModel.should_display_invitees) { + if (eventModel.should_display_invitees && !eventModel.minimal) { widgetHeight += 110; } diff --git a/assets/javascripts/lib/raw-event-helper.js b/assets/javascripts/lib/raw-event-helper.js index c40b7db9..aaa5bb08 100644 --- a/assets/javascripts/lib/raw-event-helper.js +++ b/assets/javascripts/lib/raw-event-helper.js @@ -25,6 +25,10 @@ export function buildParams(startsAt, endsAt, eventModel, siteSettings) { params.recurrence = eventModel.recurrence; } + if (eventModel.minimal) { + params.minimal = "true"; + } + if (endsAt) { params.end = moment(endsAt).tz(eventTz).format("YYYY-MM-DD HH:mm"); } diff --git a/assets/stylesheets/common/discourse-post-event-builder.scss b/assets/stylesheets/common/discourse-post-event-builder.scss index 57cb95ff..240873f5 100644 --- a/assets/stylesheets/common/discourse-post-event-builder.scss +++ b/assets/stylesheets/common/discourse-post-event-builder.scss @@ -149,7 +149,8 @@ width: 100%; } - .radio-label { + .radio-label, + .checkbox-label { display: flex; align-items: center; margin-bottom: 1em; diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 46c011de..c6e12ee4 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -411,6 +411,9 @@ en: every_weekday: "Every weekday" every_week: "Every week at this weekday" every_two_weeks: "Every two weeks at this weekday" + minimal: + label: "Minimal event" + checkbox_label: "Hide Going/Not going buttons and invitees status" url: label: "URL" placeholder: "Optional" diff --git a/db/migrate/20221223210225_add_minimal_option_to_calendar_event.rb b/db/migrate/20221223210225_add_minimal_option_to_calendar_event.rb new file mode 100644 index 00000000..56035d47 --- /dev/null +++ b/db/migrate/20221223210225_add_minimal_option_to_calendar_event.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddMinimalOptionToCalendarEvent < ActiveRecord::Migration[7.0] + def change + add_column :discourse_post_event_events, :minimal, :boolean + end +end diff --git a/lib/discourse_post_event/event_parser.rb b/lib/discourse_post_event/event_parser.rb index f43df134..57610386 100644 --- a/lib/discourse_post_event/event_parser.rb +++ b/lib/discourse_post_event/event_parser.rb @@ -10,6 +10,7 @@ VALID_OPTIONS = [ :reminders, :recurrence, :timezone, + :minimal, ] module DiscoursePostEvent