Commit ca88bc8c337bb19ce085b68c88043bf1f5a82e66

Authored by Thiago Ribeiro
2 parents 83de26da 536d9288

Merge branch 'software_rating_on_catalog' into 'master'

Software rating on catalog

See merge request !86
src/noosfero-spb/noosfero-spb-theme/css/software-catalog-page.css
@@ -53,7 +53,7 @@ @@ -53,7 +53,7 @@
53 margin: 0 0 0 15px; 53 margin: 0 0 0 15px;
54 } 54 }
55 55
56 - It's TEMPORARY 56 + It's TEMPORARY
57 .action-search-software_infos #content .search-form .doubts-catalog-software { 57 .action-search-software_infos #content .search-form .doubts-catalog-software {
58 display: none; 58 display: none;
59 }*/ 59 }*/
@@ -65,7 +65,7 @@ @@ -65,7 +65,7 @@
65 line-height: 20px; 65 line-height: 20px;
66 position:absolute; 66 position:absolute;
67 } 67 }
68 -.action-search-software_infos .search-form label, 68 +.action-search-software_infos .search-form label,
69 .action-search-software_infos .search-form label{ 69 .action-search-software_infos .search-form label{
70 margin:0px 3px 4px 32px; 70 margin:0px 3px 4px 32px;
71 line-height: 22px; 71 line-height: 22px;
@@ -310,9 +310,9 @@ @@ -310,9 +310,9 @@
310 310
311 /* Column left */ 311 /* Column left */
312 312
313 -.action-search-software_infos #search-results .search-software-item-column-left{  
314 - width: 130px;  
315 - height: 130px; 313 +.action-search-software_infos #search-results .search-software-item-column-left {
  314 + width: 140px;
  315 + height: 140px;
316 float: left; 316 float: left;
317 border-right: 1px dotted #ccc; 317 border-right: 1px dotted #ccc;
318 } 318 }
@@ -359,7 +359,7 @@ @@ -359,7 +359,7 @@
359 } 359 }
360 360
361 .action-search-software_infos #search-results .search-software-item-column-left .extra_info { 361 .action-search-software_infos #search-results .search-software-item-column-left .extra_info {
362 - width: 130px; 362 + width: 140px;
363 padding-right: 20px; 363 padding-right: 20px;
364 top: 0px; 364 top: 0px;
365 position: absolute; 365 position: absolute;
@@ -370,18 +370,32 @@ @@ -370,18 +370,32 @@
370 opacity: inherit; 370 opacity: inherit;
371 } 371 }
372 372
373 -.action-search-software_infos #search-results .search-software-item-column-left .extra_info::before{ 373 +.action-search-software_infos #search-results .search-software-item-column-left .software-date {
  374 + margin-top: 20px;
  375 + width: 130px;
  376 +}
  377 +
  378 +.action-search-software_infos #search-results .search-software-item-column-left .software-date::before{
374 content: url("../images/ic-calendar.png"); 379 content: url("../images/ic-calendar.png");
375 - margin: 6px 10px 20px 0; 380 + margin: 0px 7px 20px 0;
376 float: left; 381 float: left;
377 } 382 }
378 383
  384 +.action-search-software_infos #search-results .search-software-item-column-left .star-container.catalog_rating_block {
  385 + width: 140px;
  386 + margin-left: 0px;
  387 +}
  388 +
  389 +.action-search-software_infos #search-results .search-software-item-column-left .software-date-value {
  390 + margin-left: 23px;
  391 +}
  392 +
379 /* Column Right */ 393 /* Column Right */
380 394
381 .action-search-software_infos #search-results .search-software-item-column-right { 395 .action-search-software_infos #search-results .search-software-item-column-right {
382 - width: 70%; 396 + width: 65%;
383 float: left; 397 float: left;
384 - margin-left: 130px; 398 + margin-left: 140px;
385 padding: 0 0 0 8px; 399 padding: 0 0 0 8px;
386 font-size: 15px; 400 font-size: 15px;
387 font-family: Arial; 401 font-family: Arial;
@@ -439,3 +453,5 @@ @@ -439,3 +453,5 @@
439 font-size: 13px; 453 font-size: 13px;
440 text-decoration: underline; 454 text-decoration: underline;
441 } 455 }
  456 +
  457 +
src/noosfero-spb/noosfero-spb-theme/images/ic-doc.png 0 → 100644

268 Bytes

