Commit 6f2cc74ea7def2454531baebab64f1a4127150f9
Committed by
Thiago Ribeiro
1 parent
c896d5f4
Exists in
master
and in
21 other branches
Add rating and favorite filter to software catalog
Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
11 changed files
with
77 additions
and
4 deletions
Show diff stats
268 Bytes
src/noosfero-spb/software_communities/features/software_catalog.feature
... | ... | @@ -80,3 +80,33 @@ Feature: Search software |
80 | 80 | Then I should see "Software One" |
81 | 81 | And I should see "Software Two" |
82 | 82 | And I should see "Software Three" |
83 | + | |
84 | + @selenium | |
85 | + Scenario: See software rating on catalog | |
86 | + Given plugin "OrganizationRatings" is enabled on environment | |
87 | + And I am logged in as mpog_admin | |
88 | + And I go to /admin/plugins | |
89 | + And I check "Organization Ratings" | |
90 | + And I press "Save changes" | |
91 | + And I go to /admin/admin_panel/site_info | |
92 | + And I select "Software Público" from "environment_theme" | |
93 | + And I press "Save" | |
94 | + And I go to /account/logout | |
95 | + Given the following user | |
96 | + | login | name | | |
97 | + | joaosilva | Joao Silva | | |
98 | + And the following blocks | |
99 | + | owner | type | | |
100 | + | software-two | AverageRatingBlock | | |
101 | + | software-two | OrganizationRatingsBlock | | |
102 | + And the environment domain is "localhost" | |
103 | + And I am logged in as "joaosilva" | |
104 | + And I go to /profile/software-two/plugin/organization_ratings/new_rating | |
105 | + And I press "Enviar" | |
106 | + And I go to /search/software_infos | |
107 | + When I select "Favorites" from "sort" | |
108 | + And I sleep for 3 seconds | |
109 | + Then I should see "Software Two" before "Software One" | |
110 | + And there should be 1 div with class "small-star-positive" | |
111 | + And there should be 4 divs with class "small-star-negative" | |
112 | + | ... | ... |
src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb
... | ... | @@ -200,3 +200,7 @@ Given /^I keyup on selector "([^"]*)"$/ do |selector| |
200 | 200 | selector_founded = evaluate_script("jQuery('#{selector}').trigger('keyup').length != 0") |
201 | 201 | selector_founded.should be_true |
202 | 202 | end |
203 | + | |
204 | +Then /^there should be (\d+) divs? with class "([^"]*)"$/ do |count, klass| | |
205 | + should have_selector("div.#{klass}", :count => count) | |
206 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/ext/search_controller.rb
... | ... | @@ -105,6 +105,8 @@ class SearchController |
105 | 105 | communities_list.reverse! |
106 | 106 | elsif params[:sort] && params[:sort] == "relevance" |
107 | 107 | communities_list = sort_by_relevance(communities_list, params[:query]){ |community| [community.software_info.finality, community.name] } |
108 | + elsif params[:sort] && params[:sort] == "rating" | |
109 | + communities_list = sort_by_average_rating(communities_list) | |
108 | 110 | end |
109 | 111 | communities_list |
110 | 112 | end | ... | ... |
src/noosfero-spb/software_communities/lib/ext/search_helper.rb
... | ... | @@ -30,4 +30,16 @@ module SearchHelper |
30 | 30 | list |
31 | 31 | end |
32 | 32 | |
33 | + def sort_by_average_rating list | |
34 | + list.sort! do |a, b| | |
35 | + rating_a = OrganizationRating.average_rating(a.id) | |
36 | + rating_a = 0 if rating_a.nil? | |
37 | + rating_b = OrganizationRating.average_rating(b.id) | |
38 | + rating_b = 0 if rating_b.nil? | |
39 | + rating_a - rating_b | |
40 | + end | |
41 | + | |
42 | + list.reverse! | |
43 | + end | |
44 | + | |
33 | 45 | end | ... | ... |
src/noosfero-spb/software_communities/lib/software_info.rb
... | ... | @@ -91,12 +91,12 @@ class SoftwareInfo < ActiveRecord::Base |
91 | 91 | settings_items :another_license_version, :another_license_link |
92 | 92 | |
93 | 93 | # used on find_by_contents |
94 | - scope :like_search, lambda{ |name| | |
94 | + def self.like_search name | |
95 | 95 | joins(:community).where( |
96 | 96 | "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?", |
97 | 97 | "%#{name}%", "%#{name}%", "%#{name}%" |
98 | 98 | ) |
99 | - } | |
99 | + end | |
100 | 100 | |
101 | 101 | scope :search, lambda { |name="", database_description_id = "", |
102 | 102 | programming_language_id = "", operating_system_name_id = "", | ... | ... |
src/noosfero-spb/software_communities/public/style.css
src/noosfero-spb/software_communities/views/search/_full_community.html.erb
1 | 1 | <% software = community.software_info %> |
2 | 2 | <li class="search-software-item"> |
3 | + <% organization_average_rating = '' %> | |
4 | + <% unless community.organization_ratings.empty?%> | |
5 | + <% organization_average_rating = render :partial => 'shared/organization_average_rating_block', :locals => {:community => community}%> | |
6 | + <% end %> | |
7 | + | |
8 | + <% software_publish_date = render :partial => 'shared/software_publish_date', :locals => {:community => community, :order => @order} %> | |
9 | + | |
3 | 10 | <div class="search-software-item-column-left"> |
4 | - <%= profile_image_link community, :portrait, 'div', community.send(@order + '_label') + show_date(community.created_at) %> | |
11 | + <%= profile_image_link community, :portrait, 'div', organization_average_rating + software_publish_date %> | |
5 | 12 | </div> |
6 | 13 | |
7 | 14 | <div class="search-software-item-column-right"> | ... | ... |
src/noosfero-spb/software_communities/views/search/_software_search_form.html.erb
src/noosfero-spb/software_communities/views/shared/_organization_average_rating_block.html.erb
0 → 100644
... | ... | @@ -0,0 +1,10 @@ |
1 | +<span class="average-rating-title"><%= _("Rating") %></span> | |
2 | +<div class="star-container catalog_rating_block"> | |
3 | + <% (1..5).each do |rate_number| %> | |
4 | + <% if rate_number <= OrganizationRating.average_rating(community.id) %> | |
5 | + <div class="small-star-positive"></div> | |
6 | + <% else %> | |
7 | + <div class="small-star-negative"></div> | |
8 | + <% end %> | |
9 | + <% end %> | |
10 | +</div> | ... | ... |
src/noosfero-spb/software_communities/views/shared/_software_publish_date.html.erb
0 → 100644
-
mentioned in commit d0e8e5bc4bef6e8e98f8f5eff11ed17e2eafcdbf