From 3668e2f0dbb35f13a08c580f85f78cfd94dc141b Mon Sep 17 00:00:00 2001 From: Bradley Bain Date: Tue, 26 Feb 2019 21:35:07 -0800 Subject: [PATCH 01/41] Course review creation --- app/assets/javascripts/application.js | 3 +- .../{course_review.js => course_reviews.js} | 0 app/assets/stylesheets/application.css | 1 + ...course_review.scss => course_reviews.scss} | 2 +- app/controllers/course_review_controller.rb | 8 -- app/controllers/course_reviews_controller.rb | 49 ++++++++++++ app/models/course.rb | 8 ++ app/models/course_review.rb | 6 ++ app/views/course_review/create.html.erb | 2 - app/views/course_reviews/new.html.erb | 79 +++++++++++++++++++ .../show.html.erb | 0 app/views/courses/show.html.erb | 2 + config/routes.rb | 8 +- 13 files changed, 153 insertions(+), 15 deletions(-) rename app/assets/javascripts/{course_review.js => course_reviews.js} (100%) rename app/assets/stylesheets/{course_review.scss => course_reviews.scss} (61%) delete mode 100644 app/controllers/course_review_controller.rb create mode 100644 app/controllers/course_reviews_controller.rb delete mode 100644 app/views/course_review/create.html.erb create mode 100644 app/views/course_reviews/new.html.erb rename app/views/{course_review => course_reviews}/show.html.erb (100%) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index c85000b6..87a6e946 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -32,4 +32,5 @@ //= require sessions.js //= require static.js //= require courses.js -//= require menu.js \ No newline at end of file +//= require menu.js +//= require course_reviews.js \ No newline at end of file diff --git a/app/assets/javascripts/course_review.js b/app/assets/javascripts/course_reviews.js similarity index 100% rename from app/assets/javascripts/course_review.js rename to app/assets/javascripts/course_reviews.js diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 7afc9400..e7c4a801 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -30,6 +30,7 @@ *= require courses.scss *= require static.scss *= require menu.scss + *= require course_reviews.scss * * Global styles defined in this file *= require_self diff --git a/app/assets/stylesheets/course_review.scss b/app/assets/stylesheets/course_reviews.scss similarity index 61% rename from app/assets/stylesheets/course_review.scss rename to app/assets/stylesheets/course_reviews.scss index bb28e2de..f827bbc7 100644 --- a/app/assets/stylesheets/course_review.scss +++ b/app/assets/stylesheets/course_reviews.scss @@ -1,3 +1,3 @@ -// Place all the styles related to the course_review controller here. +// Place all the styles related to the course_reviews controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/course_review_controller.rb b/app/controllers/course_review_controller.rb deleted file mode 100644 index f9f95699..00000000 --- a/app/controllers/course_review_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CourseReviewController < ApplicationController - def show - @course_review = CourseReview.find_by(:id => params[:id]) - end - - def create - end -end diff --git a/app/controllers/course_reviews_controller.rb b/app/controllers/course_reviews_controller.rb new file mode 100644 index 00000000..9139f2e7 --- /dev/null +++ b/app/controllers/course_reviews_controller.rb @@ -0,0 +1,49 @@ +class CourseReviewsController < ApplicationController + before_action :authenticate_user!, only: [:new, :edit] + + # GET /reviews/:id + def show + @course_review = CourseReview.find_by(:id => params[:id]) + end + + # GET /reviews/course/:id/new + def new + course_id = params[:course_id] + @course = Course.find_by(:id => course_id) + + @course_review = CourseReview.new + end + + def create + @course_review = CourseReview.new( + :overall_rating => review_params[:overall_rating], + :inclusivity_rating => review_params[:inclusivity_rating], + :challenge_rating => review_params[:challenge_rating], + :work_per_week => review_params[:work_per_week], + :comments => review_params[:comments], + :course_id => review_params[:course_id], + :instructor_id => review_params[:instructor_id] + ) + + course_id = review_params[:course_id] + @course = @course_review.course #Course.find_by(:id => course_id) + + respond_to do |format| + if @course_review.save + format.html { redirect_to @course_review.course, notice: 'Your course review has been submitted successfully.' } + format.json { render json: @course_review, status: :ok } + else + format.html { render :new } + format.json { render json: @course_review.errors, status: :unprocessable_entity } + end + end + end + + # Never trust parameters from the scary internet, only allow the white list through. + def review_params + params + .require(:course_review) + .permit(:overall_rating, :challenge_rating, :inclusivity_rating, :work_per_week, :comments, + :course_id, :instructor_id, :id) + end +end diff --git a/app/models/course.rb b/app/models/course.rb index 2439df4c..fcc0148b 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -20,4 +20,12 @@ def challenge_rating def work_per_week self.course_reviews&.average(:work_per_week)&.round(2, :truncate) || 0 end + + # collect all instructors that have ever taught a section of this course + def instructors + self.course_sections + .collect{ |section| section.instructors } + .reduce(:+) + .uniq + end end diff --git a/app/models/course_review.rb b/app/models/course_review.rb index 80f367cd..44abea68 100644 --- a/app/models/course_review.rb +++ b/app/models/course_review.rb @@ -4,6 +4,12 @@ class CourseReview < ApplicationRecord belongs_to :course belongs_to :instructor + validates :course, :presence => true + validates :overall_rating, :presence => true + validates :inclusivity_rating, :presence => true + validates :challenge_rating, :presence => true + validates :work_per_week, :presence => true + accepts_nested_attributes_for :course accepts_nested_attributes_for :instructor diff --git a/app/views/course_review/create.html.erb b/app/views/course_review/create.html.erb deleted file mode 100644 index 53115d03..00000000 --- a/app/views/course_review/create.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

CourseReview#create

-

Find me in app/views/course_review/create.html.erb

diff --git a/app/views/course_reviews/new.html.erb b/app/views/course_reviews/new.html.erb new file mode 100644 index 00000000..a73ae33e --- /dev/null +++ b/app/views/course_reviews/new.html.erb @@ -0,0 +1,79 @@ +<% content_for :header do %> + <%= render 'components/page_header', :title => "Submit Course Review", :subtitle => "Leave feedback for #{@course.name}" %> +<% end %> + +<%= form_with(model: @course_review, local: true) do |form| %> + <% if @course_review.errors.any? %> +
+
The following errors prohibited this review from being submitted:
+ + <% @course_review.errors.full_messages.each do |message| %> +
+

+ <%= message %> +

+
+ <% end %> +
+ <% end %> + +
+ +
+ <%= form.label :instructor_id, :class => "label"%> +
+
+ <%= form.select :instructor_id, + options_for_select(@course.instructors.collect(&:name).zip @course.instructors.collect(&:id)), + :class => "input is-rounded" %> +
+
+
+ +
+ <%= form.label :overall_rating, :class => "label"%> +
+
+ <%= form.select :overall_rating, 1..5, :class => "input is-rounded" %> +
+
+
+ +
+ <%= form.label :inclusivity_rating, :class => "label"%> +
+
+ <%= form.select :inclusivity_rating, 1..5, :class => "input is-rounded" %> +
+
+
+ +
+ <%= form.label :challenge_rating, :class => "label"%> +
+
+ <%= form.select :challenge_rating, 1..5, :class => "input is-rounded" %> +
+
+
+ +
+ <%= form.label :work_per_week, :class => "label"%> +
+
+ <%= form.select :work_per_week, 1..10, :class => "input is-rounded" %> +
+
+
+ +
+ <%= form.label :comments, :class => "label" %> + <%= form.text_area :comments, :class => "textarea is-rounded" %> +
+ + <%= form.hidden_field :course_id, :value => @course.id %> + +
+ <%= form.submit'Submit course', :class => "button is-info" %> +
+<% end %> diff --git a/app/views/course_review/show.html.erb b/app/views/course_reviews/show.html.erb similarity index 100% rename from app/views/course_review/show.html.erb rename to app/views/course_reviews/show.html.erb diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index 5b55ffe2..802c5635 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -7,6 +7,7 @@ <%= render 'components/numerical_review', rating: @course.overall_rating, tag_classes: 'is-large is-info', show_icon: true %> + <%= link_to "Submit course review", new_course_review_path(@course.id), :class => 'button is-light' %>
@@ -81,6 +82,7 @@

