ransack_advanced_search 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +6 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/javascripts/ransack_advanced_search/application.js +13 -0
  6. data/app/assets/javascripts/ransack_advanced_search/ransack_advanced_search.js +34 -0
  7. data/app/assets/stylesheets/ransack_advanced_search/application.css +17 -0
  8. data/app/controllers/concerns/ransack_advanced_search/saved_search_utils.rb +59 -0
  9. data/app/controllers/ransack_advanced_search/application_controller.rb +5 -0
  10. data/app/helpers/ransack_advanced_search_helper.rb +39 -0
  11. data/app/models/saved_search.rb +5 -0
  12. data/app/views/ransack_advanced_search/_advanced_search.html.erb +73 -0
  13. data/app/views/ransack_advanced_search/_attribute_fields.erb +3 -0
  14. data/app/views/ransack_advanced_search/_condition_fields.erb +21 -0
  15. data/app/views/ransack_advanced_search/_grouping_fields.erb +20 -0
  16. data/app/views/ransack_advanced_search/_sort_fields.erb +3 -0
  17. data/app/views/ransack_advanced_search/_value_fields.erb +2 -0
  18. data/config/initializers/ransack_advanced_search.rb +1 -0
  19. data/config/locales/ransack.en.yml +94 -0
  20. data/config/locales/ransack.pt-BR.yml +93 -0
  21. data/config/routes.rb +2 -0
  22. data/lib/generators/ransack_advanced_search/saved_search_generator.rb +29 -0
  23. data/lib/generators/templates/create_ransack_advanced_search_saved_search.rb +11 -0
  24. data/lib/ransack_advanced_search/engine.rb +4 -0
  25. data/lib/ransack_advanced_search/version.rb +3 -0
  26. data/lib/ransack_advanced_search.rb +7 -0
  27. data/lib/tasks/ransack_advanced_search_tasks.rake +4 -0
  28. data/test/dummy/README.rdoc +261 -0
  29. data/test/dummy/Rakefile +7 -0
  30. data/test/dummy/app/assets/javascripts/application.js +15 -0
  31. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  32. data/test/dummy/app/controllers/application_controller.rb +3 -0
  33. data/test/dummy/app/helpers/application_helper.rb +2 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/test/dummy/config/application.rb +59 -0
  36. data/test/dummy/config/boot.rb +10 -0
  37. data/test/dummy/config/database.yml +25 -0
  38. data/test/dummy/config/environment.rb +5 -0
  39. data/test/dummy/config/environments/development.rb +37 -0
  40. data/test/dummy/config/environments/production.rb +67 -0
  41. data/test/dummy/config/environments/test.rb +37 -0
  42. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  43. data/test/dummy/config/initializers/inflections.rb +15 -0
  44. data/test/dummy/config/initializers/mime_types.rb +5 -0
  45. data/test/dummy/config/initializers/secret_token.rb +7 -0
  46. data/test/dummy/config/initializers/session_store.rb +8 -0
  47. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  48. data/test/dummy/config/locales/en.yml +5 -0
  49. data/test/dummy/config/routes.rb +4 -0
  50. data/test/dummy/config.ru +4 -0
  51. data/test/dummy/public/404.html +26 -0
  52. data/test/dummy/public/422.html +26 -0
  53. data/test/dummy/public/500.html +25 -0
  54. data/test/dummy/public/favicon.ico +0 -0
  55. data/test/dummy/script/rails +6 -0
  56. data/test/integration/navigation_test.rb +10 -0
  57. data/test/ransack_advanced_search_test.rb +7 -0
  58. data/test/test_helper.rb +15 -0
  59. metadata +199 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58cff2d8f37ca95aca53690bf22a9268395b0187
