From a12baf2b94e11845b8c7ef5cd00ae222ee8707fc Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Mon, 23 Oct 2017 00:29:21 +0300 Subject: [PATCH] Implement listing of things that feedback can be submitted for --- .../public/conference_feedbacks_controller.rb | 22 ++++++++++++++-- .../public/event_feedbacks_controller.rb | 14 ++++++++--- app/helpers/events_helper.rb | 11 ++++++++ app/models/feedback.rb | 8 ++++++ config/deploy.rb | 2 +- config/locales/bg.yml | 15 ++++++++--- config/locales/en.yml | 15 ++++++++--- config/routes.rb | 2 +- .../conference_feedbacks/index.html.slim | 25 +++++++++++++++++++ .../public/conference_feedbacks/new.html.slim | 2 +- .../public/event_feedbacks/new.html.slim | 2 +- 11 files changed, 103 insertions(+), 15 deletions(-) create mode 100644 lib/initfest/views/public/conference_feedbacks/index.html.slim diff --git a/app/controllers/public/conference_feedbacks_controller.rb b/app/controllers/public/conference_feedbacks_controller.rb index dc3b677..00d3ddd 100644 --- a/app/controllers/public/conference_feedbacks_controller.rb +++ b/app/controllers/public/conference_feedbacks_controller.rb @@ -1,6 +1,24 @@ class Public::ConferenceFeedbacksController < Public::ApplicationController + def index + @conference = current_conference + @unrated_events = @conference.events + .joins(:proposition).approved + .joins('LEFT JOIN feedbacks ON feedbacks.feedback_receiving_id = events.id AND feedbacks.feedback_receiving_type = "Event"') + .where('feedbacks.session_id != ? OR feedbacks.id IS NULL', session.id) + + @rated_events = @conference.events + .joins(:proposition).approved + .joins(:feedbacks) + .where(feedbacks: {session_id: session.id}).distinct + + end + def new - @feedback = current_conference.feedbacks.build + if current_conference.feedbacks.where(session_id: session.id).exists? + @feedback = current_conference.feedbacks.where(session_id: session.id).order(updated_at: :asc).last + else + @feedback = current_conference.feedbacks.build + end end def create @@ -10,7 +28,7 @@ class Public::ConferenceFeedbacksController < Public::ApplicationController if @feedback.save flash[:notice] = I18n.t('public.conference_feedbacks.new.success') - redirect_to root_path + redirect_to conference_feedbacks_path else render :new, status: :unprocessable_entity end diff --git a/app/controllers/public/event_feedbacks_controller.rb b/app/controllers/public/event_feedbacks_controller.rb index f2246da..358d732 100644 --- a/app/controllers/public/event_feedbacks_controller.rb +++ b/app/controllers/public/event_feedbacks_controller.rb @@ -1,16 +1,20 @@ class Public::EventFeedbacksController < Public::ApplicationController def new - @feedback = approved_events.find(params[:event_id]).feedbacks.build + if event.feedbacks.where(session_id: session.id).exists? + @feedback = event.feedbacks.where(session_id: session.id).order(updated_at: :asc).last + else + @feedback = event.feedbacks.build + end end def create - @feedback = approved_events.find(params[:event_id]).feedbacks.build(feedback_params) + @feedback = event.feedbacks.build(feedback_params) @feedback.ip_address = request.remote_ip @feedback.session_id = session.id if @feedback.save flash[:notice] = I18n.t('public.event_feedbacks.new.success') - redirect_to root_path + redirect_to conference_feedbacks_path else render :new, status: :unprocessable_entity end @@ -22,6 +26,10 @@ class Public::EventFeedbacksController < Public::ApplicationController params.require(:feedback).permit(:author_email, :rating, :comment) end + def event + approved_events.find(params[:event_id]) + end + def approved_events current_conference.events.joins(:proposition).approved end diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index dcedbc0..815fc65 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -23,4 +23,15 @@ module EventsHelper end end end + + def participant_names(event) + event.participants.map do |participant| + if participant.personal_profile(event.conference).present? + profile = participant.personal_profile(event.conference) + "#{profile.name}" + else + nil + end + end.compact + end end diff --git a/app/models/feedback.rb b/app/models/feedback.rb index 99a90e0..37517db 100644 --- a/app/models/feedback.rb +++ b/app/models/feedback.rb @@ -2,4 +2,12 @@ class Feedback < ActiveRecord::Base belongs_to :feedback_receiving, polymorphic: true validates :rating, presence: true, inclusion: {in: [2, 3, 4, 5 ,6]} + + before_create :destroy_older_feedbacks_by_the_session + + private + + def destroy_older_feedbacks_by_the_session + feedback_receiving.feedbacks.where(session_id: session_id).destroy_all + end end diff --git a/config/deploy.rb b/config/deploy.rb index ceff646..eec7549 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -32,7 +32,7 @@ set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/uploads', 'tmp/pids', # set :default_env, { path: "/opt/ruby/bin:$PATH" } # Default value for keep_releases is 5 -# set :keep_releases, 5 +set :keep_releases, 10 set :rvm_ruby_version, '2.2.2' diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 0a643ab..f012191 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -1,11 +1,20 @@ bg: public: - event_feedbacks: &feedbacks_bg - new: + event_feedbacks: + new: &new_feedbacks_bg feedback_for: Оценяване на „%{title}“ submit: Изпрати success: Оценката беше изпратена успешно - conference_feedbacks: *feedbacks_bg + conference_feedbacks: + new: *new_feedbacks_bg + index: + feedback_for_the_conference: Оценяване на конференцията + general_feedback_for: Оценете цялостно %{title} + change_general_feedback_for: Преоценете цялостно %{title} + feedback_for: Оценете „%{title}“ + change_feedback_for: Преоценете „%{title}“ + by: от %{authors} + feedback_incentive: Бихме били благодарни, ако споделите с нас мнението си за конференцията и събитията в нея. management: volunteers: index: diff --git a/config/locales/en.yml b/config/locales/en.yml index 6215436..13a76ad 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,11 +1,20 @@ en: public: - event_feedbacks: &feedbacks_en - new: + event_feedbacks: + new: &new_feedbacks_en feedback_for: Rating '%{title}' submit: Submit success: The feedback was submitted successfully - conference_feedbacks: *feedbacks_en + conference_feedbacks: + new: *new_feedbacks_en + index: + feedback_for_the_conference: Feedback for the conference + general_feedback_for: Submit general feedback for "%{title}" + change_general_feedback_for: Resubmit general feedback for "%{title}" + feedback_for: Submit feedback for "%{title}" + change_feedback_for: Resubmit feedback for "%{title}" + by: by %{authors} + feedback_incentive: We would be happy to receive your feedback about the conference and its events. abstract: Abstract helpers: submit: diff --git a/config/routes.rb b/config/routes.rb index 1bcb44a..56de69a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,7 +13,7 @@ Rails.application.routes.draw do end resources :volunteers resources :volunteer_teams, only: [:index] - resources :feedback, as: 'conference_feedbacks', controller: 'conference_feedbacks', only: [:new, :create] + resources :feedback, as: 'conference_feedbacks', controller: 'conference_feedbacks', only: [:new, :create, :index] end namespace :api do diff --git a/lib/initfest/views/public/conference_feedbacks/index.html.slim b/lib/initfest/views/public/conference_feedbacks/index.html.slim new file mode 100644 index 0000000..5a36d9b --- /dev/null +++ b/lib/initfest/views/public/conference_feedbacks/index.html.slim @@ -0,0 +1,25 @@ +- content_for(:title) { t('.feedback_for_the_conference') } + +h1.entry-title = t('.feedback_for_the_conference') + +p = t('.feedback_incentive') + +ul + - if @conference.feedbacks.where(session_id: session.id).exists? + li = link_to t('.change_general_feedback_for', title: @conference.title), new_conference_feedback_path + - else + li = link_to t('.general_feedback_for', title: @conference.title), new_conference_feedback_path + +ul + - @unrated_events.each do |event| + li + = link_to t('.feedback_for', title: event.title), new_event_feedback_path(event_id: event.id) + - if participant_names(event).any? + =< t('.by', authors: participant_names(event).join(', ')) + +ul + - @rated_events.each do |event| + li + = link_to t('.change_feedback_for', title: event.title), new_event_feedback_path(event_id: event.id) + - if participant_names(event).any? + =< t('.by', authors: participant_names(event).join(', ')) diff --git a/lib/initfest/views/public/conference_feedbacks/new.html.slim b/lib/initfest/views/public/conference_feedbacks/new.html.slim index 03e4028..3143800 100644 --- a/lib/initfest/views/public/conference_feedbacks/new.html.slim +++ b/lib/initfest/views/public/conference_feedbacks/new.html.slim @@ -2,7 +2,7 @@ h1.entry-title = t('.feedback_for', title: @feedback.feedback_receiving.title) -= simple_form_for @feedback, wrapper: :default, url: conference_feedbacks_path do |f| += simple_form_for @feedback, wrapper: :default, url: conference_feedbacks_path, method: :post do |f| = f.error_notification .form-inputs diff --git a/lib/initfest/views/public/event_feedbacks/new.html.slim b/lib/initfest/views/public/event_feedbacks/new.html.slim index 02c6d61..e4cdc2d 100644 --- a/lib/initfest/views/public/event_feedbacks/new.html.slim +++ b/lib/initfest/views/public/event_feedbacks/new.html.slim @@ -2,7 +2,7 @@ h1.entry-title = t('.feedback_for', title: @feedback.feedback_receiving.title) -= simple_form_for @feedback, wrapper: :default, url: event_feedbacks_path do |f| += simple_form_for @feedback, wrapper: :default, url: event_feedback_index_path, method: :post do |f| = f.error_notification .form-inputs