Skip to content

Commit dcff743

Browse files
committed
Merge branch 'main' into fix-nested-emt-attribute-label-humanize
2 parents ece5fc5 + fdd2e0c commit dcff743

31 files changed

Lines changed: 318 additions & 61 deletions

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ GEM
233233
activerecord (>= 5.a)
234234
database_cleaner-core (~> 2.0.0)
235235
database_cleaner-core (2.0.1)
236-
date (3.4.1)
236+
date (3.5.1)
237237
debug_inspector (1.2.0)
238238
delayed_job (4.1.13)
239239
activesupport (>= 3.0, < 9.0)
@@ -513,7 +513,7 @@ GEM
513513
net-http-digest_auth (1.4.1)
514514
net-http-persistent (4.0.6)
515515
connection_pool (~> 2.2, >= 2.2.4)
516-
net-imap (0.5.7)
516+
net-imap (0.5.14)
517517
date
518518
net-protocol
519519
net-ldap (0.19.0)
@@ -971,7 +971,7 @@ GEM
971971
tilt (2.6.1)
972972
time (0.4.1)
973973
date
974-
timeout (0.4.3)
974+
timeout (0.6.1)
975975
tsort (0.2.0)
976976
tzinfo (2.0.6)
977977
concurrent-ruby (~> 1.0)

app/controllers/events_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def handle_update_or_create(is_new)
5353
private
5454

