Commit c8c27930d96e43b3ed69fe9c8fb92b5d9f305cab
1 parent
344efc3c
Exists in
master
and in
5 other branches
Fix software catalog search bug
Showing
3 changed files
with
55 additions
and
51 deletions
Show diff stats
lib/ext/search_controller.rb
... | ... | @@ -73,8 +73,12 @@ class SearchController |
73 | 73 | |
74 | 74 | unless category_ids.empty? |
75 | 75 | filtered_software_list.select! do |software| |
76 | - result_ids = (software.community.category_ids & category_ids).sort | |
77 | - result_ids == category_ids.sort | |
76 | + if software.nil? || software.community.nil? | |
77 | + false | |
78 | + else | |
79 | + result_ids = (software.community.category_ids & category_ids).sort | |
80 | + result_ids == category_ids.sort | |
81 | + end | |
78 | 82 | end |
79 | 83 | end |
80 | 84 | |
... | ... | @@ -150,4 +154,5 @@ class SearchController |
150 | 154 | @categories_groupe_two = categories_sliced.next |
151 | 155 | end |
152 | 156 | end |
157 | + | |
153 | 158 | end | ... | ... |
public/views/search-software-catalog.js
... | ... | @@ -8,7 +8,7 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($, |
8 | 8 | |
9 | 9 | |
10 | 10 | function show_head_message() { |
11 | - if ($("#filter-categories-select-catalog").text()){ | |
11 | + if ($("#filter-categories-select-catalog").text().length === 0){ | |
12 | 12 | $("#filter-categories-select-catalog").hide(); |
13 | 13 | $("#filter-option-catalog-software").show(); |
14 | 14 | }else{ |
... | ... | @@ -94,28 +94,26 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($, |
94 | 94 | } |
95 | 95 | |
96 | 96 | |
97 | - function get_result_div_core(message){ | |
98 | - var div_result = $(".search-results-type-empty"); | |
99 | - var html = '<div class="search-results-innerbox search-results-type-empty"> <div>'+message+' </div></div>' | |
100 | - | |
101 | - div_result.replaceWith('<div class="search-results-innerbox search-results-type-empty"> <div>Nenhum software encontrado</div> '+message+'</div>') | |
97 | + function get_result_div_core(message) { | |
98 | + $("#search-results-empty").html(message); | |
102 | 99 | } |
103 | 100 | |
104 | 101 | |
105 | - function catalog_message(){ | |
106 | - var result_list = $("#search-results").find('.search-results-empty'); | |
107 | - var selected_categories_field = $("#filter-categories-select-catalog"); | |
102 | + function catalog_message() { | |
103 | + var empty_result = $('#empty_result').val() === 'true'; | |
104 | + var user_selected_categories = $('.categories-catalog:checked').length !== 0; | |
108 | 105 | |
109 | - if(result_list.length > 1 && selected_categories_field.html().length < 1){ | |
110 | - get_result_div_core("Tente filtros mais abrangentes"); | |
111 | - }else if (result_list.length > 1 && selected_categories_field.html().length >= 1) { | |
112 | - get_result_div_core("Tente filtros mais abrangentes ou confira os softwares das categorias individualmente"); | |
106 | + if(empty_result && !user_selected_categories) { | |
107 | + get_result_div_core($('#message-no-catalog-selected').val()); | |
108 | + } else if (empty_result && user_selected_categories) { | |
109 | + get_result_div_core($('#message-catalog-selected').val()); | |
113 | 110 | } |
114 | 111 | } |
115 | 112 | |
116 | 113 | |
117 | 114 | function update_search_page_on_ajax(response) { |
118 | 115 | response = $(response); |
116 | + | |
119 | 117 | var search_list = $("#search-results"); |
120 | 118 | var selected_categories_field = $("#filter-categories-select-catalog"); |
121 | 119 | var pagination = $("#software-pagination"); |
... | ... | @@ -126,7 +124,7 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($, |
126 | 124 | var result_pagination = response.find("#software-pagination").html(); |
127 | 125 | var result_software_count = response.find("#software-count").html(); |
128 | 126 | |
129 | - catalog_message() | |
127 | + | |
130 | 128 | |
131 | 129 | search_list.html(result_list); |
132 | 130 | selected_categories_field.html(result_categories); |
... | ... | @@ -134,6 +132,7 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($, |
134 | 132 | software_count.html(result_software_count); |
135 | 133 | show_head_message(); |
136 | 134 | highlight_searched_terms(); |
135 | + catalog_message(); | |
137 | 136 | |
138 | 137 | hide_load_after_ajax(); |
139 | 138 | } | ... | ... |
views/search/_catalog_filter.html.erb
1 | 1 | <div id="main-content-wrapper-8"> <!-- id do Noosfero --> |
2 | 2 | |
3 | -<div id="filter-catalog-software"> | |
3 | + <div id="filter-catalog-software"> | |
4 | 4 | |
5 | - <div id="filter-option-catalog-software"><%= _("More options") %></div> | |
6 | - <!--Quando tiver filtros(categorias)selecionados mostrar esta opção: Opções selecionadas--> | |
5 | + <div id="filter-option-catalog-software"><%= _("More options") %></div> | |
6 | + <!--Quando tiver filtros(categorias)selecionados mostrar esta opção: Opções selecionadas--> | |
7 | 7 | |
8 | - <div id="filter-categories-select-catalog"><%= @message_selected_options %></div> | |
8 | + <div id="filter-categories-select-catalog"><%= @message_selected_options %></div> | |
9 | 9 | |
10 | - <div id="filter-categories-option"> | |
10 | + <div id="filter-categories-option"> | |
11 | 11 | |
12 | - <div id="filter-categories-catalog"><h4> <%= _("Categories") %> </h4></div> | |
13 | - <div id="group-categories"> | |
14 | - <div id="gruop-catalog-01"> | |
15 | - <% @categories_groupe_one.each do |category| %> | |
16 | - <label> | |
17 | - <%= check_box_tag("selected_categories[]", category.id, @selected_categories.include?(category.id), :class => "categories-catalog") %> | |
18 | - <span><%= _("#{category.name}") %></span> | |
19 | - </label> <br> | |
20 | - <% end %> | |
21 | - </div> | |
22 | - <div id="group-catalog-02"> | |
23 | - <% @categories_groupe_two.each do |category| %> | |
24 | - <label> | |
25 | - <%= check_box_tag("selected_categories[]", category.id, @selected_categories.include?(category.id), :class => "categories-catalog") %> | |
26 | - <%= _("#{category.name}") %> | |
27 | - </label> <br> | |
28 | - <% end %> | |
29 | - <br /> | |
12 | + <div id="filter-categories-catalog"><h4> <%= _("Categories") %> </h4></div> | |
13 | + <div id="group-categories"> | |
14 | + <div id="gruop-catalog-01"> | |
15 | + <% @categories_groupe_one.each do |category| %> | |
16 | + <label> | |
17 | + <%= check_box_tag("selected_categories[]", category.id, @selected_categories.include?(category.id), :class => "categories-catalog") %> | |
18 | + <span><%= _("#{category.name}") %></span> | |
19 | + </label> <br> | |
20 | + <% end %> | |
21 | + </div> | |
22 | + <div id="group-catalog-02"> | |
23 | + <% @categories_groupe_two.each do |category| %> | |
24 | + <label> | |
25 | + <%= check_box_tag("selected_categories[]", category.id, @selected_categories.include?(category.id), :class => "categories-catalog") %> | |
26 | + <%= _("#{category.name}") %> | |
27 | + </label> <br> | |
28 | + <% end %> | |
29 | + <br /> | |
30 | + </div> | |
31 | + </div> | |
32 | + | |
33 | + <div class="project-software"> <%= _("Software Projects:") %> | |
34 | + <label> | |
35 | + <%= check_box_tag("include_non_public", true, @include_non_public) %> | |
36 | + <%= _("Include in results") %> | |
37 | + </label> | |
38 | + <span class"doubts-catalog-software" title="<%= _('Include software development projects that are not yet officially Brazilian Public Software.') %>">(?)</span> | |
30 | 39 | </div> |
40 | + <br /> | |
41 | + <%= button_tag _("Clean up"), :id => "cleanup-filter-catalg", :type => "button" %> | |
42 | + <%= button_tag _("Close"), :id => "close-filter-catalog", :type => "button" %> | |
31 | 43 | </div> |
32 | - | |
33 | - <div class="project-software"> <%= _("Software Projects:") %> | |
34 | - <label> | |
35 | - <%= check_box_tag("include_non_public", true, @include_non_public) %> | |
36 | - <%= _("Include in results") %> | |
37 | - </label> | |
38 | - <span class"doubts-catalog-software" title="<%= _('Include software development projects that are not yet officially Brazilian Public Software.') %>">(?)</span> | |
39 | 44 | </div> |
40 | - <br /> | |
41 | - <%= button_tag _("Clean up"), :id => "cleanup-filter-catalg", :type => "button" %> | |
42 | - <%= button_tag _("Close"), :id => "close-filter-catalog", :type => "button" %> | |
43 | -</div> | |
44 | -</div> | |
45 | 45 | </div> | ... | ... |