Commit 220876c750c8d3aac1e2c40937c119ebcfac6925
Committed by
Luciano Prestes
1 parent
95a76f2e
Exists in
master
and in
5 other branches
Add categories filter on search software info page
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
5 changed files
with
136 additions
and
14 deletions
Show diff stats
controllers/mpog_software_plugin_controller.rb
| ... | ... | @@ -15,18 +15,6 @@ class MpogSoftwarePluginController < 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 < 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 < 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 < 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 | ... | ... |
| ... | ... | @@ -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 | +})(); | ... | ... |
| ... | ... | @@ -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) %> | ... | ... |