diff --git a/app/controllers/admin/survey_questions_controller.rb b/app/controllers/admin/survey_questions_controller.rb index 0ce9a6b6..b425fc4b 100644 --- a/app/controllers/admin/survey_questions_controller.rb +++ b/app/controllers/admin/survey_questions_controller.rb @@ -3,7 +3,7 @@ module Admin class SurveyQuestionsController < Admin::BaseController load_and_authorize_resource :conference, find_by: :short_title - load_and_authorize_resource :survey, through: :conference + load_and_authorize_resource :survey load_and_authorize_resource through: :survey def new diff --git a/app/controllers/admin/surveys_controller.rb b/app/controllers/admin/surveys_controller.rb index ccc2243d..591a5ddc 100644 --- a/app/controllers/admin/surveys_controller.rb +++ b/app/controllers/admin/surveys_controller.rb @@ -6,7 +6,7 @@ module Admin load_and_authorize_resource def index - @surveys = @conference.surveys + @surveys = @conference.surveys + Survey.where(surveyable: @conference.program.events) end def new diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index ab027902..5229c88d 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -17,6 +17,7 @@ class ProposalsController < ApplicationController def show @event_schedule = @event.event_schedules.find_by(schedule_id: @program.selected_schedule_id) @speakers_ordered = @event.speakers_ordered + @surveys_after_event = @event.surveys.after_event.select(&:active?) end def new diff --git a/app/models/conference.rb b/app/models/conference.rb index c33417e0..7f606927 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -785,6 +785,16 @@ class Conference < ApplicationRecord short_title end + ## + # Returns true or false, if the event is already over or not + # + # ====Returns + # * +true+ -> If the event is over + # * +false+ -> If the event is not over yet + def ended? + end_date < Time.current + end + private # Returns a different html colour for every i and consecutive colors are diff --git a/app/models/event.rb b/app/models/event.rb index 3ed8b030..59a5d0b1 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -21,6 +21,7 @@ class Event < ApplicationRecord has_many :votes, dependent: :destroy has_many :voters, through: :votes, source: :user has_many :commercials, as: :commercialable, dependent: :destroy + has_many :surveys, as: :surveyable, dependent: :destroy belongs_to :event_type has_many :events_registrations diff --git a/app/models/survey.rb b/app/models/survey.rb index e89aad41..7143b658 100644 --- a/app/models/survey.rb +++ b/app/models/survey.rb @@ -5,12 +5,30 @@ class Survey < ActiveRecord::Base has_many :survey_questions, dependent: :destroy has_many :survey_submissions, dependent: :destroy - enum target: [:after_conference, :during_registration] + enum target: [:after_conference, :during_registration, :after_event] validates :title, presence: true + ## + # Finds active surveys + # * if a survey has either start or end date, but not both + # check is performed only on the attribute that exists + # * if a survey does not have start/end dates, then it is marked active + # further check is expected, where appropriate, depending on the survey's target + # ====Returns + # * +true+ -> If the survey is active (will accept replies) + # * +false+ -> If the survey is closed def active? - return false unless start_date && end_date - now = Time.now.in_time_zone(surveyable.timezone) - now >= start_date && now <= end_date + return true unless start_date || end_date + # Find timezone of conference (survyeable is Conference or Event) + timezone = surveyable.is_a?(Conference) ? surveyable.timezone : surveyable.conference.timezone + now = Time.current.in_time_zone(timezone) + + if start_date && end_date + now >= start_date && now <= end_date + elsif start_date && !end_date + now >= start_date + elsif !start_date && end_date + now <= end_date + end end end diff --git a/app/views/admin/events/_voting.html.haml b/app/views/admin/events/_voting.html.haml index 8a8fa4ed..3860f032 100644 --- a/app/views/admin/events/_voting.html.haml +++ b/app/views/admin/events/_voting.html.haml @@ -38,7 +38,7 @@ class: 'rating myrating' - else = rating_stars(event.user_rating(current_user), max_rating, voted: true) - = (Voting period is closed) + (Voting period is closed) - if show_votes - unless votes.blank? diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index f06c6483..835880b7 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -91,6 +91,7 @@ %b State %th .fa.fa-comment + %th Add Survey - @events.each do |event| = render 'datatable_row', event: event, diff --git a/app/views/conferences/_conference_details.html.haml b/app/views/conferences/_conference_details.html.haml index 4595aa0a..1de55697 100644 --- a/app/views/conferences/_conference_details.html.haml +++ b/app/views/conferences/_conference_details.html.haml @@ -52,5 +52,5 @@ = link_to 'Unsubscribe', conference_subscriptions_path(conference.short_title), method: :delete, class: 'btn btn-default' - if current_user && current_user.physical_tickets.by_conference(conference).any? = link_to 'My Tickets', conference_physical_tickets_path(conference.short_title), class: 'btn btn-default' - - surveys = conference.surveys.after_conference.select(&:active?) - = link_to 'Surveys', conference_surveys_path(conference.short_title), class: 'btn btn-default' if surveys.any? + - surveys_after_conference = conference.surveys.after_conference.select(&:active?) + = link_to 'Surveys', conference_surveys_path(conference.short_title), class: 'btn btn-default' if surveys_after_conference.any? && conference.ended? diff --git a/app/views/proposals/show.html.haml b/app/views/proposals/show.html.haml index 99f2d49e..ae2a93cc 100644 --- a/app/views/proposals/show.html.haml +++ b/app/views/proposals/show.html.haml @@ -122,3 +122,8 @@ %dt Room: %dd = event.room.name + .row + .col-md-12 + - if @surveys_after_event.any? && @event.ended? + .page-header + = render partial: 'surveys/list', locals: { surveys: @surveys_after_event, conference: @conference }