src/noosfero-spb/software_communities/features/software_catalog.feature
@@ -80,3 +80,33 @@ Feature: Search software @@ -80,3 +80,33 @@ Feature: Search software
80 Then I should see "Software One" 80 Then I should see "Software One"
81 And I should see "Software Two" 81 And I should see "Software Two"
82 And I should see "Software Three" 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,3 +200,7 @@ Given /^I keyup on selector "([^"]*)"$/ do |selector|
200 selector_founded = evaluate_script("jQuery('#{selector}').trigger('keyup').length != 0") 200 selector_founded = evaluate_script("jQuery('#{selector}').trigger('keyup').length != 0")
201 selector_founded.should be_true 201 selector_founded.should be_true
202 end 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,6 +105,8 @@ class SearchController
105 communities_list.reverse! 105 communities_list.reverse!
106 elsif params[:sort] && params[:sort] == "relevance" 106 elsif params[:sort] && params[:sort] == "relevance"
107 communities_list = sort_by_relevance(communities_list, params[:query]){ |community| [community.software_info.finality, community.name] } 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 end 110 end
109 communities_list 111 communities_list
110 end 112 end
src/noosfero-spb/software_communities/lib/ext/search_helper.rb
@@ -30,4 +30,16 @@ module SearchHelper @@ -30,4 +30,16 @@ module SearchHelper
30 list 30 list
31 end 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 end 45 end
src/noosfero-spb/software_communities/lib/software_info.rb
@@ -91,12 +91,12 @@ class SoftwareInfo < ActiveRecord::Base @@ -91,12 +91,12 @@ class SoftwareInfo < ActiveRecord::Base
91 settings_items :another_license_version, :another_license_link 91 settings_items :another_license_version, :another_license_link
92 92
93 # used on find_by_contents 93 # used on find_by_contents
94 - scope :like_search, lambda{ |name| 94 + def self.like_search name
95 joins(:community).where( 95 joins(:community).where(
96 "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?", 96 "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?",
97 "%#{name}%", "%#{name}%", "%#{name}%" 97 "%#{name}%", "%#{name}%", "%#{name}%"
98 ) 98 )
99 - } 99 + end
100 100
101 scope :search, lambda { |name="", database_description_id = "", 101 scope :search, lambda { |name="", database_description_id = "",
102 programming_language_id = "", operating_system_name_id = "", 102 programming_language_id = "", operating_system_name_id = "",
src/noosfero-spb/software_communities/public/style.css
@@ -110,3 +110,6 @@ @@ -110,3 +110,6 @@
110 cursor: pointer; 110 cursor: pointer;
111 } 111 }
112 112
  113 +.catalog_rating_block {
  114 + margin-top: 5px;
  115 +}
src/noosfero-spb/software_communities/views/search/_full_community.html.erb
1 <% software = community.software_info %> 1 <% software = community.software_info %>
2 <li class="search-software-item"> 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 <div class="search-software-item-column-left"> 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 </div> 12 </div>
6 13
7 <div class="search-software-item-column-right"> 14 <div class="search-software-item-column-right">
src/noosfero-spb/software_communities/views/search/_software_search_form.html.erb
@@ -51,7 +51,8 @@ @@ -51,7 +51,8 @@
51 [ 51 [
52 [_("Name A-Z"), 'asc'], 52 [_("Name A-Z"), 'asc'],
53 [_("Name Z-A"), 'desc'], 53 [_("Name Z-A"), 'desc'],
54 - [_("Relevance"), 'relevance'] 54 + [_("Relevance"), 'relevance'],
  55 + [_("Favorites"), 'rating']
55 ], :selected=>params[:sort]) 56 ], :selected=>params[:sort])
56 ) %> 57 ) %>
57 </div> 58 </div>
src/noosfero-spb/software_communities/views/shared/_organization_average_rating_block.html.erb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +<div class="star-container catalog_rating_block">
  2 + <% (1..5).each do |rate_number| %>
  3 + <% if rate_number <= OrganizationRating.average_rating(community.id) %>
  4 + <div class="medium-star-positive"></div>
  5 + <% else %>
  6 + <div class="medium-star-negative"></div>
  7 + <% end %>
  8 + <% end %>
  9 +</div>
src/noosfero-spb/software_communities/views/shared/_software_publish_date.html.erb 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +<span class="software-date">
  2 + <div class="software-date-label"><%= community.send(order + '_label') %></div>
  3 + <div class="software-date-value"><%= show_date(community.created_at) %></div>
  4 +</span>
  5 +