Commit 24776b9ef4ee7f5345c1c84beac7e12addc40c86

Authored by Arthur Esposte
2 parents d8f78c16 c8c27930
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Merge branch 'javascript_refactory'

Conflicts:
	views/search/_catalog_filter.html.erb
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
... ...
lib/software_communities_plugin.rb
... ... @@ -125,10 +125,9 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin
125 125 views/user-edit-profile.js
126 126 views/create-institution.js
127 127 views/complete-registration.js
  128 + views/search-software-catalog.js
128 129 initializer.js
129 130 app.js
130   - mpog-search.js
131   - software-catalog.js
132 131 mpog-software-block.js
133 132 mpog-download-block.js
134 133 )
... ...
public/initializer.js
... ... @@ -4,7 +4,8 @@ var dependencies = [
4 4 'NewSoftware',
5 5 'UserEditProfile',
6 6 'CreateInstitution',
7   - 'CompleteRegistration'
  7 + 'CompleteRegistration',
  8 + 'SearchSoftwareCatalog'
8 9 ];
9 10  
10 11  
... ...
public/mpog-search.js
... ... @@ -1,44 +0,0 @@
1   -(function(){
2   -
3   - function show_institutions_fields() {
4   - jQuery(".institution_fields").show();
5   - jQuery(".software_fields").hide();
6   - jQuery(".community_fields").hide();
7   - }
8   -
9   - function show_software_fields() {
10   - jQuery(".institution_fields").hide();
11   - jQuery(".software_fields").show();
12   - jQuery(".community_fields").hide();
13   - }
14   -
15   - function show_community_fields() {
16   - jQuery(".institution_fields").hide();
17   - jQuery(".software_fields").hide();
18   - jQuery(".community_fields").show();
19   - }
20   -
21   - function display_search_fields_on_page_load() {
22   - var active_search = jQuery(".search_type input[checked='checked']").val();
23   -
24   - switch(active_search) {
25   - case "Community": show_community_fields(); break;
26   - case "Software": show_software_fields(); break;
27   - case "Institution": show_institutions_fields(); break;
28   -
29   - default: show_community_fields();
30   - }
31   - }
32   -
33   - function set_events() {
34   - display_search_fields_on_page_load();
35   -
36   - jQuery("#type_Community").click(show_community_fields);
37   -
38   - jQuery("#type_Software").click(show_software_fields);
39   -
40   - jQuery("#type_Institution").click(show_institutions_fields);
41   - }
42   -
43   - jQuery(document).ready(set_events);
44   -})();
public/software-catalog.js
... ... @@ -1,219 +0,0 @@
1   -(function($){
2   - "use strict";
3   -
4   - var AJAX_URL = {
5   - software_infos:
6   - url_with_subdirectory("/search/software_infos")
7   - };
8   -
9   -
10   - function show_head_message() {
11   - if ($("#filter-categories-select-catalog").text()){
12   - $("#filter-categories-select-catalog").hide();
13   - $("#filter-option-catalog-software").show();
14   - }else{
15   - $("#filter-categories-select-catalog").show();
16   - $("#filter-option-catalog-software").hide();
17   - }
18   - }
19   -
20   -
21   - function slideDowsCategoriesOptionAndHideOptionCatalog() {
22   - $("#filter-categories-option").slideDown();
23   - $("#filter-option-catalog-software").hide();
24   - }
25   -
26   -
27   - function slideDownCategoriesOptionAndHideCategoriesSelect() {
28   - $("#filter-categories-option").slideDown();
29   - $("#filter-categories-select-catalog").hide();
30   - }
31   -
32   -
33   - function slideUpCategoriesAndShowHeadMessage() {
34   - $("#filter-categories-option").slideUp();
35   - show_head_message();
36   - }
37   -
38   -
39   - function clearCatalogCheckbox(){
40   - $("#filter-categories-option").slideUp();
41   - $("#filter-option-catalog-software").show();
42   - $("#group-categories input:checked").each(function() {
43   - $(this).prop('checked', false);
44   - });
45   -
46   - dispatch_search_ajax(update_search_page_on_ajax, true);
47   - }
48   -
49   -
50   - function selectCheckboxCategory() {
51   - $("#filter-categories-option").slideUp();
52   - $("#filter-categories-select-catalog").show();
53   - $("#filter-option-catalog-software").hide();
54   -
55   - dispatch_search_ajax(update_search_page_on_ajax, true);
56   - }
57   -
58   -
59   - function dispatch_search_ajax(callback, enable_load) {
60   - var search_params = get_search_params();
61   -
62   - if(enable_load) {
63   - open_loading("Loading");
64   - }
65   -
66   - $.ajax({
67   - url: AJAX_URL.software_infos,
68   - type: "GET",
69   - data: search_params,
70   - success: callback,
71   - error: function(){
72   - close_loading();
73   - }
74   - });
75   - }
76   -
77   -
78   - function get_search_params() {
79   - var params = {};
80   -
81   - params.query = $("#search-input").val();
82   - params.selected_categories = [];
83   -
84   - $(".categories-catalog:checked").each(function(index, element) {
85   - params.selected_categories.push(element.value);
86   - });
87   -
88   - params.software_display = $("#software_display").val();
89   - params.sort = $("#sort").val();
90   -
91   - params.include_non_public = $("#include_non_public").is(":checked");
92   -
93   - return params;
94   - }
95   -
96   - function get_result_div_core(message){
97   - var div_result = $(".search-results-type-empty");
98   - var html = '<div class="search-results-innerbox search-results-type-empty"> <div>'+message+' </div></div>'
99   -
100   - div_result.replaceWith('<div class="search-results-innerbox search-results-type-empty"> <div>Nenhum software encontrado</div> '+message+'</div>')
101   - }
102   -
103   - function catalog_message(){
104   - var result_list = $("#search-results").find('.search-results-empty').html();
105   - var selected_categories_field = $("#filter-categories-select-catalog");
106   -
107   - if(result_list.length > 1 && selected_categories_field.html().length < 1){
108   - get_result_div_core("Tente filtros mais abrangentes");
109   - }else if (result_list.length > 1 && selected_categories_field.html().length >= 1) {
110   - get_result_div_core("Tente filtros mais abrangentes ou confira os <mudar>softwares das categorias individualmente</mudar>");
111   - }
112   - }
113   -
114   - function update_search_page_on_ajax(response) {
115   - response = $(response);
116   - var search_list = $("#search-results");
117   - var selected_categories_field = $("#filter-categories-select-catalog");
118   - var pagination = $("#software-pagination");
119   - var software_count = $("#software-count");
120   -
121   - var result_list = response.find("#search-results").html();
122   - var result_categories = response.find("#filter-categories-select-catalog").html();
123   - var result_pagination = response.find("#software-pagination").html();
124   - var result_software_count = response.find("#software-count").html();
125   -
126   - catalog_message()
127   -
128   - search_list.html(result_list);
129   - selected_categories_field.html(result_categories);
130   - pagination.html(result_pagination);
131   - software_count.html(result_software_count);
132   - show_head_message();
133   - highlight_searched_terms();
134   -
135   - hide_load_after_ajax();
136   - }
137   -
138   -
139   - function hide_load_after_ajax() {
140   - if ($("#overlay_loading_modal").is(":visible")) {
141   - close_loading();
142   - setTimeout(hide_load_after_ajax, 1000);
143   - }
144   - }
145   -
146   -
147   - function highlight_searched_terms() {
148   - var searched_terms = $("#search-input").val();
149   -
150   - if( searched_terms.length === 0 ) {
151   - return undefined;
152   - }
153   -
154   - var content_result = $(".search-content-result");
155   - var regex = new RegExp("("+searched_terms.replace(/\s/g, "|")+")", "gi");
156   -
157   - content_result.each(function(i, e){
158   - var element = $(e);
159   -
160   - var new_text = element.text().replace(regex, function(text) {
161   - return "<strong>"+text+"</strong>";
162   - });
163   -
164   - element.html(new_text);
165   - });
166   - }
167   -
168   -
169   - function selectProjectSoftwareCheckbox() {
170   - $("#filter-categories-option").slideUp();
171   - $("#filter-categories-select-catalog").show();
172   - $("#filter-option-catalog-software").hide();
173   -
174   - dispatch_search_ajax(update_search_page_on_ajax, true);
175   - show_head_message();
176   - }
177   -
178   - function update_page_by_ajax_on_select_change() {
179   - dispatch_search_ajax(update_search_page_on_ajax, true);
180   - }
181   -
182   - function update_page_by_text_filter() {
183   - var text = this.value;
184   - dispatch_search_ajax(update_search_page_on_ajax, false);
185   - }
186   -
187   - function search_input_keyup() {
188   - var timer = null;
189   -
190   - $("#search-input").keyup(function() {
191   - timer = setTimeout(update_page_by_text_filter, 400);
192   - }).keydown(function() {
193   - clearTimeout(timer);
194   - });
195   - }
196   -
197   - function set_events() {
198   - $("#filter-option-catalog-software").click(slideDowsCategoriesOptionAndHideOptionCatalog);
199   - $("#filter-categories-select-catalog").click(slideDownCategoriesOptionAndHideCategoriesSelect);
200   - $("#close-filter-catalog").click(slideUpCategoriesAndShowHeadMessage);
201   - $("#cleanup-filter-catalg").click(clearCatalogCheckbox);
202   - $(".categories-catalog").click(selectCheckboxCategory);
203   - $(".project-software").click(selectProjectSoftwareCheckbox);
204   - $("#software_display").change(update_page_by_ajax_on_select_change);
205   - $("#sort").change(update_page_by_ajax_on_select_change);
206   -
207   - search_input_keyup();
208   - }
209   -
210   - $(document).ready(function(){
211   - set_events();
212   - catalog_message();
213   - show_head_message();
214   -
215   -
216   -
217   - $("#filter-categories-option").hide();
218   - });
219   -})(jQuery);
public/views/search-software-catalog.js 0 → 100644
... ... @@ -0,0 +1,230 @@
  1 +modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) {
  2 + 'use strict';
  3 +
  4 + var AJAX_URL = {
  5 + software_infos:
  6 + NoosferoRoot.urlWithSubDirectory("/search/software_infos")
  7 + };
  8 +
  9 +
  10 + function show_head_message() {
  11 + if ($("#filter-categories-select-catalog").text().length === 0){
  12 + $("#filter-categories-select-catalog").hide();
  13 + $("#filter-option-catalog-software").show();
  14 + }else{
  15 + $("#filter-categories-select-catalog").show();
  16 + $("#filter-option-catalog-software").hide();
  17 + }
  18 + }
  19 +
  20 +
  21 + function slideDowsCategoriesOptionAndHideOptionCatalog() {
  22 + $("#filter-categories-option").slideDown();
  23 + $("#filter-option-catalog-software").hide();
  24 + }
  25 +
  26 +
  27 + function slideDownCategoriesOptionAndHideCategoriesSelect() {
  28 + $("#filter-categories-option").slideDown();
  29 + $("#filter-categories-select-catalog").hide();
  30 + }
  31 +
  32 +
  33 + function slideUpCategoriesAndShowHeadMessage() {
  34 + $("#filter-categories-option").slideUp();
  35 + show_head_message();
  36 + }
  37 +
  38 +
  39 + function clearCatalogCheckbox(){
  40 + $("#filter-categories-option").slideUp();
  41 + $("#filter-option-catalog-software").show();
  42 + $("#group-categories input:checked").each(function() {
  43 + $(this).prop('checked', false);
  44 + });
  45 +
  46 + dispatch_search_ajax(update_search_page_on_ajax, true);
  47 + }
  48 +
  49 +
  50 + function selectCheckboxCategory() {
  51 + $("#filter-categories-option").slideUp();
  52 + $("#filter-categories-select-catalog").show();
  53 + $("#filter-option-catalog-software").hide();
  54 +
  55 + dispatch_search_ajax(update_search_page_on_ajax, true);
  56 + }
  57 +
  58 +
  59 + function dispatch_search_ajax(callback, enable_load) {
  60 + var search_params = get_search_params();
  61 +
  62 + if(enable_load) {
  63 + open_loading("Loading");
  64 + }
  65 +
  66 + $.ajax({
  67 + url: AJAX_URL.software_infos,
  68 + type: "GET",
  69 + data: search_params,
  70 + success: callback,
  71 + error: function(){
  72 + close_loading();
  73 + }
  74 + });
  75 + }
  76 +
  77 +
  78 + function get_search_params() {
  79 + var params = {};
  80 +
  81 + params.query = $("#search-input").val();
  82 + params.selected_categories = [];
  83 +
  84 + $(".categories-catalog:checked").each(function(index, element) {
  85 + params.selected_categories.push(element.value);
  86 + });
  87 +
  88 + params.software_display = $("#software_display").val();
  89 + params.sort = $("#sort").val();
  90 +
  91 + params.include_non_public = $("#include_non_public").is(":checked");
  92 +
  93 + return params;
  94 + }
  95 +
  96 +
  97 + function get_result_div_core(message) {
  98 + $("#search-results-empty").html(message);
  99 + }
  100 +
  101 +
  102 + function catalog_message() {
  103 + var empty_result = $('#empty_result').val() === 'true';
  104 + var user_selected_categories = $('.categories-catalog:checked').length !== 0;
  105 +
  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());
  110 + }
  111 + }
  112 +
  113 +
  114 + function update_search_page_on_ajax(response) {
  115 + response = $(response);
  116 +
  117 + var search_list = $("#search-results");
  118 + var selected_categories_field = $("#filter-categories-select-catalog");
  119 + var pagination = $("#software-pagination");
  120 + var software_count = $("#software-count");
  121 +
  122 + var result_list = response.find("#search-results").html();
  123 + var result_categories = response.find("#filter-categories-select-catalog").html();
  124 + var result_pagination = response.find("#software-pagination").html();
  125 + var result_software_count = response.find("#software-count").html();
  126 +
  127 +
  128 +
  129 + search_list.html(result_list);
  130 + selected_categories_field.html(result_categories);
  131 + pagination.html(result_pagination);
  132 + software_count.html(result_software_count);
  133 + show_head_message();
  134 + highlight_searched_terms();
  135 + catalog_message();
  136 +
  137 + hide_load_after_ajax();
  138 + }
  139 +
  140 +
  141 + function hide_load_after_ajax() {
  142 + if ($("#overlay_loading_modal").is(":visible")) {
  143 + close_loading();
  144 + setTimeout(hide_load_after_ajax, 1000);
  145 + }
  146 + }
  147 +
  148 +
  149 + function highlight_searched_terms() {
  150 + var searched_terms = $("#search-input").val();
  151 +
  152 + if( searched_terms.length === 0 ) {
  153 + return undefined;
  154 + }
  155 +
  156 + var content_result = $(".search-content-result");
  157 + var regex = new RegExp("("+searched_terms.replace(/\s/g, "|")+")", "gi");
  158 +
  159 + content_result.each(function(i, e){
  160 + var element = $(e);
  161 +
  162 + var new_text = element.text().replace(regex, function(text) {
  163 + return "<strong>"+text+"</strong>";
  164 + });
  165 +
  166 + element.html(new_text);
  167 + });
  168 + }
  169 +
  170 +
  171 + function selectProjectSoftwareCheckbox() {
  172 + $("#filter-categories-option").slideUp();
  173 + $("#filter-categories-select-catalog").show();
  174 + $("#filter-option-catalog-software").hide();
  175 +
  176 + dispatch_search_ajax(update_search_page_on_ajax, true);
  177 + show_head_message();
  178 + }
  179 +
  180 +
  181 + function update_page_by_ajax_on_select_change() {
  182 + dispatch_search_ajax(update_search_page_on_ajax, true);
  183 + }
  184 +
  185 + function update_page_by_text_filter() {
  186 + var text = this.value;
  187 + dispatch_search_ajax(update_search_page_on_ajax, false);
  188 + }
  189 +
  190 +
  191 + function search_input_keyup() {
  192 + var timer = null;
  193 +
  194 + $("#search-input").keyup(function() {
  195 + timer = setTimeout(update_page_by_text_filter, 400);
  196 + }).keydown(function() {
  197 + clearTimeout(timer);
  198 + });
  199 + }
  200 +
  201 +
  202 + function set_events() {
  203 + $("#filter-option-catalog-software").click(slideDowsCategoriesOptionAndHideOptionCatalog);
  204 + $("#filter-categories-select-catalog").click(slideDownCategoriesOptionAndHideCategoriesSelect);
  205 + $("#close-filter-catalog").click(slideUpCategoriesAndShowHeadMessage);
  206 + $("#cleanup-filter-catalg").click(clearCatalogCheckbox);
  207 + $(".categories-catalog").click(selectCheckboxCategory);
  208 + $(".project-software").click(selectProjectSoftwareCheckbox);
  209 + $("#software_display").change(update_page_by_ajax_on_select_change);
  210 + $("#sort").change(update_page_by_ajax_on_select_change);
  211 +
  212 + search_input_keyup();
  213 + }
  214 +
  215 +
  216 + return {
  217 + isCurrentPage: function() {
  218 + return $('#software-search-container').length === 1;
  219 + },
  220 +
  221 +
  222 + init: function() {
  223 + set_events();
  224 + catalog_message();
  225 + show_head_message();
  226 +
  227 + $("#filter-categories-option").hide();
  228 + }
  229 + }
  230 +});
0 231 \ No newline at end of file
... ...
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 44  
33 45 <div class="project-software"> <%= _("All Software Projects:") %>
... ... @@ -37,9 +49,4 @@
37 49 </label>
38 50 <span class"doubts-catalog-software" title="<%= _('Include software development projects that are not yet officially Brazilian Public Software.') %>">(?)</span>
39 51 </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 52 </div>
... ...