agilibox 1.4.3 → 1.11.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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +180 -32
  3. data/Rakefile +4 -0
  4. data/app/assets/javascripts/agilibox/modals.coffee +1 -0
  5. data/app/assets/stylesheets/agilibox/actions.sass +2 -0
  6. data/app/assets/stylesheets/agilibox/all.sass +3 -0
  7. data/app/assets/stylesheets/agilibox/buttons.sass +3 -0
  8. data/app/assets/stylesheets/agilibox/filters.sass +1 -0
  9. data/app/assets/stylesheets/agilibox/forms.sass +28 -0
  10. data/app/assets/stylesheets/agilibox/icons.sass +5 -0
  11. data/app/assets/stylesheets/agilibox/pagination.sass +7 -0
  12. data/app/assets/stylesheets/agilibox/tables.sass +26 -0
  13. data/app/controllers/agilibox/small_data/filters_controller.rb +2 -4
  14. data/app/controllers/concerns/agilibox/api_controller_concern.rb +4 -3
  15. data/app/controllers/concerns/agilibox/back_url_concern.rb +11 -3
  16. data/app/filters/agilibox/small_data/filter.rb +8 -2
  17. data/app/filters/agilibox/small_data/filter_strategy_by_date_begin.rb +3 -2
  18. data/app/filters/agilibox/small_data/filter_strategy_by_date_end.rb +3 -2
  19. data/app/filters/agilibox/small_data/filter_strategy_by_date_or_datetime_period.rb +2 -2
  20. data/app/filters/agilibox/small_data/filter_strategy_by_key_value.rb +14 -3
  21. data/app/filters/agilibox/small_data/filter_strategy_by_key_values.rb +4 -9
  22. data/app/helpers/agilibox/bootstrap_helper.rb +63 -0
  23. data/app/helpers/agilibox/button_helper.rb +4 -4
  24. data/app/helpers/agilibox/filters_helper.rb +2 -2
  25. data/app/helpers/agilibox/font_awesome_helper.rb +14 -4
  26. data/app/helpers/agilibox/form_helper.rb +16 -8
  27. data/app/helpers/agilibox/pagination_helper.rb +18 -2
  28. data/app/helpers/agilibox/routes_helper.rb +5 -1
  29. data/app/helpers/agilibox/sorting_helper.rb +1 -1
  30. data/app/helpers/agilibox/text_helper.rb +31 -21
  31. data/app/jobs/concerns/agilibox/setup_job_concern.rb +35 -0
  32. data/app/libs/agilibox/fcm/notifier.rb +1 -0
  33. data/app/libs/agilibox/fcm/request.rb +1 -1
  34. data/app/libs/agilibox/mini_model_serializer/serializer.rb +1 -1
  35. data/app/libs/agilibox/phone_number_sanitizer.rb +1 -1
  36. data/app/models/concerns/agilibox/model_i18n.rb +32 -6
  37. data/app/models/concerns/agilibox/pluck_distinct.rb +13 -0
  38. data/app/models/concerns/agilibox/search.rb +2 -0
  39. data/app/serializers/agilibox/serializers/base.rb +12 -6
  40. data/app/serializers/agilibox/serializers/xlsx.rb +27 -11
  41. data/app/services/agilibox/service.rb +8 -2
  42. data/app/sms/agilibox/sms/application_sms.rb +4 -4
  43. data/app/sms/agilibox/sms/message.rb +25 -0
  44. data/app/sms/agilibox/sms/strategies/amazon_sns.rb +0 -2
  45. data/app/sms/agilibox/sms/strategies/base.rb +4 -11
  46. data/app/sms/agilibox/sms/strategies/test.rb +0 -2
  47. data/app/sms/agilibox/sms.rb +11 -1
  48. data/app/views/agilibox/_flash.html.slim +2 -1
  49. data/app/views/agilibox/search/_form.html.slim +1 -12
  50. data/app/views/agilibox/search/_form_bs3.html.slim +13 -0
  51. data/app/views/agilibox/search/_form_bs4.html.slim +9 -0
  52. data/app/views/agilibox/search/_form_bs5.html.slim +8 -0
  53. data/app/views/kaminari/bootstrap4/_first_page.html.slim +2 -0
  54. data/app/views/kaminari/bootstrap4/_gap.html.slim +2 -0
  55. data/app/views/kaminari/bootstrap4/_last_page.html.slim +2 -0
  56. data/app/views/kaminari/bootstrap4/_next_page.html.slim +2 -0
  57. data/app/views/kaminari/bootstrap4/_page.html.slim +6 -0
  58. data/app/views/kaminari/bootstrap4/_paginator.html.slim +12 -0
  59. data/app/views/kaminari/bootstrap4/_prev_page.html.slim +2 -0
  60. data/config/cucumber.yml +4 -3
  61. data/config/locales/actions.fr.yml +1 -1
  62. data/lib/agilibox/active_model_custom_error_messages.rb +20 -5
  63. data/lib/agilibox/active_model_type_cast.rb +52 -0
  64. data/lib/agilibox/core_and_rails_ext.rb +1 -1
  65. data/lib/agilibox/cucumber_config.rb +20 -6
  66. data/lib/agilibox/cucumber_helpers/apparition.rb +18 -0
  67. data/lib/agilibox/cucumber_helpers/capybara.rb +2 -1
  68. data/lib/agilibox/cucumber_helpers/capybara_selectors.rb +7 -0
  69. data/lib/agilibox/cucumber_helpers/common_steps.rb +139 -0
  70. data/lib/agilibox/cucumber_helpers/cuprite.rb +20 -0
  71. data/lib/agilibox/cucumber_helpers/select2.rb +16 -3
  72. data/lib/agilibox/cucumber_helpers/turbolinks.rb +1 -1
  73. data/lib/agilibox/cucumber_helpers/zonebie.rb +4 -1
  74. data/lib/agilibox/engine.rb +6 -0
  75. data/lib/agilibox/errors_middleware.rb +50 -0
  76. data/lib/agilibox/form_back_url.rb +1 -1
  77. data/lib/agilibox/version.rb +1 -1
  78. metadata +70 -11
  79. data/app/filters/agilibox/small_data/filter_strategy_by_time_period.rb +0 -6
  80. data/lib/agilibox/active_record_comma_type_cast.rb +0 -12
  81. data/lib/agilibox/cucumber_helpers/fix_referrer.rb +0 -9
  82. data/lib/agilibox/cucumber_helpers/poltergeist.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c86e25a2a64d907710532205286243303ba59dc13be55c7e7b9c598d9fdbb771
