Commit f82cb9bdd78df56e8a5cf888733e68ab419e5435
Committed by
Tallys Martins
1 parent
76e3cbd7
Exists in
temp_ratings
Communities Ratings Plugin improvements
- users can now rate more than once. - created config for the default amount of stars marked at evaluation - created config for the minimum time between ratings from the same user. Signed-off-by: Andre Bernardes <andrebsguedes@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Showing
7 changed files
with
139 additions
and
54 deletions
Show diff stats
plugins/communities_ratings/controllers/communities_ratings_plugin_admin_controller.rb
0 → 100644
... | ... | @@ -0,0 +1,17 @@ |
1 | +class CommunitiesRatingsPluginAdminController < PluginAdminController | |
2 | + | |
3 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | |
4 | + | |
5 | + def index | |
6 | + end | |
7 | + | |
8 | + def update | |
9 | + if @environment.update_attributes(params[:environment]) | |
10 | + session[:notice] = _('Configuration updated successfully.') | |
11 | + else | |
12 | + session[:notice] = _('Configuration could not be saved.') | |
13 | + end | |
14 | + render :action => 'index' | |
15 | + end | |
16 | + | |
17 | +end | |
0 | 18 | \ No newline at end of file | ... | ... |
plugins/communities_ratings/controllers/communities_ratings_plugin_profile_controller.rb
... | ... | @@ -2,45 +2,49 @@ class CommunitiesRatingsPluginProfileController < ProfileController |
2 | 2 | before_filter :login_required |
3 | 3 | |
4 | 4 | def new_rating |
5 | - @plugins = plugins | |
6 | - community_rating = get_community_rating(user, profile, params[:community_rating_value]) | |
7 | - @actual_rate_value = if community_rating.value | |
8 | - community_rating.value | |
9 | - else | |
10 | - 0 | |
11 | - end | |
5 | + @rating_available = can_rate_now? | |
6 | + return unless @rating_available | |
7 | + | |
8 | + # @plugins = plugins | |
9 | + @default_rate = environment.communities_ratings_default_rating | |
10 | + @min_rate = Environment.communities_ratings_min_rating | |
12 | 11 | |
13 | 12 | if request.post? |
14 | - if params[:comments] and not params[:comments][:body].empty? | |
13 | + | |
14 | + unless params[:comments].blank? and params[:comments][:body].empty? | |
15 | 15 | comment = Comment.new(params[:comments]) |
16 | 16 | comment.author = current_user.person |
17 | 17 | comment.community = profile |
18 | 18 | comment.save |
19 | 19 | |
20 | + community_rating = CommunityRating.new( | |
21 | + :person => current_user.person, | |
22 | + :community => profile, | |
23 | + :value => params[:community_rating_value] | |
24 | + ) | |
20 | 25 | community_rating.comment = comment |
21 | 26 | end |
22 | 27 | |
23 | - community_rating.save! | |
24 | - session[:notice] = _("#{profile.name} successfully rated") | |
28 | + if community_rating.save | |
29 | + session[:notice] = _("#{profile.name} successfully rated!") | |
30 | + redirect_to :controller => 'profile', :action => 'index' | |
31 | + else | |
32 | + session[:notice] = _("Sorry, there were problems rating this profile.") | |
33 | + end | |
25 | 34 | end |
26 | 35 | end |
27 | 36 | |
28 | 37 | private |
29 | 38 | |
30 | - # If there is already a rate by the current logged user to this community | |
31 | - # return it or else, prepare a new one | |
32 | - def get_community_rating person, community, community_rating_value=nil | |
33 | - already_rated = CommunityRating.where( | |
34 | - :community_id=>community.id, | |
35 | - :person_id=>person.id | |
39 | + def can_rate_now? | |
40 | + ratings = CommunityRating.where( | |
41 | + :community_id=>profile.id, | |
42 | + :person_id=>user.id | |
36 | 43 | ) |
37 | 44 | |
38 | - if already_rated.count != 0 | |
39 | - already_rated.first | |
40 | - else | |
41 | - CommunityRating.new :person => person, | |
42 | - :community => community, | |
43 | - :value => community_rating_value | |
44 | - end | |
45 | + return true if ratings.empty? | |
46 | + | |
47 | + elapsed_time_since_last_rating = Time.zone.now - ratings.last.created_at | |
48 | + elapsed_time_since_last_rating > environment.communities_ratings_cooldown.hours | |
45 | 49 | end |
46 | 50 | end | ... | ... |
plugins/communities_ratings/db/migrate/20150710171028_add_communities_rating_config_to_environment.rb
0 → 100644
... | ... | @@ -0,0 +1,6 @@ |
1 | +class AddCommunitiesRatingConfigToEnvironment < ActiveRecord::Migration | |
2 | + def change | |
3 | + add_column :environments, :communities_ratings_cooldown, :integer, :default => 24 | |
4 | + add_column :environments, :communities_ratings_default_rating, :integer, :default => 1 | |
5 | + end | |
6 | +end | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +require_dependency 'environment' | |
2 | + | |
3 | +Environment.class_eval do | |
4 | + attr_accessible :communities_ratings_cooldown, :communities_ratings_default_rating | |
5 | + | |
6 | + def self.communities_ratings_min_rating | |
7 | + return 1 | |
8 | + end | |
9 | + | |
10 | + validates :communities_ratings_default_rating, | |
11 | + :presence => true, :inclusion => { | |
12 | + :in => (self.communities_ratings_min_rating)..5, message: _("must be between 0 and 5") | |
13 | + } | |
14 | + | |
15 | + validates :communities_ratings_cooldown, | |
16 | + :numericality => {greater_than_or_equal_to: 0} | |
17 | +end | |
0 | 18 | \ No newline at end of file | ... | ... |
plugins/communities_ratings/public/rate.js
... | ... | @@ -19,7 +19,9 @@ |
19 | 19 | */ |
20 | 20 | function set_global_data() { |
21 | 21 | var selected_rate = parseInt($("#selected-star-rate").val()); |
22 | + var MINIMUM_STARS = parseInt($("#MINIMUM_STARS").val()); | |
22 | 23 | DATA.selected_rate = selected_rate; |
24 | + DATA.MINIMUM_STARS = MINIMUM_STARS; | |
23 | 25 | } |
24 | 26 | |
25 | 27 | |
... | ... | @@ -94,10 +96,10 @@ |
94 | 96 | var rate_mouseover = parseInt(this.getAttribute(DATA.DATA_RATE_ATTRIBUTE)); |
95 | 97 | |
96 | 98 | // If the new rate is different from actual, update it |
97 | - if (rate_mouseover !== DATA.selected_rate) { | |
99 | + if (rate_mouseover !== DATA.selected_rate && rate_mouseover > DATA.MINIMUM_STARS) { | |
98 | 100 | DATA.selected_rate = rate_mouseover; |
99 | 101 | } else { // or else, uncheck it |
100 | - DATA.selected_rate = DATA.NOT_SELECTED_VALUE; | |
102 | + DATA.selected_rate = DATA.MINIMUM_STARS; | |
101 | 103 | } |
102 | 104 | |
103 | 105 | // Mark the selected_rate | ... | ... |
plugins/communities_ratings/views/communities_ratings_plugin_admin/index.html.erb
0 → 100644
... | ... | @@ -0,0 +1,30 @@ |
1 | +<h1><%= _("Comunities Rating Management") %> </h1> | |
2 | + | |
3 | +<%= labelled_form_for(:environment, :url => {:action => 'update'}) do |f| %> | |
4 | + | |
5 | +<table> | |
6 | + <tr> | |
7 | + <th><%= c_('Configuration') %></th> | |
8 | + <th><%= _('Value') %></th> | |
9 | + </tr> | |
10 | + <tr> | |
11 | + <td><%= _('Default amount of stars marked on evaluations') %></td> | |
12 | + <td><%= select :environment, :communities_ratings_default_rating, (Environment.communities_ratings_min_rating)..5 %></td> | |
13 | + </tr> | |
14 | + <tr> | |
15 | + <td><%= _('Time cooldown between evaluations from the same user') %></td> | |
16 | + <td><%= text_field :environment, :communities_ratings_cooldown, {size: 1} %> | |
17 | + <%= _('hours') %> | |
18 | + </td> | |
19 | + </tr> | |
20 | +</table> | |
21 | + | |
22 | + | |
23 | +<div> | |
24 | + <% button_bar do %> | |
25 | + <%= submit_button('save', c_('Save changes')) %> | |
26 | + <%= button :back, _('Back'), :controller => 'plugins' %> | |
27 | + <% end %> | |
28 | +</div> | |
29 | + | |
30 | +<% end %> | ... | ... |
plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb
... | ... | @@ -14,41 +14,50 @@ |
14 | 14 | </div> |
15 | 15 | </div> |
16 | 16 | |
17 | - <div class="star-rate-form"> | |
18 | - <div data-rate-url=<%= url_for controller: "communities_ratings_plugin_profile", :action => "rate" %>> | |
19 | - <div class="star-rate-text"> | |
20 | - <%= @plugins.dispatch(:communities_ratings_plugin_star_message).collect { |content| instance_exec(&content) }.join("") %> | |
21 | - </div> | |
17 | + <% if @rating_available %> | |
18 | + <div class="star-rate-form"> | |
19 | + <div data-rate-url=<%= url_for controller: "communities_ratings_plugin_profile", :action => "rate" %>> | |
20 | + <div class="star-rate-text"> | |
21 | + <%= @plugins.dispatch(:communities_ratings_plugin_star_message).collect { |content| instance_exec(&content) }.join("") %> | |
22 | + </div> | |
22 | 23 | |
23 | - <div class="star-container"> | |
24 | - <% (1..5).each do |rate_number| %> | |
25 | - <% if rate_number <= @actual_rate_value %> | |
26 | - <div class="star-positive" data-star-rate="<%= rate_number %>"></div> | |
27 | - <% else %> | |
28 | - <div class="star-negative" data-star-rate="<%= rate_number %>"></div> | |
24 | + <div class="star-container" data-min-rate="<%= @default_rate %>"> | |
25 | + | |
26 | + <% (1..5).each do |rate_number| %> | |
27 | + <% if rate_number <= @default_rate %> | |
28 | + <div class="star-positive" data-star-rate="<%= rate_number %>"></div> | |
29 | + <% else %> | |
30 | + <div class="star-negative" data-star-rate="<%= rate_number %>"></div> | |
31 | + <% end %> | |
29 | 32 | <% end %> |
30 | - <% end %> | |
31 | - </div> | |
33 | + </div> | |
32 | 34 | |
33 | - <div class="star-notice star-hide"> | |
34 | - <%= _("Rated as") %> <span></span> <%= _("stars") %> | |
35 | + <div class="star-notice star-hide"> | |
36 | + <%= _("Rated as") %> <span></span> <%= _("stars") %> | |
37 | + </div> | |
35 | 38 | </div> |
36 | - </div> | |
37 | 39 | |
38 | - <div class="star-comment-container"> | |
39 | - <%= form_for :comments do |c| %> | |
40 | - <div class="formfieldline formfield type-text"> | |
41 | - <%= c.label :body, _('Comment (Optional):'), :class => "formlabel" %> | |
42 | - <%= c.text_area :body %> | |
43 | - </div> | |
40 | + <div class="star-comment-container"> | |
41 | + <%= form_for :comments do |c| %> | |
42 | + <div class="formfieldline formfield type-text"> | |
43 | + <%= c.label :body, _('Comment (Optional):'), :class => "formlabel" %> | |
44 | + <%= c.text_area :body %> | |
45 | + </div> | |
44 | 46 | |
45 | - <%= @plugins.dispatch(:communities_ratings_plugin_comments_extra_fields).collect { |content| instance_exec(&content) }.join("") %> | |
46 | - <div class="button-bar"> | |
47 | - <%= c.submit _("Send"), class: "button icon-save submit with-text" %> | |
48 | - </div> | |
47 | + <%= @plugins.dispatch(:communities_ratings_plugin_comments_extra_fields).collect { |content| instance_exec(&content) }.join("") %> | |
49 | 48 | |
50 | - <input type="hidden" id="selected-star-rate" name="community_rating_value" value="<%= @actual_rate_value %>"> | |
51 | - <% end %> | |
52 | - </div> | |
49 | + <div class="button-bar"> | |
50 | + <%= submit_button(:save, _('Save'), :cancel => {controller: 'profile', action: 'index'}) %> | |
51 | + </div> | |
52 | + | |
53 | + <input type="hidden" id="selected-star-rate" name="community_rating_value" value="<%= @default_rate %>"> | |
54 | + <input type="hidden" id="MINIMUM_STARS" name="community_rating_min_value" value="<%= @min_rate %>"> | |
55 | + <% end %> | |
56 | + </div> | |
57 | + <% else %> | |
58 | + <div class="star-rate-form rating-cooldown"> | |
59 | + <%= _("Hi, #{current_user.name}! The administrators set the minimum time of #{environment.communities_ratings_cooldown} hour(s) between each evaluation. You can take a drive into our web site while you wait for the next record") %> | |
60 | + </div> | |
61 | + <% end %> | |
53 | 62 | </div> |
54 | 63 | </div> | ... | ... |