There are no reviews for this course at this time.

+

<%= link_to "Submit course review", new_course_review_path(@course.id), :class => 'button is-info' %>

<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6f4e9778..cea4e033 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,13 +1,15 @@ Rails.application.routes.draw do - get 'instructors/show' - get 'course_review/show' - get 'course_review/create' root :to => 'static#index' ActiveAdmin.routes(self) resources :events + scope controller: :course_reviews do + get 'courses/:course_id/review/new' => :new, as: :new_course_review + post 'reviews' => :create, as: :course_reviews + end + scope controller: :courses do get 'courses' => :index get 'courses/export' => :export_course_sections From 8001c47c90afaa38afd8da511d16a4e07bc5fda4 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Mon, 18 Mar 2019 00:47:10 -0700 Subject: [PATCH 02/41] Update _application_header.html.erb --- .../components/_application_header.html.erb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/views/components/_application_header.html.erb b/app/views/components/_application_header.html.erb index f82a38db..664b322e 100644 --- a/app/views/components/_application_header.html.erb +++ b/app/views/components/_application_header.html.erb @@ -21,7 +21,22 @@ - <%= link_to "Courses", :courses, :class => "navbar-item" %> + +
+ <% if course_sections %> +
+ +
+
+ <% course_sections.each do |section| %> + <% campus_background_color_class = + case section.course_meeting_details.first.try(:campus).try(:to_sym) + when :pomona + "campus_PO" + when :claremont_mckenna + "campus_CM" + when :harvey_mudd + "campus_HM" + when :scripps + "campus_SC" + when :pitzer + "campus_PZ" + else + "campus_KS" + end + %> + +
+
+ + <%= link_to course_path(section.course), :class => 'no-underline' do %> + <%= section.code %> - <%= section.course.name %> + <% end %> + + + <%= link_to course_path(section.course), :class => 'no-underline' do %> + <%= render 'components/numerical_review', + rating: section.course.overall_rating, + tag_classes: "#{campus_background_color_class} has-text-white has-brightness", + show_icon: true %> + <% end %> + +
+
+
+
+

+ <% section.instructors.each do |instructor| %> + <%= link_to instructor_path(instructor), :class => 'no-underline' do %> + <%= instructor.name %>   + <%= render 'components/numerical_review', + rating: instructor.overall_rating, show_icon: true %> + <% end %> + +
+ <% end %> + +
+ <%= section.credit %> credits +

+
+
+
+
+

+ <%= raw section.description %> +

+
+
+
+
+ <% section.course_meeting_details.each do |detail| %> +

<%= detail.to_s %>