4
- data.tar.gz: 0750edb2e73c200f92de9d02f32c286eb91a13724d37e41dfdc13c3496c4b629
3
+ metadata.gz: 73e2e45e1fed7a2e0cec02d337dc0afa3bf0112e4b26ec3168d8b62e0f64c961
4
+ data.tar.gz: 9a79efe0583a84370cc71d57468e6083b77032053c59ae702c9c557a3cac3dd4
5
5
  SHA512:
6
- metadata.gz: 3f4ce3e7ca71bd6c8acbfed1f6fdf33f8934b4b5fbf78dc78ef2b1c30459e45bac7e972d20b7ad7fdbe6f54d3f72e6f998cfcfdeb24ec34fe90f7418ff49b268
7
- data.tar.gz: 77cd7f7c4590d09d704c72cd2e9c78e892634416669d6779463be1ed958ab72d2efd4294dc8ad3d7df9b69bb71060fd8fa500ca7864758bd97775a91058584a7
6
+ metadata.gz: 80764451b386701e1e0033ed885589c1e95bff2bd973cc022dc706ce828fc86f1ac8c947c8bbe5b6f394e395fa5c1e9f933b45fb0173fe03d7ef3c088bc2eed2
7
+ data.tar.gz: 727f23e415b4aa280e2d96bc91d3016636e2e8f76a8a197218b9a8ef93797e638fb9637f880603293476c0ad6960fcd6d1974f74a1669184f20624f4b8169222
data/CHANGELOG.md CHANGED
@@ -2,74 +2,239 @@
2
2
 
