From 5a167ead35303a66224768d8be6626601844fea9 Mon Sep 17 00:00:00 2001 From: Tallys Martins Date: Wed, 9 Sep 2015 06:17:25 -0300 Subject: [PATCH] Refactoring PLugin to fit new Ratings Structure --- db/migrate/20150701134012_add_new_fields_to_comments.rb | 13 ------------- db/migrate/20150814185902_add_people_benefited_and_saved_value_to_create_community_rating.rb | 11 ----------- db/migrate/20150814185902_add_people_benefited_and_saved_value_to_organization_rating.rb | 11 +++++++++++ lib/ext/community_rating.rb | 5 ----- lib/ext/create_community_rating_comment.rb | 5 ----- lib/ext/organization_rating.rb | 5 +++++ lib/software_communities_plugin.rb | 12 ++++++------ views/box_organizer/_statistic_block.html.erb | 4 ++-- views/comments_extra_fields.html.erb | 4 ++-- views/communities_ratings_extra_fields_show_data.html.erb | 10 ---------- views/organization_ratings_extra_fields_show_data.html.erb | 10 ++++++++++ 11 files changed, 36 insertions(+), 54 deletions(-) delete mode 100644 db/migrate/20150701134012_add_new_fields_to_comments.rb delete mode 100644 db/migrate/20150814185902_add_people_benefited_and_saved_value_to_create_community_rating.rb create mode 100644 db/migrate/20150814185902_add_people_benefited_and_saved_value_to_organization_rating.rb delete mode 100644 lib/ext/community_rating.rb delete mode 100644 lib/ext/create_community_rating_comment.rb create mode 100644 lib/ext/organization_rating.rb delete mode 100644 views/communities_ratings_extra_fields_show_data.html.erb create mode 100644 views/organization_ratings_extra_fields_show_data.html.erb diff --git a/db/migrate/20150701134012_add_new_fields_to_comments.rb b/db/migrate/20150701134012_add_new_fields_to_comments.rb deleted file mode 100644 index 28c90e6..0000000 --- a/db/migrate/20150701134012_add_new_fields_to_comments.rb +++ /dev/null @@ -1,13 +0,0 @@ -class AddNewFieldsToComments < ActiveRecord::Migration - def self.up - change_table :comments do |t| - t.integer :people_benefited - t.decimal :saved_value - end - end - - def self.down - remove_column :comments, :people_benefited - remove_column :comments, :saved_value - end -end diff --git a/db/migrate/20150814185902_add_people_benefited_and_saved_value_to_create_community_rating.rb b/db/migrate/20150814185902_add_people_benefited_and_saved_value_to_create_community_rating.rb deleted file mode 100644 index 5dbadaa..0000000 --- a/db/migrate/20150814185902_add_people_benefited_and_saved_value_to_create_community_rating.rb +++ /dev/null @@ -1,11 +0,0 @@ -class AddPeopleBenefitedAndSavedValueToCreateCommunityRating < ActiveRecord::Migration - def up - add_column :community_ratings, :people_benefited, :integer - add_column :community_ratings, :saved_value, :decimal - end - - def down - remove_column :community_ratings, :people_benefited - remove_column :community_ratings, :saved_value - end -end diff --git a/db/migrate/20150814185902_add_people_benefited_and_saved_value_to_organization_rating.rb b/db/migrate/20150814185902_add_people_benefited_and_saved_value_to_organization_rating.rb new file mode 100644 index 0000000..d6c186c --- /dev/null +++ b/db/migrate/20150814185902_add_people_benefited_and_saved_value_to_organization_rating.rb @@ -0,0 +1,11 @@ +class AddPeopleBenefitedAndSavedValueToOrganizationRating < ActiveRecord::Migration + def up + add_column :organization_ratings, :people_benefited, :integer + add_column :organization_ratings, :saved_value, :decimal + end + + def down + remove_column :organization_ratings, :people_benefited + remove_column :organization_ratings, :saved_value + end +end diff --git a/lib/ext/community_rating.rb b/lib/ext/community_rating.rb deleted file mode 100644 index 1ecedb9..0000000 --- a/lib/ext/community_rating.rb +++ /dev/null @@ -1,5 +0,0 @@ -require_dependency "community_rating" - -class CommunityRating - attr_accessible :people_benefited, :saved_value -end diff --git a/lib/ext/create_community_rating_comment.rb b/lib/ext/create_community_rating_comment.rb deleted file mode 100644 index 71dcd8c..0000000 --- a/lib/ext/create_community_rating_comment.rb +++ /dev/null @@ -1,5 +0,0 @@ -require_dependency "create_community_rating_comment" - -CreateCommunityRatingComment.class_eval do - attr_accessible :people_benefited, :saved_value -end \ No newline at end of file diff --git a/lib/ext/organization_rating.rb b/lib/ext/organization_rating.rb new file mode 100644 index 0000000..cedb7ca --- /dev/null +++ b/lib/ext/organization_rating.rb @@ -0,0 +1,5 @@ +require_dependency "organization_rating" + +class OrganizationRating + attr_accessible :people_benefited, :saved_value +end diff --git a/lib/software_communities_plugin.rb b/lib/software_communities_plugin.rb index d8508e8..ebf8193 100644 --- a/lib/software_communities_plugin.rb +++ b/lib/software_communities_plugin.rb @@ -80,28 +80,28 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin end end - def communities_ratings_plugin_comments_extra_fields + def organization_ratings_plugin_comments_extra_fields if context.profile.software? Proc::new { render :file => 'comments_extra_fields' } end end - def communities_ratings_plugin_star_message + def organization_ratings_plugin_star_message Proc::new do _("Rate this software") end end - def communities_ratings_title + def organization_ratings_title Proc::new do "

