Skip to content

Commit 3073e20

Browse files
committed
Add registration url to events
1 parent fa1d6fd commit 3073e20

File tree

9 files changed

+91
-79
lines changed

9 files changed

+91
-79
lines changed

app/models/better_together/category.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class Category < ApplicationRecord # rubocop:todo Style/Documentation
2222
validates :type, presence: true
2323

2424
def self.permitted_attributes(id: false, destroy: false)
25-
super + [
26-
:type, :icon
25+
super + %i[
26+
type icon
2727
]
2828
end
2929

app/models/better_together/event.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Event < ApplicationRecord
2828
translates :description, backend: :action_text
2929

3030
validates :name, presence: true
31+
validates :registration_url, format: { with: URI::DEFAULT_PARSER.make_regexp(%w[http https]) }, allow_blank: true,
32+
allow_nil: true
3133

3234
scope :draft, lambda {
3335
start_query = arel_table[:starts_at].eq(nil)
@@ -46,7 +48,7 @@ class Event < ApplicationRecord
4648

4749
def self.permitted_attributes(id: false, destroy: false)
4850
super + %i[
49-
starts_at ends_at
51+
starts_at ends_at registration_url
5052
] + [
5153
{
5254
address_attributes: BetterTogether::Address.permitted_attributes(id: true)

app/models/better_together/event_category.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# frozen_string_literal: true
2+
13
module BetterTogether
4+
# Categories specifically for events
25
class EventCategory < Category
36
has_many :events, through: :categorizations, source: :categorizable, source_type: 'BetterTogether::Event'
47
end

app/views/better_together/events/_form.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@
7878
<%= form.select :category_ids, options_from_collection_for_select(resource_class.category_class_name.constantize.positioned.all.includes(:string_translations), :id, :name, event.category_ids), { include_blank: true, multiple: true }, class: 'form-select', data: { controller: 'better_together--slim_select' } %>
7979
<small class="form-text text-muted"><%= t('hints.categories.select_multiple') %></small>
8080
</div>
81+
82+
<div class="col mb-3 pb-3 border-bottom">
83+
<%= required_label form, :registration_url, class: "form-label" %>
84+
<%= form.url_field :registration_url, class: 'form-control' %>
85+
</div>
8186
</div>
8287

8388
<div class="row">

app/views/better_together/events/show.html.erb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
<!-- Person About Section -->
6363
<section id="about" class="row collapse show" aria-labelledby="about-tab" aria-expanded="true" data-bs-parent="#platformTabs">
6464
<div class="col-md-12">
65+
<div class="event-datetime card-text text-muted mt-2">
66+
<i class="fas fa-eye me-2"></i> <%= @event.privacy.humanize %>
67+
</div>
6568
<% if @event.location&.name&.present? %>
6669
<div class="event-location card-text text-muted mt-2">
6770
<i class="fas fa-map-marker-alt me-2"></i> <%= @event.location %>
@@ -72,12 +75,20 @@
7275
<i class="fas fa-calendar-alt me-2"></i> <%= l(@event.starts_at, format: :event) %>
7376
</div>
7477
<% end %>
75-
<%= categories_badge(@event) %>
76-
<div class="event-datetime card-text text-muted mt-2">
77-
<i class="fas fa-eye me-2"></i> <%= @event.privacy.humanize %>
78-
</div>
78+
<% if @event.registration_url.present? %>
79+
<div class="event-datetime card-text text-muted mt-2">
80+
<i class="fas fa-ticket me-2"></i> <%= link_to t('better_together.events.register'), @event.registration_url, target: '_blank', class: 'text-decoration-none' %>
81+
</div>
82+
<% end %>
83+
84+
<% if @event.categories.any? %>
85+
<div class="event-categories mt-2">
86+
<%= categories_badge(@event) %>
87+
</div>
88+
<% end %>
89+
7990
<!-- Description Section -->
80-
<p class="card-text text-muted">
91+
<p class="card-text mt-3 text-muted">
8192
<%= @resource.description.presence || 'No description available.' %>
8293
</p>
8394
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
# Adds an optional registration url for events
4+
class AddRegistrationUrlToBetterTogetherEvents < ActiveRecord::Migration[7.1]
5+
def change
6+
change_table :better_together_events do |t|
7+
t.string :registration_url
8+
end
9+
end
10+
end

spec/dummy/db/schema.rb

Lines changed: 47 additions & 69 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
# frozen_string_literal: true
2+
13
FactoryBot.define do
2-
factory :event_category do
3-
4+
factory :event_category do # rubocop:todo Lint/EmptyBlock
45
end
56
end

spec/models/better_together/event_category_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'rails_helper'
24

35
module BetterTogether

0 commit comments

Comments
 (0)