3
3
  ## Next version
4
4
 
5
- ## 1.4.3
5
+ ## v1.11.0
6
+ - Add ActionDispatch::Http::MimeNegotiation::InvalidType to errors middleware
7
+ - Fix inverted forbidden/unauthorized
8
+
9
+ ## v1.10.5
10
+ - Fix hidden_inputs_for_get_form again
11
+
12
+ ## v1.10.4
13
+ - Fix hidden_inputs_for_get_form
14
+
15
+ ## v1.10.3
16
+ - Fix search forms to preserve GET params
17
+
18
+ ## v1.10.2
19
+ - Filters improvements
20
+
21
+ ## v1.10.1
22
+ - Fix date filters
23
+
24
+ ## v1.10.0
25
+ - Add date support to XLSX serializer
26
+ - Remove AXLSX serializer
27
+
28
+ ## v1.9.20
29
+ - Add bootstrap 5 search form
30
+
31
+ ## v1.9.19
32
+ - Add bootstrap 4/5 pagination support
33
+
34
+ ## v1.9.18
35
+ - Rails 6.1 compatibility
36
+
37
+ ## v1.9.17
38
+ - Fix capybara selector
39
+
40
+ ## v1.9.16
41
+ - Fix Rails 6.1 warnings
42
+
43
+ ## v1.9.15
44
+ - Add `modal:before-close` event
45
+
46
+ ## v1.9.14
47
+ - Fix syntax error on Ruby < 2.7
48
+
49
+ ## v1.9.13
50
+ - Add apparition capybara driver
51
+
52
+ ## v1.9.12
53
+ - Fix some Ruby 2.7 warnings
54
+
55
+ ## v1.9.11
56
+ - Fix some Ruby 2.7 warnings
57
+
58
+ ## v1.9.10
59
+ - Fix some Ruby 2.7 warnings
60
+
61
+ ## v1.9.9
62
+ - Add error to ErrorsMiddleware
63
+
64
+ ## v1.9.8
65
+ - Fix `tags` helper
66
+
67
+ ## v1.9.7
68
+ - Change XLSX export
69
+
70
+ ## v1.9.6
71
+ - Fix info helper with false
72
+ - Update Rubocop + fix offences
73
+
74
+ ## 1.9.5
75
+ - Fix warnings on Rails 6
76
+
77
+ ## 1.9.4
78
+ - Cucumber : disable Zonebie
79
+
80
+ ## 1.9.3
81
+ - No change
82
+
83
+ ## 1.9.2
84
+ - ErrorsMiddleware improvements
85
+
86
+ ## 1.9.1
87
+ - Add ErrorsMiddleware
88
+
89
+ ## 1.9.0
90
+ - Remove phantomjs/poltergeist support
91
+ - BackUrlConcern transforms absolute URLs to relative
92
+
93
+ ## 1.8.0
94
+ - SMS improvements
95
+ - Replace TapMethods by Tapenade gem
96
+ - Add nilify_blanks dependency
97
+
98
+ ## 1.7.4
99
+ - Add `tap_update_columns`and `tap_update_column`
100
+
101
+ ## 1.7.3
102
+ - Do not require auth in FiltersController
103
+ - Refactor FiltersController Pundit after_actions
104
+
105
+ ## 1.7.2
106
+ - Fix FontAwesome helper
107
+
108
+ ## 1.7.1
109
+ - Cuprite : improve config + increase timeout
110
+
111
+ ## 1.7.0
112
+ - ActiveRecord/ActiveModel type cast : refactor + add date + add boolean
113
+
114
+ ## 1.6.2
115
+ - Fix cucumber/capybara helpers
116
+
117
+ ## 1.6.1
118
+ - Add `SetupJobConcern`
119
+
120
+ ## 1.6.0
121
+ - Remove `GetHTTP`
122
+ - I18n fixes
123
+ - Add `Agilibox::TapMethods`
124
+ - Filters CSS : add flex-wrap
125
+ - Add `bs_card` helper
126
+ - Add `:br` separator to `info` helper
127
+ - TextHelper refactors
128
+ - Update dummy app to Rails 5.2
129
+ - Replace AXLSX by SpreadsheetArchitect
130
+
131
+ ## 1.5.13
132
+ - Fix `info` helper with nested blank value
133
+
134
+ ## 1.5.12
135
+ - Cuprite config improvements
136
+
137
+ ## 1.5.11
138
+ - Add `nbsp` helper
139
+ - Add `PluckDistinct` model concern
140
+ - Add pagination helpers
141
+
142
+ ## 1.5.10
143
+ - Cucumber Helpers : add cuprite support
6
144
 