+ <% end %> +
+
+
+
+ <%= button_to "Leave Review", + :courses_add, + :class => "button", + :method => :post, + :remote => true, + :params => {:section_id => section.id} %> +
+
+
+
+ <% end %> +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/courses/partials/_reviews_search_form.html.erb b/app/views/courses/partials/_reviews_search_form.html.erb new file mode 100644 index 00000000..8bd580ff --- /dev/null +++ b/app/views/courses/partials/_reviews_search_form.html.erb @@ -0,0 +1,127 @@ +<% academic_terms = @academic_terms %> +<% departments = @departments %> + +<%= form_with url: courses_search_url, remote: true do |f| %> +
+ +
+
+ <%= f.text_field :keywords, :class => "input", :placeholder => "Keywords" %> +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ <%= f.select :department, options_for_select( + departments.collect(&:name) + ), :prompt => "(any)" %> +
+
+
+ +
+ <%= f.submit "Search", :class => "button is-link search-button margin-bottom-0" %> + Show advanced search +
+<% end %> diff --git a/app/views/courses/reviews.html.erb b/app/views/courses/reviews.html.erb new file mode 100644 index 00000000..08509f4e --- /dev/null +++ b/app/views/courses/reviews.html.erb @@ -0,0 +1,6 @@ +<% content_for :header do %> + <%= render "components/page_header", :title => "Course Reviews" %> +<% end %> + +<%= render 'courses/partials/reviews_search_form' %> +<%= render 'courses/partials/reviews_course_list' %> \ No newline at end of file From 2fa2a9ea0790ff83d957f45483f36e1ed39ea9d8 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Mon, 18 Mar 2019 00:50:01 -0700 Subject: [PATCH 06/41] Update courses.scss --- app/assets/stylesheets/courses.scss | 41 ++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/courses.scss b/app/assets/stylesheets/courses.scss index f5ffb950..fd6d38c3 100644 --- a/app/assets/stylesheets/courses.scss +++ b/app/assets/stylesheets/courses.scss @@ -516,14 +516,49 @@ select { height: 885px; } +#reviews-list-results { + height:auto; + overflow:auto; +} + +#reviews-list-results .button_to { + display: inline-block; +} + .course-tags { flex-wrap: wrap; margin-bottom: 0.5rem !important; height: 3.0rem !important; } -.campus-label { - border-radius: 4px; - padding: 3px; +.expandable { + display: none; + + .search-button { + margin-right: 0.5rem; + } +} + +.checkboxes { + display: flex; + flex-wrap: wrap; + + .checkbox { + border-radius: 4px; + padding: 4px 8px; + } + + .day-checkbox { + background: #b5b5b5; + color: white; + text-transform: uppercase; + font-size: 0.75rem; + margin-bottom: 5px; + } + + input[type="checkbox"] { + margin-top: -3px; + vertical-align: middle; + } } From 48f626d640256851968c0341d4690c130af062b9 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Mon, 18 Mar 2019 00:50:11 -0700 Subject: [PATCH 07/41] Update courses.js --- app/assets/javascripts/courses.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/courses.js b/app/assets/javascripts/courses.js index c28b05b3..5ec43ad0 100644 --- a/app/assets/javascripts/courses.js +++ b/app/assets/javascripts/courses.js @@ -1,6 +1,17 @@ // Place all the behaviors and hooks related to the matching controller here. // All this logic will automatically be available in application.js. // You can use CoffeeScript in this file: http://coffeescript.org/ -$( document ).ready(function() { +$(document).ready(function () { $('select[id*="time"]').wrap('
'); + + $(".expand-search-options").click(function (e) { + e.preventDefault(); + $(".expandable").toggle('slow', 'swing', function () { + if ($('.expandable').css('display') == 'block') { + $(".expand-search-options").text("Hide advanced search") + } else { + $(".expand-search-options").text("Show advanced search") + } + }); + }); }); From eec35c6e600eb94be09960c11aa46475e6ab272c Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Mon, 18 Mar 2019 00:50:28 -0700 Subject: [PATCH 08/41] Update search_course_sections.js.erb --- .../courses/search_course_sections.js.erb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/views/courses/search_course_sections.js.erb b/app/views/courses/search_course_sections.js.erb index 3cb9c009..4b50742c 100644 --- a/app/views/courses/search_course_sections.js.erb +++ b/app/views/courses/search_course_sections.js.erb @@ -1,8 +1,11 @@ -$("#course-list-container") - .html("<%= escape_javascript(render partial: 'courses/partials/course_list', locals: { course_sections: @course_sections }) %>"); - -$("#course-list-container") - .removeClass("is-hidden"); - -$("#course-schedule-container") - .addClass("is-5"); \ No newline at end of file +if ($("#course-list-container").length) { + $("#course-list-container") + .html("<%= escape_javascript(render partial: 'courses/partials/course_list', locals: { course_sections: @course_sections }) %>"); + $("#course-list-container") + .removeClass("is-hidden"); + $("#course-schedule-container") + .addClass("is-5"); +} else { + $("#reviews-course-list-container") + .html("<%= escape_javascript(render partial: 'courses/partials/reviews_course_list', locals: { course_sections: @course_sections }) %>"); +} From 5e47eb8ed8251daeddbf6c02c3ea71b2d274ff40 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Wed, 20 Mar 2019 13:36:14 -0700 Subject: [PATCH 09/41] Update reviews.html.erb --- app/views/courses/reviews.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/courses/reviews.html.erb b/app/views/courses/reviews.html.erb index 08509f4e..30a9bf2c 100644 --- a/app/views/courses/reviews.html.erb +++ b/app/views/courses/reviews.html.erb @@ -1,5 +1,5 @@ <% content_for :header do %> - <%= render "components/page_header", :title => "Course Reviews" %> + <%= render "components/page_header", :title => "Course Reviews", :subtitle => "Search courses" %> <% end %> <%= render 'courses/partials/reviews_search_form' %> From 3dd08638c4d81f6d14e309c78413c814a734d0cf Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Wed, 20 Mar 2019 13:37:11 -0700 Subject: [PATCH 10/41] Update _reviews_course_list.html.erb --- app/views/courses/partials/_reviews_course_list.html.erb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/views/courses/partials/_reviews_course_list.html.erb b/app/views/courses/partials/_reviews_course_list.html.erb index 505c7ac6..724820e8 100644 --- a/app/views/courses/partials/_reviews_course_list.html.erb +++ b/app/views/courses/partials/_reviews_course_list.html.erb @@ -3,10 +3,8 @@
<% if course_sections %> -
- +
+ Showing <%= course_sections.length %> results
<% course_sections.each do |section| %> From ba2738232f7262c9d989427f58064848926f7899 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Wed, 20 Mar 2019 13:37:42 -0700 Subject: [PATCH 11/41] Update application.css --- app/assets/stylesheets/application.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 10cb3dbb..05e35648 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -126,4 +126,8 @@ .has-brightness { filter: brightness(1.25); +} + +.results-heading { + margin: 20px auto 10px 0; } \ No newline at end of file From 38eba7ee325c4e8fec4c2fee7d2288d9f85a7479 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Wed, 20 Mar 2019 13:38:02 -0700 Subject: [PATCH 12/41] Update instructors_controller.rb --- app/controllers/instructors_controller.rb | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/controllers/instructors_controller.rb b/app/controllers/instructors_controller.rb index 385675c6..63e62350 100644 --- a/app/controllers/instructors_controller.rb +++ b/app/controllers/instructors_controller.rb @@ -1,5 +1,32 @@ class InstructorsController < ApplicationController + before_action :authenticate_user! + + def index + @departments = Department.all + end + def show @instructor = Instructor.find(params[:id]) end + + def search + instructor_name = params[:instructor].strip unless params[:instructor].empty? + + matches_query = Instructor + + matches = matches_query.order("id").all + + if (instructor_name) + matches = matches.select {|instructor| instructor.name.downcase.include? instructor_name.downcase} + end + + matches = matches.uniq + + @instructors = matches + respond_to do |format| + format.html {render :json => matches.to_json, :status => :ok} + format.json {render :json => matches.to_json, :status => :ok} + format.js + end + end end From 66524fd05b5150e39fbef7dfb18bf23939ff9f53 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Wed, 20 Mar 2019 13:38:22 -0700 Subject: [PATCH 13/41] Update search_course_sections.js.erb --- app/views/courses/search_course_sections.js.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/courses/search_course_sections.js.erb b/app/views/courses/search_course_sections.js.erb index 4b50742c..571efbf2 100644 --- a/app/views/courses/search_course_sections.js.erb +++ b/app/views/courses/search_course_sections.js.erb @@ -7,5 +7,7 @@ if ($("#course-list-container").length) { .addClass("is-5"); } else { $("#reviews-course-list-container") - .html("<%= escape_javascript(render partial: 'courses/partials/reviews_course_list', locals: { course_sections: @course_sections }) %>"); + .hide() + .html("<%= escape_javascript(render partial: 'courses/partials/reviews_course_list', locals: { course_sections: @course_sections }) %>") + .fadeIn('slow'); } From a31c8b92064c26a04a313d92abb272688a284e01 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Wed, 20 Mar 2019 13:38:38 -0700 Subject: [PATCH 14/41] Update routes.rb --- config/routes.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index f40406d5..cb13352c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,7 +22,9 @@ end scope controller: :instructors do + get 'instructors' => :index get 'instructors/:id' => :show, as: :instructor + match 'instructors/search' => :search, :via => [:get, :post] end scope controller: :menu do From 4c97122fada0ef8f04a7d86dcaf135992e85bf36 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Wed, 20 Mar 2019 13:39:01 -0700 Subject: [PATCH 15/41] Add index.html.erb --- app/views/instructors/index.html.erb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 app/views/instructors/index.html.erb diff --git a/app/views/instructors/index.html.erb b/app/views/instructors/index.html.erb new file mode 100644 index 00000000..e746770f --- /dev/null +++ b/app/views/instructors/index.html.erb @@ -0,0 +1,6 @@ +<% content_for :header do %> +<%= render "components/page_header", :title => "Instructor Reviews", :subtitle => "Search instructors" %> +<% end %> + +<%= render 'instructors/partials/instructors_search_form' %> +<%= render 'instructors/partials/instructors_list' %> \ No newline at end of file From 8d71046b2071cdd028c28968c4955a78f913c07f Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Wed, 20 Mar 2019 13:39:14 -0700 Subject: [PATCH 16/41] Add search.js.erb --- app/views/instructors/search.js.erb | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 app/views/instructors/search.js.erb diff --git a/app/views/instructors/search.js.erb b/app/views/instructors/search.js.erb new file mode 100644 index 00000000..2893a070 --- /dev/null +++ b/app/views/instructors/search.js.erb @@ -0,0 +1,4 @@ +$("#instructors-list-container") + .hide() + .html("<%= escape_javascript(render partial: 'instructors/partials/instructors_list', locals: { instructors: @instructors }) %>") + .fadeIn('slow'); \ No newline at end of file From 3beb212f1b6c3c9d12d8483101cec0e0411bda57 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Wed, 20 Mar 2019 13:39:27 -0700 Subject: [PATCH 17/41] Add _instructors_list.html.erb --- .../partials/_instructors_list.html.erb | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/views/instructors/partials/_instructors_list.html.erb diff --git a/app/views/instructors/partials/_instructors_list.html.erb b/app/views/instructors/partials/_instructors_list.html.erb new file mode 100644 index 00000000..3d0826e1 --- /dev/null +++ b/app/views/instructors/partials/_instructors_list.html.erb @@ -0,0 +1,23 @@ +<% instructors = @instructors %> + + +
+ <% if instructors %> +
+ Showing <%= instructors.length %> results +
+
+ <% instructors.each do |instructor| %> +
+
+ <%= instructor.name %> + <%= render 'components/numerical_review', rating: instructor.overall_rating, tag_classes: 'is-info', show_icon: true %> +
+
+ +
+
+ <% end %> +
+ <% end %> +
\ No newline at end of file From 3660aa838bff357daeef7bc52b319b6b1f570c5d Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Wed, 20 Mar 2019 13:40:41 -0700 Subject: [PATCH 18/41] Add _instructors_search_form.html.erb --- .../partials/_instructors_search_form.html.erb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/views/instructors/partials/_instructors_search_form.html.erb diff --git a/app/views/instructors/partials/_instructors_search_form.html.erb b/app/views/instructors/partials/_instructors_search_form.html.erb new file mode 100644 index 00000000..773d767e --- /dev/null +++ b/app/views/instructors/partials/_instructors_search_form.html.erb @@ -0,0 +1,10 @@ +<%= form_with url: instructors_search_url, remote: true do |f| %> +
+
+ <%= f.text_field :instructor, :class => "input", :placeholder => "Instructor name" %> +
+
+ <%= f.submit "Search", :class => "button is-link search-button margin-bottom-0" %> +
+
+<% end %> \ No newline at end of file From c9fbe36fc862256058845d7633a93276f0a4cd57 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Tue, 26 Mar 2019 01:07:12 -0700 Subject: [PATCH 19/41] Update _application_header.html.erb --- app/views/components/_application_header.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/components/_application_header.html.erb b/app/views/components/_application_header.html.erb index 664b322e..3732917b 100644 --- a/app/views/components/_application_header.html.erb +++ b/app/views/components/_application_header.html.erb @@ -23,17 +23,17 @@ From 814be91cc91edf8d5fa89a965f5bcb5508d57016 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Tue, 26 Mar 2019 01:07:27 -0700 Subject: [PATCH 20/41] Update _instructors_list.html.erb --- app/views/instructors/partials/_instructors_list.html.erb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/instructors/partials/_instructors_list.html.erb b/app/views/instructors/partials/_instructors_list.html.erb index 3d0826e1..626e53e1 100644 --- a/app/views/instructors/partials/_instructors_list.html.erb +++ b/app/views/instructors/partials/_instructors_list.html.erb @@ -14,7 +14,10 @@ <%= render 'components/numerical_review', rating: instructor.overall_rating, tag_classes: 'is-info', show_icon: true %>
- +

