From f8d6283f44d46942ff25cde841a856c069585256 Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 11 Mar 2022 14:28:16 -0800 Subject: [PATCH 1/2] Add surveys during proposal submission --- .rubocop_todo.yml | 2 +- app/controllers/proposals_controller.rb | 1 + app/models/conference.rb | 4 ++++ app/models/survey.rb | 2 +- app/views/proposals/index.html.haml | 7 +++++++ spec/features/surveys_spec.rb | 26 +++++++++++++++++++++++++ 6 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b4637d3e69..d06f5c594f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -442,7 +442,7 @@ Metrics/BlockNesting: # Offense count: 14 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 652 + Max: 655 # Offense count: 29 # Configuration parameters: IgnoredMethods. diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 692b4db01a..88ca22aed4 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -12,6 +12,7 @@ def index @event = @program.events.new @event.event_users.new(user: current_user, event_role: 'submitter') @events = current_user.proposals(@conference) + @surveys = @conference.surveys.during_proposal.select(&:active?) end def show diff --git a/app/models/conference.rb b/app/models/conference.rb index cac3a84932..58b6fe6013 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -57,6 +57,10 @@ class Conference < ApplicationRecord has_many :event_types, through: :program has_many :surveys, as: :surveyable, dependent: :destroy do + def during_proposal + where(target: targets[:during_proposal]) + end + def for_registration where(target: targets[:during_registration]) end diff --git a/app/models/survey.rb b/app/models/survey.rb index 66783e90df..ccc5f42329 100644 --- a/app/models/survey.rb +++ b/app/models/survey.rb @@ -5,7 +5,7 @@ class Survey < ActiveRecord::Base has_many :survey_questions, dependent: :destroy has_many :survey_submissions, dependent: :destroy - enum target: [:after_conference, :during_registration, :after_event] + enum target: [:after_conference, :during_registration, :after_event, :during_proposal] validates :title, presence: true ## diff --git a/app/views/proposals/index.html.haml b/app/views/proposals/index.html.haml index cf57c6444b..961c536876 100644 --- a/app/views/proposals/index.html.haml +++ b/app/views/proposals/index.html.haml @@ -117,3 +117,10 @@ .col-md-12 - if can? :create, @event = link_to "New Proposal", new_conference_program_proposal_path(@conference.short_title), class: 'btn btn-success pull-right' + + - if @surveys.any? + .row + .col-md-12 + %h2 Surveys + + = render partial: 'surveys/list', locals: { surveys: @surveys, conference: @conference } diff --git a/spec/features/surveys_spec.rb b/spec/features/surveys_spec.rb index 52f8b40d90..98fcc493ed 100644 --- a/spec/features/surveys_spec.rb +++ b/spec/features/surveys_spec.rb @@ -52,4 +52,30 @@ expect(find(:link, survey.title).sibling('.fa-solid')[:title]).to eq('Thank you for filling out the survey') end end + + context 'as a speaker' do + let(:speaker) { create(:user) } + + before :each do + sign_in speaker + end + + scenario 'respond to a survey during proposal submission', feature: true, js: true do + create :cfp, program: conference.program + create :event, program: conference.program, submitter: speaker + survey = create(:survey, surveyable: conference, target: :during_proposal) + create :boolean_mandatory, survey: survey + + visit conference_program_proposals_path(conference.short_title) + expect(find(:link, survey.title).sibling('.fa-solid')[:title]).to eq('Please fill out the survey') + + click_link survey.title + choose 'Yes' + click_button 'Submit' + expect(flash).to eq('Successfully responded to survey.') + + visit conference_program_proposals_path(conference.short_title) + expect(find(:link, survey.title).sibling('.fa-solid')[:title]).to eq('Thank you for filling out the survey') + end + end end From 1260786a625b557fb5674b702935b2df8abe57f2 Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Tue, 14 Mar 2023 17:00:53 -0700 Subject: [PATCH 2/2] Add surveys to proposal todo list --- .haml-lint_todo.yml | 1 + app/models/event.rb | 3 +++ app/models/survey.rb | 4 ++++ app/views/admin/events/show.html.haml | 5 +++++ app/views/proposals/_tooltip.html.haml | 4 ++++ app/views/proposals/index.html.haml | 2 +- app/views/surveys/_list.html.haml | 2 +- spec/features/surveys_spec.rb | 6 ++++++ 8 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 8d6474cdce..decbeb3c66 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -38,6 +38,7 @@ linters: - "app/views/admin/emails/index.html.haml" - "app/views/admin/events/_proposal.html.haml" - "app/views/admin/events/index.html.haml" + - "app/views/admin/events/show.html.haml" - "app/views/admin/tracks/index.html.haml" - "app/views/admin/tracks/show.html.haml" - "app/views/admin/versions/_object_desc_and_link.html.haml" diff --git a/app/models/event.rb b/app/models/event.rb index dc7202c287..cf2914b421 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -228,8 +228,11 @@ def speaker_emails # # Returns +Hash+ def progress_status + surveys = conference.surveys.during_proposal.select(&:active?) + { registered: speakers.all? { |speaker| program.conference.user_registered? speaker }, + surveys: (surveys.all? { |survey| survey.replied?(submitter) } if surveys.present?), commercials: commercials.any?, biographies: speakers.all? { |speaker| !speaker.biography.blank? }, subtitle: !subtitle.blank?, diff --git a/app/models/survey.rb b/app/models/survey.rb index ccc5f42329..66c10667be 100644 --- a/app/models/survey.rb +++ b/app/models/survey.rb @@ -36,4 +36,8 @@ def active? def closed? !active? end + + def replied?(user_id) + survey_submissions.where(user_id: user_id).any? + end end diff --git a/app/views/admin/events/show.html.haml b/app/views/admin/events/show.html.haml index 4b76483886..0831f49f03 100644 --- a/app/views/admin/events/show.html.haml +++ b/app/views/admin/events/show.html.haml @@ -67,6 +67,11 @@ %td= link_to "#{'Speaker'.pluralize(@event.speakers.count)} must be registered to the conference", admin_conference_registrations_path(@event.program.conference.short_title) %td{ 'class' => class_for_todo(progress_status['registered']) } %span{ 'class' => [icon_for_todo(progress_status['registered']), 'fa-lg'] } + - unless progress_status['surveys'].nil? + %tr + %td= link_to 'Respond to surveys', admin_conference_surveys_path(@event.program.conference.short_title) + %td{ 'class' => class_for_todo(progress_status['surveys']) } + %span{ 'class' => [icon_for_todo(progress_status['surveys']), 'fa-lg'] } %tr %td - speakers_count = @event.speakers.count diff --git a/app/views/proposals/_tooltip.html.haml b/app/views/proposals/_tooltip.html.haml index b10b5a7a19..d91cf92311 100644 --- a/app/views/proposals/_tooltip.html.haml +++ b/app/views/proposals/_tooltip.html.haml @@ -7,6 +7,10 @@ Speaker(s) registered to the conference - else = link_to 'Speaker(s) not registered to the conference', new_conference_conference_registration_path(event.program.conference.short_title) + - unless progress_status['surveys'].nil? + %li{'class'=>class_for_todo(progress_status['surveys'])} + %span{'class'=>icon_for_todo(progress_status['surveys'])} + = link_to 'Respond to surveys', '#surveys' %li{'class'=>class_for_todo(progress_status['biographies'])} %span{'class'=>icon_for_todo(progress_status['biographies'])} - if progress_status['biographies'] diff --git a/app/views/proposals/index.html.haml b/app/views/proposals/index.html.haml index 961c536876..ace97ad07a 100644 --- a/app/views/proposals/index.html.haml +++ b/app/views/proposals/index.html.haml @@ -121,6 +121,6 @@ - if @surveys.any? .row .col-md-12 - %h2 Surveys + %h2#surveys Surveys = render partial: 'surveys/list', locals: { surveys: @surveys, conference: @conference } diff --git a/app/views/surveys/_list.html.haml b/app/views/surveys/_list.html.haml index 200fe7e90e..aa78503747 100644 --- a/app/views/surveys/_list.html.haml +++ b/app/views/surveys/_list.html.haml @@ -1,5 +1,5 @@ - surveys.each do |survey| - - if survey.survey_submissions.find_by(user: current_user) + - if survey.replied?(current_user) %i.fa-solid.fa-square-check.text-success{ title: 'Thank you for filling out the survey' } - else %i.fa-solid.fa-square-minus.text-danger{ title: 'Please fill out the survey' } diff --git a/spec/features/surveys_spec.rb b/spec/features/surveys_spec.rb index 98fcc493ed..eefb1758c9 100644 --- a/spec/features/surveys_spec.rb +++ b/spec/features/surveys_spec.rb @@ -67,6 +67,9 @@ create :boolean_mandatory, survey: survey visit conference_program_proposals_path(conference.short_title) + within('.progress') { expect(page).to have_text '4 left' } + click_on 'Complete your proposal' + within('.popover') { expect(find(:link, 'Respond to surveys')).to have_sibling('.fa-xmark') } expect(find(:link, survey.title).sibling('.fa-solid')[:title]).to eq('Please fill out the survey') click_link survey.title @@ -75,6 +78,9 @@ expect(flash).to eq('Successfully responded to survey.') visit conference_program_proposals_path(conference.short_title) + within('.progress') { expect(page).to have_text '3 left' } + click_on 'Complete your proposal' + within('.popover') { expect(find(:link, 'Respond to surveys')).to have_sibling('.fa-check') } expect(find(:link, survey.title).sibling('.fa-solid')[:title]).to eq('Thank you for filling out the survey') end end