145
+ ## 1.5.9
146
+ - I18n fix
147
+ - Add `bs_progress_bar` helper
148
+
149
+ ## 1.5.8
150
+ - Add GetHTTP#response
151
+
152
+ ## 1.5.7
153
+ - `download_button` and `export_button` fixes
154
+ - checkboxes-dropdown CSS improvements
155
+ - Change searchbar CSS
156
+
157
+ ## 1.5.6
158
+ - Various fixes on filters
159
+
160
+ ## 1.5.5
161
+ - Add ModelI18n::raise_on_missing_translations option
162
+
163
+ ## 1.5.4
164
+ - Cucumber "click on" steps improvement
165
+
166
+ ## 1.5.3
167
+ - Fix FontAwesome >=5.6
168
+
169
+ ## 1.5.2
170
+ - GetHTTP service improvements
171
+ - New common steps + improvements
172
+
173
+ ## 1.5.1
174
+ - Add CSS helpers
175
+ - Add Cucumber common steps
176
+ - Add Cucumber select2 helper
177
+
178
+ ## 1.5.0
179
+ - Add `GetHTTP`
180
+ - Add BS4 search form
181
+
182
+ ## 1.4.4
183
+ - Fix i18n error on `info` helper
184
+
185
+ ## 1.4.3
7
186
  - `form_buttons` helper fixes and improvements
8
187
 
9
188
  ## 1.4.2
10
-
11
189
  - Fix FontAwesome helper
12
190
 
13
191
  ## 1.4.1
14
-
15
192
  - FCM request handle JSON errors
16
193
 
17
194
  ## 1.4.0
18
-
19
195
  - Add `Agilibox::Email`
20
196
  - Add `Agilibox.parent_controller` config
21
197
  - Add `Agilibox.parent_mailer` config
22
198
  - Filters improvements
23
199
 
24
200
  ## 1.3.6
25
-
26
201
  - Remove deprecated `Agilibox::SortableUUIDGenerator::generate`
27
202
  - `Agilibox::ActiveRecordUUIDConcern` improvements
28
203
  - `Agilibox::DefaultValuesConcern` improvements
29
204
  - Fix FontAwesome version error
30
205
 
31
206
  ## 1.3.5
32
-
33
207
  - Add `Agilibox::Monkey`
34
208
 
35
209
  ## 1.3.4
36
-
37
210
  - Support FontAwesome v4
38
211
 
39
212
  ## 1.3.3
40
-
41
213
  - Fix error messages
42
214
 
43
215
  ## 1.3.2
44
-
45
216
  - Add `Agilibox::ActiveModelCustomErrorMessages`
46
217
 
47
218
  ## 1.3.1
48
-
49
219
  - `ApiControllerConcern` refactor + helpers
50
220
 
51
221
  ## 1.3.0
52
-
53
222
  - ApiControllerConcern : add `model_errors` in json response
54
223
  - `json_response` is now a `HashWithIndifferentAccess`
55
224
 