Courses taught:

+

Challenge rating:<%= render 'components/star_review', rating: instructor.challenge_rating, tag_classes: 'is-medium' %>

+

Inclusivity rating:<%= render 'components/star_review', rating: instructor.inclusivity_rating, tag_classes: 'is-medium' %>

+

Average work per week:<%= instructor.work_per_week %> hours

<% end %> From c1ff4e9095162799d1b247bde0521a78c4049171 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Tue, 26 Mar 2019 01:07:41 -0700 Subject: [PATCH 21/41] Update _instructors_search_form.html.erb --- .../_instructors_search_form.html.erb | 54 +++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/app/views/instructors/partials/_instructors_search_form.html.erb b/app/views/instructors/partials/_instructors_search_form.html.erb index 773d767e..bc642775 100644 --- a/app/views/instructors/partials/_instructors_search_form.html.erb +++ b/app/views/instructors/partials/_instructors_search_form.html.erb @@ -1,10 +1,46 @@ -<%= form_with url: instructors_search_url, remote: true do |f| %> -
-
- <%= f.text_field :instructor, :class => "input", :placeholder => "Instructor name" %> -
-
- <%= f.submit "Search", :class => "button is-link search-button margin-bottom-0" %> -
+
+
+
Search Instructors
-<% end %> \ No newline at end of file +
+ <%= form_with url: instructors_search_url, remote: true do |f| %> + +
+
+ <%= f.text_field :instructor, :class => "input", :placeholder => "Instructor name" %> +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ <%= f.submit "Search", :class => "button is-link search-button margin-bottom-0" %> +
+ <% end %> +
+
\ No newline at end of file From 7c04bd3171e56f963e1f4f4990a6dcc04f860554 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Tue, 26 Mar 2019 01:08:04 -0700 Subject: [PATCH 22/41] Update _reviews_course_list.html.erb --- app/views/courses/partials/_reviews_course_list.html.erb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/views/courses/partials/_reviews_course_list.html.erb b/app/views/courses/partials/_reviews_course_list.html.erb index 724820e8..6617f915 100644 --- a/app/views/courses/partials/_reviews_course_list.html.erb +++ b/app/views/courses/partials/_reviews_course_list.html.erb @@ -4,7 +4,7 @@
<% if course_sections %>
- Showing <%= course_sections.length %> results + Showing <%= course_sections.length %> results
<% course_sections.each do |section| %> @@ -76,12 +76,7 @@
- <%= button_to "Leave Review", - :courses_add, - :class => "button", - :method => :post, - :remote => true, - :params => {:section_id => section.id} %> + <%= link_to "Leave Review", course_rate_path(section.course), :class => "button" %>
From 0a1da420ebe73edbd3960212aa82f4b273f8ff87 Mon Sep 17 00:00:00 2001 From: Pavle Rohalj Date: Tue, 26 Mar 2019 01:09:13 -0700 Subject: [PATCH 23/41] Update _reviews_search_form.html.erb --- .../partials/_reviews_search_form.html.erb | 228 +++++++++--------- 1 file changed, 118 insertions(+), 110 deletions(-) diff --git a/app/views/courses/partials/_reviews_search_form.html.erb b/app/views/courses/partials/_reviews_search_form.html.erb index 8bd580ff..f27eb987 100644 --- a/app/views/courses/partials/_reviews_search_form.html.erb +++ b/app/views/courses/partials/_reviews_search_form.html.erb @@ -1,127 +1,135 @@ <% academic_terms = @academic_terms %> <% departments = @departments %> -<%= form_with url: courses_search_url, remote: true do |f| %> -
- -
-
- <%= f.text_field :keywords, :class => "input", :placeholder => "Keywords" %> -
-
+
+
+
Search Courses
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
-
- -
-
- <%= f.select :department, options_for_select( - departments.collect(&:name) - ), :prompt => "(any)" %> +
+ <%= form_with url: courses_search_url, remote: true do |f| %> +
+ +
+
+ <%= f.text_field :keywords, :class => "input", :placeholder => "Keywords" %> +
+
-
-
- diff --git a/app/views/courses/partials/_reviews_course_list.html.erb b/app/views/course_reviews/partials/_reviews_course_list.html.erb similarity index 62% rename from app/views/courses/partials/_reviews_course_list.html.erb rename to app/views/course_reviews/partials/_reviews_course_list.html.erb index 153d3c02..f59816b9 100644 --- a/app/views/courses/partials/_reviews_course_list.html.erb +++ b/app/views/course_reviews/partials/_reviews_course_list.html.erb @@ -1,15 +1,15 @@ -<% course_sections = @course_sections %> +<% courses = local_assigns.fetch(:courses, []) %>
- <% if course_sections %> + <% if courses %>
- Showing <%= course_sections.length %> results + Showing <%= courses.length %> results
- <% course_sections.each do |section| %> + <% courses.each do |course| %> <% campus_background_color_class = - case section.course_meeting_details.first.try(:campus).try(:to_sym) + case course.schools.first when :pomona "campus_PO" when :claremont_mckenna @@ -28,14 +28,14 @@
- <%= link_to course_path(section.course), :class => 'no-underline' do %> - <%= section.code %> - <%= section.course.name %> + <%= link_to course_path(course), :class => 'no-underline' do %> + <%= course.code %> - <%= course.name %> <% end %> - <%= link_to course_path(section.course), :class => 'no-underline' do %> + <%= link_to course_path(course), :class => 'no-underline' do %> <%= render 'components/numerical_review', - rating: section.course.overall_rating, + rating: course.overall_rating, tag_classes: "#{campus_background_color_class} has-text-white has-brightness", show_icon: true %> <% end %> @@ -45,7 +45,7 @@

- <% section.instructors.each do |instructor| %> + <% course.instructors.each do |instructor| %> <%= link_to instructor_path(instructor), :class => 'no-underline' do %> <%= instructor.name %>   <%= render 'components/numerical_review', @@ -55,27 +55,12 @@
<% end %>
- <%= section.credit %> credits

