From 8e1d03a3180e9b53b86e520a7f17749dc24f3860 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Sat, 25 Jul 2020 17:38:44 -0700 Subject: [PATCH] Allow scheduling volunteers for sessions. Also fix a small bug for admin registrations edit. --- app/controllers/proposals_controller.rb | 3 +- app/helpers/application_helper.rb | 12 +++++- app/models/event.rb | 3 ++ app/models/event_user.rb | 4 +- app/models/user.rb | 11 +++++ .../_registration_info.html.haml | 2 +- app/views/proposals/_proposal_form.html.haml | 7 +++- app/views/proposals/_speaker_info.haml | 19 +++++++++ app/views/proposals/_volunteer_info.haml | 11 +++++ app/views/proposals/_volunteers_table.haml | 19 +++++++++ app/views/proposals/index.html.haml | 10 +++++ app/views/proposals/show.html.haml | 40 ++++++++----------- 12 files changed, 110 insertions(+), 31 deletions(-) create mode 100644 app/views/proposals/_speaker_info.haml create mode 100644 app/views/proposals/_volunteer_info.haml create mode 100644 app/views/proposals/_volunteers_table.haml diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 692b4db0..adfdbea0 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -12,6 +12,7 @@ class ProposalsController < ApplicationController @event = @program.events.new @event.event_users.new(user: current_user, event_role: 'submitter') @events = current_user.proposals(@conference) + @volunteer_events = current_user.volunteer_duties(@conference) end def show @@ -171,7 +172,7 @@ class ProposalsController < ApplicationController params.require(:event).permit(:event_type_id, :track_id, :difficulty_level_id, :title, :subtitle, :abstract, :description, :require_registration, :max_attendees, :language, - speaker_ids: [] + speaker_ids: [], volunteer_ids: [] ) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b255cdfa..9115b51e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -123,6 +123,16 @@ module ApplicationHelper user_selector_input(:speakers, form, '', true) end + def volunteer_links(event) + safe_join(event.volunteers.map do |volunteer| + link_to(volunteer.name, admin_user_path(volunteer)) + end, ',') + end + + def volunteer_selector_input(form) + user_selector_input(:volunteers, form, '', true) + end + def responsibles_selector_input(form) user_selector_input( :responsibles, @@ -144,7 +154,7 @@ module ApplicationHelper (form.object.send(field)&.map(&:id) || form.object.send(field)&.id) ), input_html: { - class: 'select-help-toggle', + class: 'select-help-toggle js-userSelector', multiple: multiple, placeholder: (multiple ? 'Select users...' : 'Select a user...') } diff --git a/app/models/event.rb b/app/models/event.rb index 388bede8..342ef870 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -18,6 +18,9 @@ class Event < ApplicationRecord has_one :submitter_event_user, -> { where(event_role: 'submitter') }, class_name: 'EventUser' has_one :submitter, through: :submitter_event_user, source: :user + has_many :volunteer_event_users, -> { where(event_role: 'volunteer') }, class_name: 'EventUser' + has_many :volunteers, through: :volunteer_event_users, source: :user + has_many :votes, dependent: :destroy has_many :voters, through: :votes, source: :user has_many :commercials, as: :commercialable, dependent: :destroy diff --git a/app/models/event_user.rb b/app/models/event_user.rb index 5e4d9b20..f8a2b66a 100644 --- a/app/models/event_user.rb +++ b/app/models/event_user.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true class EventUser < ApplicationRecord - # TODO: Do we need these roles? - ROLES = [%w[Speaker speaker], %w[Submitter submitter], %w[Moderator moderator]] + ROLES = [%w[Speaker speaker], %w[Submitter submitter], %w[Moderator moderator], + %w[Volunteer volunteer]] belongs_to :event, touch: true belongs_to :user diff --git a/app/models/user.rb b/app/models/user.rb index 1a2b19b1..986a96ed 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -256,6 +256,12 @@ class User < ApplicationRecord result end + # TODO: Use a real authorization in the right place.... + def manages_volunteers?(conference) + organizer_roles = get_roles['organizer'] + organizer_roles&.include?(conference.short_title) # TODO or Volunteer Coorinator. + end + def registered registrations = self.registrations if registrations.count == 0 @@ -290,6 +296,11 @@ class User < ApplicationRecord proposals(conference).count end + def volunteer_duties(conference) + events.where(program_id: conference.program.id, 'event_users.event_role': 'volunteer') + end + + def self.empty? User.count == 1 && User.first.email == 'deleted@localhost.osem' end diff --git a/app/views/conference_registrations/_registration_info.html.haml b/app/views/conference_registrations/_registration_info.html.haml index a04952d9..e8968298 100644 --- a/app/views/conference_registrations/_registration_info.html.haml +++ b/app/views/conference_registrations/_registration_info.html.haml @@ -18,6 +18,6 @@ You are registered for #{pluralize(@registration.events.count, 'event')}. They are at the end of this list. - @registration.events_ordered.each do |event| - = render 'event', event: event, event_schedule: event.event_schedules.first + = render 'conference_registrations/event', event: event, event_schedule: event.event_schedules.first = render 'conferences/code_of_conduct', organization: @conference.organization diff --git a/app/views/proposals/_proposal_form.html.haml b/app/views/proposals/_proposal_form.html.haml index 89942deb..021b9c76 100644 --- a/app/views/proposals/_proposal_form.html.haml +++ b/app/views/proposals/_proposal_form.html.haml @@ -6,6 +6,9 @@ = speaker_selector_input f + - if current_user.manages_volunteers?(@conference) + = volunteer_selector_input f + = track_selector_input f = f.input :event_type_id, as: :select, @@ -67,8 +70,8 @@ :javascript $(document).ready(function() { - $('#event_speaker_ids').selectize({ + $('.js-userSelector').selectize({ plugins: ['remove_button'], maxItems: 100 - } ) + }) }); diff --git a/app/views/proposals/_speaker_info.haml b/app/views/proposals/_speaker_info.haml new file mode 100644 index 00000000..d757d9b4 --- /dev/null +++ b/app/views/proposals/_speaker_info.haml @@ -0,0 +1,19 @@ +.speakerinfo + .row + .col-md-4 + = image_tag speaker.profile_picture(:size => 120), class: 'img-responsive img-rounded' + .col-md-8 + %h4 + = link_to speaker.name, user_path(speaker.id) + %br + - if speaker.email_public? + = mail_to "#{ speaker.email }" do + %i.fa.fa-envelope-o.fa-2x + - if speaker.affiliation? + .text-muted + from + = speaker.affiliation + - if speaker.biography? + .row.speakerbio + .col-md-12 + = markdown(speaker.biography) diff --git a/app/views/proposals/_volunteer_info.haml b/app/views/proposals/_volunteer_info.haml new file mode 100644 index 00000000..f5e3e21b --- /dev/null +++ b/app/views/proposals/_volunteer_info.haml @@ -0,0 +1,11 @@ +.speakerinfo + .row + .col-md-4 + = image_tag speaker.profile_picture(:size => 120), class: 'img-responsive img-rounded' + .col-md-8 + %h4 + = link_to speaker.name, user_path(speaker.id) + - if speaker.affiliation? + .text-muted + from + = speaker.affiliation diff --git a/app/views/proposals/_volunteers_table.haml b/app/views/proposals/_volunteers_table.haml new file mode 100644 index 00000000..df99ce53 --- /dev/null +++ b/app/views/proposals/_volunteers_table.haml @@ -0,0 +1,19 @@ +%table.table.table-striped#events + - events.each do |event| + %tr + %td.col-md-7{style: "padding:20px 8px 20px 8px;"} + = link_to event.title, conference_program_proposal_path(@conference.short_title, event.id) + %br + %small.text-muted + = event.event_type.title + = "(#{event.event_type.length} min)" + = "in #{event.track.name}" if event.track + - if event.require_registration + %br + = link_to registered_text(event), registrations_conference_program_proposal_path(@conference.short_title, event), class: 'btn btn-xs btn-danger' + + %td.col-md-2{style: "padding:20px 8px 20px 8px;"} + - event_schedule = event.event_schedules.find_by(schedule_id: @program.selected_schedule_id) + - if event_schedule.present? + = inyourtz(event_schedule.start_time, @conference.timezone) do + = event_schedule.start_time.strftime("%Y %B %e - %H:%M") diff --git a/app/views/proposals/index.html.haml b/app/views/proposals/index.html.haml index cf57c644..129f54f5 100644 --- a/app/views/proposals/index.html.haml +++ b/app/views/proposals/index.html.haml @@ -70,6 +70,9 @@ %span{ title: event.state.humanize, class: "fa #{status_icon(event)}" } %td.col-md-7{style: "padding:20px 8px 20px 8px;"} + - if event.volunteers.include?(current_user) + %strong You are volunteer host for: + %br = link_to event.title, conference_program_proposal_path(@conference.short_title, event.id) %br %small.text-muted @@ -113,6 +116,13 @@ method: :patch, class: 'btn btn-mini btn-success', id: "review_event_#{event.id}" = link_to 'Edit', edit_conference_program_proposal_path(@conference.short_title, event.id), class: 'btn btn-default', id: "edit_proposal_#{event.id}" + + - if @volunteer_events.any? + %h2 + Volunteer Events + %small + Thanks for being a host at #{@conference.title} + = render 'volunteers_table', events: @volunteer_events .row .col-md-12 - if can? :create, @event diff --git a/app/views/proposals/show.html.haml b/app/views/proposals/show.html.haml index 043fab11..61c99d70 100644 --- a/app/views/proposals/show.html.haml +++ b/app/views/proposals/show.html.haml @@ -29,29 +29,20 @@ .row .col-md-3 - %h3 - if @event.speakers.any? - Presented by: + %h3 + Presented by: - @speakers_ordered.each do |speaker| - .speakerinfo - .row - .col-md-4 - = image_tag speaker.profile_picture(:size => 120), class: 'img-responsive img-rounded' - .col-md-8 - %h4 - = link_to speaker.name, user_path(speaker.id) - %br - - if speaker.email_public? - = mail_to "#{ speaker.email }" do - %i.fa.fa-envelope-o.fa-2x - - if speaker.affiliation? - .text-muted - from - = speaker.affiliation - -if speaker.biography? - .row.speakerbio - .col-md-12 - = markdown(speaker.biography) + = render 'speaker_info', speaker: speaker + / end speakers. + - if @event.volunteers.any? + %h3 + Volunteer Hosts + %br + %small Thanks for helping with #{@conference.title}! + - @event.volunteers.each do |volunteer| + = render 'volunteer_info', speaker: volunteer, show_bio: false + .col-md-9 .row .col-md-12 @@ -93,9 +84,10 @@ .col-md-12 %dt Conference: %dd= link_to @event.program.conference.title, conference_path(@conference) - .col-md-12 - %dt Language: - %dd= @event.language if @event.language + - if @event.language + .col-md-12 + %dt Language: + %dd= @event.language .col-md-12 %dt Track: %dd