56
225
  ## 1.2.3
57
-
58
226
  - Add FCM
59
227
 
60
228
  ## 1.2.2
61
-
62
229
  - Add CollectionUpdate
63
230
  - Rename Agilibox::SortableUUIDGenerator::generate to ::call
64
231
 
65
232
  ## 1.2.1
66
-
67
233
  - Fix flash partial
68
234
  - Filter by date/datetime period now allows custom periods
69
235
  - Sorter class improvements
70
236
 
71
237
  ## 1.2.0
72
-
73
238
  - Add `Agilibox::MiniFormObject`
74
239
  - Replace time period filter by date+datetime period filters
75
240
  - JS Modal improvements
@@ -80,7 +245,6 @@
80
245
  - you now need to add `Agilibox::CucumberConfig.require_poltergeist!` or `Agilibox::CucumberConfig.require_chrome_headless!` to your `env.rb`
81
246
 
82
247
  ## 1.1.0
83
-
84
248
  - Search concern improvements
85
249
  - Date helper improvements
86
250
  - Add `boolean_icon` helper
@@ -89,34 +253,28 @@
89
253
  - Switch to FontAwesome 5 + `icon` helper improvements
90
254
 
91
255
  ## 1.0.15
92
-
93
256
  - `ApiControllerConcern#render_json_error` improvements
94
257
  - Add Agilibox::Service object
95
258
  - Fix SMS AmazonSNS strategy bug
96
259
  - Fix time period filter
97
260
 
98
261
  ## 1.0.14
99
-
100
262
  - Sorting helper improvements
101
263
  - FormBackUrl fixes
102
264
  - FiltersHelper fixes
103
265
 
104
266
  ## 1.0.13
105
-
106
267
  - Modal JS fix
107
268
 
108
269
  ## 1.0.12
109
-
110
270
  - `.checkboxes-dropdown` CSS fix
111
271
  - Fix sorting helper
112
272
 
113
273
  ## 1.0.11
114
-
115
274
  - Add Agilibox::SMS
116
275
  - Test helpers improvements
117
276
 
118
277
  ## 1.0.10
119
-
120
278
  - Add TokenGenerator
121
279
  - Add PhoneNumberSanitizer
122
280
  - Add engine_file helper to Kernel
@@ -127,21 +285,17 @@
127
285
  - Add ApiControllerConcern
128
286
 
129
287
  ## 1.0.9
130
-
131
288
  - Fix Model#tv
132
289
  - Add cucumber helpers
133
290
 
134
291
  ## 1.0.8
135
-
136
292
  - Serializers improvements
137
293
 
138
294
  ## 1.0.7
139
-
140
295
  - Search form add reset button
141
296
  - Filter form fix default submit button
142
297
 
143
298
  ## 1.0.6
144
-
145
299
  - Add checkboxes_dropdown helper
146
300
  - Add FilterStrategyByKeyValues
147
301
  - bs_button improvements
@@ -151,32 +305,26 @@
151
305
  - Split i18n files
152
306
 
153
307
  ## 1.0.5
154
-
155
308
  - Fix `import_button` helper
156
309
  - Add mime types
157
310
 
158
311
  ## 1.0.4
159
-
160
312
  - Search now ignore accents
161
313
  - Add Sorter class
162
314
 
163
315
  ## 1.0.3
164
-
165
316
  - Add `ta` (translate action) helper
166
317
  - Add `blank` css class to `info` helper
167
318
  - Add autocomplete.coffee
168
319
 
169
320
  ## 1.0.2
170
-
171
321
  - Button helper changes
172
322
  - Modals use event delegation
173
323
 
174
324
  ## 1.0.1
175
-
176
325
  - Remove AXLSX dependency
177
326
 
178
327
  ## 1.0.0
179
-
180
328
  - First version imported from agilidee/dorsale
181
329
  - `sortable_column_order` now returns symbols
182
330
  - modal fixes + allow upload