-

- <%= raw section.description %> -

-
-
-
-
- <% section.course_meeting_details.each do |detail| %> -

<%= detail.to_s %>

- <% end %> -
-
-
-
- <%= link_to "Leave a review", review_course_section_path(section.course), :class => "button" %> + <%= link_to "Leave a review", review_course_section_path(course), :class => "button" %>
diff --git a/app/views/course_reviews/partials/_reviews_course_search_form.html.erb b/app/views/course_reviews/partials/_reviews_course_search_form.html.erb new file mode 100644 index 00000000..96a777b9 --- /dev/null +++ b/app/views/course_reviews/partials/_reviews_course_search_form.html.erb @@ -0,0 +1,75 @@ +<% academic_terms = @academic_terms %> +<% departments = @departments %> + +
+
+
Search Courses
+
+
+ <%= form_with url: course_reviews_search_url, remote: true do |f| %> +
+ +
+
+ <%= f.text_field :keywords, :class => "input", :placeholder => "Keywords" %> +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ <%= f.select :department, options_for_select( + departments.collect(&:name) + ), :prompt => "(any)" %> +
+
+
+ +
+ <%= f.submit "Search", :class => "button is-link search-button margin-bottom-1" %> + Show advanced + search +
+ <% end %> +
+
\ No newline at end of file diff --git a/app/views/instructors/partials/_instructors_list.html.erb b/app/views/course_reviews/partials/_reviews_instructors_list.html.erb similarity index 100% rename from app/views/instructors/partials/_instructors_list.html.erb rename to app/views/course_reviews/partials/_reviews_instructors_list.html.erb diff --git a/app/views/instructors/partials/_instructors_search_form.html.erb b/app/views/course_reviews/partials/_reviews_instructors_search_form.html.erb similarity index 100% rename from app/views/instructors/partials/_instructors_search_form.html.erb rename to app/views/course_reviews/partials/_reviews_instructors_search_form.html.erb diff --git a/app/views/course_reviews/search_course_reviews.js.erb b/app/views/course_reviews/search_course_reviews.js.erb new file mode 100644 index 00000000..31184383 --- /dev/null +++ b/app/views/course_reviews/search_course_reviews.js.erb @@ -0,0 +1,5 @@ +$("#reviews-course-list-container") + .hide() + .html("<%= escape_javascript(render partial: 'course_reviews/partials/reviews_course_list', locals: { courses: @courses }) %>") + .fadeIn('slow'); + diff --git a/app/views/course_reviews/search_instructor_reviews.js.erb b/app/views/course_reviews/search_instructor_reviews.js.erb new file mode 100644 index 00000000..6cc51bb0 --- /dev/null +++ b/app/views/course_reviews/search_instructor_reviews.js.erb @@ -0,0 +1,4 @@ +$("#instructors-list-container") + .hide() + .html("<%= escape_javascript(render partial: 'course_reviews/partials/reviews_instructors_list', locals: { instructors: @instructors }) %>") + .fadeIn('slow'); \ No newline at end of file diff --git a/app/views/course_reviews/show_course_reviews.html.erb b/app/views/course_reviews/show_course_reviews.html.erb new file mode 100644 index 00000000..48263c16 --- /dev/null +++ b/app/views/course_reviews/show_course_reviews.html.erb @@ -0,0 +1,6 @@ +<% content_for :header do %> + <%= render "components/page_header", :title => "Course Reviews" %> +<% end %> + +<%= render 'course_reviews/partials/reviews_course_search_form' %> +<%= render 'course_reviews/partials/reviews_course_list' %> \ No newline at end of file diff --git a/app/views/course_reviews/show_instructor_reviews.erb b/app/views/course_reviews/show_instructor_reviews.erb new file mode 100644 index 00000000..675f266a --- /dev/null +++ b/app/views/course_reviews/show_instructor_reviews.erb @@ -0,0 +1,6 @@ +<% content_for :header do %> +<%= render "components/page_header", :title => "Instructor Reviews" %> +<% end %> + +<%= render 'course_reviews/partials/reviews_instructors_search_form' %> +<%= render 'course_reviews/partials/reviews_instructors_list' %> \ No newline at end of file diff --git a/app/views/courses/partials/_reviews_search_form.html.erb b/app/views/courses/partials/_reviews_search_form.html.erb deleted file mode 100644 index f27eb987..00000000 --- a/app/views/courses/partials/_reviews_search_form.html.erb +++ /dev/null @@ -1,135 +0,0 @@ -<% academic_terms = @academic_terms %> -<% departments = @departments %> - -
-
-
Search Courses
-
-
- <%= form_with url: courses_search_url, remote: true do |f| %> -
- -
-
- <%= f.text_field :keywords, :class => "input", :placeholder => "Keywords" %> -
-
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
-
- -
-
- <%= f.select :department, options_for_select( - departments.collect(&:name) - ), :prompt => "(any)" %> -
-
-
- -
- <%= f.submit "Search", :class => "button is-link search-button margin-bottom-1" %> - Show advanced - search -
- <% end %> -
-
\ No newline at end of file diff --git a/app/views/courses/reviews.html.erb b/app/views/courses/reviews.html.erb deleted file mode 100644 index 08509f4e..00000000 --- a/app/views/courses/reviews.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<% content_for :header do %> - <%= render "components/page_header", :title => "Course Reviews" %> -<% end %> - -<%= render 'courses/partials/reviews_search_form' %> -<%= render 'courses/partials/reviews_course_list' %> \ No newline at end of file diff --git a/app/views/courses/search_course_sections.js.erb b/app/views/courses/search_course_sections.js.erb index 571efbf2..3cb9c009 100644 --- a/app/views/courses/search_course_sections.js.erb +++ b/app/views/courses/search_course_sections.js.erb @@ -1,13 +1,8 @@ -if ($("#course-list-container").length) { - $("#course-list-container") - .html("<%= escape_javascript(render partial: 'courses/partials/course_list', locals: { course_sections: @course_sections }) %>"); - $("#course-list-container") - .removeClass("is-hidden"); - $("#course-schedule-container") - .addClass("is-5"); -} else { - $("#reviews-course-list-container") - .hide() - .html("<%= escape_javascript(render partial: 'courses/partials/reviews_course_list', locals: { course_sections: @course_sections }) %>") - .fadeIn('slow'); -} +$("#course-list-container") + .html("<%= escape_javascript(render partial: 'courses/partials/course_list', locals: { course_sections: @course_sections }) %>"); + +$("#course-list-container") + .removeClass("is-hidden"); + +$("#course-schedule-container") + .addClass("is-5"); \ No newline at end of file diff --git a/app/views/instructors/index.html.erb b/app/views/instructors/index.html.erb deleted file mode 100644 index b4693935..00000000 --- a/app/views/instructors/index.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<% content_for :header do %> -<%= render "components/page_header", :title => "Instructor Reviews" %> -<% end %> - -<%= render 'instructors/partials/instructors_search_form' %> -<%= render 'instructors/partials/instructors_list' %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 11fed03d..2bc07a33 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -25,21 +25,26 @@ end scope controller: :course_reviews do - get 'courses/:course_id/review/new' => :new, as: :new_course_review - post 'reviews' => :create, as: :course_reviews + get 'reviews/courses' => :show_course_reviews, as: :course_reviews + get 'reviews/instructors' => :show_instructor_reviews, as: :instructor_reviews + get 'reviews/courses/:course_id/new' => :new, as: :new_course_review + post 'reviews/courses/search' => :search_course_reviews, as: :course_reviews_search + post 'reviews/instructors/search' => :search_instructor_reviews, as: :instructor_reviews_search + post 'reviews/courses' => :create, as: :create_course_review end scope controller: :courses do - get 'courses' => :reviews - get 'courses/export' => :export_course_sections - get 'scheduler' => :index + get 'courses/planner' => :index, as: :course_planner + get 'courses/planner/export' => :export_course_sections, as: :courses_export + post 'courses/planner/add' => :add_course_section_to_schedule, as: :courses_add + post 'courses/planner/remove' => :remove_course_section_from_schedule, as: :courses_remove + post 'courses/planner/clear' => :clear_course_sections_from_schedule, as: :courses_clear + post 'courses/planner/save' => :save_course_sections_to_schedule, as: :courses_save + + match 'courses/search' => :search_course_sections, :via => [:get, :post] + get 'courses/:id/review' => :add_review_course_section, as: :review_course_section get 'courses/:id' => :show, as: :course - post 'courses/add' => :add_course_section_to_schedule - post 'courses/remove' => :remove_course_section_from_schedule - post 'courses/clear' => :clear_course_sections_from_schedule - post 'courses/save' => :save_course_sections_to_schedule - match 'courses/search' => :search_course_sections, :via => [:get, :post] end scope controller: :instructors do From 8ec3b8682a44911e63bde508b023df3ff9b8c599 Mon Sep 17 00:00:00 2001 From: Bradley Bain Date: Wed, 8 May 2019 01:56:58 -0700 Subject: [PATCH 38/41] UI improvements and review submission --- app/controllers/courses_controller.rb | 5 -- app/models/course.rb | 4 +- app/models/course_section.rb | 2 +- app/models/instructor.rb | 14 ++++ app/views/components/_star_review_input.erb | 20 +++--- app/views/course_reviews/new.html.erb | 70 ++++++++++++++++++- .../partials/_reviews_course_list.html.erb | 25 ++++--- .../_reviews_instructors_list.html.erb | 42 +++++++++-- .../_reviews_instructors_search_form.html.erb | 2 +- .../add_review_course_section.html.erb | 34 --------- app/views/courses/show.html.erb | 6 +- .../add_instructor_review.html.erb | 34 --------- 12 files changed, 151 insertions(+), 107 deletions(-) delete mode 100644 app/views/courses/add_review_course_section.html.erb delete mode 100644 app/views/instructors/add_instructor_review.html.erb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 229f7674..2ae90aca 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -14,11 +14,6 @@ def show @course = Course.find(params[:id]) end - - def add_review_course_section - @course = Course.find(params[:id]) - end - def export_course_sections user_course_schedule = CourseSchedule.find_by(:user => current_user) course_sections = user_course_schedule.course_sections.includes(:course_meeting_details).where.not(course_meeting_details: {course_section_id: nil}) diff --git a/app/models/course.rb b/app/models/course.rb index 985a9747..1b11de05 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -24,7 +24,7 @@ def work_per_week # collect all instructors that have ever taught a section of this course def instructors self.course_sections - .collect{ |section| section.instructors } + &.collect{ |section| section.instructors } .reduce(:+) .uniq end @@ -33,7 +33,7 @@ def instructors def schools # matches = matches.select {|section| schools.any? {|campus| section.course_meeting_details.any? {|detail| detail.campus == campus.to_s}}} self.course_sections - .collect{ |section| section.schools } + &.collect{ |section| section.schools } .reduce(:+) .uniq end diff --git a/app/models/course_section.rb b/app/models/course_section.rb index 8afb5c62..e808682b 100644 --- a/app/models/course_section.rb +++ b/app/models/course_section.rb @@ -13,7 +13,7 @@ def has_meeting_time?(course_meeting_detail) def schools self.course_meeting_details - .collect{ |detail| detail.campus.to_sym } + &.collect{ |detail| detail.campus.to_sym } .uniq end end diff --git a/app/models/instructor.rb b/app/models/instructor.rb index 39eb19c3..ccf376d4 100644 --- a/app/models/instructor.rb +++ b/app/models/instructor.rb @@ -1,5 +1,6 @@ class Instructor < ApplicationRecord has_many :course_reviews + has_and_belongs_to_many :course_sections def overall_rating self.course_reviews&.average(:overall_rating)&.round(2, :truncate) || 0 @@ -16,4 +17,17 @@ def challenge_rating def work_per_week self.course_reviews&.average(:work_per_week)&.round(2, :truncate) || 0 end + + def school + self.course_sections + &.first + &.schools + &.first + end + + def courses + self.course_sections + &.collect{| section| section.course } + &.uniq + end end diff --git a/app/views/components/_star_review_input.erb b/app/views/components/_star_review_input.erb index 261786fa..dd5d7ece 100644 --- a/app/views/components/_star_review_input.erb +++ b/app/views/components/_star_review_input.erb @@ -2,25 +2,25 @@
- + - + - + - + - + - + - + - + - + - +
\ No newline at end of file diff --git a/app/views/course_reviews/new.html.erb b/app/views/course_reviews/new.html.erb index a73ae33e..0d8c97f8 100644 --- a/app/views/course_reviews/new.html.erb +++ b/app/views/course_reviews/new.html.erb @@ -1,8 +1,8 @@ <% content_for :header do %> - <%= render 'components/page_header', :title => "Submit Course Review", :subtitle => "Leave feedback for #{@course.name}" %> + <%= render 'components/page_header', :title => "Submit Course Review", :subtitle => "Leave feedback for #{@course.code}: #{@course.name}" %> <% end %> -<%= form_with(model: @course_review, local: true) do |form| %> + + +<%= form_with(model: @course_review, local: true) do |form| %> + <% if @course_review.errors.any? %> +
+
The following errors prohibited this review from being submitted:
+ + <% @course_review.errors.full_messages.each do |message| %> +
+

