Skip to content

Commit

Permalink
Merge pull request #889 from ElixirTeSS/hybrid-events
Browse files Browse the repository at this point in the history
Hybrid event support
  • Loading branch information
fbacall authored Sep 12, 2023
2 parents 9c20460 + 6656445 commit aa5898f
Show file tree
Hide file tree
Showing 29 changed files with 179 additions and 89 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
background-image: image-url("modern/icons/trainers-icon.svg");
}

.virtual-event-icon {
.online-event-icon {
background-image: image-url("modern/icons/virtual-event-icon.svg");
}

Expand Down
2 changes: 0 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ module ApplicationHelper
ICONS = {
started: { icon: 'fa-hourglass-half', message: 'This event has already started' },
expired: { icon: 'fa-hourglass-end', message: 'This event has finished' },
online: { icon: 'fa-desktop', message: 'This is an online event' },
face_to_face: { icon: 'fa-users', message: 'This is a physical event' },
scraped_today: { icon: 'fa-check-circle-o', message: 'This record was updated today' },
not_scraped_recently: { icon: 'fa-exclamation-circle', message: 'This record has not been updated since %SUB%' },
event: { icon: 'fa-calendar', message: 'This is a training event' },
Expand Down
19 changes: 15 additions & 4 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ class Event < ApplicationRecord
operation_names
end
string :target_audience, multiple: true
boolean :online
boolean :online do
online? || hybrid?
end
time :last_scraped
string :user do
user.username if user
Expand All @@ -95,6 +97,9 @@ class Event < ApplicationRecord
# :nocov:
end

# TODO: Rails 7 - Migrate this to use hash-syntax with explicit values, e.g.: { onsite: 0, online: 1, hybrid: 2 }
enum presence: [:onsite, :online, :hybrid]

belongs_to :user
has_one :edit_suggestion, as: :suggestible, dependent: :destroy
has_one :link_monitor, as: :lcheck, dependent: :destroy
Expand Down Expand Up @@ -429,6 +434,12 @@ def duplicate
c
end

def online= value
value = :online if value.is_a?(TrueClass) || value == '1' || value == 1 || value == 'true'
value = :onsite if value.is_a?(FalseClass) || value == '0' || value == 0 || value == 'false'
self.presence = value
end

private

def allowed_url
Expand Down Expand Up @@ -457,22 +468,22 @@ def fix_online
downcased_var = self[key]&.downcase
dic.lookup(key).each do |v|
if downcased_var&.include?(v)
self.online = true
self.presence = :online
return
end
end
end
end

def fix_keywords
fix_online if !self&.online.present?
fix_online unless online? || hybrid?

[
[TargetAudienceDictionary, :target_audience],
[EventTypeDictionary, :event_types],
[EligibilityDictionary, :eligibility],
].each do |dict, var|
if not self[var].present?
if self[var].blank?
self[var] = []
end
dic = dict.instance
Expand Down
10 changes: 9 additions & 1 deletion app/serializers/event_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class EventSerializer < ApplicationSerializer

:organizer, :sponsors, :contact, :host_institutions,

:online, :venue, :city, :county, :country, :postcode, :latitude, :longitude,
:online, :presence, :venue, :city, :county, :country, :postcode, :latitude, :longitude,

:capacity, :cost_basis, :cost_value, :cost_currency,

Expand All @@ -24,6 +24,14 @@ class EventSerializer < ApplicationSerializer
has_many :collections
has_many :materials

def online
object.online? || object.hybrid?
end

def presence
object.presence.to_s
end

def report
Hash[Event::SENSITIVE_FIELDS.map { |f| [f, object.send(f)] }]
end
Expand Down
23 changes: 7 additions & 16 deletions app/views/events/_event.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@
<%= item_order_badge(collection_item) if defined? collection_item %>
<div class="with-left-icon">
<div class="icon-container hidden-xs">
<!-- TODO: hybrid events-->
<% if event.online? %>
<i class="icon icon-h2 virtual-event-icon"></i><br/>
<span class="muted">Online</span>
<% else %>
<i class="icon icon-h2 onsite-event-icon"></i><br/>
<span class="muted">Face-to-face</span>
<% end %>
<i class="icon icon-h2 <%= event.presence %>-event-icon"></i><br/>
<span class="muted"><%= t("activerecord.attributes.event.presence.#{event.presence}") %></span>
</div>

<div class="right-container">
Expand Down Expand Up @@ -40,19 +34,16 @@

<p><%= neatly_printed_date_range(event.start, event.end) %></p>

<% if event.online? %>
<p class="visible-xs-block">
<i class="icon icon-md virtual-event-icon"></i> <span class="muted">Online</span>
</p>
<% else %>
<% if event.onsite? %>
<% location = [event.city, event.country].reject { |field_value| field_value.blank? }.join(", ") %>
<% if location.present? %>
<p class="dont-break-out"><i class="fa fa-map-marker"></i> <%= location %></p>
<% end %>
<p class="visible-xs-block">
<i class="icon icon-md onsite-event-icon"></i> <span class="muted">Face-to-face</span>
</p>
<% end %>
<p class="visible-xs-block">
<i class="icon icon-md <%= event.presence %>-event-icon"></i>
<span class="muted"><%= t("activerecord.attributes.event.presence.#{event.presence}") %></span>
</p>
</div>
</div>

Expand Down
20 changes: 9 additions & 11 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
<%= render partial: 'common/error_summary', locals: { resource: @event } %>

<!-- Field: Online? -->
<!-- Field: presence -->
<div class="form-group">
<%= label_tag('type') %> <br/>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default <%= 'active' unless @event.online? %>">
<%= f.radio_button 'online', 'false', class: 'location', data: { role: 'online-switch' },
checked: !@event.online?, autocomplete: 'off' %>
<%= icon_for(:face_to_face, :small) %> Face-to-face
</label>
<label class="btn btn-default <%= 'active' if @event.online? %>">
<%= f.radio_button 'online', 'true', class: 'location', data: { role: 'online-switch' },
checked: @event.online?, autocomplete: 'off' %>
<i class="fa fa-desktop" aria-hidden="true" id="online-symbol"></i> Online
</label>
<% [:onsite, :hybrid, :online].each do |presence| %>
<% active = @event.send("#{presence}?") %>
<label class="btn btn-lg btn-secondary <%= 'active' if active %>">
<%= f.radio_button 'online', presence, class: 'location', data: { role: 'online-switch' },
checked: active, autocomplete: 'off' %>
<i class="icon icon-lg <%= presence %>-event-icon"></i> <%= t("activerecord.attributes.event.presence.#{presence}") %>
</label>
<% end %>
</div>
</div>

Expand Down
3 changes: 2 additions & 1 deletion app/views/events/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
base_fields = [:id, :external_id, :title, :subtitle, :url, :organizer, :description, :start, :end, :sponsors, :venue,
:city, :country, :postcode, :latitude, :longitude, :created_at, :updated_at, :source, :slug,
:content_provider_id, :user_id, :online, :last_scraped, :scraper_record, :keywords, :event_types,
:content_provider_id, :user_id, :last_scraped, :scraper_record, :keywords, :event_types,
:target_audience, :capacity, :eligibility, :contact, :host_institutions, :prerequisites,
:tech_requirements, :cost_basis, :cost_value ]

Expand All @@ -9,6 +9,7 @@ json.array!(@events) do |event|
fields += Event::SENSITIVE_FIELDS if policy(event).view_report?

json.extract! event, *fields
json.online(event.online? || event.hybrid?)

json.partial! 'common/ontology_terms', type: 'scientific_topics', resource: event
json.partial! 'common/ontology_terms', type: 'operations', resource: event
Expand Down
15 changes: 0 additions & 15 deletions app/views/events/partials/_icon_info.html.erb

This file was deleted.

8 changes: 1 addition & 7 deletions app/views/events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
<% end %>
<% end %>

<!-- TODO: refactor event type using...-->
<%#= render :partial => 'events/partials/icon_info' %>
<h2 class="mt-0">
<% if @event.has_node? -%>
<%= elixir_node_icon %>
Expand All @@ -29,11 +27,7 @@
<%= suggestion_icon(@event, 'large') -%>
<% end %>

<% if @event.online? %>
<i class="icon icon-h2 virtual-event-icon"></i>
<% else %>
<i class="icon icon-h2 onsite-event-icon"></i>
<% end %>
<i class="icon icon-h2 <%= @event.presence %>-event-icon" ></i>

<%= @event.title %>
</h2>
Expand Down
3 changes: 2 additions & 1 deletion app/views/events/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fields = [

:organizer, :sponsors, :contact, :host_institutions,

:online, :venue, :city, :county, :country, :postcode, :latitude, :longitude,
:venue, :city, :county, :country, :postcode, :latitude, :longitude,

:capacity, :cost_basis, :cost_value, :cost_currency,

Expand All @@ -22,6 +22,7 @@ fields = [
fields += Event::SENSITIVE_FIELDS if policy(@event).view_report?

json.extract! @event, *fields
json.online(@event.online? || @event.hybrid?)

json.partial! 'common/ontology_terms', type: 'scientific_topics', resource: @event
json.partial! 'common/ontology_terms', type: 'operations', resource: @event
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ en:
surname: 'Last name'
event:
county: Region
presence:
online: Online
onsite: Face-to-face
hybrid: Hybrid
about:
registry: >
TeSS is a platform that was developed to provide a one-stop shop for trainers and trainees to discover
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20230724162231_convert_online_to_integer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ConvertOnlineToInteger < ActiveRecord::Migration[6.1]
def up
change_column_default :events, :online, nil
change_column :events, :online, :integer, using: 'online::integer', default: 0
end

def down
change_column_default :events, :online, nil
change_column :events, :online, :boolean, using: 'online::boolean', default: false
end
end
5 changes: 5 additions & 0 deletions db/migrate/20230803095429_rename_events_online_to_presence.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameEventsOnlineToPresence < ActiveRecord::Migration[6.1]
def change
rename_column :events, :online, :presence
end
end
6 changes: 3 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_06_17_092354) do
ActiveRecord::Schema.define(version: 2023_08_03_095429) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -200,7 +200,7 @@
t.string "slug"
t.integer "content_provider_id"
t.integer "user_id"
t.boolean "online", default: false
t.integer "presence", default: 0
t.decimal "cost_value"
t.date "last_scraped"
t.boolean "scraper_record", default: false
Expand All @@ -227,7 +227,7 @@
t.string "cost_basis"
t.string "cost_currency"
t.string "fields", default: [], array: true
t.index ["online"], name: "index_events_on_online"
t.index ["presence"], name: "index_events_on_presence"
t.index ["slug"], name: "index_events_on_slug", unique: true
t.index ["user_id"], name: "index_events_on_user_id"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bioschemas/course_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.type
end

def self.bioschemas_profile
'https://bioschemas.org/profiles/Course/0.10-DRAFT'
'https://bioschemas.org/profiles/Course/1.0-RELEASE'
end

property :name, :title
Expand Down
3 changes: 2 additions & 1 deletion lib/bioschemas/course_instance_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.type
end

def self.bioschemas_profile
'https://bioschemas.org/profiles/CourseInstance/0.9-DRAFT'
'https://bioschemas.org/profiles/CourseInstance/1.0-RELEASE'
end

property :startDate, :start
Expand All @@ -29,5 +29,6 @@ def self.bioschemas_profile
event.sponsors.map { |sponsor| { '@type' => 'Organization', 'name' => sponsor } }
}
property :maximumAttendeeCapacity, :capacity
property :courseMode, :presence
end
end
10 changes: 9 additions & 1 deletion public/api/definitions/tess.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ paths:
type: string
- name: online
in: query
description: Only show online events?
description: Only show events with online access?
schema:
type: boolean
- name: sponsor[]
Expand Down Expand Up @@ -1010,6 +1010,14 @@ components:
type: boolean
nullable: true
description: Does the event take place online?
presence:
type: string
nullable: true
description: Is the event onsite (face-to-face), online or hybrid?
enum:
- onsite
- online
- hybrid
cost-basis:
type: string
nullable: true
Expand Down
33 changes: 33 additions & 0 deletions test/controllers/events_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,22 @@ class EventsControllerTest < ActionController::TestCase
assert_valid_legacy_json_response
end

test 'should show hybrid event as json' do
event = events(:hybrid_event)

get :show, params: { id: event, format: :json }
assert_response :success
assert assigns(:event)
assert_valid_legacy_json_response

body = nil
assert_nothing_raised do
body = JSON.parse(response.body)
end

assert_equal true, body['online']
end

test 'should show event as json-api' do
@event.scientific_topic_uris = ['http://edamontology.org/topic_0654']
@event.save!
Expand All @@ -268,6 +284,23 @@ class EventsControllerTest < ActionController::TestCase
assert_equal "application/vnd.api+json; charset=utf-8", response.content_type, 'response content_type not matched.'
end

test 'should show hybrid event as json-api' do
event = events(:hybrid_event)

get :show, params: { id: event, format: :json_api }
assert_response :success
assert assigns(:event)
assert_valid_json_api_response

body = nil
assert_nothing_raised do
body = JSON.parse(response.body)
end

assert_equal true, body['data']['attributes']['online']
assert_equal 'hybrid', body['data']['attributes']['presence']
end

#UPDATE TEST
test 'should update event' do
sign_in @event.user
Expand Down
Loading

0 comments on commit aa5898f

Please sign in to comment.