data/Rakefile CHANGED
@@ -35,3 +35,7 @@ end
35
35
 
36
36
 
37
37
  task default: :test
38
+
39
+ task "assets:precompile" do
40
+ Rake::Task["app:assets:precompile"].invoke
41
+ end
@@ -34,6 +34,7 @@ window.modal =
34
34
 
35
35
  close: (event) ->
36
36
  event.preventDefault() if event
37
+ $(document).trigger("modal:before-close")
37
38
  $("body").removeClass("modal-open")
38
39
  $("#modal").remove()
39
40
  $(document).trigger("modal:close")
@@ -0,0 +1,2 @@
1
+ .actions.top
2
+ text-align: right
@@ -1,7 +1,10 @@
1
+ @import agilibox/actions
1
2
  @import agilibox/buttons
2
3
  @import agilibox/filters
3
4
  @import agilibox/flash
4
5
  @import agilibox/forms
6
+ @import agilibox/icons
5
7
  @import agilibox/modals
6
8
  @import agilibox/pagination
7
9
  @import agilibox/print
10
+ @import agilibox/tables
@@ -6,3 +6,6 @@
6
6
  // .btn-default has been removed in Bootstrap 4
7
7
  .btn-default
8
8
  @extend .btn-outline-primary !optional
9
+
10
+ .btn + .btn
11
+ margin-left: 0.5em
@@ -6,6 +6,7 @@
6
6
  padding: 8px
7
7
  box-shadow: none
8
8
  display: flex
9
+ flex-wrap: wrap
9
10
  flex-direction: initial
10
11
  background: #F0F0F0
11
12
 
@@ -1,5 +1,7 @@
1
1
  .checkboxes-dropdown
2
2
  .checkbox
3
+ display: block
4
+
3
5
  label
4
6
  position: static
5
7
  margin: 0
@@ -10,6 +12,15 @@
10
12
  margin: 0 0.5em 0 0
11
13
  width: auto
12
14
 
15
+ .dropdown-menu
16
+ width: 350px
17
+ max-height: 400px
18
+ max-height: calc(100vh - 300px)
19
+ overflow: auto
20
+
21
+ @media (min-height: 700px)
22
+ max-height: 400px
23
+
13
24
  // Chrome and Safari does not trigger display:none submit buttons on <enter> key press
14
25
  .hidden-submit
15
26
  position: absolute
@@ -19,3 +30,20 @@
19
30
  height: 0
20
31
  width: 0
21
32
  visibility: hidden
33
+
34
+ form.search
35
+ max-width: 25em
36
+
37
+ .search-middle form.search,
38
+ .search-right form.search,
39
+ margin-left: auto
40
+
41
+ .search-left form.search,
42
+ .search-middle form.search,
43
+ margin-right: auto
44
+
45
+ .form-actions
46
+ text-align: center
47
+ margin-top: 45px
48
+ padding-top: 15px
49
+ border-top: 1px solid #ccc
@@ -0,0 +1,5 @@
1
+ .fa,
2
+ .fab,
3
+ .far,
4
+ .fas,
5
+ @extend .fa-fw
@@ -4,3 +4,10 @@
4
4
 
5
5
  li
6
6
  display: inline-block
7
+
8
+ .pagination
9
+ li
10
+ @extend .page-item !optional
11
+
12
+ a
13
+ @extend .page-link !optional
@@ -0,0 +1,26 @@
1
+ table.default
2
+ @extend .table
3
+ @extend .table-bordered
4
+ @extend .table-hover
5
+
6
+ th.actions,
7
+ td.actions,
8
+ width: 5em
9
+ white-space: nowrap
10
+ text-align: center
11
+
12
+ th
13
+ text-align: center
14
+ vertical-align: middle !important
15
+
16
+ td[class*="date"]
17
+ width: 8em
18
+ text-align: center
19
+
20
+ td[class*="count"],
21
+ width: 1em
22
+ text-align: center
23
+
24
+ td[class*="total"],
25
+ td[class*="amount"],
26
+ text-align: right
@@ -1,12 +1,10 @@
1
1
  class Agilibox::SmallData::FiltersController < ::Agilibox::ApplicationController