+ <%= message %> +

+
+ <% end %> +
+ <% end %> + +
+ <%= form.label :instructor_id %> +
+
+ <%= form.select :instructor_id, + options_for_select(@course.instructors.collect(&:name).zip @course.instructors.collect(&:id)), + :class => "input is-rounded" %> +
+
+
+ +
+ <%= form.label :overall_rating %> +
+ <%= render 'components/star_review_input', :id => "course_review[overall_rating]", tag_classes: 'is-medium' %> +
+
+ +
+ <%= form.label :challenge_rating %> +
+ <%= render 'components/star_review_input', :id => "course_review[challenge_rating]", tag_classes: 'is-medium' %> +
+
+
+ <%= form.label :inclusivity_rating %> +
+ <%= render 'components/star_review_input', :id => "course_review[inclusivity_rating]", tag_classes: 'is-medium' %> +
+
+
+ <%= form.label :work_per_week %> +
+
+ <%= form.select :work_per_week, options_for_select((0..20)) %> +
hours +
+
+
+ <%= form.label :comments %> +
+ <%= form.text_area :comments, :class => "textarea", :placeholder => "Your thoughts about the course", :rows => 6 %> +
+
+ <%= form.hidden_field :course_id, :value => @course.id %> + <%= form.submit "Submit", :class => "button is-link margin-bottom-0" %> +
+<% end %> \ No newline at end of file diff --git a/app/views/course_reviews/partials/_reviews_course_list.html.erb b/app/views/course_reviews/partials/_reviews_course_list.html.erb index f59816b9..712c4027 100644 --- a/app/views/course_reviews/partials/_reviews_course_list.html.erb +++ b/app/views/course_reviews/partials/_reviews_course_list.html.erb @@ -44,23 +44,30 @@
-

+

Challenge rating:<%= render 'components/star_review', rating: course.challenge_rating, tag_classes: 'is-medium' %>

+

Inclusivity rating:<%= render 'components/star_review', rating: course.inclusivity_rating, tag_classes: 'is-medium' %>

+