#{_("Use reports")}

" end end - def communities_ratings_plugin_extra_fields_show_data user_rating + def organization_ratings_plugin_extra_fields_show_data user_rating if logged_in? is_admin = environment.admins.include?(current_user.person) - is_admin ||= user_rating.community.admins.include?(current_user.person) + is_admin ||= user_rating.organization.admins.include?(current_user.person) if is_admin and context.profile.software? Proc::new { - render :file => 'communities_ratings_extra_fields_show_data', + render :file => 'organization_ratings_extra_fields_show_data', :locals => {:user_rating => user_rating} } end diff --git a/views/box_organizer/_statistic_block.html.erb b/views/box_organizer/_statistic_block.html.erb index c8c5061..48037c8 100644 --- a/views/box_organizer/_statistic_block.html.erb +++ b/views/box_organizer/_statistic_block.html.erb @@ -1,6 +1,6 @@
- <% suggestion_benefited_people = @block.owner.community_ratings.collect{|community_rating| community_rating.people_benefited.to_f}.inject(:+) || 0.0 %> - <% suggestion_saved_resources = @block.owner.community_ratings.collect{|community_rating| community_rating.saved_value.to_f}.inject(:+) || 0.0 %> + <% suggestion_benefited_people = @block.owner.organization_ratings.collect{ |r| r.people_benefited.to_f }.inject(:+) || 0.0 %> + <% suggestion_saved_resources = @block.owner.organization_ratings.collect{ |r| r.saved_value.to_f }.inject(:+) || 0.0 %> <%= labelled_form_field _('Benefited People'), text_field(:block, :benefited_people) %>

<%= _("Portal suggested value: ") %> <%= "%d" % (suggestion_benefited_people) %>

diff --git a/views/comments_extra_fields.html.erb b/views/comments_extra_fields.html.erb index bbaacb1..f50992a 100644 --- a/views/comments_extra_fields.html.erb +++ b/views/comments_extra_fields.html.erb @@ -10,12 +10,12 @@
<%= label_tag "comments_people_benefited", _("Number of Beneficiaries")%> - <%= text_field_tag "community_rating[people_benefited]", "" %> + <%= text_field_tag "organization_rating[people_benefited]", "" %>
<%= label_tag "comments_saved_value", _("Saved resources")%> - <%= text_field_tag "community_rating[saved_value]", "", :placeholder=>"R$"%> + <%= text_field_tag "organization_rating[saved_value]", "", :placeholder=>"R$"%>
diff --git a/views/communities_ratings_extra_fields_show_data.html.erb b/views/communities_ratings_extra_fields_show_data.html.erb deleted file mode 100644 index 1d77fc3..0000000 --- a/views/communities_ratings_extra_fields_show_data.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -
-
- People benefited : <%= user_rating.people_benefited unless user_rating.nil? %> -
- -
- Saved Value : <%= user_rating.saved_value unless user_rating.nil? %> -
-
- diff --git a/views/organization_ratings_extra_fields_show_data.html.erb b/views/organization_ratings_extra_fields_show_data.html.erb new file mode 100644 index 0000000..1d77fc3 --- /dev/null +++ b/views/organization_ratings_extra_fields_show_data.html.erb @@ -0,0 +1,10 @@ +
+
+ People benefited : <%= user_rating.people_benefited unless user_rating.nil? %> +
+ +
+ Saved Value : <%= user_rating.saved_value unless user_rating.nil? %> +
+
+ -- libgit2 0.21.2