Skip to content

Commit a412d13

Browse files
authored
Update event show and tests (#535)
1 parent 11d8abd commit a412d13

File tree

6 files changed

+318
-83
lines changed

6 files changed

+318
-83
lines changed

app/controllers/events_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def index
88
end
99

1010
def show
11+
@event = @event.decorate
1112
end
1213

1314
def new # all logged in users can create events
@@ -16,7 +17,6 @@ def new # all logged in users can create events
1617
end
1718

1819
def edit
19-
@event = @event.decorate
2020
set_form_variables
2121
unless @event.created_by == current_user || current_user.super_user?
2222
redirect_to events_path, alert: "You are not authorized to edit this event."
@@ -64,6 +64,7 @@ def destroy
6464
private
6565

6666
def set_form_variables
67+
@event = @event.decorate
6768
@event.build_main_image if @event.main_image.blank?
6869
@event.gallery_images.build
6970
end

app/views/events/show.html.erb

Lines changed: 107 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,126 @@
1-
<div class="detail py-6 min-h-screen">
2-
<div class="max-w-5xl mx-auto px-4">
3-
4-
<div class="flex justify-end mb-6">
5-
<%= link_to("Index", events_path, class: "btn btn-secondary-outline") %>
6-
<% if current_user.super_user? %>
7-
<%= link_to("Edit", edit_event_path(@event), class: "btn btn-primary-outline") %>
8-
<% end %>
9-
</div>
10-
<div class="max-w-3xl mx-auto bg-white border border-gray-200 rounded-xl shadow p-6">
11-
<div class="header-row flex justify-between items-center">
12-
<div class="text-left">
13-
<div class="pt-4 mb-4">Event Details</div>
14-
</div>
1+
<div class="min-h-screen py-8">
2+
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
3+
4+
<!-- Outer Soft Container (Events = blue theme) -->
5+
<div class="bg-blue-50 border border-gray-200 rounded-xl shadow-md hover:shadow-lg transition-shadow duration-200 p-6">
6+
7+
<!-- Top Right Actions -->
8+
<div class="text-right mb-4 space-x-2">
9+
<%= link_to "Index", events_path, class: "btn btn-secondary-outline" %>
1510

16-
<div>
11+
<% if current_user.super_user? %>
12+
<%= link_to "Edit", edit_event_path(@event),
13+
class: "btn btn-secondary-outline admin-only bg-blue-100" %>
14+
<% end %>
15+
16+
<span class="inline-block">
1717
<%= render "bookmarks/editable_bookmark_button", resource: @event %>
18-
</div>
18+
</span>
1919
</div>
2020

21-
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-3">
22-
<div>
23-
<%= title_with_badges(@event) %>
24-
</div>
25-
</div>
21+
<!-- Inner White Card -->
22+
<div class="bg-white rounded-lg shadow p-8">
2623

27-
<div class="images">
28-
<!-- Hero Image -->
29-
<% if @event.main_image&.file&.attached? %>
30-
<div class="mb-8">
31-
<%= image_tag @event.main_image.file,
32-
class: "w-full rounded-lg shadow-sm border border-gray-200",
33-
alt: @event.title %>
34-
</div>
35-
<% end %>
24+
<div class="grid grid-cols-1 md:grid-cols-5 gap-10">
25+
26+
<!-- Left Column -->
27+
<div class="md:col-span-3">
28+
29+
<!-- Title + Badges -->
30+
<div class="my-3">
31+
<%= title_with_badges(@event, font_size: "text-3xl") %>
32+
</div>
33+
34+
<!-- Dates Section -->
35+
<div class="space-y-6">
36+
37+
<div class="">
38+
<%= @event.times(display_day: true, display_date: true) %>
39+
</div>
3640

37-
<!-- Gallery Images -->
38-
<% if @event.gallery_images.any? { |img| img.persisted? && img.file.attached? } %>
39-
<div class="event-gallery single-event-detail text-center mb-4">
40-
<div class="flex flex-wrap justify-center gap-4 mx-auto max-w-3xl">
41-
<% @event.gallery_images.each_with_index do |gallery_image, idx| %>
42-
<% if gallery_image.file&.attached? %>
43-
<%= image_tag url_for(gallery_image.file),
44-
alt: "Gallery Image #{idx + 1}",
45-
data: { file_preview_target: "preview" },
46-
class: "w-32 h-32 object-cover border border-gray-300 shadow-sm" %>
41+
<div class="registration-section flex flex-col gap-4 mb-6">
42+
<!-- ⭐ BUTTONS -->
43+
<div class="flex flex-wrap items-center gap-3">
44+
<% registered = @event.event_registrations.exists?(registrant_id: current_user.id) %>
45+
46+
<% if registered %>
47+
<%= button_to "De-register",
48+
event_registrant_registration_path(event_id: @event),
49+
method: :delete,
50+
data: { turbo_confirm: "Are you sure?" },
51+
class: "btn btn-secondary-outline" %>
52+
53+
<% elsif @event.registerable? %>
54+
<%= button_to "Register",
55+
event_registrant_registration_path(event_id: @event),
56+
class: "btn btn-primary-outline" %>
57+
<% else %>
58+
<span class="text-sm text-gray-500 italic">Registration closed</span>
59+
<% end %>
60+
61+
<% if registered %>
62+
<span class="text-xs bg-green-100 text-green-700 px-2 py-0.5 rounded-full">
63+
You are registered!
64+
</span>
65+
<% end %>
66+
</div>
67+
68+
<!-- ⭐ CALENDAR LINKS -->
69+
<% if registered %>
70+
<div class="flex gap-2 items-center text-sm text-gray-700">
71+
<%= @event.calendar_links %>
72+
</div>
4773
<% end %>
74+
75+
</div>
76+
77+
<% if @event.registration_close_date %>
78+
<div>
79+
<p class="font-semibold text-gray-700">Registration Close Date</p>
80+
<p class="text-gray-900">
81+
<%= @event.registration_close_date&.strftime("%B %d, %Y %l:%M %P") || "—" %>
82+
</p>
83+
</div>
4884
<% end %>
85+
4986
</div>
5087
</div>
51-
<% end %>
52-
</div>
5388

54-
<div class="mb-3">
55-
<p class="font-bold text-gray-700">Description:</p>
56-
<p class="text-gray-900"><%= @event.description.presence || "—" %></p>
57-
</div>
89+
<!-- Right Column -->
90+
<div class="md:col-span-2 space-y-6">
5891

59-
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-3">
60-
<div>
61-
<p class="font-bold text-gray-700">Start Date:</p>
62-
<p class="text-gray-900"><%= @event.start_date&.strftime("%B %d, %Y %l:%M %p") || "—" %></p>
63-
</div>
92+
<!-- Main Image Hero Image -->
93+
<% if @event.main_image&.file&.attached? %>
94+
<div>
95+
<%= image_tag @event.main_image.file,
96+
class: "w-full rounded-lg shadow-sm border border-gray-200",
97+
alt: @event.main_image.file.blob.filename.to_s %>
98+
</div>
99+
<% end %>
64100

65-
<div>
66-
<p class="font-bold text-gray-700">End Date:</p>
67-
<p class="text-gray-900"><%= @event.end_date&.strftime("%B %d, %Y %l:%M %p") || "—" %></p>
101+
<!-- Gallery Image Thumbnails -->
102+
<% if @event.gallery_images.any? { |img| img.persisted? && img.file.attached? } %>
103+
<div class="flex flex-wrap justify-start gap-3">
104+
<% @event.gallery_images.each_with_index do |gallery_image, idx| %>
105+
<% if gallery_image.file&.attached? %>
106+
<%= image_tag url_for(gallery_image.file),
107+
alt: "Gallery Image #{idx + 1}: #{gallery_image.file.blob.filename.to_s}",
108+
class: "w-24 h-24 object-cover rounded border shadow-sm" %>
109+
<% end %>
110+
<% end %>
111+
</div>
112+
<% end %>
113+
114+
</div>
68115
</div>
69116

70-
<div class="md:col-span-2">
71-
<p class="font-bold text-gray-700">Registration Close Date:</p>
72-
<p class="text-gray-900"><%= @event.registration_close_date&.strftime("%B %d, %Y %l:%M %p") || "—" %></p>
117+
<!-- FULL-WIDTH DESCRIPTION -->
118+
<div class="mt-6 md:col-span-5">
119+
<p class="text-gray-900 leading-relaxed">
120+
<%= @event.description.presence || "—" %>
121+
</p>
73122
</div>
123+
74124
</div>
75125
</div>
76126
</div>

spec/factories/events.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,27 @@
22
factory :event do
33
title { "sample title" }
44
description { "sample description" }
5-
start_date { 1.day.from_now }
6-
end_date { 2.days.from_now }
7-
registration_close_date { 3.days.ago }
5+
start_date { 12.day.from_now }
6+
end_date { 14.days.from_now }
7+
registration_close_date { 13.days.from_now }
88
publicly_visible { true }
9+
10+
trait :registration_closed do
11+
after(:build) do |event|
12+
event.registration_close_date = 13.days.ago
13+
end
14+
end
15+
16+
trait :main_image_with_file do
17+
after(:build) do |event|
18+
event.main_image = build(:image, :with_file, owner: event)
19+
end
20+
end
21+
22+
trait :gallery_image_with_file do
23+
after(:build) do |event|
24+
event.gallery_images << build(:image, :with_file, owner: event)
25+
end
26+
end
927
end
1028
end

spec/factories/images.rb

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,30 @@
22
factory :image do
33
association :owner, factory: :user
44

5-
association :report
5+
# Default to no type -- must use a trait
66

7-
file_file_name { "test.jpg" }
8-
file_content_type { "image/jpeg" }
9-
file_file_size { 1024 }
10-
file_updated_at { Time.zone.now }
7+
# --- Traits for type-specific subclasses ---
8+
factory :main_image, class: "Images::MainImage"
9+
factory :gallery_image, class: "Images::GalleryImage"
10+
11+
trait :with_file do
12+
after(:build) do |image|
13+
image.file.attach(
14+
io: File.open(Rails.root.join("app", "assets", "images", "missing.png")),
15+
filename: "missing.png",
16+
content_type: "image/png"
17+
)
18+
end
19+
end
1120

1221
trait :invalid_format do
13-
file_content_type { "image/webp" }
14-
file_file_name { "invalid.webp" }
22+
after(:build) do |image|
23+
image.file.attach(
24+
io: File.open(Rails.root.join("app", "assets", "images", "invalid.webp")),
25+
filename: "invalid.webp",
26+
content_type: "image/webp"
27+
)
28+
end
1529
end
1630
end
17-
end
31+
end

0 commit comments

Comments
 (0)