Skip to content

Commit fb42b4f

Browse files
authored
Merge pull request #1289 from ElixirTeSS/event-people
Event instructors and contributors
2 parents aa10463 + 1286879 commit fb42b4f

9 files changed

Lines changed: 124 additions & 6 deletions

File tree

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GIT
22
remote: https://github.com/ElixirTeSS/TeSS_RDF_Extractors
3-
revision: 135ce24ef909bf5f7c6e14ccb1e404b51478ab07
3+
revision: 88f54016b4ecea8ac3639315bbe029c9cf891586
44
branch: master
55
specs:
66
tess_rdf_extractors (1.2.0)
@@ -388,7 +388,7 @@ GEM
388388
net-protocol
389389
netrc (0.11.0)
390390
nio4r (2.7.4)
391-
nokogiri (1.19.1)
391+
nokogiri (1.19.2)
392392
mini_portile2 (~> 2.8.2)
393393
racc (~> 1.4)
394394
numerizer (0.1.1)

app/controllers/events_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def event_params
247247
external_resources_attributes: %i[id url title _destroy],
248248
external_resources: %i[url title], material_ids: [],
249249
llm_interaction_attributes: %i[id scrape_or_process model prompt input output needs_processing _destroy],
250-
locked_fields: [])
250+
locked_fields: [], instructors: [:name, :orcid], contributors: [:name, :orcid])
251251
end
252252

253253
def event_report_params

app/models/event.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Event < ApplicationRecord
2020
include HasEdamTerms
2121
include HasLanguage
2222
include InSpace
23+
include HasPeople
2324

2425
before_validation :fix_keywords, on: :create, if: :scraper_record
2526
before_validation :presence_default
@@ -51,6 +52,13 @@ class Event < ApplicationRecord
5152
text :operations do
5253
operations_and_synonyms
5354
end
55+
text :contributors do
56+
contributors.map(&:display_name)
57+
end
58+
text :instructors do
59+
instructors.map(&:display_name)
60+
end
61+
5462
# sort title
5563
string :sort_title do
5664
title.downcase.gsub(/^(an?|the) /, '')
@@ -105,6 +113,12 @@ class Event < ApplicationRecord
105113
string :collections, multiple: true do
106114
collections.where(public: true).pluck(:title)
107115
end
116+
string :contributors, multiple: true do
117+
contributors.map(&:display_name)
118+
end
119+
string :instructors, multiple: true do
120+
instructors.map(&:display_name)
121+
end
108122
end
109123
# :nocov:
110124
end
@@ -121,11 +135,13 @@ class Event < ApplicationRecord
121135
has_many :event_materials, dependent: :destroy
122136
has_many :materials, through: :event_materials
123137
has_many :widget_logs, as: :resource
138+
has_many :stars, as: :resource, dependent: :destroy
124139

125140
has_ontology_terms(:scientific_topics, branch: EDAM.topics)
126141
has_ontology_terms(:operations, branch: EDAM.operations)
127142

128-
has_many :stars, as: :resource, dependent: :destroy
143+
has_person_role :contributors
144+
has_person_role :instructors
129145

130146
auto_strip_attributes :title, :description, :url, squish: false
131147

@@ -196,7 +212,7 @@ def expired?
196212
def self.facet_fields
197213
field_list = %w[ content_provider keywords scientific_topics operations tools fields online event_types
198214
start venue city country organizer sponsors target_audience eligibility language
199-
user node collections ]
215+
user node collections contributors instructors]
200216

201217
field_list.delete('operations') if TeSS::Config.feature['disabled'].include? 'operations'
202218
field_list.delete('scientific_topics') if TeSS::Config.feature['disabled'].include? 'topics'

app/views/bioschemas/_preview_button.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= form_tag(polymorphic_path([:preview, resource.class])) do |f| %>
1+
<%= form_tag(polymorphic_path([:preview, resource.class]), class: 'mt-3') do |f| %>
22
<%= attributes_to_hidden_fields(resource.class.model_name.param_key, resource_params) %>
33

44
<%= submit_tag('Preview', class: 'btn btn-primary', formtarget: '_blank', data: { disable_with: false }) %>

app/views/common/_extra_metadata.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
<%= display_people(resource, :authors) if resource.respond_to?(:authors) %>
6464
<%= display_people(resource, :contributors) if resource.respond_to?(:contributors) %>
65+
<%= display_people(resource, :instructors) if resource.respond_to?(:instructors) %>
6566
<%= display_attribute(resource, :remote_created_date) if resource.respond_to?(:remote_created_date) %>
6667
<%= display_attribute(resource, :remote_updated_date) if resource.respond_to?(:remote_updated_date) %>
6768
<%= display_attribute(resource, :scientific_topics) {

app/views/events/_form.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@
175175
<%= f.multi_input :sponsors, errors: @event.errors[:sponsors], hint: t('events.hints.sponsors') %>
176176
<% end %>
177177

178+
<!-- Field: Contributors -->
179+
<%= render partial: "common/people_form", locals: { f: f, field_name: 'contributors', role: 'contributor' } %>
180+
181+
<!-- Field: Instructors -->
182+
<%= render partial: "common/people_form", locals: { f: f, field_name: 'instructors', role: 'instructor' } %>
183+
178184
<div class="form-group">
179185
<%= f.submit(class: 'btn btn-primary') %>
180186
<%= link_to 'Back', :back, class: 'btn btn-default' %>

lib/bioschemas/course_instance_generator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ def self.bioschemas_profile
2020
}
2121
property :maximumAttendeeCapacity, :capacity
2222
property :courseMode, :presence
23+
property :contributor, -> (event) { event.contributors.map { |p| person(p) } }
24+
property :instructor, -> (event) { event.instructors.map { |p| person(p) } }
2325
end
2426
end

