Commit ed4e22e2af91ef88e823fb0479c0a226d3ec5b06
1 parent
bb3b9e56
Exists in
master
and in
5 other branches
Add function to search filter for fields of software
Signed-off-by: Gustavo Jaruga <darksshades@hotmail.com> Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Showing
4 changed files
with
65 additions
and
54 deletions
Show diff stats
lib/mpog_software_plugin.rb
| ... | ... | @@ -353,11 +353,16 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 353 | 353 | elsif params[:action] == "communities" and params[:type] == "Institution" |
| 354 | 354 | |
| 355 | 355 | elsif params[:action] == "communities" and params[:type] == "Software" |
| 356 | - SoftwareInfo.search(params[:name], params[:database_description][:id], | |
| 357 | - params[:programming_language][:id], params[:operating_system][:id], | |
| 358 | - params[:controlled_vocabulary], params[:license_info][:id], params[:e_ping], params[:e_mag], | |
| 359 | - params[:icp_brasil], params[:e_arq], params[:internacionalizable]) | |
| 360 | - | |
| 356 | + softwares = SoftwareInfo.search(params[:name], params[:database_description][:id], | |
| 357 | + params[:programming_language][:id], params[:operating_system][:id], | |
| 358 | + params[:license_info][:id], params[:e_ping], params[:e_mag], params[:internacionalizable], | |
| 359 | + params[:icp_brasil], params[:e_arq], params[:controlled_vocabulary]) | |
| 360 | + communities = [] | |
| 361 | + | |
| 362 | + softwares.each do |s| | |
| 363 | + communities << s.community | |
| 364 | + end | |
| 365 | + communities | |
| 361 | 366 | else |
| 362 | 367 | [] # An empty list will trigger noosfero's default communities search |
| 363 | 368 | end | ... | ... |
lib/software_info.rb
| ... | ... | @@ -21,9 +21,10 @@ class SoftwareInfo < ActiveRecord::Base |
| 21 | 21 | joins(:community).where("name ilike ?", "%#{name}%") |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - scope :search, lambda { |name="", database_description="", programming_language="", operating_system="", | |
| 25 | - controlled_vocabulary="", license_info="", e_ping="", e_mag="", | |
| 26 | - icp_brasil="", e_arq="", internacionalizable=""| | |
| 24 | + scope :search, lambda { |name="", database_description_id = "", | |
| 25 | + programming_language_id = "", operating_system_name_id = "", | |
| 26 | + license_info_id = "", e_ping = "", e_mag = "", internacionalizable = "", | |
| 27 | + icp_brasil = "", e_arq = "", controlled_vocabulary = "" | | |
| 27 | 28 | |
| 28 | 29 | like_sql = "" |
| 29 | 30 | values = [] |
| ... | ... | @@ -33,61 +34,66 @@ class SoftwareInfo < ActiveRecord::Base |
| 33 | 34 | values << "%#{name}%" |
| 34 | 35 | end |
| 35 | 36 | |
| 36 | - unless database_description.nil? and database_description.blank? | |
| 37 | - software_databases = SoftwareDatabase.where(:database_description_id => database_description) | |
| 38 | - like_sql << "software_databases ILIKE ? AND " | |
| 39 | - values << "%#{software_databases}%" | |
| 37 | + if (not database_description_id.nil?) and (not database_description_id.blank?) | |
| 38 | + like_sql << "software_databases.database_description_id = ? AND " | |
| 39 | + values << "#{database_description_id}" | |
| 40 | 40 | end |
| 41 | 41 | |
| 42 | - unless programming_language.nil? and programming_language.blank? | |
| 43 | - like_sql << "programming_language_id ILIKE ? AND " | |
| 44 | - values << "%#{programming_language}%" | |
| 42 | + if (not programming_language_id.nil?) and (not programming_language_id.blank?) | |
| 43 | + like_sql << "software_languages.programming_language_id = ? AND " | |
| 44 | + values << "#{programming_language_id}" | |
| 45 | 45 | end |
| 46 | 46 | |
| 47 | - unless operating_system.nil? and operating_system.blank? | |
| 48 | - like_sql << "operating_system_id ILIKE ? AND " | |
| 49 | - values << "%#{operating_system}%" | |
| 47 | + if (not operating_system_name_id.nil?) and (not operating_system_name_id.blank?) | |
| 48 | + like_sql << "operating_systems.operating_system_name_id = ? AND " | |
| 49 | + values << "#{operating_system_name_id}" | |
| 50 | 50 | end |
| 51 | 51 | |
| 52 | - unless license_info.nil? and license_info.blank? | |
| 53 | - like_sql << "license_info_id ILIKE ? AND " | |
| 54 | - values << "%#{license_info}%" | |
| 52 | + if (not license_info_id.nil?) and (not license_info_id.blank?) | |
| 53 | + like_sql << "license_info_id = ? AND " | |
| 54 | + values << "#{license_info_id}" | |
| 55 | 55 | end |
| 56 | 56 | |
| 57 | - unless e_ping.nil? and e_ping.blank? and e_ping == "Any" | |
| 58 | - like_sql << "e_ping ILIKE ? AND " | |
| 59 | - values << "%#{e_ping}%" | |
| 57 | + if (not internacionalizable.nil?) and (not internacionalizable.blank?) | |
| 58 | + like_sql << "internacionalizable = ? AND " | |
| 59 | + values << "#{internacionalizable}" | |
| 60 | 60 | end |
| 61 | 61 | |
| 62 | - unless e_mag.nil? and e_mag.blank? and e_mag == "Any" | |
| 63 | - like_sql << "e_mag ILIKE ? AND " | |
| 64 | - values << "%#{e_mag}%" | |
| 62 | + if (not icp_brasil.nil?) and (not icp_brasil.blank?) | |
| 63 | + like_sql << "icp_brasil = ? AND " | |
| 64 | + values << "#{icp_brasil}" | |
| 65 | 65 | end |
| 66 | 66 | |
| 67 | - unless icp_brasil.nil? and icp_brasil.blank? and icp_brasil == "Any" | |
| 68 | - like_sql << "icp_brasil ILIKE ? AND " | |
| 69 | - values << "%#{icp_brasil}%" | |
| 67 | + if (not e_ping.nil?) and (not e_ping.blank?) | |
| 68 | + like_sql << "e_ping = ? AND " | |
| 69 | + values << "#{e_ping}" | |
| 70 | 70 | end |
| 71 | 71 | |
| 72 | - unless e_arq.nil? and e_arq.blank? and e_arq == "Any" | |
| 73 | - like_sql << "e_arq ILIKE ? AND " | |
| 74 | - values << "%#{e_arq}%" | |
| 72 | + if (not e_mag.nil?) and (not e_mag.blank?) | |
| 73 | + like_sql << "e_mag = ? AND " | |
| 74 | + values << "#{e_mag}" | |
| 75 | 75 | end |
| 76 | 76 | |
| 77 | - unless internacionalizable.nil? and internacionalizable.blank? and internacionalizable == "Any" | |
| 78 | - like_sql << "internacionalizable ILIKE ? AND " | |
| 79 | - values << "%#{internacionalizable}%" | |
| 77 | + if (not e_arq.nil?) and (not e_arq.blank?) | |
| 78 | + like_sql << "e_arq = ? AND " | |
| 79 | + values << "#{e_arq}" | |
| 80 | + end | |
| 81 | + | |
| 82 | + if (not controlled_vocabulary.nil?) and (not controlled_vocabulary.blank?) | |
| 83 | + controlled_vocabulary = controlled_vocabulary.gsub(' ', '').underscore | |
| 84 | + like_sql << "controlled_vocabulary.#{controlled_vocabulary} = ? AND " | |
| 85 | + values << "true" | |
| 80 | 86 | end |
| 81 | 87 | |
| 82 | 88 | like_sql = like_sql[0..like_sql.length-5] |
| 83 | 89 | |
| 84 | 90 | { |
| 85 | - :joins => :community, | |
| 91 | + :joins => [:community, :software_databases, :software_languages, | |
| 92 | + :operating_systems, :controlled_vocabulary], | |
| 86 | 93 | :conditions=>[like_sql, *values] |
| 87 | 94 | } |
| 88 | 95 | } |
| 89 | 96 | |
| 90 | - | |
| 91 | 97 | def validate_operating_platform |
| 92 | 98 | self.errors.add(:operating_platform, _("can't be blank")) if self.operating_platform.blank? && self.errors.messages[:operating_platform].nil? |
| 93 | 99 | end | ... | ... |
public/mpog-search.js
| ... | ... | @@ -19,7 +19,7 @@ |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | function display_search_fields_on_page_load() { |
| 22 | - var active_search = jQuery(".search_type input[checked='checked'").val(); | |
| 22 | + var active_search = jQuery(".search_type input[checked='checked']").val(); | |
| 23 | 23 | |
| 24 | 24 | switch(active_search) { |
| 25 | 25 | case "Community": show_community_fields(); break; | ... | ... |
views/search/search_forms/_software_fields.html.erb
| ... | ... | @@ -43,17 +43,17 @@ |
| 43 | 43 | <td> <%= _("Adherent to e-PING ?") %> </td> |
| 44 | 44 | <td> |
| 45 | 45 | <label> |
| 46 | - <%= radio_button_tag(:e_ping, "any", true) %> | |
| 46 | + <%= radio_button_tag(:e_ping, "", true) %> | |
| 47 | 47 | <%= _("Any") %> |
| 48 | 48 | </label> |
| 49 | 49 | |
| 50 | 50 | <label> |
| 51 | - <%= radio_button_tag(:e_ping, "yes") %> | |
| 51 | + <%= radio_button_tag(:e_ping, true) %> | |
| 52 | 52 | <%= _("Yes") %> |
| 53 | 53 | </label> |
| 54 | 54 | |
| 55 | 55 | <label> |
| 56 | - <%= radio_button_tag(:e_ping, "no") %> | |
| 56 | + <%= radio_button_tag(:e_ping, false) %> | |
| 57 | 57 | <%= _("No") %> |
| 58 | 58 | </label> |
| 59 | 59 | </td> |
| ... | ... | @@ -63,17 +63,17 @@ |
| 63 | 63 | <td> <%= _("Adherent to e-MAG ?") %> </td> |
| 64 | 64 | <td> |
| 65 | 65 | <label> |
| 66 | - <%= radio_button_tag(:e_mag, "any", true) %> | |
| 66 | + <%= radio_button_tag(:e_mag, "", true) %> | |
| 67 | 67 | <%= _("Any") %> |
| 68 | 68 | </label> |
| 69 | 69 | |
| 70 | 70 | <label> |
| 71 | - <%= radio_button_tag(:e_mag, "yes") %> | |
| 71 | + <%= radio_button_tag(:e_mag, true) %> | |
| 72 | 72 | <%= _("Yes") %> |
| 73 | 73 | </label> |
| 74 | 74 | |
| 75 | 75 | <label> |
| 76 | - <%= radio_button_tag(:e_mag, "no") %> | |
| 76 | + <%= radio_button_tag(:e_mag, false) %> | |
| 77 | 77 | <%= _("No") %> |
| 78 | 78 | </label> |
| 79 | 79 | </td> |
| ... | ... | @@ -83,17 +83,17 @@ |
| 83 | 83 | <td> <%= _("Adherent to ICP-Brasil ?") %> </td> |
| 84 | 84 | <td> |
| 85 | 85 | <label> |
| 86 | - <%= radio_button_tag(:icp_brasil, "any", true) %> | |
| 86 | + <%= radio_button_tag(:icp_brasil, "", true) %> | |
| 87 | 87 | <%= _("Any") %> |
| 88 | 88 | </label> |
| 89 | 89 | |
| 90 | 90 | <label> |
| 91 | - <%= radio_button_tag(:icp_brasil, "yes") %> | |
| 91 | + <%= radio_button_tag(:icp_brasil, true) %> | |
| 92 | 92 | <%= _("Yes") %> |
| 93 | 93 | </label> |
| 94 | 94 | |
| 95 | 95 | <label> |
| 96 | - <%= radio_button_tag(:icp_brasil, "no") %> | |
| 96 | + <%= radio_button_tag(:icp_brasil, false) %> | |
| 97 | 97 | <%= _("No") %> |
| 98 | 98 | </label> |
| 99 | 99 | </td> |
| ... | ... | @@ -103,17 +103,17 @@ |
| 103 | 103 | <td> <%= _("Adherent to e-ARQ ?") %> </td> |
| 104 | 104 | <td> |
| 105 | 105 | <label> |
| 106 | - <%= radio_button_tag(:e_arq, "any", true) %> | |
| 106 | + <%= radio_button_tag(:e_arq, "", true) %> | |
| 107 | 107 | <%= _("Any") %> |
| 108 | 108 | </label> |
| 109 | 109 | |
| 110 | 110 | <label> |
| 111 | - <%= radio_button_tag(:e_arq, "yes") %> | |
| 111 | + <%= radio_button_tag(:e_arq, true) %> | |
| 112 | 112 | <%= _("Yes") %> |
| 113 | 113 | </label> |
| 114 | 114 | |
| 115 | 115 | <label> |
| 116 | - <%= radio_button_tag(:e_arq, "no") %> | |
| 116 | + <%= radio_button_tag(:e_arq, false) %> | |
| 117 | 117 | <%= _("No") %> |
| 118 | 118 | </label> |
| 119 | 119 | </td> |
| ... | ... | @@ -123,17 +123,17 @@ |
| 123 | 123 | <td> <%= _("Internacionalizable ?") %> </td> |
| 124 | 124 | <td> |
| 125 | 125 | <label> |
| 126 | - <%= radio_button_tag(:internacionalizable, "any", true) %> | |
| 126 | + <%= radio_button_tag(:internacionalizable, "", true) %> | |
| 127 | 127 | <%= _("Any") %> |
| 128 | 128 | </label> |
| 129 | 129 | |
| 130 | 130 | <label> |
| 131 | - <%= radio_button_tag(:internacionalizable, "yes") %> | |
| 131 | + <%= radio_button_tag(:internacionalizable, true) %> | |
| 132 | 132 | <%= _("Yes") %> |
| 133 | 133 | </label> |
| 134 | 134 | |
| 135 | 135 | <label> |
| 136 | - <%= radio_button_tag(:internacionalizable, "no") %> | |
| 136 | + <%= radio_button_tag(:internacionalizable, false) %> | |
| 137 | 137 | <%= _("No") %> |
| 138 | 138 | </label> |
| 139 | 139 | </td> | ... | ... |