4
+ data.tar.gz: c4686f564b1c1b45d981ecc29c97b6367bec2399
5
+ SHA512:
6
+ metadata.gz: 31acaca1592e2d482bc0e65d922c5db0c06a432aa8d5fa36537a0597f4fae9f906535154bf324f9e0323d2b79cd6c8f92397a7cb61b6b3e35d20ab55b108b2c8
7
+ data.tar.gz: 92d0c9a03397df1a6edf0673288ad324f6c45ba7132d99f996b6def7bdd015238ab3c72b2b758b414754fa2a85ce6aa9405b39a5590ee6b1ee94dbb35d9b5e5b
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 David Brusius
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = RansackAdvancedSearch
2
+
3
+ inflect.irregular 'saved_search', 'saved_searches'
4
+
5
+
6
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'RansackAdvancedSearch'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,34 @@
1
+ (function() {
2
+ this.Search = (function() {
3
+ function Search(templates) {
4
+ this.templates = templates != null ? templates : {};
5
+ }
6
+
7
+ Search.prototype.remove_fields = function(button) {
8
+ return $(button).closest('.fields').remove();
9
+ };
10
+
11
+ Search.prototype.add_fields = function(button, type, content) {
12
+ var new_id, regexp;
13
+ new_id = new Date().getTime();
14
+ regexp = new RegExp('new_' + type, 'g');
15
+ return $(button).before(content.replace(regexp, new_id));
16
+ };
17
+
18
+ Search.prototype.nest_fields = function(button, type) {
19
+ var id_regexp, new_id, object_name, sanitized_object_name, template;
20
+ new_id = new Date().getTime();
21
+ id_regexp = new RegExp('new_' + type, 'g');
22
+ template = this.templates[type];
23
+ object_name = $(button).closest('.fields').attr('data-object-name');
24
+ sanitized_object_name = object_name.replace(/\]\[|[^-a-zA-Z0-9:.]/g, '_').replace(/_$/, '');
25
+ template = template.replace(/new_object_name\[/g, object_name + "[");
26
+ template = template.replace(/new_object_name_/, sanitized_object_name + '_');
27
+ return $(button).before(template.replace(id_regexp, new_id));
28
+ };
29
+
30
+ return Search;
31
+
32
+ })();
33
+
34
+ }).call(this);
@@ -0,0 +1,17 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
14
+
15
+ .ransack-advanced-search i.remove_fields {
16
+ cursor: pointer;
17
+ }
@@ -0,0 +1,59 @@
1
+ module RansackAdvancedSearch
2
+ module SavedSearchUtils
3
+ extend ActiveSupport::Concern
4
+
5
+ # Perform saved searches actions to provide full functionality with one method
6
+ def perform_saved_searches_actions(context, params={})
7
+ get_saved_searches(context)
8
+ save_or_update_saved_search(params.merge(context: context))
9
+ get_params_to_search(context)
10
+ end
11
+
12
+ # Get list of Saved Search by context
13
+ def get_saved_searches(context)
14
+ @saved_searches = SavedSearch.where(context: context)
15
+ end
16
+
17
+ # Return params of Saved Search or search form params
18
+ def get_params_to_search(context)
19
+ if params[:saved_search].present?
20
+ @saved_search = SavedSearch.find_by(id: params[:saved_search], context: context)
21
+ end
22
+ return params[:q] if params[:use_search_params].present?
23
+ params[:q] = @saved_search.try(:search_params) || params[:q]
24
+ end
25
+
26
+ # Save or update Saved Search
27
+ def save_or_update_saved_search(params)
28
+ if params[:save_new_search].present? || params[:save_search].present?
29
+ if params[:save_new_search].present?
30
+ @saved_search = new_saved_search(params)
31
+ elsif params[:save_search].present? && params[:saved_search].present?
32
+ @saved_search = update_saved_search(params)
33
+ elsif params[:save_search].present?
34
+ @saved_search = new_saved_search(params)
35
+ end
36
+
37
+ if @saved_search.save
38
+ flash[:notice] = t('ransack.saved_search.save.success')
39
+ else
40
+ flash[:error] = t('ransack.saved_search.save.error')
41
+ end
42
+ end
43
+ end
44
+
45
+ def new_saved_search(params)
46
+ SavedSearch.new(
47
+ context: params[:context], description: params[:description],
48
+ search_params: params[:q]
49
+ )
50
+ end
51
+
52
+ def update_saved_search(params)
53
+ saved_search = SavedSearch.find_by(id: params[:saved_search], context: params[:context])
54
+ saved_search.description = params[:description]
55
+ saved_search.search_params = params[:q]
56
+ saved_search
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ module RansackAdvancedSearch
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery :with => :exception
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ module RansackAdvancedSearchHelper
2
+ def setup_search_form(builder)
3
+ fields = builder.grouping_fields builder.object.new_grouping,
4
+ object_name: 'new_object_name', child_index: "new_grouping" do |f|
5
+ render('ransack_advanced_search/grouping_fields', f: f)
6
+ end
7
+ content_for :ransack_setup, %Q{
8
+ var search = new Search({grouping: "#{escape_javascript(fields)}"});
9
+ $(document).on("click", "button.add_fields", function() {
10
+ search.add_fields(this, $(this).data('fieldType'), $(this).data('content'));
11
+ return false;
12
+ });
13
+ $(document).on("click", "i.remove_fields", function() {
14
+ search.remove_fields(this);
15
+ return false;
16
+ });
17
+ $(document).on("click", "button.nest_fields", function() {
18
+ search.nest_fields(this, $(this).data('fieldType'));
19
+ return false;
20
+ });
21
+ }.html_safe
22
+ end
23
+
24
+ def button_to_remove_fields
25
+ content_tag :i, nil, class: 'remove_fields glyphicon glyphicon-remove text-danger'
26
+ end
27
+
28
+ def button_to_add_fields(name, f, type)
29
+ new_object = f.object.send "build_#{type}"
30
+ fields = f.send("#{type}_fields", new_object, child_index: "new_#{type}") do |builder|
31
+ render('ransack_advanced_search/' + type.to_s + "_fields", f: builder)
32
+ end
33
+ content_tag :button, name, :class => 'add_fields btn btn-default btn-sm', :type => 'button', 'data-field-type' => type, 'data-content' => "#{fields}"
34
+ end
35
+
36
+ def button_to_nest_fields(name, type)
37
+ content_tag :button, name, :class => 'nest_fields', 'data-field-type' => type
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ class SavedSearch < ActiveRecord::Base
2
+ validates_presence_of :context, :description, :search_params
3
+
4
+ serialize :search_params
5
+ end
@@ -0,0 +1,73 @@
1
+ <div class="ransack-advanced-search">
2
+
3
+ <div class="row">
4
+ <div class="col-md-4">
5
+ <div class="panel panel-primary">
6
+ <div class="panel-heading"><%= t('ransack.saved_search.title') %></div>
7
+ <div class="list-group lista-buscas">
8
+ <% @saved_searches.each do |saved_search| %>
9
+ <%= link_to url_for(saved_search: saved_search.id), method: :post, class: 'list-group-item' do %>
10
+ <%= saved_search.description %>
11
+ <% end %>
12
+ <% end %>
13
+ <% if @saved_searches.empty? %>
14
+ <%= link_to '#', class: 'list-group-item' do %>
15
+ <em><%= t('ransack.saved_search.empty_list') %></em>
16
+ <% end %>
17
+ <% end %>
18
+ </div>
19
+ </div>
20
+ </div>
21
+ <div class="col-md-8">
22
+ <%= search_form_for(@search, url: search_url, html: { method: :post, class: 'form-vertical', role: 'form' }) do |f| %>
23
+
24
+ <% setup_search_form f %>
25
+
26
+ <div class="form-group">
27
+ <%= label_tag 'Descrição da Busca (necessária para salvar a busca)' %>
28
+ <%= text_field_tag :description, @saved_search.try(:description), class: 'form-control input-sm' %>
29
+ <% if @saved_search %>
30
+ <%= hidden_field_tag :saved_search, @saved_search.id %>
31
+ <%= hidden_field_tag :use_search_params, true %>
32
+ <% end %>
33
+ </div>
34
+
35
+ <h4><%= t('ransack.advanced_search.sort.title') %></h4>
36
+ <div class="form-group">
37
+ <%= f.sort_fields do |s| %>
38
+ <%= render 'ransack_advanced_search/sort_fields', f: s %>
39
+ <% end %>
40
+ <%= button_to_add_fields t('ransack.advanced_search.sort.add'), f, :sort %>
41
+ </div>
42
+
43
+ <h4><%= t('ransack.advanced_search.condition_group.title') %></h4>
44
+ <div class="form-group">
45
+ <%= f.grouping_fields do |g| %>
46
+ <%= render 'ransack_advanced_search/grouping_fields', f: g %>
47
+ <% end %>
48
+ <%= button_to_add_fields t('ransack.advanced_search.condition_group.add'),
49
+ f, :grouping %>
50
+ </div>
51
+
52
+ <!-- <%= label_tag :distinct, 'Return distinct records?' %> -->
53
+ <!-- <%= check_box_tag :distinct, '1', params[:distinct].to_i == 1 %> -->
54
+ <div class="form-group">
55
+ <%= f.submit t('ransack.advanced_search.form.submit_text'), class: 'btn btn-primary' %>
56
+ <%= f.submit t('ransack.advanced_search.form.save_submit_text'), name: 'save_search', class: 'btn btn-primary' %>
57
+ <%= f.submit t('ransack.advanced_search.form.save_new_submit_text'), name: 'save_new_search', class: 'btn btn-primary' %>
58
+ </div>
59
+ <% end %>
60
+ </div>
61
+ </div>
62
+ </div>
63
+
64
+ <% content_for(:ransack_advanced_search_setup) do %>
65
+ <%= stylesheet_link_tag 'ransack_advanced_search/application', media: 'all' %>
66
+ <%= javascript_include_tag 'ransack_advanced_search/application' %>
67
+
68
+ <script>
69
+ $(document).ready(function () {
70
+ <%= yield(:ransack_setup) %>
71
+ });
72
+ </script>
73
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <%= content_tag(:span,
2
+ f.attribute_select({associations: %w(posts comments)}, {class: 'form-control input-sm'}),
3
+ { class: 'fields', 'data-object-name' => f.object_name }, false) %>
@@ -0,0 +1,21 @@
1
+ <%= content_tag :div, {
2
+ class: 'fields condition', 'data-object-name' => f.object_name
3
+ } do %>
4
+
5
+ <%= content_tag(:span, button_to_remove_fields,
6
+ nil, false) %>
7
+
8
+ <%= f.attribute_fields do |a| %>
9
+ <%= render 'ransack_advanced_search/attribute_fields', f: a %>
10
+ <% end %>
11
+
12
+ <%= f.predicate_select({}, {class: 'form-control input-sm'}) %>
13
+
14
+ <%= f.value_fields do |v| %>
15
+ <%= render 'ransack_advanced_search/value_fields', f: v %>
16
+ <% end %>
17
+
18
+ <%= button_to_add_fields t('ransack.advanced_search.attribute_value.add'),
19
+ f, :value %>
20
+
21
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <%= content_tag :div, { class: 'fields',
2
+ 'data-object-name' => f.object_name } do %>
3
+
4
+
5
+ <%= content_tag(:span, "#{t('ransack.advanced_search.condition_group.match')}
6
+ #{f.combinator_select} #{t('ransack.advanced_search.condition_group.match_condition')}
7
+ #{button_to_remove_fields}", nil, false) %>
8
+
9
+ <%= f.condition_fields do |c| %>
10
+ <%= render 'ransack_advanced_search/condition_fields', f: c %>
11
+ <% end %>
12
+
13
+ <%= button_to_add_fields t('ransack.advanced_search.attribute_field.add'),
14
+ f, :condition %>
15
+
16
+ <%= f.grouping_fields do |g| %>
17
+ <%= render 'ransack_advanced_search/grouping_fields', f: g %>
18
+ <% end %>
19
+
20
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <%= content_tag(:span,
2
+ "#{f.sort_select({}, {class: 'form-control input-sm'})} #{button_to_remove_fields}",
3
+ { class: 'fields', 'data-object-name' => f.object_name }, false) %>
@@ -0,0 +1,2 @@
1
+ <%= content_tag(:span, f.text_field(:value, {class: 'form-control input-sm'}),
2
+ { class: 'fields value', 'data-object-name' => f.object_name }, false) %>
@@ -0,0 +1 @@
1
+ Rails.application.config.i18n.fallbacks = [:en]
@@ -0,0 +1,94 @@
1
+ en:
2
+ ransack:
3
+ advanced_search:
4
+ form:
5
+ submit_text: Search
6
+ save_submit_text: Save and Search
7
+ save_new_submit_text: Save as new and Search
8
+ sort:
9
+ title: Sort
10
+ label_title: Sort by
11
+ add: Add Sort
12
+ condition_group:
13
+ title: Condition Groups
14
+ add: Add Condition Group
15
+ match: Match
16
+ match_condition: conditions
17
+ attribute_field:
18
+ add: Add Condition
19
+ attribute_value:
20
+ add: Add Value
21
+ saved_search:
22
+ title: Saved Searches
23
+ empty_list: There are no saved searches in this context.
24
+ save:
25
+ success: Search saved successfully.
26
+ error: Error while saving the search. You must enter a description of the search and at least one filter.
27
+ search: "search"
28
+ predicate: "predicate"
29
+ and: "and"
30
+ or: "or"
31
+ any: "any"
32
+ all: "all"
33
+ combinator: "combinator"
34
+ attribute: "attribute"
35
+ value: "value"
36
+ condition: "condition"
37
+ sort: "sort"
38
+ asc: "ascending"
39
+ desc: "descending"
40
+ predicates:
41
+ eq: "equals"
42
+ eq_any: "equals any"
43
+ eq_all: "equals all"
44
+ not_eq: "not equal to"
45
+ not_eq_any: "not equal to any"
46
+ not_eq_all: "not equal to all"
47
+ matches: "matches"
48
+ matches_any: "matches any"
49
+ matches_all: "matches all"
50
+ does_not_match: "doesn't match"
51
+ does_not_match_any: "doesn't match any"
52
+ does_not_match_all: "doesn't match all"
53
+ lt: "less than"
54
+ lt_any: "less than any"
55
+ lt_all: "less than all"
56
+ lteq: "less than or equal to"
57
+ lteq_any: "less than or equal to any"
58
+ lteq_all: "less than or equal to all"
59
+ gt: "greater than"
60
+ gt_any: "greater than any"
61
+ gt_all: "greater than all"
62
+ gteq: "greater than or equal to"
63
+ gteq_any: "greater than or equal to any"
64
+ gteq_all: "greater than or equal to all"
65
+ in: "in"
66
+ in_any: "in any"
67
+ in_all: "in all"
68
+ not_in: "not in"
69
+ not_in_any: "not in any"
70
+ not_in_all: "not in all"
71
+ cont: "contains"
72
+ cont_any: "contains any"
73
+ cont_all: "contains all"
74
+ not_cont: "doesn't contain"
75
+ not_cont_any: "doesn't contain any"
76
+ not_cont_all: "doesn't contain all"
77
+ start: "starts with"
78
+ start_any: "starts with any"
79
+ start_all: "starts with all"
80
+ not_start: "doesn't start with"
81
+ not_start_any: "doesn't start with any"
82
+ not_start_all: "doesn't start with all"
83
+ end: "ends with"
84
+ end_any: "ends with any"
85
+ end_all: "ends with all"
86
+ not_end: "doesn't end with"
87
+ not_end_any: "doesn't end with any"
88
+ not_end_all: "doesn't end with all"
89
+ 'true': "is true"
90
+ 'false': "is false"
91
+ present: "is present"
92
+ blank: "is blank"
93
+ 'null': "is null"
94
+ not_null: "is not null"
@@ -0,0 +1,93 @@
1
+ pt-BR:
2
+ ransack:
3
+ advanced_search:
4
+ form:
5
+ submit_text: Pesquisar
6
+ save_submit_text: Salvar e Pesquisar
7
+ save_new_submit_text: Salvar nova e Pesquisar
8
+ sort:
9
+ title: Ordenação
10
+ add: Adicionar ordenação
11
+ condition_group:
12
+ title: Grupos de filtros
13
+ add: Adicionar grupo
14
+ match: Filtrar
15
+ match_condition: condições
16
+ attribute_field:
17
+ add: Adicionar filtro
18
+ attribute_value:
19
+ add: Adicionar valor
20
+ saved_search:
21
+ title: Buscas Salvas
22
+ empty_list: Não existem buscas salvas para este contexto.
23
+ save:
24
+ success: Busca salva com sucesso.
25
+ error: Erro ao salvar a busca. Você precisa informar a descrição da busca e pelo menos um filtro.
26
+ search: "pesquisar"
27
+ predicate: "predicado"
28
+ and: "e"
29
+ or: "ou"
30
+ any: "alguma das"
31
+ all: "todas as"
32
+ combinator: "combinador"
33
+ attribute: "atributo"
34
+ value: "valor"
35
+ condition: "condição"
36
+ sort: "classificar"
37
+ asc: "ascendente"
38
+ desc: "descendente"
39
+ predicates:
40
+ eq: "igual"
41
+ eq_any: "igual a algum"
42
+ eq_all: "igual a todos"
43
+ not_eq: "não é igual a"
44
+ not_eq_any: "não é igual a algum"
45
+ not_eq_all: "não é igual a todos"
46
+ matches: "corresponde"
47
+ matches_any: "corresponde a algum"
48
+ matches_all: "corresponde a todos"
49
+ does_not_match: "não corresponde"
50
+ does_not_match_any: "não corresponde a algum"
51
+ does_not_match_all: "não corresponde a todos"
52
+ lt: "menor que"
53
+ lt_any: "menor que algum"
54
+ lt_all: "menor que todos"
55
+ lteq: "menor ou igual a"
56
+ lteq_any: "menor ou igual a algum"
57
+ lteq_all: "menor ou igual a todos"
58
+ gt: "maior que"
59
+ gt_any: "maior que algum"
60
+ gt_all: "maior que todos"
61
+ gteq: "maior que ou igual a"
62
+ gteq_any: "maior que ou igual a algum"
63
+ gteq_all: "maior que ou igual a todos"
64
+ in: "em"
65
+ in_any: "em algum"
66
+ in_all: "em todos"
67
+ not_in: "não em"
68
+ not_in_any: "não em algum"
69
+ not_in_all: "não em todos"
70
+ cont: "contém"
71
+ cont_any: "contém algum"
72
+ cont_all: "contém todos"
73
+ not_cont: "não contém"
74
+ not_cont_any: "não contém algum"
75
+ not_cont_all: "não contém todos"
76
+ start: "começa com"
77
+ start_any: "começa com algum"
78
+ start_all: "começa com todos"
79
+ not_start: "não começa com"
80
+ not_start_any: "não começa com algum"
81
+ not_start_all: "não começa com algum"
82
+ end: "termina com"
83
+ end_any: "termina com algum"
84
+ end_all: "termina com todos"
85
+ not_end: "não termina com"
86
+ not_end_any: "não termina com algum"
87
+ not_end_all: "não termina com todos"
88
+ 'true': "é verdadeiro"
89
+ 'false': "é falso"
90
+ present: "está presente"
91
+ blank: "está em branco"
92
+ 'null': "é nullo"
93
+ not_null: "não é nulo"
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ RansackAdvancedSearch::Engine.routes.draw do
2
+ end
@@ -0,0 +1,29 @@
1
+ require 'rails/generators/base'
2
+ require 'rails/generators/migration'
3
+
4
+ module RansackAdvancedSearch
5
+ module Generators
6
+ class SavedSearchGenerator < Rails::Generators::Base
7
+ source_root File.expand_path("../../templates", __FILE__)
8
+ include Rails::Generators::Migration
9
+ desc "Creates a Saved Search model and migrations to save advanced searches made with Ransack."
10
+ class_option :orm
11
+
12
+ desc 'add the migrations'
13
+ def self.next_migration_number(path)
14
+ unless @prev_migration_nr
15
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
16
+ else
17
+ @prev_migration_nr += 1
18
+ end
19
+ @prev_migration_nr.to_s
20
+ end
21
+
22
+ def copy_migrations
23
+ migration_template "create_ransack_advanced_search_saved_search.rb", "db/migrate/create_ransack_advanced_search_saved_search.rb"
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ class CreateRansackAdvancedSearchSavedSearch < ActiveRecord::Migration
2
+ def change
3
+ create_table :saved_searches do |t|
4
+ t.string :context, null: false
5
+ t.string :description, null: false
6
+ t.text :search_params, null: false
7
+
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module RansackAdvancedSearch
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RansackAdvancedSearch
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'ransack_advanced_search/engine'
2
+ require 'rails'
3
+ require 'ransack'
4
+
5
+
6
+ module RansackAdvancedSearch
7
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ransack_advanced_search do
3
+ # # Task goes here
4
+ # end