From 893e3c6e5eae0b308ab982c112f9982fbf66c55f Mon Sep 17 00:00:00 2001 From: Luciano Prestes Cavalcanti Date: Wed, 3 Dec 2014 11:09:27 -0200 Subject: [PATCH] Fix addition of categories as filters --- lib/ext/search_controller.rb | 6 +++--- public/software-catalog.js | 11 ++--------- views/search/_catalog_filter.html.erb | 67 ++++++++++++++++++++++++++++++++++++++++++------------------------- 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/lib/ext/search_controller.rb b/lib/ext/search_controller.rb index 6fbd75a..145da2f 100644 --- a/lib/ext/search_controller.rb +++ b/lib/ext/search_controller.rb @@ -11,13 +11,13 @@ class SearchController def software_infos @titles[:software_infos] = "Software Infos" + @category_filters = [] if params[:filter].blank? results = filter_communities_list{|community| community.software?} else - integer_filters = [] - params[:filter].split(",").each{|f| integer_filters << f.to_i} - results = filter_communities_list{|community| community.software? && !(community.category_ids & integer_filters).blank?} + params[:filter].split(",").each{|f| @category_filters << f.to_i} + results = filter_communities_list{|community| community.software? && !(community.category_ids & @category_filters).blank?} end results = results.paginate(:per_page => 24, :page => params[:page]) diff --git a/public/software-catalog.js b/public/software-catalog.js index 8e2652b..1025b5b 100644 --- a/public/software-catalog.js +++ b/public/software-catalog.js @@ -9,10 +9,8 @@ function create_catalog_element(first, value, id) { var li_tag = document.createElement("li"); - if( first ) - li_tag.innerHTML = value + " x"; - else - li_tag.innerHTML = ", " + value + " x"; + li_tag.className = "category_box"; + li_tag.innerHTML = value + " x"; return li_tag; } @@ -88,12 +86,7 @@ jQuery(".catalog-remove-item").click(remote_catalog_item); } - function clear_filters() { - jQuery("#filter").val(""); - } - jQuery(document).ready(function(){ - clear_filters(); set_autocomplate(); set_events(); }); diff --git a/views/search/_catalog_filter.html.erb b/views/search/_catalog_filter.html.erb index d8b6d88..3ab9c52 100644 --- a/views/search/_catalog_filter.html.erb +++ b/views/search/_catalog_filter.html.erb @@ -1,34 +1,51 @@ +
-
-
    -
    +
    +
      + <% @category_filters.each do |filter_id| %> +
    • <%= _(Category.find(filter_id).name) %> + x +
    • + <% end %> +
    +
    -
    - <%= text_field(:software, :catalog, :id=>"software-catalog") %> -
    +
    + <%= text_field(:software, :catalog, :id=>"software-catalog") %> +
    \ No newline at end of file -- libgit2 0.21.2