Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Use event category's color for calendar event #441

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/serializers/discourse_post_event/event_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class EventSerializer < ApplicationSerializer
attributes :reminders
attributes :recurrence
attributes :minimal
attributes :category_color

def can_act_on_discourse_post_event
scope.can_act_on_discourse_post_event?(object)
Expand Down Expand Up @@ -128,5 +129,9 @@ def should_display_invitees
(object.public? && object.invitees.count > 0) ||
(object.private? && object.raw_invitees.count > 0)
end

def category_color
object.post.topic.category.color
nattsw marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default Component.extend({
end: ends_at || starts_at,
allDay: !isNotFullDayEvent(moment(starts_at), moment(ends_at)),
url: getURL(`/t/-/${post.topic.id}/${post.post_number}`),
backgroundColor: `#${event.category_color}`,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function initializeDiscourseCalendar(api) {
end: ends_at || starts_at,
allDay: !isNotFullDayEvent(moment(starts_at), moment(ends_at)),
url: getURL(`/t/-/${post.topic.id}/${post.post_number}`),
backgroundColor: `#${browsedCategory.color}`,
});
});

Expand Down
1 change: 0 additions & 1 deletion assets/stylesheets/common/upcoming-events-calendar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
.fc-event,
.fc-event-dot {
color: var(--secondary);
background-color: var(--tertiary);
border: 1px solid transparent;

.fc-time {
Expand Down
42 changes: 27 additions & 15 deletions spec/serializers/discourse_post_event/event_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,42 @@
SiteSetting.discourse_post_event_enabled = true
end

let(:post_1) { Fabricate(:post) }
let(:event_1) { Fabricate(:event, post: post_1, status: Event.statuses[:private]) }
let(:invitee_1) { Fabricate(:user) }
let(:invitee_2) { Fabricate(:user) }
let(:group_1) do
Fabricate(:group).tap do |g|
g.add(invitee_1)
g.add(invitee_2)
g.save!
end
end
fab!(:category) { Fabricate(:category, color: "b878e2") }
fab!(:topic) { Fabricate(:topic, category: category) }
fab!(:post) { Fabricate(:post, topic: topic) }

context "with a private event" do
fab!(:private_event) { Fabricate(:event, post: post, status: Event.statuses[:private]) }
fab!(:invitee_1) { Fabricate(:user) }
fab!(:invitee_2) { Fabricate(:user) }
fab!(:group_1) do
Fabricate(:group).tap do |g|
g.add(invitee_1)
g.add(invitee_2)
g.save!
end
end

context "when some invited users have not rsvp-ed yet" do
before do
event_1.update_with_params!(raw_invitees: [group_1.name])
Invitee.create_attendance!(invitee_1.id, event_1.id, :going)
event_1.reload
private_event.update_with_params!(raw_invitees: [group_1.name])
Invitee.create_attendance!(invitee_1.id, private_event.id, :going)
private_event.reload
end

it "returns the correct stats" do
json = EventSerializer.new(event_1, scope: Guardian.new).as_json
json = EventSerializer.new(private_event, scope: Guardian.new).as_json
expect(json[:event][:stats]).to eq(going: 1, interested: 0, invited: 2, not_going: 0)
end
end
end

context "with a public event" do
fab!(:event) { Fabricate(:event, post: post) }

it "returns the event category's color" do
json = EventSerializer.new(event, scope: Guardian.new).as_json
expect(json[:event][:category_color]).to eq(category.color)
end
end
end