2
+ skip_before_action :verify_authenticity_token, raise: false
3
+ skip_before_action :authenticate_user!, raise: false
2
4
  skip_after_action :verify_authorized, raise: false
3
5
  skip_after_action :verify_policy_scoped, raise: false
4
- skip_before_action :verify_authenticity_token, raise: false
5
6
 
6
7
  def create
7
- skip_authorization if respond_to?(:skip_authorization)
8
- skip_policy_scope if respond_to?(:skip_policy_scope)
9
-
10
8
  filters = ::Agilibox::SmallData::Filter.new(cookies)
11
9
  new_filters = params.fetch(:filters, {}).permit!.to_h
12
10
  filters.merge new_filters
@@ -31,13 +31,14 @@ module Agilibox::ApiControllerConcern
31
31
 
32
32
  def json_errors_hash_for_model(object)
33
33
  object.errors
34
- .map { |a, m| [a, message: m, full_message: object.errors.full_message(a, m)] }
34
+ .to_hash
35
+ .map { |a, m| [a, message: m.first, full_message: object.errors.full_message(a, m.first)] }
35
36
  .uniq(&:first)
36
37
  .to_h
37
38
  end
38
39
 
39
40
  def json_error_string_for_model(object)
40
- json_errors_hash_for_model(object).values.map { |e| e[:full_message] }.join(", ")
41
+ json_errors_hash_for_model(object).values.pluck(:full_message).join(", ")
41
42
  end
42
43
 
43
44
  def render_not_found
@@ -53,7 +54,7 @@ module Agilibox::ApiControllerConcern
53
54
  end
54
55
 
55
56
  def render_forbidden_or_unauthorized
56
- current_user ? render_unauthorized : render_forbidden
57
+ current_user ? render_forbidden : render_unauthorized
57
58
  end
58
59
 
59
60
  included do |controller|
@@ -7,12 +7,20 @@ module Agilibox::BackUrlConcern
7
7
  end
8
8
 
9
9
  def back_url
10
- [
10
+ url = [
11
11
  params[:back_url],
12
12
  request.referer,
13
13
  default_back_url,
14
- main_app.root_path,
14
+ main_app.try(:root_path),
15
15
  "/",
16
- ].select(&:present?).first
16
+ ].find(&:present?)
17
+
18
+ uri = URI.parse(url)
19
+ uri.host = nil
20
+ uri.port = nil
21
+ uri.scheme = nil
22
+ uri.user = nil
23
+ uri.password = nil
24
+ uri.to_s
17
25
  end
18
26
  end
@@ -1,4 +1,6 @@
1
1
  class Agilibox::SmallData::Filter
2
+ include ActiveModel::Model
3
+
2
4
  STRATEGIES = {}
3
5
 
4
6
  attr_reader :jar
@@ -43,7 +45,7 @@ class Agilibox::SmallData::Filter
43
45
  end
44
46
 
45
47
  def respond_to_missing?(method, *)
46
- strategies.key?(method.to_s) || strategies.key?(method.to_s.chomp("="))
48
+ super || strategies.key?(method.to_s) || strategies.key?(method.to_s.chomp("="))
47
49
  end
48
50
 
49
51
  def read
@@ -60,8 +62,12 @@ class Agilibox::SmallData::Filter
60
62
  write read.merge(new_filters)
61
63
  end
62
64
 
65
+ def actives_count
66
+ read.count { |k, v| strategies.key?(k.to_s) && v.present? }
67
+ end
68
+
63
69
  def any?
64
- read.select { |k, v| strategies.key?(k.to_s) && v.present? }.any?
70
+ actives_count.positive?
65
71
  end
66
72
 
67
73
  def empty?
