diff --git a/src/noosfero-spb/noosfero-spb-theme/images/ic-doc.png b/src/noosfero-spb/noosfero-spb-theme/images/ic-doc.png new file mode 100644 index 0000000..5d11940 Binary files /dev/null and b/src/noosfero-spb/noosfero-spb-theme/images/ic-doc.png differ diff --git a/src/noosfero-spb/software_communities/features/software_catalog.feature b/src/noosfero-spb/software_communities/features/software_catalog.feature index e0988cf..8bb6207 100644 --- a/src/noosfero-spb/software_communities/features/software_catalog.feature +++ b/src/noosfero-spb/software_communities/features/software_catalog.feature @@ -80,3 +80,33 @@ Feature: Search software Then I should see "Software One" And I should see "Software Two" And I should see "Software Three" + + @selenium + Scenario: See software rating on catalog + Given plugin "OrganizationRatings" is enabled on environment + And I am logged in as mpog_admin + And I go to /admin/plugins + And I check "Organization Ratings" + And I press "Save changes" + And I go to /admin/admin_panel/site_info + And I select "Software Público" from "environment_theme" + And I press "Save" + And I go to /account/logout + Given the following user + | login | name | + | joaosilva | Joao Silva | + And the following blocks + | owner | type | + | software-two | AverageRatingBlock | + | software-two | OrganizationRatingsBlock | + And the environment domain is "localhost" + And I am logged in as "joaosilva" + And I go to /profile/software-two/plugin/organization_ratings/new_rating + And I press "Enviar" + And I go to /search/software_infos + When I select "Favorites" from "sort" + And I sleep for 3 seconds + Then I should see "Software Two" before "Software One" + And there should be 1 div with class "small-star-positive" + And there should be 4 divs with class "small-star-negative" + diff --git a/src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb b/src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb index de191e4..5a82382 100644 --- a/src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb +++ b/src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb @@ -200,3 +200,7 @@ Given /^I keyup on selector "([^"]*)"$/ do |selector| selector_founded = evaluate_script("jQuery('#{selector}').trigger('keyup').length != 0") selector_founded.should be_true end + +Then /^there should be (\d+) divs? with class "([^"]*)"$/ do |count, klass| + should have_selector("div.#{klass}", :count => count) +end diff --git a/src/noosfero-spb/software_communities/lib/ext/search_controller.rb b/src/noosfero-spb/software_communities/lib/ext/search_controller.rb index e96cd63..156ce2a 100644 --- a/src/noosfero-spb/software_communities/lib/ext/search_controller.rb +++ b/src/noosfero-spb/software_communities/lib/ext/search_controller.rb @@ -105,6 +105,8 @@ class SearchController communities_list.reverse! elsif params[:sort] && params[:sort] == "relevance" communities_list = sort_by_relevance(communities_list, params[:query]){ |community| [community.software_info.finality, community.name] } + elsif params[:sort] && params[:sort] == "rating" + communities_list = sort_by_average_rating(communities_list) end communities_list end diff --git a/src/noosfero-spb/software_communities/lib/ext/search_helper.rb b/src/noosfero-spb/software_communities/lib/ext/search_helper.rb index 025a3b8..02bb150 100644 --- a/src/noosfero-spb/software_communities/lib/ext/search_helper.rb +++ b/src/noosfero-spb/software_communities/lib/ext/search_helper.rb @@ -30,4 +30,16 @@ module SearchHelper list end + def sort_by_average_rating list + list.sort! do |a, b| + rating_a = OrganizationRating.average_rating(a.id) + rating_a = 0 if rating_a.nil? + rating_b = OrganizationRating.average_rating(b.id) + rating_b = 0 if rating_b.nil? + rating_a - rating_b + end + + list.reverse! + end + end diff --git a/src/noosfero-spb/software_communities/lib/software_info.rb b/src/noosfero-spb/software_communities/lib/software_info.rb index af080a7..73e8a32 100644 --- a/src/noosfero-spb/software_communities/lib/software_info.rb +++ b/src/noosfero-spb/software_communities/lib/software_info.rb @@ -91,12 +91,12 @@ class SoftwareInfo < ActiveRecord::Base settings_items :another_license_version, :another_license_link # used on find_by_contents - scope :like_search, lambda{ |name| + def self.like_search name joins(:community).where( "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?", "%#{name}%", "%#{name}%", "%#{name}%" ) - } + end scope :search, lambda { |name="", database_description_id = "", programming_language_id = "", operating_system_name_id = "", diff --git a/src/noosfero-spb/software_communities/public/style.css b/src/noosfero-spb/software_communities/public/style.css index 5d4c536..900b2ff 100644 --- a/src/noosfero-spb/software_communities/public/style.css +++ b/src/noosfero-spb/software_communities/public/style.css @@ -110,3 +110,6 @@ cursor: pointer; } +.catalog_rating_block { + margin-top: 5px; +} diff --git a/src/noosfero-spb/software_communities/views/search/_full_community.html.erb b/src/noosfero-spb/software_communities/views/search/_full_community.html.erb index 23e2b14..47a5475 100644 --- a/src/noosfero-spb/software_communities/views/search/_full_community.html.erb +++ b/src/noosfero-spb/software_communities/views/search/_full_community.html.erb @@ -1,7 +1,14 @@ <% software = community.software_info %>