Commit 1dfdc8fe4eeebd464ade0377a47ef91df1181bda
1 parent
2de7d812
Exists in
temp_soft_comm_refactoring
Small fixies in software catalog - it's still broken
Showing
7 changed files
with
185 additions
and
180 deletions
Show diff stats
src/noosfero-spb/software_communities/lib/ext/search_controller.rb
1 | -# require_dependency 'search_controller' | ||
2 | - | ||
3 | -# class SearchController | ||
4 | - | ||
5 | -# def communities | ||
6 | -# delete_communities = [] | ||
7 | -# valid_communities_string = Community.get_valid_communities_string | ||
8 | -# Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)} | ||
9 | - | ||
10 | -# @scope = visible_profiles(Community) | ||
11 | -# @scope = @scope.where(["id NOT IN (?)", delete_communities]) unless delete_communities.empty? | ||
12 | - | ||
13 | -# full_text_search | ||
14 | -# end | ||
15 | - | ||
16 | -# def software_infos | ||
17 | -# prepare_software_search_page | ||
18 | -# results = filter_software_infos_list | ||
19 | -# @software_count = results.count | ||
20 | -# results = results.paginate(:per_page => @per_page, :page => params[:page]) | ||
21 | -# @searches[@asset] = {:results => results} | ||
22 | -# @search = results | ||
23 | - | ||
24 | -# render :layout=>false if request.xhr? | ||
25 | -# end | ||
26 | - | ||
27 | -# protected | ||
28 | - | ||
29 | -# def filter_communities_list | ||
30 | -# unfiltered_list = visible_profiles(Community) | ||
31 | - | ||
32 | -# unless params[:query].nil? | ||
33 | -# unfiltered_list = unfiltered_list.select do |com| | ||
34 | -# com.name.downcase =~ /#{params[:query].downcase}/ | ||
35 | -# end | ||
36 | -# end | ||
37 | - | ||
38 | -# communities_list = [] | ||
39 | -# unfiltered_list.each do |profile| | ||
40 | -# if profile.class == Community && !profile.is_template? && yield(profile) | ||
41 | -# communities_list << profile | ||
42 | -# end | ||
43 | -# end | ||
44 | - | ||
45 | -# communities_list | ||
46 | -# end | ||
47 | - | ||
48 | -# def filter_software_infos_list | ||
49 | -# filtered_software_list = get_filtered_software_list | ||
50 | -# filtered_community_list = get_communities_list(filtered_software_list) | ||
51 | -# sort_communities_list filtered_community_list | ||
52 | -# end | ||
53 | - | ||
54 | -# def get_filter_category_ids | ||
55 | -# category_ids = [] | ||
56 | -# unless params[:selected_categories_id].blank? | ||
57 | -# category_ids = params[:selected_categories_id] | ||
58 | -# end | ||
59 | -# category_ids.map(&:to_i) | ||
60 | -# end | ||
61 | - | ||
62 | -# def get_filtered_software_list | ||
63 | -# params[:query] ||= "" | ||
64 | -# visible_communities = visible_profiles(Community) | ||
65 | - | ||
66 | -# filtered_software_list = SoftwareCommunitiesPlugin::SoftwareInfo.search_by_query(params[:query]) | ||
67 | - | ||
68 | -# if params[:only_softwares] | ||
69 | -# params[:only_softwares].collect!{ |software_name| software_name.to_slug } | ||
70 | -# filtered_software_list = SoftwareCommunitiesPlugin::SoftwareInfo.all.select{ |s| params[:only_softwares].include?(s.identifier) } | ||
71 | -# @public_software_selected = false | ||
72 | -# end | ||
73 | - | ||
74 | -# filtered_software_list.select!{ |software| visible_communities.include?(software.community) } | ||
75 | -# category_ids = get_filter_category_ids | ||
76 | - | ||
77 | -# unless category_ids.empty? | ||
78 | -# filtered_software_list.select! do |software| | ||
79 | -# if software.nil? || software.community.nil? | ||
80 | -# false | ||
81 | -# else | ||
82 | -# result_ids = (software.community.category_ids & category_ids).sort | ||
83 | -# result_ids == category_ids.sort | ||
84 | -# end | ||
85 | -# end | ||
86 | -# end | ||
87 | - | ||
88 | -# filtered_software_list | ||
89 | -# end | ||
90 | - | ||
91 | -# def get_communities_list software_list | ||
92 | -# filtered_community_list = [] | ||
93 | -# software_list.each do |software| | ||
94 | -# if !@public_software_selected || software.public_software? | ||
95 | -# filtered_community_list << software.community unless software.community.nil? | ||
96 | -# end | ||
97 | -# end | ||
98 | -# filtered_community_list | ||
99 | -# end | ||
100 | - | ||
101 | -# def sort_communities_list communities_list | ||
102 | -# communities_list.sort! {|a, b| a.name.downcase <=> b.name.downcase} | ||
103 | - | ||
104 | -# if params[:sort] && params[:sort] == "desc" | ||
105 | -# communities_list.reverse! | ||
106 | -# elsif params[:sort] && params[:sort] == "relevance" | ||
107 | -# communities_list = sort_by_relevance(communities_list, params[:query]){ |community| [community.software_info.finality, community.name] } | ||
108 | -# end | ||
109 | -# communities_list | ||
110 | -# end | ||
111 | - | ||
112 | -# def prepare_software_search_page | ||
113 | -# prepare_software_infos_params | ||
114 | -# prepare_software_infos_message | ||
115 | -# prepare_software_infos_category_groups | ||
116 | -# prepare_software_infos_category_enable | ||
117 | -# end | ||
118 | - | ||
119 | -# def prepare_software_infos_params | ||
120 | -# @asset = "software_communities_plugin/software_infos" | ||
121 | -# @assets = [@asset] | ||
122 | -# @titles["software_communities_plugin/software_infos"] = _("Result Search") | ||
123 | -# @selected_categories_id = params[:selected_categories_id] | ||
124 | -# @selected_categories_id ||= [] | ||
125 | -# @selected_categories_id = @selected_categories_id.map(&:to_i) | ||
126 | -# @all_selected = params[:software_type] == "all" | ||
127 | -# @public_software_selected = !@all_selected | ||
128 | -# @per_page = prepare_per_page | ||
129 | -# end | ||
130 | - | ||
131 | -# def prepare_per_page | ||
132 | -# return 15 if params[:software_display].nil? | ||
133 | - | ||
134 | -# if params[:software_display] == "all" | ||
135 | -# SoftwareCommunitiesPlugin::SoftwareInfo.count | ||
136 | -# else | ||
137 | -# params[:software_display].to_i | ||
138 | -# end | ||
139 | -# end | ||
140 | - | ||
141 | -# def prepare_software_infos_message | ||
142 | -# @message_selected_options = "" | ||
143 | - | ||
144 | -# @selected_categories = [] | ||
145 | -# unless @selected_categories_id.empty? | ||
146 | -# @message_selected_options = _("Selected options: ") | ||
147 | - | ||
148 | -# @selected_categories = Category.find(@selected_categories_id) | ||
149 | -# @message_selected_options += @selected_categories.collect { |category| | ||
150 | -# "#{category.name}; " | ||
151 | -# }.join() | ||
152 | -# end | ||
153 | -# end | ||
154 | - | ||
155 | -# def prepare_software_infos_category_groups | ||
156 | -# @categories = Category.software_categories.sort{|a, b| a.name <=> b.name} | ||
157 | -# end | ||
158 | - | ||
159 | -# def prepare_software_infos_category_enable | ||
160 | -# @enabled_check_box = Hash.new | ||
161 | -# categories = Category.software_categories | ||
162 | - | ||
163 | -# categories.each do |category| | ||
164 | -# if category.software_infos.count > 0 | ||
165 | -# @enabled_check_box[category] = :enabled | ||
166 | -# else | ||
167 | -# @enabled_check_box[category] = :disabled | ||
168 | -# end | ||
169 | -# end | ||
170 | -# end | ||
171 | -# end | 1 | +require_dependency 'search_controller' |
2 | + | ||
3 | +class SearchController | ||
4 | + | ||
5 | + # def communities | ||
6 | + # delete_communities = [] | ||
7 | + # valid_communities_string = Community.get_valid_communities_string | ||
8 | + # Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)} | ||
9 | + | ||
10 | + # @scope = visible_profiles(Community) | ||
11 | + # @scope = @scope.where(["id NOT IN (?)", delete_communities]) unless delete_communities.empty? | ||
12 | + | ||
13 | + # full_text_search | ||
14 | + # end | ||
15 | + | ||
16 | + # def software_infos | ||
17 | + # prepare_software_search_page | ||
18 | + # results = filter_software_infos_list | ||
19 | + # @software_count = results.count | ||
20 | + # results = results.paginate(:per_page => @per_page, :page => params[:page]) | ||
21 | + # @searches[@asset] = {:results => results} | ||
22 | + # @search = results | ||
23 | + | ||
24 | + # render :layout=>false if request.xhr? | ||
25 | + # end | ||
26 | + | ||
27 | + protected | ||
28 | + | ||
29 | + def filter_communities_list | ||
30 | + unfiltered_list = visible_profiles(Community) | ||
31 | + | ||
32 | + unless params[:query].nil? | ||
33 | + unfiltered_list = unfiltered_list.select do |com| | ||
34 | + com.name.downcase =~ /#{params[:query].downcase}/ | ||
35 | + end | ||
36 | + end | ||
37 | + | ||
38 | + communities_list = [] | ||
39 | + unfiltered_list.each do |profile| | ||
40 | + if profile.class == Community && !profile.is_template? && yield(profile) | ||
41 | + communities_list << profile | ||
42 | + end | ||
43 | + end | ||
44 | + | ||
45 | + communities_list | ||
46 | + end | ||
47 | + | ||
48 | + def filter_software_infos_list | ||
49 | + filtered_software_list = get_filtered_software_list | ||
50 | + # filtered_community_list = get_communities_list(filtered_software_list) | ||
51 | + sort_communities_list filtered_software_list | ||
52 | + end | ||
53 | + | ||
54 | + def get_filter_category_ids | ||
55 | + category_ids = [] | ||
56 | + unless params[:selected_categories_id].blank? | ||
57 | + category_ids = params[:selected_categories_id] | ||
58 | + end | ||
59 | + category_ids.map(&:to_i) | ||
60 | + end | ||
61 | + | ||
62 | + def get_filtered_software_list | ||
63 | + params[:query] ||= "" | ||
64 | + visible_communities = visible_profiles(Community) | ||
65 | + | ||
66 | + filtered_software_list = SoftwareCommunitiesPlugin::SoftwareInfo.search_by_query(params[:query]) | ||
67 | + | ||
68 | + if params[:only_softwares] | ||
69 | + params[:only_softwares].collect!{ |software_name| software_name.to_slug } | ||
70 | + filtered_software_list = SoftwareCommunitiesPlugin::SoftwareInfo.all.select{ |s| params[:only_softwares].include?(s.identifier) } | ||
71 | + @public_software_selected = false | ||
72 | + end | ||
73 | + | ||
74 | + filtered_software_list.select!{ |software| visible_communities.include?(software.community) } | ||
75 | + category_ids = get_filter_category_ids | ||
76 | + | ||
77 | + unless category_ids.empty? | ||
78 | + filtered_software_list.select! do |software| | ||
79 | + if software.nil? || software.community.nil? | ||
80 | + false | ||
81 | + else | ||
82 | + result_ids = (software.community.category_ids & category_ids).sort | ||
83 | + result_ids == category_ids.sort | ||
84 | + end | ||
85 | + end | ||
86 | + end | ||
87 | + | ||
88 | + ids = filtered_software_list.pluck(:id) | ||
89 | + visible_communities.joins(:software_infos).where("software_infos.id IN ?", ids) | ||
90 | + end | ||
91 | + | ||
92 | + def sort_communities_list communities_list | ||
93 | + communities_list.order('name') | ||
94 | + | ||
95 | + if params[:sort] && params[:sort] == "desc" | ||
96 | + communities_list.order('name DESC') | ||
97 | + elsif params[:sort] && params[:sort] == "relevance" | ||
98 | + communities_list = sort_by_relevance(communities_list, params[:query]){ |community| [community.software_info.finality, community.name] } | ||
99 | + end | ||
100 | + communities_list | ||
101 | + end | ||
102 | + | ||
103 | + def prepare_software_search_page | ||
104 | + prepare_software_infos_params | ||
105 | + prepare_software_infos_message | ||
106 | + prepare_software_infos_category_groups | ||
107 | + prepare_software_infos_category_enable | ||
108 | + end | ||
109 | + | ||
110 | + def prepare_software_infos_params | ||
111 | + @asset = "software_communities_plugin/software_infos" | ||
112 | + @assets = [@asset] | ||
113 | + @titles["software_communities_plugin/software_infos"] = _("Result Search") | ||
114 | + @selected_categories_id = params[:selected_categories_id] | ||
115 | + @selected_categories_id ||= [] | ||
116 | + @selected_categories_id = @selected_categories_id.map(&:to_i) | ||
117 | + @all_selected = params[:software_type] == "all" | ||
118 | + @public_software_selected = !@all_selected | ||
119 | + @per_page = prepare_per_page | ||
120 | + end | ||
121 | + | ||
122 | + def prepare_per_page | ||
123 | + return 15 if params[:software_display].nil? | ||
124 | + | ||
125 | + if params[:software_display] == "all" | ||
126 | + SoftwareCommunitiesPlugin::SoftwareInfo.count | ||
127 | + else | ||
128 | + params[:software_display].to_i | ||
129 | + end | ||
130 | + end | ||
131 | + | ||
132 | + def prepare_software_infos_message | ||
133 | + @message_selected_options = "" | ||
134 | + | ||
135 | + @selected_categories = [] | ||
136 | + unless @selected_categories_id.empty? | ||
137 | + @message_selected_options = _("Selected options: ") | ||
138 | + | ||
139 | + @selected_categories = Category.find(@selected_categories_id) | ||
140 | + @message_selected_options += @selected_categories.collect { |category| | ||
141 | + "#{category.name}; " | ||
142 | + }.join() | ||
143 | + end | ||
144 | + end | ||
145 | + | ||
146 | + def prepare_software_infos_category_groups | ||
147 | + @categories = Category.software_categories.sort{|a, b| a.name <=> b.name} | ||
148 | + end | ||
149 | + | ||
150 | + def prepare_software_infos_category_enable | ||
151 | + @enabled_check_box = Hash.new | ||
152 | + categories = Category.software_categories | ||
153 | + | ||
154 | + categories.each do |category| | ||
155 | + if category.software_infos.count > 0 | ||
156 | + @enabled_check_box[category] = :enabled | ||
157 | + else | ||
158 | + @enabled_check_box[category] = :disabled | ||
159 | + end | ||
160 | + end | ||
161 | + end | ||
162 | +end |
src/noosfero-spb/software_communities/lib/software_communities_plugin.rb
@@ -114,6 +114,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | @@ -114,6 +114,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | ||
114 | person.has_permission_without_plugins?(permission, target) | 114 | person.has_permission_without_plugins?(permission, target) |
115 | end | 115 | end |
116 | 116 | ||
117 | + | ||
117 | def filter_search_scope(scope, asset) | 118 | def filter_search_scope(scope, asset) |
118 | # Select only communities that are not related to any software. | 119 | # Select only communities that are not related to any software. |
119 | if asset.to_s == 'communities' | 120 | if asset.to_s == 'communities' |
@@ -136,10 +137,19 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | @@ -136,10 +137,19 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | ||
136 | def new_search_assets | 137 | def new_search_assets |
137 | class_name_underscored = "software_communities_plugin/software_infos" | 138 | class_name_underscored = "software_communities_plugin/software_infos" |
138 | block = proc do | 139 | block = proc do |
140 | + prepare_software_search_page | ||
141 | + results = filter_software_infos_list | ||
139 | @scope = visible_profiles(Community) | 142 | @scope = visible_profiles(Community) |
140 | @asset = class_name_underscored | 143 | @asset = class_name_underscored |
141 | @assets = [@asset] | 144 | @assets = [@asset] |
142 | @titles[class_name_underscored] = _("Result Search") | 145 | @titles[class_name_underscored] = _("Result Search") |
146 | + @categories = Category.software_categories.sort{|a, b| a.name <=> b.name} | ||
147 | + @selected_categories_id = params[:selected_categories_id] | ||
148 | + @selected_categories_id ||= [] | ||
149 | + @selected_categories_id = @selected_categories_id.map(&:to_i) | ||
150 | + @all_selected = params[:software_type] == "all" | ||
151 | + @public_software_selected = !@all_selected | ||
152 | + @per_page = prepare_per_page | ||
143 | params[:limit] = 24 | 153 | params[:limit] = 24 |
144 | end | 154 | end |
145 | 155 |
src/noosfero-spb/software_communities/public/views/search-software-catalog.js
@@ -2,8 +2,8 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot', 'SoftwareCat | @@ -2,8 +2,8 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot', 'SoftwareCat | ||
2 | 'use strict'; | 2 | 'use strict'; |
3 | 3 | ||
4 | var AJAX_URL = { | 4 | var AJAX_URL = { |
5 | - software_infos: | ||
6 | - NoosferoRoot.urlWithSubDirectory("/search/software_infos") | 5 | + softwares: |
6 | + NoosferoRoot.urlWithSubDirectory("/search/softwares") | ||
7 | }; | 7 | }; |
8 | 8 | ||
9 | 9 | ||
@@ -15,7 +15,7 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot', 'SoftwareCat | @@ -15,7 +15,7 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot', 'SoftwareCat | ||
15 | } | 15 | } |
16 | 16 | ||
17 | $.ajax({ | 17 | $.ajax({ |
18 | - url: AJAX_URL.software_infos, | 18 | + url: AJAX_URL.softwares, |
19 | type: "GET", | 19 | type: "GET", |
20 | data: search_params, | 20 | data: search_params, |
21 | success: update_search_page_on_ajax, | 21 | success: update_search_page_on_ajax, |
src/noosfero-spb/software_communities/views/search/_catalog_filter.html.erb
1 | <div id="filter-catalog-software"> | 1 | <div id="filter-catalog-software"> |
2 | - | ||
3 | <div id="filter-categories-option"> | 2 | <div id="filter-categories-option"> |
4 | - <div id="filter-categories-catalog"><h4> <%= _("Categories") %> </h4></div> | 3 | + <div id="filter-categories-catalog"> |
4 | + <h4><%= _("Categories") %></h4> | ||
5 | + </div> | ||
5 | <div id="group-categories"> | 6 | <div id="group-categories"> |
6 | <ul> | 7 | <ul> |
7 | <% unless @categories.blank? %> | 8 | <% unless @categories.blank? %> |
@@ -15,8 +16,11 @@ | @@ -15,8 +16,11 @@ | ||
15 | </ul> | 16 | </ul> |
16 | </div> | 17 | </div> |
17 | </div> | 18 | </div> |
18 | - <div id="filter-option-catalog-software"><%= _("More options") %></div> | 19 | + <div id="filter-option-catalog-software"> |
20 | + <%= _("More options") %> | ||
21 | + </div> | ||
19 | <div id="filter-option-catalog-close"> | 22 | <div id="filter-option-catalog-close"> |
20 | <%= button_tag _("Clean up"), :id => "cleanup-filter-catalg", :type => "button" %> | 23 | <%= button_tag _("Clean up"), :id => "cleanup-filter-catalg", :type => "button" %> |
21 | <%= button_tag _("Close"), :id => "close-filter-catalog", :type => "button" %> | 24 | <%= button_tag _("Close"), :id => "close-filter-catalog", :type => "button" %> |
22 | </div> | 25 | </div> |
26 | +</div> |
src/noosfero-spb/software_communities/views/search/_catalog_result_list.html.erb
@@ -38,7 +38,7 @@ | @@ -38,7 +38,7 @@ | ||
38 | <div id="individually-category"> | 38 | <div id="individually-category"> |
39 | <% @selected_categories.each do |category| %> | 39 | <% @selected_categories.each do |category| %> |
40 | <br /> | 40 | <br /> |
41 | - <%= link_to _("#{category.name}") + " (#{category.software_infos.count})", {:controller => :search, :action => :software_infos, :selected_categories_id => [category.id]} %> | 41 | + <%= link_to _("#{category.name}") + " (#{category.software_infos.count})", {:controller => :search, :action => :softwares, :selected_categories_id => [category.id]} %> |
42 | <% end %> | 42 | <% end %> |
43 | </div> | 43 | </div> |
44 | 44 |
src/noosfero-spb/software_communities/views/search/_full_community.html.erb
@@ -34,7 +34,7 @@ | @@ -34,7 +34,7 @@ | ||
34 | <li> | 34 | <li> |
35 | <%= link_to _("#{category.name}"), { | 35 | <%= link_to _("#{category.name}"), { |
36 | :controller => :search, | 36 | :controller => :search, |
37 | - :action => :software_infos, | 37 | + :action => :softwares, |
38 | :selected_categories_id => [category.id], | 38 | :selected_categories_id => [category.id], |
39 | :software_type => params[:software_type] | 39 | :software_type => params[:software_type] |
40 | } %> | 40 | } %> |
src/noosfero-spb/software_communities/views/search/_software_search_form.html.erb
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | <div class='search-form'> | 2 | <div class='search-form'> |
3 | <h3> <%= _("Search Software Catalog") %> </h3> | 3 | <h3> <%= _("Search Software Catalog") %> </h3> |
4 | 4 | ||
5 | - <%= form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.path : nil ) }, | 5 | + <%= form_tag( { :controller => 'search', :action => 'softwares', :asset => @asset, :category_path => ( @category ? @category.path : nil ) }, |
6 | :method => 'get') do %> | 6 | :method => 'get') do %> |
7 | 7 | ||
8 | <div style="margin:0;padding:0;display:inline"> | 8 | <div style="margin:0;padding:0;display:inline"> |