filch 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.travis.yml +7 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +303 -0
  8. data/Rakefile +10 -0
  9. data/app/controllers/filch_controller.rb +13 -0
  10. data/app/views/filch/_associations.html.haml +25 -0
  11. data/app/views/filch/_attributes.html.haml +30 -0
  12. data/app/views/filch/_distinct.html.haml +4 -0
  13. data/app/views/filch/_eq.html.haml +7 -0
  14. data/app/views/filch/_form.html.haml +26 -0
  15. data/app/views/filch/_group.html.haml +4 -0
  16. data/app/views/filch/_gt.html.haml +2 -0
  17. data/app/views/filch/_limit.html.haml +5 -0
  18. data/app/views/filch/_lt.html.haml +2 -0
  19. data/app/views/filch/_null.html.haml +5 -0
  20. data/app/views/filch/_options.html.haml +11 -0
  21. data/app/views/filch/_order.html.haml +4 -0
  22. data/app/views/filch/_pg_group.html.haml +6 -0
  23. data/app/views/filch/_pluck.html.haml +4 -0
  24. data/app/views/filch/_quick.html.haml +3 -0
  25. data/app/views/filch/_scopes.html.haml +11 -0
  26. data/app/views/filch/_search.html.haml +12 -0
  27. data/bin/console +14 -0
  28. data/bin/setup +8 -0
  29. data/config/initializers/assets.rb +1 -0
  30. data/config/initializers/ransack.rb +100 -0
  31. data/config/routes.rb +3 -0
  32. data/filch.gemspec +40 -0
  33. data/lib/filch.rb +375 -0
  34. data/lib/filch/datalist.rb +26 -0
  35. data/lib/filch/engine.rb +5 -0
  36. data/lib/filch/error.rb +4 -0
  37. data/lib/filch/model_find.rb +17 -0
  38. data/lib/filch/ransack_plus.rb +34 -0
  39. data/lib/filch/version.rb +3 -0
  40. data/vendor/assets/javascripts/filch.js +1 -0
  41. data/vendor/assets/javascripts/filchColClick.js +6 -0
  42. data/vendor/assets/javascripts/filchDataList.js +21 -0
  43. data/vendor/assets/javascripts/unhideForm.js +19 -0
  44. metadata +202 -0
