Class: PresentationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PresentationsController
- Defined in:
- app/controllers/presentations_controller.rb
Constant Summary collapse
- @@eval_options =
{ 4 => "Outstanding", 3 => "Good", 2 => "Minimally Acceptable", 1 => "Poor" }
Instance Method Summary collapse
-
#create ⇒ Object
POST /course/:person_id/presentations.
- #create_feedback ⇒ Object
- #edit_feedback ⇒ Object
- #index ⇒ Object
-
#index_for_course ⇒ Object
GET /courses/:course_id/presentations.
- #my_presentations ⇒ Object
-
#new ⇒ Object
GET /course/:person_id/presentations/new.
- #new_feedback ⇒ Object
- #show_feedback ⇒ Object
- #today ⇒ Object
- #update_feedback ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
POST /course/:person_id/presentations
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/presentations_controller.rb', line 74 def create @course = Course.find(params[:course_id]) @presentation = Presentation.new(:name => params[:presentation][:name], :team_id => params[:presentation][:team_id], :presentation_date => params[:presentation][:presentation_date], :task_number => params[:presentation][:task_number], :course_id => params[:course_id], :creator_id => current_user.id) human_name = params[:presentation][:user] unless human_name.blank? user = User.find_by_human_name(human_name) if user.nil? flash[:error] = "Can't find person #{human_name}" render :action => "new" and return else @presentation.user_id = user.id end end respond_to do |format| if @presentation.save format.html { redirect_to(course_presentations_path, :course_id => params[:course_id], :notice => 'Successfully created the presentation.') } else format.html { render :action => "new" } end end end |
#create_feedback ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/controllers/presentations_controller.rb', line 126 def create_feedback # Check existence of requested presentation @feedback = PresentationFeedback.new(params[:feedback]) @questions = PresentationQuestion.existing_questions @eval_options = @@eval_options @feedback.evaluator = current_user @presentation = Presentation.find(params[:id]) @feedback.presentation = @presentation @presentation.save # Necessary checks here respond_to do |format| is_successful = true params[:evaluation].each do |key, value| answer = PresentationFeedbackAnswer.new(value) begin question = PresentationQuestion.find(key) rescue ActiveRecord::RecordNotFound => e is_successful = false break end @feedback.answers << answer answer.question = question end if is_successful && @feedback.save @presentation.feedback_email_sent = true if @presentation.feedback_email_sent? @presentation.send_presentation_feedback_email(show_feedback_for_presentation_url(:id => params[:id])) end format.html { redirect_back_or_default(today_presentations_url) } else format.html { render :action => "new_feedback" } end end end |
#edit_feedback ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'app/controllers/presentations_controller.rb', line 187 def edit_feedback store_previous_location @presentation = Presentation.find(params[:id]) feedbacks = PresentationFeedback.where(:presentation_id => params[:id]) @feedback = nil @eval_options = @@eval_options @questions = PresentationQuestion.where(:deleted => false) feedbacks.each do |f| if f.evaluator_id == current_user.id @feedback = f # break end end @ratings = [] @comments = [] @questions.each do |q| feedback_answer = PresentationFeedbackAnswer.where(:question_id => q.id, :feedback_id => @feedback.id) @ratings << feedback_answer.first. @comments << feedback_answer.first.comment end respond_to do |format| format.html end end |
#index ⇒ Object
37 38 39 |
# File 'app/controllers/presentations_controller.rb', line 37 def index @presentations = Presentation.order("presentation_date DESC") end |
#index_for_course ⇒ Object
GET /courses/:course_id/presentations
42 43 44 45 46 47 48 49 |
# File 'app/controllers/presentations_controller.rb', line 42 def index_for_course @course = Course.find(params[:course_id]) if (current_user.is_admin? || @course.faculty.include?(current_user)) @presentations = Presentation.find_all_by_course_id(@course.id) else (:admin, root_path) end end |
#my_presentations ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/presentations_controller.rb', line 13 def my_presentations user = User.find_by_param(params[:id]) if (current_user.id != user.id) unless (current_user.is_staff?)||(current_user.is_admin?) flash[:error] = I18n.t(:not_your_presentation) redirect_to root_path and return end end @presentations = Presentation.find_by_presenter(user) end |
#new ⇒ Object
GET /course/:person_id/presentations/new
52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/presentations_controller.rb', line 52 def new @course = Course.find(params[:course_id]) if (current_person.is_admin? || @course.faculty.include?(current_user)) @presentation = Presentation.new(:presentation_date => Date.today) @course =Course.find_by_id(params[:course_id]) else (:admin, root_path) end end |
#new_feedback ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/controllers/presentations_controller.rb', line 106 def new_feedback store_previous_location # Check existence of requested presentation @feedback = PresentationFeedback.new @feedback.presentation_id = params[:id] @questions = PresentationQuestion.existing_questions @eval_options = @@eval_options @presentation = Presentation.find(params[:id]) @ratings = [] @comments = [] # Check whether this user has already created a feedback respond_to do |format| format.html end end |
#show_feedback ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'app/controllers/presentations_controller.rb', line 219 def show_feedback @presentation = Presentation.find(params[:id]) unless @presentation.can_view_feedback?(current_user) flash[:error] = I18n.t(:not_your_presentation) redirect_to root_path and return end @feedbacks = PresentationFeedback.where(:presentation_id => params[:id]) @faculty_feedbacks = [] @student_feedbacks = [] @questions = PresentationQuestion.where(:deleted => false) @feedbacks.each do |f| evaluator = User.find(f.evaluator_id) if evaluator.is_staff? @faculty_feedbacks << f elsif evaluator.is_student? @student_feedbacks << f end end @faculty_ratings = Presentation.(@faculty_feedbacks, @questions) @student_ratings = Presentation.(@student_feedbacks, @questions) @faculty_comments = Presentation.find_comments(@faculty_feedbacks, @questions) @student_comments = Presentation.find_comments(@student_feedbacks, @questions) respond_to do |format| format.html end end |
#today ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/presentations_controller.rb', line 24 def today if current_user.is_student? team_id = Team.find_by_person(current_person) #@presentations = Presentation.where( # "(team_id is Null AND user_id != :id) OR (team_id is not Null AND team_id != :team_id)", # {:id => current_user.id, :team_id => team_id}) @presentations = Presentation.order("presentation_date DESC") else @presentations = Presentation.order("presentation_date DESC") end @presentations = Presentation.where(:presentation_date => Date.today) end |
#update_feedback ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'app/controllers/presentations_controller.rb', line 169 def update_feedback feedback = PresentationFeedback.find_by_evaluator_id_and_presentation_id(current_user, params[:id]) params[:evaluation].each do |key, value| answer = PresentationFeedbackAnswer.find_by_feedback_id_and_question_id(feedback.id, key) if answer answer. = value["rating"] answer.comment = value["comment"] answer.save end end respond_to do |format| flash[:notice] = I18n.t(:presentation_feedback_updated) format.html { redirect_back_or_default(today_presentations_url) } end end |