Average work per week: <%= course.work_per_week %> hours

+
+

Instructors who have taught this course

+
+
<% course.instructors.each do |instructor| %> - <%= link_to instructor_path(instructor), :class => 'no-underline' do %> - <%= instructor.name %>   + + <%= link_to instructor_path(instructor), :class => 'no-underline' do %> + <%= instructor.name %>   + <% end %> + <%= render 'components/numerical_review', rating: instructor.overall_rating, show_icon: true %> - <% end %> - -
+     <% end %> -
-

+
+
- <%= link_to "Leave a review", review_course_section_path(course), :class => "button" %> + <%= link_to "Leave a review", new_course_review_path(course), :class => "button #{campus_background_color_class}" %>
diff --git a/app/views/course_reviews/partials/_reviews_instructors_list.html.erb b/app/views/course_reviews/partials/_reviews_instructors_list.html.erb index cdb0264d..2bde5cc4 100644 --- a/app/views/course_reviews/partials/_reviews_instructors_list.html.erb +++ b/app/views/course_reviews/partials/_reviews_instructors_list.html.erb @@ -8,17 +8,45 @@
<% instructors.each do |instructor| %> -
-
+ <% campus_background_color_class = + case instructor.school + when :pomona + "campus_PO" + when :claremont_mckenna + "campus_CM" + when :harvey_mudd + "campus_HM" + when :scripps + "campus_SC" + when :pitzer + "campus_PZ" + else + "campus_KS" + end + %> + +
+
<%= instructor.name %> <%= render 'components/numerical_review', rating: instructor.overall_rating, tag_classes: 'is-info', show_icon: true %>
-

Courses:

-

Challenge rating:<%= render 'components/star_review', rating: instructor.challenge_rating, tag_classes: 'is-medium' %>

-

Inclusivity rating:<%= render 'components/star_review', rating: instructor.inclusivity_rating, tag_classes: 'is-medium' %>

-

Average work per week:<%= instructor.work_per_week %> hours

- <%= link_to "Leave a review", review_instructor_path(instructor), :class => "button" %> +

Challenge rating:<%= render 'components/star_review', rating: instructor.challenge_rating, tag_classes: 'is-medium' %>

+

Inclusivity rating:<%= render 'components/star_review', rating: instructor.inclusivity_rating, tag_classes: 'is-medium' %>

+

Average work per week: <%= instructor.work_per_week %> hours

+
+

Courses taught by this instructor

+
+
+ <% instructor.courses.each do |course| %> + + <%= link_to course_path(course), :class => "has-text-white no-underline" do %> + <%= course.code %> + <% end %> + + <% end %> +
+
<% end %> diff --git a/app/views/course_reviews/partials/_reviews_instructors_search_form.html.erb b/app/views/course_reviews/partials/_reviews_instructors_search_form.html.erb index bc642775..0b3a1a35 100644 --- a/app/views/course_reviews/partials/_reviews_instructors_search_form.html.erb +++ b/app/views/course_reviews/partials/_reviews_instructors_search_form.html.erb @@ -3,7 +3,7 @@
Search Instructors
- <%= form_with url: instructors_search_url, remote: true do |f| %> + <%= form_with url: instructor_reviews_search_url, remote: true do |f| %>
diff --git a/app/views/courses/add_review_course_section.html.erb b/app/views/courses/add_review_course_section.html.erb deleted file mode 100644 index 7f802045..00000000 --- a/app/views/courses/add_review_course_section.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<% content_for :header do %> - <%= render 'components/page_header', :title => "#{@course.code}: #{@course.name}", :subtitle => "Leave a review" %> -<% end %> - -<%= form_with url: nil, remote: true do |f| %> -
-
Challenge rating
-
- <%= render 'components/star_review_input', :id => "challenge", tag_classes: 'is-medium' %> -
-
-
-
Inclusivity rating
-
- <%= render 'components/star_review_input', :id => "inclusivity", tag_classes: 'is-medium' %> -
-
-
- -
-
- <%= f.select :academic_term, options_for_select((0..20)) %> -
-
-
-
- -
- <%= f.text_area :keywords, :class => "textarea", :placeholder => "Your thoughts about the course", :rows => 6 %> -
-
- <%= f.submit "Submit", :class => "button is-link margin-bottom-0" %> -
-<% end %> \ No newline at end of file diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index 802c5635..03ff9afd 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -7,7 +7,6 @@ <%= render 'components/numerical_review', rating: @course.overall_rating, tag_classes: 'is-large is-info', show_icon: true %> - <%= link_to "Submit course review", new_course_review_path(@course.id), :class => 'button is-light' %>
@@ -78,6 +77,11 @@

<% end %> +
+
+

<%= link_to "Submit course review", new_course_review_path(@course.id), :class => 'button is-info' %>