@@ -0,0 +1,26 @@
1
+ module Filch
2
+ # Ransack for a datalist
3
+ class Datalist
4
+ def datalist
5
+ yield self
6
+ end
7
+
8
+ def self.quick(model, column, params)
9
+ col = model.columns_hash[column]
10
+ attrs = model.ransackable_attributes
11
+ if attrs.include?(column) && col.default == '{}'
12
+ arrayify(model, params, column)
13
+ else
14
+ model.ransack(params).result
15
+ .group("#{model.name.pluralize}.#{column}")
16
+ .limit(5).pluck(column)
17
+ end
18
+ end
19
+
20
+ # unnest a PostGress Array.
21
+ def self.arrayify(model, params, column)
22
+ model.ransack(params).result.group(Arel.sql('unnest')).limit(5)
23
+ .pluck(Arel.sql("unnest(#{column})"))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Filch
2
+ # allows app access to filch/app/
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Filch
2
+ # error stuff
3
+ class Error < StandardError; end
4
+ end
@@ -0,0 +1,17 @@
1
+ module Filch
2
+ # return a model from a string representing the model.name
3
+ # or return the first model
4
+ class ModelFind
5
+ def self.find(find_model = nil)
6
+ models = all_models
7
+ found_model = models.select { |model| model.name == find_model }.first
8
+ found_model || models.first if models.any? || ApplicationRecord.new
9
+ end
10
+
11
+ def self.all_models
12
+ Rails.application.eager_load!
13
+ ActiveRecord::Base.descendants
14
+ ApplicationRecord.descendants
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ module Filch
2
+ # Ransack for results, and then manipulate data as necessary.
3
+ class RansackPlus
4
+ def initialize(model, params)
5
+ @params = params
6
+ @params[:limit] = limit_fix(params[:limit]) if @params
7
+ @q = model.ransack(@params)
8
+ @result = ransack_result
9
+ end
10
+ attr_reader :q, :result
11
+
12
+ # get the results!
13
+ def ransack_result
14
+ return [] unless @params
15
+ @q.result
16
+ end
17
+
18
+ # adjust the limit for certain scenarios.
19
+ # ransack doesn't return a list if limit is 1 so change to 2.
20
+ # also, default to 50 if limit is not set.
21
+ def limit_fix(limit = 50)
22
+ case limit
23
+ when '0'
24
+ @params.delete(:limit)
25
+ when '1'
26
+ '2'
27
+ when ''
28
+ '50'
29
+ else
30
+ limit
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Filch
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1,6 @@
1
+ function filchColClick() {
2
+ toggleShowHide(this);
3
+ dl = $('#'+$(this).attr('datalist'));
4
+ //datalistUpdate(dl);
5
+ $(dl).trigger('update');
6
+ }
@@ -0,0 +1,21 @@
1
+ function filchDataList() {
2
+ dl = $('#'+$(this).attr('list'));
3
+ // if ($(this).attr('id').includes('_eq')) {
4
+ // console.log('DISABLED');
5
+ // $(this).attr('disabled', 'disabled');
6
+ // }
7
+ // else {
8
+ // console.log('why');
9
+ // }
10
+ dl.trigger('update');
11
+ $(this).removeAttr('disabled');
12
+ }
13
+
14
+ function dlUpdate() {
15
+ // ordering breaks group by. change it for quicksearch, then change back
16
+ old_order = $('#q_s').val();
17
+ // $('#q_s').val($(this).attr('updateInner_addvars'));
18
+ $('.q_s').val(null);
19
+ datalistUpdate(this);
20
+ $('.q_s').val(old_order);
21
+ }
@@ -0,0 +1,19 @@
1
+ function unhideForm(elem) {
2
+ console.log('unhide');
3
+
4
+ serial = $(this).serializeArray();
5
+ $(serial).each(function(index) {
6
+ serial_i = serial[index];
7
+ $(serial[index]).css('color', 'green');
8
+ elem = "[name='"+serial_i.name+"']";
9
+ console.log(elem);
10
+ // s = '.' + $(this).attr('id') + " [name='"+serial_i + "']";
11
+ v = serial_i.value;
12
+ $(elem).closest("table").hide();
13
+ if ( v !== 0 && v != '' ) {
14
+ console.log(v);
15
+ $(elem).closest("table").show();
16
+ // $(s).toggle();
17
+ }
18
+ });
19
+ }
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ynweber
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: haml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: js_weber
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ransack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest-reporters
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '1.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '1.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
125
+ description: |-
126
+ Creates search forms based on templates configurable in
127
+ model. Using Ransack.
128
+ email:
129
+ - foo
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".travis.yml"
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - app/controllers/filch_controller.rb
142
+ - app/views/filch/_associations.html.haml
143
+ - app/views/filch/_attributes.html.haml
144
+ - app/views/filch/_distinct.html.haml
145
+ - app/views/filch/_eq.html.haml
146
+ - app/views/filch/_form.html.haml
147
+ - app/views/filch/_group.html.haml
148
+ - app/views/filch/_gt.html.haml
149
+ - app/views/filch/_limit.html.haml
150
+ - app/views/filch/_lt.html.haml
151
+ - app/views/filch/_null.html.haml
152
+ - app/views/filch/_options.html.haml
153
+ - app/views/filch/_order.html.haml
154
+ - app/views/filch/_pg_group.html.haml
155
+ - app/views/filch/_pluck.html.haml
156
+ - app/views/filch/_quick.html.haml
157
+ - app/views/filch/_scopes.html.haml
158
+ - app/views/filch/_search.html.haml
159
+ - bin/console
160
+ - bin/setup
161
+ - config/initializers/assets.rb
162
+ - config/initializers/ransack.rb
163
+ - config/routes.rb
164
+ - filch.gemspec
165
+ - lib/filch.rb
166
+ - lib/filch/datalist.rb
167
+ - lib/filch/engine.rb
168
+ - lib/filch/error.rb
169
+ - lib/filch/model_find.rb
170
+ - lib/filch/ransack_plus.rb
171
+ - lib/filch/version.rb
172
+ - vendor/assets/javascripts/filch.js
173
+ - vendor/assets/javascripts/filchColClick.js
174
+ - vendor/assets/javascripts/filchDataList.js
175
+ - vendor/assets/javascripts/unhideForm.js
176
+ homepage: https://bitbucket.org/ynweber/filch/
177
+ licenses:
178
+ - MIT
179
+ metadata:
180
+ homepage_uri: https://bitbucket.org/ynweber/filch/
181
+ source_code_uri: https://bitbucket.org/ynweber/filch/src
182
+ changelog_uri: https://bitbucket.org/ynweber/filch/commits/
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubygems_version: 3.0.6
199
+ signing_key:
200
+ specification_version: 4
201
+ summary: a search form builder.
202
+ test_files: []