spree_reviews_rating 0.70.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/README.md +30 -0
  2. data/app/assets/images/background.gif +0 -0
  3. data/app/assets/images/cancel-off-big.png +0 -0
  4. data/app/assets/images/cancel-off.png +0 -0
  5. data/app/assets/images/cancel-on-big.png +0 -0
  6. data/app/assets/images/cancel-on.png +0 -0
  7. data/app/assets/images/coffee.png +0 -0
  8. data/app/assets/images/face-a-off.png +0 -0
  9. data/app/assets/images/face-a.png +0 -0
  10. data/app/assets/images/face-b-off.png +0 -0
  11. data/app/assets/images/face-b.png +0 -0
  12. data/app/assets/images/face-c-off.png +0 -0
  13. data/app/assets/images/face-c.png +0 -0
  14. data/app/assets/images/face-d-off.png +0 -0
  15. data/app/assets/images/face-d.png +0 -0
  16. data/app/assets/images/face-off.png +0 -0
  17. data/app/assets/images/medal-off.png +0 -0
  18. data/app/assets/images/medal-on.png +0 -0
  19. data/app/assets/images/ratyloader.gif +0 -0
  20. data/app/assets/images/star-half-big.png +0 -0
  21. data/app/assets/images/star-half.png +0 -0
  22. data/app/assets/images/star-off-big.png +0 -0
  23. data/app/assets/images/star-off.png +0 -0
  24. data/app/assets/images/star-on-big.png +0 -0
  25. data/app/assets/images/star-on.png +0 -0
  26. data/app/assets/javascripts/admin/spree_reviews_rating.js +1 -0
  27. data/app/assets/javascripts/store/review/index.js +15 -0
  28. data/app/assets/javascripts/store/review/new.js +17 -0
  29. data/app/assets/javascripts/store/spree_reviews_rating.js +450 -0
  30. data/app/assets/stylesheets/admin/spree_reviews_rating.css +3 -0
  31. data/app/assets/stylesheets/store/spree_reviews_rating.css +95 -0
  32. data/app/controllers/admin/feedback_reviews_controller.rb +6 -0
  33. data/app/controllers/admin/review_settings_controller.rb +16 -0
  34. data/app/controllers/admin/reviews_controller.rb +20 -0
  35. data/app/controllers/feedback_reviews_controller.rb +20 -0
  36. data/app/controllers/products_controller_decorator.rb +3 -0
  37. data/app/controllers/reviews_controller.rb +52 -0
  38. data/app/helpers/admin/feedback_reviews_helper.rb +2 -0
  39. data/app/helpers/feedback_reviews_helper.rb +2 -0
  40. data/app/helpers/reviews_helper.rb +11 -0
  41. data/app/models/app_configuration_decorator.rb +16 -0
  42. data/app/models/feedback_review.rb +10 -0
  43. data/app/models/product_decorator.rb +16 -0
  44. data/app/models/review.rb +21 -0
  45. data/app/models/review_sweeper.rb +21 -0
  46. data/app/models/reviews_ability.rb +12 -0
  47. data/app/overrides/add_review_bottom_sidebar.rb +4 -0
  48. data/app/overrides/add_reviews_after_product_properties.rb +4 -0
  49. data/app/overrides/add_reviews_tab_to_admin.rb +4 -0
  50. data/app/overrides/add_reviews_to_admin_configuration_menu.rb +4 -0
  51. data/app/views/admin/feedback_reviews/index.html.erb +21 -0
  52. data/app/views/admin/review_settings/edit.html.erb +30 -0
  53. data/app/views/admin/review_settings/show.html.erb +30 -0
  54. data/app/views/admin/reviews/_form.html.erb +10 -0
  55. data/app/views/admin/reviews/edit.html.erb +17 -0
  56. data/app/views/admin/reviews/index.html.erb +51 -0
  57. data/app/views/feedback_reviews/_form.html.erb +15 -0
  58. data/app/views/feedback_reviews/_summary.html.erb +6 -0
  59. data/app/views/feedback_reviews/create.js.erb +7 -0
  60. data/app/views/reviews/_fine_print.html.erb +9 -0
  61. data/app/views/reviews/_form.html.erb +23 -0
  62. data/app/views/reviews/_stars.html.erb +16 -0
  63. data/app/views/reviews/all_list.html.erb +42 -0
  64. data/app/views/reviews/index.html.erb +1 -0
  65. data/app/views/reviews/new.html.erb +5 -0
  66. data/app/views/reviews/submissionguidelines.html.erb +6 -0
  67. data/app/views/reviews/terms.html.erb +6 -0
  68. data/app/views/shared/_rating.html.erb +25 -0
  69. data/app/views/shared/_review.html.erb +17 -0
  70. data/app/views/shared/_review_link.html.erb +4 -0
  71. data/app/views/shared/_review_summary.html.erb +10 -0
  72. data/app/views/shared/_reviews.html.erb +13 -0
  73. data/app/views/shared/_shortrating.html.erb +8 -0
  74. data/lib/generators/spree_reviews_rating/install/install_generator.rb +29 -0
  75. data/lib/spree_reviews_rating/engine.rb +24 -0
  76. data/lib/spree_reviews_rating.rb +2 -0
  77. metadata +213 -0
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require admin/spree_core
3
+ */
@@ -0,0 +1,95 @@
1
+ #reviews {
2
+ padding: 10px;
3
+ }
4
+
5
+ #reviews h6 {
6
+ font-size: 16pt;
7
+ margin: 0px;
8
+ }
9
+
10
+ #reviews div.header {
11
+ font-size: 12pt;
12
+ font-weight: bold;
13
+ border-bottom: 1px #2222aa dashed;
14
+ margin-top: 10px;
15
+ margin-bottom: 10px;
16
+ }
17
+
18
+ #reviews div.review {
19
+ border-bottom: 1px #2222aa dashed;
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #reviews div.review span.title {
24
+ font-size: 11pt;
25
+ font-weight: bold;
26
+ }
27
+
28
+ #reviews div.review span.attribution {
29
+ font-size: 8pt;
30
+ }
31
+ .ratings p {
32
+ font-size: 12px;
33
+ margin: 5px;
34
+ }
35
+ .button-review, .cancel-review {
36
+ color: #C2C2C2;
37
+ text-decoration: none;
38
+ }
39
+ .button-review:hover, .cancel-review:hover {
40
+ text-decoration: underline;
41
+ }
42
+
43
+ #new_review h6 {
44
+ font-size: 10pt;
45
+ margin: 0px;
46
+ padding: 5px 3px;
47
+ }
48
+
49
+ #new_review .review_name_field {
50
+ font-size: 12px;
51
+ margin-top: 5px;
52
+ }
53
+ #new_review p {
54
+ margin-top: 5px;
55
+ margin-bottom: 0px;
56
+ }
57
+
58
+ #new_review .review_name_field input {
59
+ width: 200px;
60
+ height: 28px;
61
+ padding: 1px;
62
+ margin-bottom: 14px;
63
+ }
64
+
65
+ #new_review .review_review_field textarea {
66
+ width: 200px;
67
+ height: 80px;
68
+ padding: 1px;
69
+ }
70
+
71
+ .lit {
72
+ background-color: #aaaaaa;
73
+ color: #0000bb;
74
+ margin-right: 1px;
75
+ padding-left: 1px;
76
+ }
77
+
78
+ .unlit {
79
+ background-color: #aaaaaa;
80
+ color: #000000;
81
+ margin-right: 1px;
82
+ padding-left: 1px;
83
+ }
84
+
85
+ .star-rating-control {
86
+ display: inline-block;
87
+ height: 15px;
88
+ }
89
+
90
+ .review_hr {
91
+ size: 1px;
92
+ background: silver;
93
+ border: none;
94
+ margin: 1em 0;
95
+ }
@@ -0,0 +1,6 @@
1
+ class Admin::FeedbackReviewsController < Admin::ResourceController
2
+ def index
3
+ @review = Review.find(params[:review_id])
4
+ @collection = @review.feedback_reviews
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ class Admin::ReviewSettingsController < Admin::BaseController
2
+ def update
3
+ # workaround for unset checkbox behaviour
4
+ params[:preferences][:include_unapproved_reviews] = false if params[:preferences][:include_unapproved_reviews].blank?
5
+ params[:preferences][:feedback_rating] = false if params[:preferences][:feedback_rating].blank?
6
+ params[:preferences][:show_email] = false if params[:preferences][:show_email].blank?
7
+ params[:preferences][:require_login] = false if params[:preferences][:require_login].blank?
8
+ Spree::Config.set(params[:preferences])
9
+
10
+ respond_to do |format|
11
+ format.html {
12
+ redirect_to admin_review_settings_path
13
+ }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ class Admin::ReviewsController < Admin::ResourceController
2
+ helper ReviewsHelper
3
+
4
+ def index
5
+ @unapproved_reviews = Review.not_approved.find(:all, :order => "created_at DESC")
6
+ @approved_reviews = Review.approved.find(:all, :order => "created_at DESC")
7
+ end
8
+
9
+ def approve
10
+ r = Review.find(params[:id])
11
+
12
+ if r.update_attribute(:approved, true)
13
+ r.product.recalculate_rating
14
+ flash[:notice] = t("info_approve_review")
15
+ else
16
+ flash[:error] = t("error_approve_review")
17
+ end
18
+ redirect_to admin_reviews_path
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ class FeedbackReviewsController < Spree::BaseController
2
+ helper Spree::BaseHelper
3
+
4
+ def create
5
+ params[:feedback_review][:rating].sub!(/\s*stars/,'') unless params[:feedback_review][:rating].blank?
6
+
7
+ @review = Review.find_by_id(params[:review_id])
8
+ if @review && @feedback_review = @review.feedback_reviews.new(params[:feedback_review])
9
+ authorize! :create, @feedback_review
10
+ @feedback_review.save
11
+ end
12
+
13
+ respond_to do |format|
14
+ format.html { redirect_to :back }
15
+ format.js { render :action => :create }
16
+ end
17
+
18
+ end
19
+ end
20
+
@@ -0,0 +1,3 @@
1
+ ProductsController.class_eval do
2
+ helper ReviewsHelper
3
+ end
@@ -0,0 +1,52 @@
1
+ class ReviewsController < Spree::BaseController
2
+ helper Spree::BaseHelper
3
+
4
+ before_filter :load_product, :only => [:index, :new, :create]
5
+ rescue_from ActiveRecord::RecordNotFound, :with => :render_404
6
+
7
+ def index
8
+ @approved_reviews = Review.approved.find_all_by_product_id(@product.id)
9
+ end
10
+
11
+ def all_list
12
+ @approved_reviews = Review.approved.order("created_at DESC")
13
+ respond_to do |f|
14
+ f.html
15
+ end
16
+ end
17
+
18
+ def new
19
+ @review = Review.new(:product => @product)
20
+ authorize! :new, @review
21
+ render :layout => false
22
+ end
23
+
24
+ # save if all ok
25
+ def create
26
+ #params[:review][:rating].sub!(/\s*stars/,'') unless params[:review][:rating].blank?
27
+
28
+ @review = Review.new(params[:review])
29
+ @review.product = @product
30
+ @review.user = current_user if user_signed_in?
31
+ @review.location = request.remote_ip
32
+
33
+ authorize! :create, @review
34
+
35
+ if @review.save
36
+ flash[:notice] = t('review_successfully_submitted')
37
+ redirect_to (product_path(@product))
38
+ else
39
+ render :action => "new"
40
+ end
41
+ end
42
+
43
+ def terms
44
+ end
45
+
46
+ private
47
+
48
+ def load_product
49
+ @product = Product.find_by_permalink!(params[:product_id])
50
+ end
51
+
52
+ end
@@ -0,0 +1,2 @@
1
+ module Admin::FeedbackReviewsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module FeedbackReviewsHelper
2
+ end
@@ -0,0 +1,11 @@
1
+ module ReviewsHelper
2
+ def mk_stars(m)
3
+ (1..5).collect {|n| n <= m ? star("lit") : star("unlit") }.join
4
+ end
5
+
6
+ def txt_stars(n, show_out_of = true)
7
+ res = I18n.t('star', :count => n)
8
+ res += ' ' + t('out_of_5') if show_out_of
9
+ res
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ AppConfiguration.class_eval do
2
+ # include non-approved reviews in (public) listings
3
+ preference :include_unapproved_reviews, :boolean, :default => false
4
+
5
+ # control how many reviews are shown in summaries etc.
6
+ preference :preview_size, :integer, :default => 3
7
+
8
+ # show a reviewer's email address
9
+ preference :show_email, :boolean, :default => false
10
+
11
+ # show helpfullness rating form elements
12
+ preference :feedback_rating, :boolean, :default => false
13
+
14
+ # require login to post reviews
15
+ preference :require_login, :boolean, :default => true
16
+ end
@@ -0,0 +1,10 @@
1
+ class FeedbackReview < ActiveRecord::Base
2
+ belongs_to :review
3
+ belongs_to :user
4
+
5
+ validates_presence_of :review_id
6
+ validates_numericality_of :rating, :only_integer => true, :greater_than_or_equal_to => 1, :less_than_or_equal_to => 5, :message => I18n.t('you_must_enter_value_for_rating')
7
+
8
+ default_scope order("created_at DESC")
9
+
10
+ end
@@ -0,0 +1,16 @@
1
+ Product.class_eval do
2
+ has_many :reviews
3
+
4
+ def get_stars
5
+ {:star => avg_rating.round, :rcount => reviews_count}
6
+ end
7
+
8
+ def recalculate_rating
9
+ reviews_count = reviews.reload.approved.count
10
+ if reviews_count > 0
11
+ self.update_attributes(:avg_rating => self.reviews.approved.sum(:rating).to_f / reviews_count, :reviews_count => reviews_count)
12
+ else
13
+ self.update_attribute :avg_rating, 0
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ class Review < ActiveRecord::Base
2
+ belongs_to :product
3
+ belongs_to :user
4
+ has_many :feedback_reviews
5
+
6
+ validates_presence_of :name, :review
7
+ validates_numericality_of :rating, :only_integer => true
8
+ default_scope order("created_at DESC")
9
+ scope :not_approved, where("approved = ?", false)
10
+
11
+ scope :approved, lambda {|*args| {:conditions => ["(? = ?) or (approved = ?)", Spree::Config[:include_unapproved_reviews], true, true ]}}
12
+
13
+ scope :oldest_first, :order => "created_at asc"
14
+ scope :preview, :limit => Spree::Config[:preview_size], :order => "created_at desc"
15
+ attr_protected :user_id, :product_id, :location
16
+
17
+ def feedback_stars
18
+ return 0 if feedback_reviews.count <= 0
19
+ ((feedback_reviews.sum(:rating)/feedback_reviews.count) + 0.5).floor
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ class ReviewSweeper < ActionController::Caching::Sweeper
2
+ observe Review
3
+
4
+ def after_create(review)
5
+ expire_cache_for(review)
6
+ end
7
+
8
+ def after_update(review)
9
+ expire_cache_for(review)
10
+ end
11
+
12
+ def after_destroy(review)
13
+ expire_cache_for(review)
14
+ end
15
+
16
+ private
17
+
18
+ def expire_cache_for(review)
19
+ review.product.recalculate_rating
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ class ReviewsAbility
2
+ include CanCan::Ability
3
+
4
+ def initialize(user)
5
+ can :create, Review do |review|
6
+ user.has_role?(:user) || !Spree::Config[:require_login]
7
+ end
8
+ can :create, FeedbackReview do |review|
9
+ user.has_role?(:user) || !Spree::Config[:require_login]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ Deface::Override.new(:virtual_path => "layouts/spree_application",
2
+ :name => "review_sidebar",
3
+ :insert_bottom => "div#sidebar",
4
+ :partial => "shared/review_link")
@@ -0,0 +1,4 @@
1
+ Deface::Override.new(:virtual_path => "products/show",
2
+ :name => "converted_product_properties_767643482",
3
+ :insert_after => "[data-hook='product_properties']",
4
+ :partial => "shared/reviews")
@@ -0,0 +1,4 @@
1
+ Deface::Override.new(:virtual_path => "admin/shared/_product_sub_menu",
2
+ :name => "reviews_admin_tab",
3
+ :insert_bottom => "[data-hook='admin_product_sub_tabs']",
4
+ :text => "<%= tab(:reviews, :label => 'review_management') %>")
@@ -0,0 +1,4 @@
1
+ Deface::Override.new(:virtual_path => "admin/configurations/index",
2
+ :name => "converted_admin_configurations_menu_286465532",
3
+ :insert_after => "[data-hook='admin_configurations_menu']",
4
+ :text => "<%= configurations_menu_item(t('spree_reviews.review_settings'), admin_review_settings_path, t('spree_reviews.manage_review_settings')) %>")
@@ -0,0 +1,21 @@
1
+ <h1><%= link_to t('feedback_review_for', :review => @review.title ), admin_reviews_path %></h1>
2
+
3
+
4
+ <table class="index">
5
+ <tr>
6
+ <th><%= t('date_') %></th>
7
+ <th><%= t('user') %></th>
8
+ <th><%= t('stars') %></th>
9
+ <th></th>
10
+ </tr>
11
+ <% @collection.each do |feedback| %>
12
+ <tr id="<%= dom_id(feedback) %>">
13
+ <td><%= l feedback.created_at %></td>
14
+ <td><%= feedback.user.try(:login) || "anonimus" %></td>
15
+ <td><%= feedback.rating %></td>
16
+ <td class="actions">
17
+ <%= link_to_delete feedback %>
18
+ </td>
19
+ </tr>
20
+ <% end %>
21
+ </table>
@@ -0,0 +1,30 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <h1><%= t("spree_reviews.review_settings") %></h1>
4
+
5
+ <%= form_tag(admin_review_settings_path, :method => :put) do %>
6
+ <p>
7
+ <label><%= t("spree_reviews.include_unapproved") %>:</label>
8
+ <%= check_box_tag('preferences[include_unapproved_reviews]', "1", Spree::Config[:include_unapproved_reviews]) %>
9
+ </p>
10
+ <p>
11
+ <label><%= t("spree_reviews.feedback_rating") %>:</label>
12
+ <%= check_box_tag('preferences[feedback_rating]', "1", Spree::Config[:feedback_rating]) %>
13
+ </p>
14
+ <p>
15
+ <label><%= t("spree_reviews.show_email") %>:</label>
16
+ <%= check_box_tag('preferences[show_email]', "1", Spree::Config[:show_email]) %>
17
+ </p>
18
+ <p>
19
+ <label><%= t("spree_reviews.require_login") %>:</label>
20
+ <%= check_box_tag('preferences[require_login]', "1", Spree::Config[:require_login]) %>
21
+ </p>
22
+ <p>
23
+ <label><%= t('spree_reviews.preview_size') %>:</label>
24
+ <%= text_field_tag('preferences[preview_size]', Spree::Config[:preview_size], :size => 3) %>
25
+ </p>
26
+ <p class="form-buttons">
27
+ <%= button t('update') %>
28
+ <%= t("or") %> <%= link_to t("cancel"), admin_review_settings_url %>
29
+ </p>
30
+ <% end %>
@@ -0,0 +1,30 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <h1><%= t("spree_reviews.review_settings") %></h1>
4
+
5
+ <table>
6
+ <tr>
7
+ <th scope="row"><%= t("spree_reviews.include_unapproved") %>:</th>
8
+ <td><%= Spree::Config[:include_unapproved_reviews] ? t('yes') : t('no') %></td>
9
+ </tr>
10
+ <tr>
11
+ <th scope="row"><%= t("spree_reviews.feedback_rating") %>:</th>
12
+ <td><%= Spree::Config[:feedback_rating] ? t('yes') : t('no') %></td>
13
+ </tr>
14
+ <tr>
15
+ <th scope="row"><%= t("spree_reviews.show_email") %>:</th>
16
+ <td><%= Spree::Config[:show_email] ? t('yes') : t('no') %></td>
17
+ </tr>
18
+ <tr>
19
+ <th scope="row"><%= t("spree_reviews.require_login") %>:</th>
20
+ <td><%= Spree::Config[:require_login] ? t('yes') : t('no') %></td>
21
+ </tr>
22
+ <tr>
23
+ <th scope="row"><%= t("spree_reviews.preview_size") %>:</th>
24
+ <td><%= Spree::Config[:preview_size] %></td>
25
+ </tr>
26
+ </table>
27
+
28
+ <p>
29
+ <%= link_to_with_icon('edit', t("edit"), edit_admin_review_settings_path) %>
30
+ </p>