test/integration/bioschemas_test.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class BioschemasTest < ActionDispatch::IntegrationTest
8080
event = events(:course_event)
8181
event.external_resources.create!({ title: 'Cool website', url: 'https://external-resource.pizza' })
8282
event.node_names = ['Test Node']
83+
event.contributors = [{ name: 'Contri Butor', orcid: '0000-0002-1694-233X' }]
84+
event.instructors = [{ name: 'Josiah Carberry', orcid: 'https://orcid.org/0000-0002-1825-0097' }, { name: 'Gordon Freeman' }]
8385
event.save!
8486
url = event_url(event.slug)
8587

@@ -213,6 +215,37 @@ class BioschemasTest < ActionDispatch::IntegrationTest
213215
assert_includes providers, ['ELIXIR Test Node', 'http://example.com']
214216
assert_includes providers, ['Goblet', 'http://mygoblet.org']
215217
assert_includes providers, ['University of Manchester', nil]
218+
219+
# Contributors
220+
q = RDF::Query.new do
221+
pattern RDF::Query::Pattern.new(course_instance_uri, RDF::Vocab::SCHEMA.contributor, :contributor_info)
222+
pattern RDF::Query::Pattern.new(:contributor_info, RDF::Vocab::SCHEMA.name, :name)
223+
pattern RDF::Query::Pattern.new(:contributor_info, RDF::Vocab::SCHEMA.identifier, :identifier, optional: true)
224+
end
225+
results = graph.query(q)
226+
assert_equal 1, results.count
227+
contributors = results.map { |r| { name: r.name.to_s,
228+
id: r.contributor_info.to_s.start_with?('http') ? r.contributor_info.to_s : nil,
229+
identifier: r[:identifier]&.to_s }}
230+
assert_includes contributors, { name: 'Contri Butor',
231+
id: 'https://orcid.org/0000-0002-1694-233X',
232+
identifier: 'https://orcid.org/0000-0002-1694-233X' }
233+
234+
# Instructors
235+
q = RDF::Query.new do
236+
pattern RDF::Query::Pattern.new(course_instance_uri, RDF::Vocab::SCHEMA.instructor, :instructor_info)
237+
pattern RDF::Query::Pattern.new(:instructor_info, RDF::Vocab::SCHEMA.name, :name)
238+
pattern RDF::Query::Pattern.new(:instructor_info, RDF::Vocab::SCHEMA.identifier, :identifier, optional: true)
239+
end
240+
results = graph.query(q)
241+
assert_equal 2, results.count
242+
instructors = results.map { |r| { name: r.name.to_s,
243+
id: r.instructor_info.to_s.start_with?('http') ? r.instructor_info.to_s : nil,
244+
identifier: r[:identifier]&.to_s }}
245+
assert_includes instructors, { name: 'Josiah Carberry',
246+
id: 'https://orcid.org/0000-0002-1825-0097',
247+
identifier: 'https://orcid.org/0000-0002-1825-0097' }
248+
assert_includes instructors, { name: 'Gordon Freeman', id: nil, identifier: nil }
216249
end
217250

218251
test 'handles non-list markdown for prereqs on course event' do

test/models/event_test.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,4 +804,64 @@ class EventTest < ActiveSupport::TestCase
804804

805805
assert_equal 1, (e.reload.ontology_term_links.to_a - ontology_term_links).length
806806
end
807+
808+
test 'should set contributors from array of hashes' do
809+
@event.contributors = [
810+
{ name: 'John Doe', orcid: '0000-0002-1825-0097' },
811+
{ name: 'Jane Smith' }
812+
]
813+
@event.save!
814+
@event.reload
815+
816+
assert_equal 2, @event.contributors.size
817+
john = @event.contributors.find { |c| c.name == 'John Doe' }
818+
assert_not_nil john
819+
assert_equal '0000-0002-1825-0097', john.orcid
820+
end
821+
822+
test 'should set contributors from array of Person objects' do
823+
person1 = Person.new(resource: @event, name: 'Alice Wonder')
824+
person2 = Person.new(resource: @event, name: 'Bob Builder')
825+
826+
827+
assert_not_includes @event.contributors.map(&:name), person1.name
828+
829+
@event.contributors = [person1, person2]
830+
@event.save!
831+
@event.reload
832+
833+
assert_equal 2, @event.contributors.size
834+
assert_includes @event.contributors.map(&:name), person1.name
835+
assert_includes @event.contributors.map(&:name), person2.name
836+
end
837+
838+
test 'should set instructors from array of hashes' do
839+
@event.instructors = [
840+
{ name: 'John Doe', orcid: '0000-0002-1825-0097' },
841+
{ name: 'Jane Smith' }
842+
]
843+
@event.save!
844+
@event.reload
845+
846+
assert_equal 2, @event.instructors.size
847+
john = @event.instructors.find { |c| c.name == 'John Doe' }
848+
assert_not_nil john
849+
assert_equal '0000-0002-1825-0097', john.orcid
850+
end
851+
852+
test 'should set instructors from array of Person objects' do
853+
person1 = Person.new(resource: @event, name: 'Alice Wonder')
854+
person2 = Person.new(resource: @event, name: 'Bob Builder')
855+
856+
857+
assert_not_includes @event.instructors.map(&:name), person1.name
858+
859+
@event.instructors = [person1, person2]
860+
@event.save!
861+
@event.reload
862+
863+
assert_equal 2, @event.instructors.size
864+
assert_includes @event.instructors.map(&:name), person1.name
865+
assert_includes @event.instructors.map(&:name), person2.name
866+
end
807867
end

0 commit comments

Comments
 (0)