Commit 220876c750c8d3aac1e2c40937c119ebcfac6925

Authored by Gabriela Navarro
Committed by Luciano Prestes
1 parent 95a76f2e
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

Add categories filter on search software info page

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
controllers/mpog_software_plugin_controller.rb
... ... @@ -15,18 +15,6 @@ class MpogSoftwarePluginController &lt; ApplicationController
15 15 end
16 16 end
17 17  
18   - def get_institutions
19   - list = []
20   -
21   - if request.xhr? and params[:query]
22   - list = Institution.search_institution(params[:query]).map{ |institution|
23   - {:value=>institution.name, :id=>institution.id}
24   - }
25   - end
26   -
27   - render :json => list.to_json
28   - end
29   -
30 18 def hide_registration_incomplete_percentage
31 19 response = false
32 20  
... ... @@ -151,6 +139,30 @@ class MpogSoftwarePluginController &lt; ApplicationController
151 139 end
152 140 end
153 141  
  142 + def get_institutions
  143 + list = []
  144 +
  145 + if request.xhr? and params[:query]
  146 + list = Institution.search_institution(params[:query]).map{ |institution|
  147 + {:value=>institution.name, :id=>institution.id}
  148 + }
  149 + end
  150 +
  151 + render :json => list.to_json
  152 + end
  153 +
  154 + def get_categories
  155 + list = []
  156 +
  157 + if request.xhr? and params[:query]
  158 + Category.where("name ILIKE ?", "%#{params[:query]}%").collect { |c|
  159 + list << {:label=>c.name, :id=>c.id} if c.name != "Software"
  160 + }
  161 + end
  162 +
  163 + render :json => list.to_json
  164 + end
  165 +
154 166 def get_brazil_states
155 167 redirect_to "/" unless request.xhr?
156 168  
... ... @@ -227,7 +239,7 @@ class MpogSoftwarePluginController &lt; ApplicationController
227 239 software_list.each do |software|
228 240 software[:name] = Community.find(software.community_id).name
229 241 software[:languages_list] = []
230   -
  242 +
231 243 software.software_languages.each do |sl|
232 244 software[:languages_list] << {}
233 245 index = software[:languages_list].count - 1
... ...
lib/mpog_software_plugin.rb
... ... @@ -140,7 +140,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
140 140 end
141 141  
142 142 def js_files
143   - ["spb-utils.js", "mpog-software.js", "mpog-software-validations.js", "mpog-user-validations.js", "mpog-institution-validations.js", "mpog-incomplete-registration.js", "mpog-search.js", "jquery.maskedinput.min.js"]
  143 + ["spb-utils.js", "mpog-software.js", "mpog-software-validations.js", "mpog-user-validations.js", "mpog-institution-validations.js", "mpog-incomplete-registration.js", "mpog-search.js", "jquery.maskedinput.min.js", "software-catalog.js"]
144 144 end
145 145  
146 146 def add_new_organization_buttons
... ...
public/software-catalog.js 0 → 100644
... ... @@ -0,0 +1,75 @@
  1 +(function(){
  2 + "use strict";
  3 + var AJAX_URL = {
  4 + get_categories:
  5 + url_with_subdirectory("/plugin/mpog_software/get_categories")
  6 + };
  7 +
  8 + function create_catalog_element(html_list, value, id) {
  9 + var li_tag = document.createElement("li");
  10 + var first = html_list.length == 0;
  11 +
  12 + if( first )
  13 + li_tag.innerHTML = value + " <span class='catalog-remove-item'>x</span>";
  14 + else
  15 + li_tag.innerHTML = ", " + value + " <span class='catalog-remove-item'>x</span>";
  16 +
  17 + return li_tag;
  18 + }
  19 +
  20 + function add_item_to_catalog(value, id) {
  21 + var already_has = false;
  22 +
  23 + jQuery("#catalog-list ul li").each(function(i, li){
  24 + var regex = new RegExp(value, "g");
  25 +
  26 + if( regex.test(li.innerHTML) ) {
  27 + already_has = true;
  28 + }
  29 + });
  30 +
  31 + if( !already_has ) {
  32 + jQuery("#catalog-list ul").append(create_catalog_element(jQuery("#catalog-list ul li"), value, id));
  33 + }
  34 + }
  35 +
  36 + function remote_catalog_item() {
  37 + jQuery(this).parent().remove();
  38 + }
  39 +
  40 + function set_autocomplate() {
  41 + jQuery("#software-catalog").autocomplete({
  42 + source : function(request, response){
  43 + jQuery.ajax({
  44 + type: "GET",
  45 + url: AJAX_URL.get_categories,
  46 + data: {query: request.term},
  47 + success: function(result){
  48 + response(result);
  49 + }
  50 + })
  51 + },
  52 +
  53 + select : function (event, selected) {
  54 + var value = selected.item.value;
  55 + var id = selected.item.id;
  56 +
  57 + this.value = "";
  58 +
  59 + add_item_to_catalog(value, id);
  60 + set_events();
  61 +
  62 + return false;
  63 + }
  64 + });
  65 + }
  66 +
  67 + function set_events() {
  68 + jQuery(".catalog-remove-item").click(remote_catalog_item);
  69 + }
  70 +
  71 + jQuery(document).ready(function(){
  72 + set_autocomplate();
  73 + set_events();
  74 + });
  75 +})();
... ...
views/search/_catalog_filter.html.erb 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +<style type="text/css">
  2 + #catalog-list ul li {
  3 + display: inline;
  4 + margin-right: 5px;
  5 + font-size: 14px;
  6 + }
  7 +
  8 + #catalog-list ul li span {
  9 + display: none;
  10 + cursor: pointer;
  11 + }
  12 +
  13 + #catalog-list ul li:hover span {
  14 + display: inline-block;
  15 + }
  16 +
  17 + .catalog-remove-item {
  18 + padding: 3px;
  19 + border: solid 1px #999;
  20 + border-radius: 3px;
  21 + background: #d4d4d4;
  22 + }
  23 +</style>
  24 +
  25 +<div>
  26 + <div id="catalog-list">
  27 + <ul></ul>
  28 + </div>
  29 +
  30 + <div id="catalog-filter">
  31 + <%= text_field(:software, :catalog, :id=>"software-catalog") %>
  32 + </div>
  33 +</div>
0 34 \ No newline at end of file
... ...
views/search/software_infos.html.erb
... ... @@ -2,6 +2,8 @@
2 2  
3 3 <%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %>
4 4  
  5 +<%= render :partial => "catalog_filter" %>
  6 +
5 7 <%= render :partial => 'results_header' %>
6 8  
7 9 <%= display_results(@searches, @asset) %>
... ...