@@ -1,6 +1,7 @@
1
1
  class Agilibox::SmallData::FilterStrategyByDateBegin < ::Agilibox::SmallData::FilterStrategyByKeyValue
2
2
  def apply(query, value)
3
- value = Time.zone.parse(value).beginning_of_day
4
- query.where("#{key} >= ?", value)
3
+ value = Date.parse(value)
4
+ column = column_for(query)
5
+ query.where("#{column} >= ?", value)
5
6
  end
6
7
  end
@@ -1,6 +1,7 @@
1
1
  class Agilibox::SmallData::FilterStrategyByDateEnd < ::Agilibox::SmallData::FilterStrategyByKeyValue
2
2
  def apply(query, value)
3
- value = Time.zone.parse(value).end_of_day
4
- query.where("#{key} <= ?", value)
3
+ value = Date.parse(value)
4
+ column = column_for(query)
5
+ query.where("#{column} <= ?", value)
5
6
  end
6
7
  end
@@ -1,6 +1,6 @@
1
1
  class Agilibox::SmallData::FilterStrategyByDateOrDatetimePeriod < ::Agilibox::SmallData::FilterStrategyByKeyValue
2
2
  def initialize(*)
3
- if self.class == Agilibox::SmallData::FilterStrategyByDateOrDatetimePeriod
3
+ if instance_of?(Agilibox::SmallData::FilterStrategyByDateOrDatetimePeriod)
4
4
  raise "please use FilterStrategyByDatePeriod or FilterStrategyByDatetimePeriod"
5
5
  end
6
6
 
@@ -46,7 +46,7 @@ class Agilibox::SmallData::FilterStrategyByDateOrDatetimePeriod < ::Agilibox::Sm
46
46
  b = b.end_of_day if b
47
47
  end
48
48
 
49
- column = key.is_a?(Symbol) ? "#{query.model.table_name}.#{key}" : key.to_s
49
+ column = column_for(query)
50
50
 
51
51
  query = query.where("#{column} >= ?", a) if a
52
52
  query = query.where("#{column} <= ?", b) if b
@@ -2,15 +2,26 @@ class Agilibox::SmallData::FilterStrategyByKeyValue < ::Agilibox::SmallData::Fil
2
2
  attr_reader :key
3
3
 
4
4
  def initialize(key = nil)
5
+ super()
5
6
  @key = key
6
7
  end
7
8
 
8
9
  def apply(query, value)
9
10
  value = true if value == "true"
10
11
  value = false if value == "false"
11
- value = nil if value == "nil"
12
- value = nil if value == "null"
13
12
 
14
- query.where("#{key} = ?", value)
13
+ column = column_for(query)
14
+
15
+ if value.to_s.in?(%w(nil null))
16
+ query.where("#{column} IS NULL")
17
+ elsif value.to_s.in?(%w(not_nil not_null))
18
+ query.where("#{column} IS NOT NULL")
19
+ else
20
+ query.where("#{column} = ?", value)
21
+ end
22
+ end
23
+
24
+ def column_for(query)
25
+ key.is_a?(Symbol) ? "#{query.model.table_name}.#{key}" : key.to_s
15
26
  end
16
27
  end
@@ -1,16 +1,11 @@
1
- class Agilibox::SmallData::FilterStrategyByKeyValues < ::Agilibox::SmallData::FilterStrategy
2
- attr_reader :key
3
-
4
- def initialize(key = nil)
5
- @key = key
6
- end
7
-
1
+ class Agilibox::SmallData::FilterStrategyByKeyValues < ::Agilibox::SmallData::FilterStrategyByKeyValue
8
2
  def apply(query, value)
9
- value = value.split(" ") if value.is_a?(String)
3
+ value = value.split if value.is_a?(String)
10
4
  value = value.select(&:present?)
5
+ column = column_for(query)
11
6
 
12
7
  if value.any?
13
- query.where("#{key} IN (?)", value)
8
+ query.where("#{column} IN (?)", value)
14
9
  else
15
10
  query
16
11
  end