+
+
<% else %>
diff --git a/app/views/instructors/add_instructor_review.html.erb b/app/views/instructors/add_instructor_review.html.erb deleted file mode 100644 index 98a6b4e6..00000000 --- a/app/views/instructors/add_instructor_review.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<% content_for :header do %> - <%= render 'components/page_header', :title => @instructor.name, :subtitle => "Leave a review" %> -<% end %> - -<%= form_with url: nil, remote: true do |f| %> -
-
Challenge rating
-
- <%= render 'components/star_review_input', :id => "challenge", tag_classes: 'is-medium' %> -
-
-
-
Inclusivity rating
-
- <%= render 'components/star_review_input', :id => "inclusivity", tag_classes: 'is-medium' %> -
-
-
Inclusivity - -
-
- <%= f.select :academic_term, options_for_select((0..20)) %> -
-
-
-
- -
- <%= f.text_area :keywords, :class => "textarea", :placeholder => "Your thoughts about the instructor", :rows => 6 %> -
-
- <%= f.submit "Submit", :class => "button is-link margin-bottom-0" %> -
-<% end %> \ No newline at end of file From 963f19ab2d12c15c32b42e2e59e84184ad70037d Mon Sep 17 00:00:00 2001 From: Bradley Bain Date: Wed, 8 May 2019 02:02:37 -0700 Subject: [PATCH 39/41] Require authentication to interact with reviews --- app/controllers/course_reviews_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/course_reviews_controller.rb b/app/controllers/course_reviews_controller.rb index a2d9b961..bf91e873 100644 --- a/app/controllers/course_reviews_controller.rb +++ b/app/controllers/course_reviews_controller.rb @@ -1,5 +1,5 @@ class CourseReviewsController < ApplicationController - before_action :authenticate_user!, only: [:new, :edit] + before_action :authenticate_user! # GET /reviews/:id def show From 7ec6d44fda062cfca3762af3c02ab270204a6099 Mon Sep 17 00:00:00 2001 From: Bradley Bain Date: Wed, 8 May 2019 02:08:11 -0700 Subject: [PATCH 40/41] Add view detailed reviews button --- .../course_reviews/partials/_reviews_course_list.html.erb | 1 + .../partials/_reviews_instructors_list.html.erb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/views/course_reviews/partials/_reviews_course_list.html.erb b/app/views/course_reviews/partials/_reviews_course_list.html.erb index 712c4027..e654b9fb 100644 --- a/app/views/course_reviews/partials/_reviews_course_list.html.erb +++ b/app/views/course_reviews/partials/_reviews_course_list.html.erb @@ -68,6 +68,7 @@
<%= link_to "Leave a review", new_course_review_path(course), :class => "button #{campus_background_color_class}" %> + <%= link_to "View detailed reviews", course_path(course), :class => "button is-light" %>
diff --git a/app/views/course_reviews/partials/_reviews_instructors_list.html.erb b/app/views/course_reviews/partials/_reviews_instructors_list.html.erb index 2bde5cc4..9e5312d4 100644 --- a/app/views/course_reviews/partials/_reviews_instructors_list.html.erb +++ b/app/views/course_reviews/partials/_reviews_instructors_list.html.erb @@ -47,6 +47,10 @@ <% end %>
+ +
+ <%= link_to "View detailed reviews", instructor_path(instructor), :class => "button is-light" %> +
<% end %> From 3bad7a130f483569895a763232229e53dd4c034a Mon Sep 17 00:00:00 2001 From: Bradley Bain Date: Wed, 8 May 2019 16:20:03 -0700 Subject: [PATCH 41/41] Allow delete course reviews --- app/admin/course_review.rb | 7 ++ app/controllers/course_reviews_controller.rb | 14 +++- app/models/course_review.rb | 1 + app/models/housing_review.rb | 4 + app/views/course_reviews/new.html.erb | 76 ------------------- .../partials/_course_search_form.html.erb | 3 + app/views/courses/show.html.erb | 7 ++ app/views/housing_reviews/index.html.erb | 6 +- app/views/instructors/show.html.erb | 7 ++ config/routes.rb | 1 + ...03_add_user_reference_to_course_reviews.rb | 3 + db/schema.rb | 4 +- 12 files changed, 49 insertions(+), 84 deletions(-) create mode 100644 app/admin/course_review.rb create mode 100644 db/migrate/20190508222503_add_user_reference_to_course_reviews.rb diff --git a/app/admin/course_review.rb b/app/admin/course_review.rb new file mode 100644 index 00000000..28b0243c --- /dev/null +++ b/app/admin/course_review.rb @@ -0,0 +1,7 @@ +course_review_page = Proc.new do + menu parent: "Models" + + permit_params :overall_rating, :challenge_rating, :inclusivity_rating, :comments, :course_id, :work_per_week +end + +ActiveAdmin.register CourseReview, :namespace => :admin, &course_review_page \ No newline at end of file diff --git a/app/controllers/course_reviews_controller.rb b/app/controllers/course_reviews_controller.rb index bf91e873..5d1009de 100644 --- a/app/controllers/course_reviews_controller.rb +++ b/app/controllers/course_reviews_controller.rb @@ -14,6 +14,16 @@ def new @course_review = CourseReview.new end + # DELETE /reviews/course/:course_id/: + def destroy + course_review = CourseReview.find_by(:id => params[:id]) + if current_user.id == course_review.user_id + course_review.destroy + end + + redirect_to course_path(course_review.course), notice: "Course review was successfully deleted." + end + def show_course_reviews @academic_terms = AcademicTerm.current_academic_year @departments = Department.all @@ -31,10 +41,10 @@ def create :work_per_week => review_params[:work_per_week], :comments => review_params[:comments], :course_id => review_params[:course_id], - :instructor_id => review_params[:instructor_id] + :instructor_id => review_params[:instructor_id], + :user_id => current_user.id, ) - course_id = review_params[:course_id] @course = @course_review.course #Course.find_by(:id => course_id) respond_to do |format| diff --git a/app/models/course_review.rb b/app/models/course_review.rb index 44abea68..f813714e 100644 --- a/app/models/course_review.rb +++ b/app/models/course_review.rb @@ -3,6 +3,7 @@ class CourseReview < ApplicationRecord belongs_to :course belongs_to :instructor + belongs_to :user, :optional => true validates :course, :presence => true validates :overall_rating, :presence => true diff --git a/app/models/housing_review.rb b/app/models/housing_review.rb index 5025b480..0216c600 100644 --- a/app/models/housing_review.rb +++ b/app/models/housing_review.rb @@ -3,4 +3,8 @@ class HousingReview < ApplicationRecord belongs_to :user, :optional => true validates :housing_room, presence: true + + def written_at + self.created_at.strftime("%B %Y") + end end diff --git a/app/views/course_reviews/new.html.erb b/app/views/course_reviews/new.html.erb index 0d8c97f8..bfcc1216 100644 --- a/app/views/course_reviews/new.html.erb +++ b/app/views/course_reviews/new.html.erb @@ -2,82 +2,6 @@ <%= render 'components/page_header', :title => "Submit Course Review", :subtitle => "Leave feedback for #{@course.code}: #{@course.name}" %> <% end %> - - <%= form_with(model: @course_review, local: true) do |form| %> <% if @course_review.errors.any? %>
diff --git a/app/views/courses/partials/_course_search_form.html.erb b/app/views/courses/partials/_course_search_form.html.erb index c57d9464..5ecd840a 100644 --- a/app/views/courses/partials/_course_search_form.html.erb +++ b/app/views/courses/partials/_course_search_form.html.erb @@ -77,6 +77,8 @@
+ + +
diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb index 03ff9afd..0b3d71ed 100644 --- a/app/views/courses/show.html.erb +++ b/app/views/courses/show.html.erb @@ -75,6 +75,13 @@

Review written <%= review.written_at %>

+ <% if !current_user.nil? && review.user_id == current_user.id %> +
+
+ <%= link_to "Delete", delete_course_review_path(review), :method => 'delete', class: "button is-danger is-outlined" %> +
+
+ <% end %>
<% end %>
diff --git a/app/views/housing_reviews/index.html.erb b/app/views/housing_reviews/index.html.erb index 675c909b..a57ad190 100644 --- a/app/views/housing_reviews/index.html.erb +++ b/app/views/housing_reviews/index.html.erb @@ -78,11 +78,7 @@
-

Review written <%= review.created_at.strftime("%b %Y") %> - <% unless review.user_id.nil? %> - by <%= review.user.first_name %> - <% end %> -

+

Review written <%= review.written_at %>

<% if !current_user.nil? && review.user_id == current_user.id %> diff --git a/app/views/instructors/show.html.erb b/app/views/instructors/show.html.erb index cbf0e6e3..f83f08f8 100644 --- a/app/views/instructors/show.html.erb +++ b/app/views/instructors/show.html.erb @@ -75,6 +75,13 @@

Review written <%= review.written_at %>

+ <% if !current_user.nil? && review.user_id == current_user.id %> +
+
+ <%= link_to "Delete", delete_course_review_path(review), :method => 'delete', class: "button is-danger is-outlined" %> +
+
+ <% end %>
<% end %> <% else %> diff --git a/config/routes.rb b/config/routes.rb index 2bc07a33..0fb1a411 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,6 +31,7 @@ post 'reviews/courses/search' => :search_course_reviews, as: :course_reviews_search post 'reviews/instructors/search' => :search_instructor_reviews, as: :instructor_reviews_search post 'reviews/courses' => :create, as: :create_course_review + delete 'reviews/:id' => :destroy, :as => :delete_course_review end scope controller: :courses do diff --git a/db/migrate/20190508222503_add_user_reference_to_course_reviews.rb b/db/migrate/20190508222503_add_user_reference_to_course_reviews.rb new file mode 100644 index 00000000..37a748b1 --- /dev/null +++ b/db/migrate/20190508222503_add_user_reference_to_course_reviews.rb @@ -0,0 +1,3 @@ +class AddUserReferenceToCourseReviews < ActiveRecord::Migration[5.2] + add_reference :course_reviews, :user, index: true +end diff --git a/db/schema.rb b/db/schema.rb index ba7433dc..c8707ca9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_04_05_190517) do +ActiveRecord::Schema.define(version: 2019_05_08_222503) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -92,8 +92,10 @@ t.datetime "updated_at", null: false t.bigint "course_id" t.bigint "instructor_id" + t.bigint "user_id" t.index ["course_id"], name: "index_course_reviews_on_course_id" t.index ["instructor_id"], name: "index_course_reviews_on_instructor_id" + t.index ["user_id"], name: "index_course_reviews_on_user_id" end create_table "course_schedules", force: :cascade do |t|