5555
def event_params
56-
params.require(:event).permit(:title, :description, :start_date, :end_date, :url, :address, :city, :country, :time_zone,
56+
params.require(:event).permit(:title, :description, :start_date, :end_date, :url,
57+
:location_type, :event_type_id, :address, :city, :country, :time_zone,
5758
{ project_ids: [] }, { publication_ids: [] }, { presentation_ids: [] },
5859
{ special_auth_codes_attributes: [:code, :expiration_date, :id, :_destroy] },
5960
{ data_file_ids: [] },{document_ids: []}, { publication_ids: [] }, { extended_metadata_attributes: determine_extended_metadata_keys } )

app/models/event.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ class Event < ApplicationRecord
44
has_and_belongs_to_many :presentations, -> { distinct }
55
has_and_belongs_to_many :documents, -> { distinct }
66

7+
# no presence validation so value can be nil (Not specified)
8+
enum :location_type, { in_person: 0, hybrid: 1, online: 2 }
9+
belongs_to :event_type, optional: true
10+
711
before_destroy {documents.clear}
812

913
before_save :set_timezone
@@ -41,6 +45,7 @@ class Event < ApplicationRecord
4145
validates :country, country:true, allow_blank: true
4246

4347
has_filter :country
48+
has_filter :event_type
4449
has_filter start_date: Seek::Filtering::DateFilter.new(field: :start_date)
4550

4651
validate :validate_data_files

app/models/event_type.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
# EventType model
3+
#
4+
# Represents a category/type of events. Associates many `Event` records; when an
5+
# EventType is removed the association on events is nullified. Validates presence
6+
# and uniqueness of the `title` attribute.
7+
class EventType < ApplicationRecord
8+
has_many :events, dependent: :nullify
9+
10+
validates :title, presence: true, uniqueness: true
11+
end

app/serializers/event_serializer.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class EventSerializer < BaseSerializer
22
attributes :title, :description, :url,
3+
:location_type,
34
:address, :city, :country,
45
:start_date, :end_date
56

@@ -9,6 +10,10 @@ class EventSerializer < BaseSerializer
910
has_many :publications
1011
has_many :presentations
1112

13+
attribute :event_type do
14+
object.event_type&.title
15+
end
16+
1217
def country
1318
if object.country
1419
if object.country.length == 2 #a code

app/views/events/_form.html.erb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@
1818
<%= f.text_area :description, :rows => 5, :class=>"form-control rich-text-edit" %>
1919
</div>
2020

21+
<div class="form-group">
22+
<div class="row">
23+
<div class="col-md-6 col-xs-12">
24+
<%= f.label :event_type_id, "#{t('event')} type" %>
25+
<% event_type_options = EventType.order(:title).map do |et|
26+
tooltip_attributes = et.description.present? ? { title: et.description } : {}
27+
[et.title, et.id, tooltip_attributes]
28+
end %>
29+
<%= f.select :event_type_id,
30+
options_for_select(event_type_options, f.object.event_type_id),
31+
{ include_blank: 'Not specified' },
32+
class: 'form-control' %>
33+
</div>
34+
<div class="col-md-6 col-xs-12">
35+
<%= f.label :location_type, "Location type" %>
36+
<%= f.select :location_type,
37+
Event.location_types.keys.map { |k| [k.humanize, k] },
38+
{ include_blank: 'Not specified' },
39+
{ class: 'form-control' } %>
40+
</div>
41+
</div>
42+
</div>
43+
2144
<div id="event-dates">
2245
<div class="form-group">
2346
<div class="row">

app/views/events/_resource_list_item.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
<div class="col-sm-6">
55
<%= list_item_attribute "Start Date", date_as_string(resource.start_date, false, false, resource.time_zone) %>
66
<%= list_item_attribute "End Date", resource.end_date.nil? ? text_or_not_specified(nil) : date_as_string(resource.end_date, false, false, resource.time_zone) %>
7-
<%= list_item_optional_attribute "#{t('event')} Website", h(resource.url), h(resource.url) %>
7+
<%= list_item_optional_attribute "#{t('event')} type", resource.event_type&.title %>
88
</div>
99

1010
<div class="col-sm-6">
11+
<%= list_item_optional_attribute "#{t('event')} Website", h(resource.url), h(resource.url) %>
1112
<%= list_item_attribute "Country", (country_text_or_not_specified resource.country) %>
1213
<%= list_item_optional_attribute "City", h(resource.city) %>
1314
</div>

app/views/events/show.html.erb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
<div class="tab-content">
66
<%= tab_pane('overview') do %>
7+
78
<%= item_description @event.description -%>
89

910
<div class="row">
@@ -12,12 +13,23 @@
1213

1314
<%= render :partial => 'projects/show_project_relationship', :locals => {:resource => @event} %>
1415

15-
<% unless @event.contributor.nil? then %>
16+
<% if @event.contributor.present? %>
1617
<p>
1718
<label>Created by:</label>
1819
<%= link_to @event.contributor.name, @event.contributor -%>
1920
</p>
2021
<% end %>
22+
23+
<p class="event_type">
24+
<label><%= t('event') %> type:</label>
25+
<%= text_or_not_specified @event.event_type&.title %>
26+
</p>
27+
28+
<p class='location_type'>
29+
<label>Location type:</label>
30+
<%= text_or_not_specified @event.location_type&.humanize %>
31+
</p>
32+
2133
<p>
2234
<label>Start Time:</label>
2335
<% if @event.start_date.nil? %>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
conference:
2+
title: 'Conference'
3+
description: 'Large formal meeting or series of meetings'
4+
workshop:
5+
title: 'Workshop'
6+
description: 'Hands-on session or training'
7+
seminar:
8+
title: 'Seminar'
9+
description: 'Educational presentation or lecture'
10+
webinar:
11+
title: 'Webinar'
12+
description: 'Online seminar'
13+
meetup:
14+
title: 'Meetup'
15+
description: 'Informal gathering'
16+
hackathon:
17+
title: 'Hackathon'
18+
description: 'Collaborative programming event'
19+
meeting:
20+
title: 'Meeting'
21+
description: 'A general project meeting'
22+
deliverable:
23+
title: 'Deliverable'
24+
description: 'A project deliverable submission'
25+
milestone:
26+
title: 'Milestone'
27+
description: 'A project milestone'
28+
experiment:
29+
title: 'Experiment'
30+
description: 'A scientific experiment'
31+
experiment_phase:
32+
title: 'Experiment Phase'
33+
description: 'A phase within a scientific experiment'
34+
35+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddLocationTypeToEvents < ActiveRecord::Migration[7.2]
2+
def change
3+
add_column :events, :location_type, :integer
4+
end
5+
end

0 commit comments

Comments
 (0)