active_admin_date_range_preset 0.4.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9017cfc30106119dd13d0064a6fd63d8d6eacb3bf6e526a97eb26793f8d47c21
4
- data.tar.gz: eb4e677c8381eff213f9ab5efd4c924e7a38f0543b2e6b159e650a86c1deb85b
3
+ metadata.gz: d3cae599dda0f084558bdfe20d9521b54a3cc21c0fce528268319ad244013987
4
+ data.tar.gz: 23c046e1ab9f57b901b0cd7f3beba397043dc4c22b5fab646d725b49e7d0a903
5
5
  SHA512:
6
- metadata.gz: c5ed90bdb897e4463d9979b6bf70edd059b4ff3f3b2454ad6b989b31257e3fa1eb5e9109810c5ec73f5fdcbc032b0190b7bde3c0731c89e43ef14a52e3713e46
7
- data.tar.gz: d1e948d843d9aa35bcc40592fcbce5fcdc5d4044bd70747c4c872cf27c9606723240ea046500df9010825e8bc3a67191a839eb9f8f6ad747018c223bef9bf416
6
+ metadata.gz: 5323afd071fb10ffcc929276b046ea7ebb7453328f613e3d15bb11aa738d7be2c086abf7c5afa5711e15bcbc757d1b68b076af37165831acb68d1d6bc9e4019a
7
+ data.tar.gz: e9ee89a404faaf6c11d4454b45b5957618b4e80d946acbd0fc52bb3b5082112515b90fc35a348682a9015a0c878f21af6348acb8030075ba7c3062fea708e342
data/README.md CHANGED
@@ -12,24 +12,69 @@ This is how it looks like
12
12
  <img width="1008" height="942" alt="combined" src="https://github.com/user-attachments/assets/cbe22410-078e-4f2b-894b-4457c13e3e22" />
13
13
 
14
14
 
15
+
15
16
  ## Compatibility
16
17
 
17
- Active Admin 3.2 or newer, in the 3.x series. Rails 8.0 or newer, Ruby 3.3 or
18
- newer. CI covers Active Admin 3.2 and 3.5 on Ruby 3.3, 3.4 and 4.0 against
19
- Rails 8.0 and 8.1 — every Rails series still supported upstream.
18
+ Active Admin 3.2 or newer, including Active Admin 4. Rails 8.0 or newer, Ruby
19
+ 3.3 or newer. CI covers Active Admin 3.2 and 3.5 on Ruby 3.3, 3.4 and 4.0
20
+ against Rails 8.0 and 8.1, and Active Admin 4.0.0.beta23 on Rails 8.0 and 8.1.
21
+
22
+ The plugin is one plain JavaScript file with no jQuery. Active Admin 3 loads it
23
+ through Sprockets, Active Admin 4 as an ES module from its import map. Both get
24
+ the same API, `window.ActiveAdminDateRangePreset`.
20
25
 
21
- Version 0.4.0 raised the Rails floor from 7.1 to 8.0. Every 7.x series is out
22
- of support — 7.1 since October 2025, 7.2 since August 2026 — and none of them
23
- is tested. Stay on 0.3.x if you are still on Rails 7.
26
+ Version 0.4.0 raised the Rails floor from 7.1 to 8.0. Stay on 0.3.x if you are
27
+ still on Rails 7.
24
28
 
25
29
  The Rails and Ruby floors are declared explicitly because Active Admin 3.2
26
30
  still allows `railties >= 6.1` and Ruby `>= 2.6`, both long past end of life
27
31
  and neither tested here.
28
32
 
29
- Active Admin 4 is not supported. It drops `jquery-rails` and the
30
- `app/assets/javascripts` tree, and this gem is a jQuery plugin shipped through
31
- Sprockets, so nothing here loads there. Supporting it means a rewrite rather
32
- than a port, and that is tracked separately.
33
+ ## Upgrading from 0.x
34
+
35
+ The jQuery plugin `$.fn.date_range_ext_preset` is gone. Replace each call with
36
+ `ActiveAdminDateRangePreset.init`, which takes a CSS selector (or an element,
37
+ or a list of elements) and the same options:
38
+
39
+ ```javascript
40
+ // before
41
+ $('form.filter_form div.filter_date_range').date_range_ext_preset({ show_time: true });
42
+ $.fn.date_range_ext_preset.defaults.hours_offset = 3;
43
+
44
+ // after
45
+ document.addEventListener('DOMContentLoaded', function () {
46
+ ActiveAdminDateRangePreset.init('form.filter_form div.filter_date_range', { show_time: true });
47
+ });
48
+ ActiveAdminDateRangePreset.defaults.hours_offset = 3;
49
+ ```
50
+
51
+ Every option keeps its name and meaning, `show_time` included. A call that
52
+ turned time on for some inputs becomes:
53
+
54
+ ```javascript
55
+ // before
56
+ $('.my_pairs').date_range_ext_preset({ show_time: true });
57
+
58
+ // after
59
+ document.addEventListener('DOMContentLoaded', function () {
60
+ ActiveAdminDateRangePreset.init('.my_pairs', { show_time: true });
61
+ });
62
+ ```
63
+
64
+ To turn it on for every pair, including the ones set up automatically, set
65
+ the default instead:
66
+
67
+ ```javascript
68
+ ActiveAdminDateRangePreset.defaults.show_time = true;
69
+ ```
70
+
71
+ `show_time` still affects text inputs only. Native `date` and `datetime-local`
72
+ inputs get the format their `type` requires.
73
+
74
+ `gteq_input` and `lteq_input` are now CSS selectors or elements instead of
75
+ jQuery selectors. The markup and CSS classes are unchanged. The stylesheet is
76
+ plain CSS now, so `@import "active_admin_date_range_preset";` in
77
+ `active_admin.scss` keeps working.
33
78
 
34
79
  ## Installation
35
80
 
@@ -43,162 +88,173 @@ And then execute:
43
88
 
44
89
  $ bundle install
45
90
 
46
- Or install it yourself as:
91
+ ### Active Admin 3 (Sprockets)
47
92
 
48
- $ gem install active_admin_date_range_preset
93
+ In `app/assets/javascripts/active_admin.js`:
49
94
 
50
- ##### Using assets via Sprockets
51
-
52
- JS asset
53
- ```//= require active_admin_date_range_preset```
54
-
55
- CSS
56
- ```@import "active_admin_date_range_preset";```
95
+ ```javascript
96
+ //= require active_admin_date_range_preset
97
+ ```
57
98
 
58
- ##### Using assets via Webpacker (or any other assets bundler) as a NPM module (Yarn package)
99
+ In `app/assets/stylesheets/active_admin.scss`:
59
100
 
60
- Execute:
101
+ ```scss
102
+ @import "active_admin_date_range_preset";
103
+ ```
61
104
 
62
- $ npm i @activeadmin-plugins/active_admin_date_range_preset
105
+ ### Active Admin 4 (import map)
63
106
 
64
- Or
107
+ The gem pins the module `active_admin_date_range_preset` into
108
+ `ActiveAdmin.importmap`. If your Active Admin has the `javascript_modules`
109
+ setting, the gem adds itself to it and pages import it automatically.
110
+ Otherwise, override `app/views/active_admin/_html_head.html.erb` (copy it from
111
+ Active Admin) and add after the `javascript_importmap_tags` line:
65
112
 
66
- $ yarn add @activeadmin-plugins/active_admin_date_range_preset
113
+ ```erb
114
+ <%= javascript_import_module_tag "active_admin_date_range_preset" %>
115
+ ```
67
116
 
68
- Or add manually to `package.json`:
117
+ If you use active_admin_theme 4, add the module to its list in an initializer
118
+ instead:
69
119
 
70
- ```json
71
- "dependencies": {
72
- "@activeadmin-plugins/active_admin_date_range_preset": "0.3.1"
73
- }
120
+ ```ruby
121
+ ActiveAdminTheme.javascripts += %w[active_admin_date_range_preset]
74
122
  ```
75
- and execute:
76
123
 
77
- $ yarn
124
+ For the CSS, either link the stylesheet in the same `_html_head` override
125
+ (Propshaft serves it from the gem):
78
126
 
79
- Add the following line into `app/assets/javascripts/active_admin.js`:
80
-
81
- ```javascript
82
- import '@activeadmin-plugins/active_admin_date_range_preset';
127
+ ```erb
128
+ <%= stylesheet_link_tag "active_admin_date_range_preset" %>
83
129
  ```
84
130
 
85
- Add the following line into `app/assets/stylesheets/active_admin.scss`:
131
+ or import it into the Tailwind entry that builds `active_admin.css`, from the
132
+ npm package or from the gem's path (`bundle show active_admin_date_range_preset`):
86
133
 
87
134
  ```css
88
- @import '@activeadmin-plugins/active_admin_date_range_preset';
135
+ @import "@activeadmin-plugins/active_admin_date_range_preset";
89
136
  ```
90
137
 
91
- Your sidebar filters should now have link "Set Range"
138
+ The menu follows Active Admin 4's dark mode (the `.dark` class on `<html>`).
92
139
 
93
- ## Development
140
+ ### npm package
94
141
 
95
- The specs run against a throwaway Rails app built by `spec/support/rails_template.rb`.
96
- It is generated automatically on the first run (or via `bundle exec rake setup`) into
97
- `spec/rails/rails-<version>/`, which is gitignored.
142
+ $ npm i @activeadmin-plugins/active_admin_date_range_preset
98
143
 
99
- ```sh
100
- bundle install
101
- bundle exec rspec spec
144
+ ```javascript
145
+ import '@activeadmin-plugins/active_admin_date_range_preset';
102
146
  ```
103
147
 
104
- Pick the versions under test with env vars:
105
-
106
- ```sh
107
- RAILS=8.0.0 AA=3.5.0 bundle install
108
- RAILS=8.0.0 AA=3.5.0 bundle exec rspec spec
148
+ ```css
149
+ @import '@activeadmin-plugins/active_admin_date_range_preset';
109
150
  ```
110
151
 
111
152
  ## Usage
112
153
 
113
- in New/Edit formtastic forms:
154
+ ### Forms
155
+
156
+ Put `datetime_preset_pair` on the wrapper of the first input of a pair. The
157
+ next input is the end of the range. Pairs with this class are set up on page
158
+ load.
114
159
 
115
160
  ```ruby
116
- f.input :date_from, as: :date_time_picker, wrapper_html: { class: 'datetime_preset_pair', data: { show_time: 'true' } }
117
- f.input :date_to, as: :date_time_picker
161
+ f.input :date_from, as: :string, wrapper_html: { class: 'datetime_preset_pair', data: { show_time: 'true' } }
162
+ f.input :date_to, as: :string
118
163
  ```
119
164
 
120
- Input can be "as :string" or any other type compatible with "input type=text"
121
- Main point is to set for first input-pair wrapper-class
165
+ The value format follows the input's `type`:
122
166
 
123
- ```wrapper_html: { class: 'datetime_preset_pair' }```
167
+ | Input | Value |
168
+ | --- | --- |
169
+ | `type="date"` | `2015-06-10` |
170
+ | `type="datetime-local"` | `2015-06-10T00:00`, with `:SS` when its `step` allows seconds |
171
+ | text | `2015-06-10`, or `2015-06-10 00:00:00` with `show_time` |
124
172
 
125
- input name('date_from' and 'date_to') can be named whatever your need
173
+ `data-show-time` overrides `show_time` for that pair, in both directions.
126
174
 
127
- By default inputs are filled with date("yyyy-mm-dd"). If you need time add
175
+ ### Filters
128
176
 
129
- ```data: { show_time: 'true' }```
177
+ A wrapper that holds both inputs uses its first and last input. Add the class
178
+ to a date_range filter:
130
179
 
180
+ ```ruby
181
+ filter :created_at, as: :date_range, wrapper_html: { class: 'datetime_preset_pair' }
182
+ ```
131
183
 
132
- ## Using with ActiveAdminDatetimepicker
184
+ Or set up every date_range filter from JavaScript:
133
185
 
134
- If you use GEM https://github.com/activeadmin-plugins/active_admin_datetimepicker
135
- and want apply this plugin to filter-inputs for this gem you need:
186
+ ```javascript
187
+ // Active Admin 3
188
+ ActiveAdminDateRangePreset.init('form.filter_form div.filter_date_range');
189
+ // Active Admin 4
190
+ ActiveAdminDateRangePreset.init('form.filters-form div.date_range');
191
+ ```
136
192
 
137
- First apply ActiveAdminDatetimepicker to any filters your need
193
+ On Active Admin 4, put that call in a module script in your `_html_head`
194
+ override, after the import:
138
195
 
139
- ```ruby
140
- filter :time_start, as: :date_time_range
196
+ ```erb
197
+ <script type="module">
198
+ import "active_admin_date_range_preset";
199
+ ActiveAdminDateRangePreset.init("form.filters-form div.date_range");
200
+ </script>
141
201
  ```
142
202
 
143
- In active_admin.js
203
+ Active Admin 4's own date_range filter renders native date inputs, so the
204
+ presets write `YYYY-MM-DD` there.
144
205
 
145
- Add following lines to JavaScript
206
+ ### With active_admin_datetimepicker
207
+
208
+ [active_admin_datetimepicker](https://github.com/activeadmin-plugins/active_admin_datetimepicker)
209
+ range filters (`filter :time_start, as: :date_time_range`) render as
210
+ `div.filter_date_time_range` on Active Admin 3 and 4. Init them by that
211
+ selector, the same way on both:
146
212
 
147
213
  ```javascript
148
- $(function () {
149
- $('form.filter_form div.filter_date_time_range').date_range_ext_preset();
150
- });
214
+ ActiveAdminDateRangePreset.init('form div.filter_date_time_range');
151
215
  ```
152
216
 
153
- Now all you "date_time_range" inputs has button "Set range"
217
+ On Active Admin 4 their inputs are `datetime-local` (or `date` for a date
218
+ column), so the presets write `YYYY-MM-DDTHH:MM` (or `YYYY-MM-DD`). In forms,
219
+ put `datetime_preset_pair` on the first picker's `wrapper_html` as for any
220
+ other pair.
154
221
 
222
+ ### Custom inputs
155
223
 
156
- ## Custom usage
157
-
158
- You can assign "Set range" almost to any input-text-pair filters/forms.
159
- For example, you have complex form where input-pairs are not close to each other and not standard.
224
+ The link goes into the first `label` of the element you init. When the inputs
225
+ are elsewhere on the page, point at them:
160
226
 
161
227
  ```javascript
162
- $(function () {
163
- $('.any_jquery_selector').date_range_ext_preset({
164
- lteq_input: '.jquery_selector_to_first_input',
165
- gteq_input: '.jquery_selector_to_second_input'
166
- });
228
+ ActiveAdminDateRangePreset.init('.any_selector', {
229
+ gteq_input: '#date_from',
230
+ lteq_input: '#date_to'
167
231
  });
168
232
  ```
169
- ".any_jquery_selector" is pointed to place where button "Set range" will appear.
170
- Set lteq_input and gteq_input to point to inputs if they not near main selector.
171
233
 
234
+ Calling `init` again on the same element replaces its setup, so a call with
235
+ options after the automatic one wins.
172
236
 
173
- ## Global and local settings
237
+ ### Test hooks
174
238
 
175
- There are several settings, which can be set globally or locally.
239
+ The "Set range" link carries `data-date-range-preset-toggle`, the menu
240
+ `data-date-range-preset-menu`, and each preset `data-date-range-preset` with its
241
+ key: `today`, `yesterday`, `week`, `month`, `last_week`, `last_month`, then
242
+ `custom_0`, `custom_1`, ... for `add_range` entries.
176
243
 
177
- Example how to set settings for only specific inputs
244
+ ## Settings
178
245
 
179
- ```javascript
180
- $('.any_jquery_selector').date_range_ext_preset({
181
- setting_name: "setting_value"
182
- });
183
- ```
184
- Example how to set global settings. Write it before the `$(function () { ... })` block
246
+ Pass settings to `init` for some elements, or set them for every later `init`
247
+ on `ActiveAdminDateRangePreset.defaults`. Defaults are read each time a menu
248
+ opens, so they apply to pairs that were set up before you changed them.
185
249
 
186
250
  ```javascript
187
- $.fn.date_range_ext_preset.defaults.setting_name = "setting_value"
188
- ```
251
+ // End date is the same day, not the next one.
252
+ // Today true : 2015-06-12 - 2015-06-12
253
+ // Today false: 2015-06-12 - 2015-06-13
254
+ ActiveAdminDateRangePreset.defaults.date_to_human_readable = true;
189
255
 
190
- You can set global defaults in your active_admin.js like this:
191
-
192
- ```javascript
193
- # End date will be full-day, not next.
194
- # Today true : 2015-06-12 - 2015-06-12
195
- # Today false: 2015-06-12 - 2015-06-13
196
- $.fn.date_range_ext_preset.defaults.date_to_human_readable = true
197
-
198
- # Display time
199
- # Today: 2015-06-12 00:00:00 - 2015-06-13 00:00:00
200
- # Today with human_readable=true: 2015-06-12 00:00:00 - 2015-16-12 23:59:59
201
- $.fn.date_range_ext_preset.defaults.show_time = true
256
+ // Text inputs get the time too: 2015-06-12 00:00:00 - 2015-06-13 00:00:00
257
+ ActiveAdminDateRangePreset.defaults.show_time = true;
202
258
  ```
203
259
 
204
260
  ### date_to_human_readable
@@ -221,7 +277,8 @@ value: true/false
221
277
 
222
278
  default: false
223
279
 
224
- If true then will show date and time, usually it will be 00:00:00
280
+ If true, text inputs get date and time, usually 00:00:00. Native inputs ignore
281
+ it: their `type` decides.
225
282
 
226
283
  ### hours_offset
227
284
 
@@ -231,29 +288,45 @@ default: 0
231
288
 
232
289
  To work correctly this plugin needs to detect current date-time. And it uses UTC. But if you need your local timezone or some other time-shift, your can set this option:
233
290
 
234
- Example:
235
291
  ```javascript
236
- $.fn.date_range_ext_preset.defaults.hours_offset = +3
292
+ ActiveAdminDateRangePreset.defaults.hours_offset = +3;
237
293
  // or
238
- $.fn.date_range_ext_preset.defaults.hours_offset = -3
294
+ ActiveAdminDateRangePreset.defaults.hours_offset = -3;
239
295
  ```
240
296
 
241
- ### Addition ranges
297
+ ### add_range
242
298
 
243
299
  ```javascript
244
- $(function () {
245
-
246
- $('.filter_form .filter_date_range').date_range_ext_preset({
247
- date_to_human_readable: true, # affects last day
248
- add_range: [
249
- {
250
- title: 'Last 30 days',
251
- // date_to_human_readable affects end-date, sow must do this:
252
- start: new Date(new Date().setDate(new Date().getDate() - 29)),
253
- end: new Date(new Date().setDate(new Date().getDate() + 1))
254
- }
255
- ]
256
- });
257
-
300
+ ActiveAdminDateRangePreset.init('form.filter_form div.filter_date_range', {
301
+ date_to_human_readable: true, // affects the end date
302
+ add_range: [
303
+ {
304
+ title: 'Last 30 days',
305
+ // date_to_human_readable moves the end date back a second, so end tomorrow:
306
+ start: new Date(new Date().setDate(new Date().getDate() - 29)),
307
+ end: new Date(new Date().setDate(new Date().getDate() + 1))
308
+ }
309
+ ]
258
310
  });
259
311
  ```
312
+
313
+ ## Development
314
+
315
+ The specs run against a throwaway Rails app built by `spec/support/rails_template.rb`.
316
+ It is generated automatically on the first run (or via `bundle exec rake setup`) into
317
+ `spec/rails/rails-<version>-aa<version>/`, which is gitignored.
318
+
319
+ ```sh
320
+ bundle install
321
+ bundle exec rspec spec
322
+ ```
323
+
324
+ Pick the versions under test with env vars. `AA=4.x` switches the bundle from
325
+ Sprockets to Propshaft, importmap-rails and Tailwind:
326
+
327
+ ```sh
328
+ RAILS=8.0.0 AA=3.5.0 bundle install
329
+ RAILS=8.0.0 AA=3.5.0 bundle exec rspec spec
330
+ AA=4.0.0.beta23 bundle install
331
+ AA=4.0.0.beta23 bundle exec rspec spec
332
+ ```
@@ -0,0 +1,2 @@
1
+ # Pinned into ActiveAdmin.importmap, the map the Active Admin 4 layout renders.
2
+ pin "active_admin_date_range_preset", to: "active_admin_date_range_preset.js", preload: false
@@ -1,3 +1,3 @@
1
1
  module ActiveAdminDateRangePreset
2
- VERSION = "0.4.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -2,10 +2,29 @@ require "activeadmin"
2
2
  require "active_admin_date_range_preset/version"
3
3
 
4
4
  module ActiveAdminDateRangePreset
5
- module Rails
6
- class Engine < ::Rails::Engine
5
+ JAVASCRIPT_MODULE = "active_admin_date_range_preset".freeze
7
6
 
7
+ def self.aa_v4?
8
+ Gem::Version.new(ActiveAdmin::VERSION) >= Gem::Version.new("4.0.0.beta1")
9
+ end
10
+
11
+ module Rails
12
+ class Engine < ::Rails::Engine
13
+ # Active Admin 4 renders its own import map, so the module is pinned
14
+ # there. Propshaft serves it from vendor/assets/javascripts, which every
15
+ # engine adds to the asset paths.
16
+ initializer "active_admin_date_range_preset.importmap", after: "active_admin.importmap" do |app|
17
+ next unless ActiveAdminDateRangePreset.aa_v4? && app.config.respond_to?(:importmap)
18
+
19
+ ActiveAdmin.importmap.draw(root.join("config", "importmap.rb"))
8
20
  end
9
- end
10
21
 
22
+ # javascript_modules is pending upstream (activeadmin/activeadmin#9148).
23
+ config.after_initialize do
24
+ if ActiveAdmin.application.respond_to?(:javascript_modules)
25
+ ActiveAdmin.application.javascript_modules |= [JAVASCRIPT_MODULE]
26
+ end
27
+ end
28
+ end
29
+ end
11
30
  end
@@ -1,245 +1,317 @@
1
- $(function () {
2
- // options:
3
- // gteq_input: jQuery-selecotr for input date_from
4
- // lteq_input: jQuery-selecotr for input date_to
5
- // hours_offset: Int number - hours +/- to correct time
6
- $.fn.date_range_ext_preset = function(options) {
7
- // settings
8
- options = options || {};
9
- let opts = $.extend({}, $.fn.date_range_ext_preset.defaults, options);
10
-
11
- // aditional functions
12
- function num_with_leading_zero(num, digitsCount = 2) {
13
- let s = num + '';
14
- while (s.length < digitsCount) {
15
- s = '0' + s;
16
- }
17
- return s;
18
- }
1
+ // Plain script with no imports or exports, so the same file runs as a classic
2
+ // script (Sprockets on Active Admin 3) and as an ES module (importmap on
3
+ // Active Admin 4). Either way the API is window.ActiveAdminDateRangePreset.
4
+ (function () {
5
+ if (window.ActiveAdminDateRangePreset) { return; }
19
6
 
20
- // formated date YYYY-MM-DD, with converting to UTC
21
- // note: getMonth Returns the month (from 0-11), so we do +1
22
- function formatDate(date, el_opts) {
23
- let str = date.getFullYear() + '-' + num_with_leading_zero(date.getMonth()+1) + '-' + num_with_leading_zero(date.getDate());
24
- if (el_opts.show_time) {
25
- str += (' ' + num_with_leading_zero(date.getHours()) + ':' + num_with_leading_zero(date.getMinutes()) + ':' + num_with_leading_zero(date.getSeconds()));
26
- }
27
- return str;
28
- }
7
+ var defaults = {
8
+ // Manual global time shift, from UTC can be +/- number
9
+ hours_offset: 0,
29
10
 
30
- // Days from the Monday that opens this date's week. getDay() counts from
31
- // Sunday, so a plain `- getDay() + 1` lands on tomorrow for Sundays and
32
- // hands back the week that has not started yet.
33
- function days_since_monday(date) {
34
- return (date.getDay() + 6) % 7;
35
- }
11
+ // date_to_human_readable = true, then "date_to" consider as including full day without last second
12
+ // For example Today will be:
13
+ // true
14
+ // 2015-06-10 - 2015-06-10
15
+ // 2015-06-10 00:00:00 - 2015-06-10 23:59:59
16
+ // false
17
+ // 2015-06-10 - 2015-06-11
18
+ // 2015-06-10 00:00:00 - 2015-06-11 00:00:00
19
+ date_to_human_readable: false,
36
20
 
37
- function unbindClickEventBlockTimerange() {
38
- $('.block_timerange').remove();
39
- $('body').off('click.CalendarRangeSet');
40
- }
21
+ // Display time or not on text inputs: 2015-06-10 vs 2015-06-10 00:00:00
22
+ show_time: false,
23
+
24
+ // Array of additional ranges: { title: 'Last 30 days', start: Date, end: Date }
25
+ add_range: []
26
+ };
27
+
28
+ var PRESETS = [
29
+ { key: 'today', title: 'Today', range: function (now) {
30
+ var start = day(now, 0);
31
+ return [start, day(start, 1)];
32
+ } },
33
+ { key: 'yesterday', title: 'Yesterday', range: function (now) {
34
+ return [day(now, -1), day(now, 0)];
35
+ } },
36
+ { key: 'week', title: 'This Week', range: function (now) {
37
+ var start = day(now, -daysSinceMonday(now));
38
+ return [start, day(start, 7)];
39
+ } },
40
+ { key: 'month', title: 'This Month', range: function (now) {
41
+ return [
42
+ new Date(now.getFullYear(), now.getMonth(), 1),
43
+ new Date(now.getFullYear(), now.getMonth() + 1, 1)
44
+ ];
45
+ } },
46
+ { key: 'last_week', title: 'Last Week', range: function (now) {
47
+ var end = day(now, -daysSinceMonday(now));
48
+ return [day(end, -7), end];
49
+ } },
50
+ { key: 'last_month', title: 'Last Month', range: function (now) {
51
+ return [
52
+ new Date(now.getFullYear(), now.getMonth() - 1, 1),
53
+ new Date(now.getFullYear(), now.getMonth(), 1)
54
+ ];
55
+ } }
56
+ ];
57
+
58
+ function day(date, shift) {
59
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + shift);
60
+ }
61
+
62
+ // getDay() counts from Sunday, so a plain `- getDay() + 1` lands on
63
+ // tomorrow for Sundays and hands back the week that has not started yet.
64
+ function daysSinceMonday(date) {
65
+ return (date.getDay() + 6) % 7;
66
+ }
41
67
 
42
- // local datetime now
43
- let now = new Date();
44
- // UTC datetime now
45
- let now_utc = new Date(
68
+ function pad(num) {
69
+ return (num < 10 ? '0' : '') + num;
70
+ }
71
+
72
+ // Native date inputs only accept ISO values, so the input's type picks the
73
+ // format; text inputs keep the format the plugin has always written.
74
+ function formatFor(input, date, opts) {
75
+ var ymd = date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate());
76
+ var hm = pad(date.getHours()) + ':' + pad(date.getMinutes());
77
+ var hms = hm + ':' + pad(date.getSeconds());
78
+ if (input.type === 'date') { return ymd; }
79
+ if (input.type === 'datetime-local') { return ymd + 'T' + (allowsSeconds(input) ? hms : hm); }
80
+ return opts.show_time ? ymd + ' ' + hms : ymd;
81
+ }
82
+
83
+ // The default step of a datetime-local input is 60 seconds, and a value with
84
+ // seconds then fails validation and blocks the form submit.
85
+ function allowsSeconds(input) {
86
+ var step = input.getAttribute('step');
87
+ return step === 'any' || (step !== null && Number(step) % 60 !== 0);
88
+ }
89
+
90
+ // "Now" in UTC shifted by hours_offset, as a local Date whose fields hold
91
+ // those wall-clock values.
92
+ function shiftedNow(opts) {
93
+ var now = new Date();
94
+ var utc = new Date(
46
95
  now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),
47
96
  now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(),
48
97
  now.getUTCMilliseconds()
49
98
  );
50
- // datetime object, UTC with hours offset
51
- let datetime = new Date(now_utc.getTime() + opts.hours_offset * 60 * 60 * 1000);
52
-
53
- // PLUGIN BEGIN
54
- return this.each(function(i, el) {
55
- let $this = $(el);
56
-
57
- // Re-initialising an element replaces its wiring instead of adding to
58
- // it. The auto-init below was dead from jQuery 3 onwards, so hosts
59
- // worked around it by calling the plugin themselves; now that it works
60
- // again both run, and without this the label grows a second "Set range"
61
- // whose handler tears down the first one's popup.
62
- //
63
- // Replacing rather than skipping matters: the auto-init registers its
64
- // ready callback before anything a host adds to active_admin.js, so
65
- // bailing out on the second call would silently drop the host's
66
- // options. Reading the link itself rather than a data flag keeps the
67
- // guard and the thing it guards from drifting apart across clone() and
68
- // Turbo cache restores, which copy the node but not jQuery's data.
69
- $this.find('a.btn_timerange').remove();
70
- $this.off('click.dateRangeExtPreset');
71
-
72
- // Per element, because data-show-time is read off the element itself.
73
- // Writing it back into the shared opts let one pair's setting reach
74
- // every other pair in the same call, and formatDate reads the flag at
75
- // click time rather than here, so the leak was not even order-dependent.
76
- let el_opts = $.extend({}, opts);
77
-
78
- // The attribute is authoritative in both directions when present. Only
79
- // ever assigning true made it impossible for one element to opt out of
80
- // a show_time the call or the defaults had turned on.
81
- if (typeof $this.data('show-time') != 'undefined') {
82
- el_opts.show_time = $this.data('show-time').toString() == 'true';
83
- }
99
+ return new Date(utc.getTime() + opts.hours_offset * 60 * 60 * 1000);
100
+ }
84
101
 
85
- // detect inputs
86
- let lteq_input = $this.find('input:last');
87
- if (options.lteq_input) {
88
- lteq_input = $(options.lteq_input);
89
- } else if ($this.hasClass('datetime_preset_pair')) {
90
- lteq_input = $this.next().find('input');
91
- }
102
+ function setValue(input, value) {
103
+ input.value = value;
104
+ input.dispatchEvent(new Event('input', { bubbles: true }));
105
+ input.dispatchEvent(new Event('change', { bubbles: true }));
106
+ }
92
107
 
93
- let gteq_input = $this.find('input:first');
94
- if (options.gteq_input) {
95
- gteq_input = $(options.gteq_input);
96
- } else if ($this.hasClass('datetime_preset_pair')) {
97
- gteq_input = $this.find('input');
98
- }
108
+ // Also takes a jQuery object, which hosts migrating from the jQuery plugin
109
+ // still pass.
110
+ function resolveInput(option) {
111
+ if (!option) { return null; }
112
+ if (typeof option === 'string') { return document.querySelector(option); }
113
+ return option.jquery ? option[0] || null : option;
114
+ }
99
115
 
100
- // filter modifying
101
- let main_btn_html = '<a href="#" class="btn_timerange">Set range</a>';
102
- $this.find('label').addClass('datetime_preset_filter_label').append(main_btn_html);
116
+ function fieldInputs(el) {
117
+ return el.querySelectorAll('input:not([type="hidden"]):not([type="submit"])');
118
+ }
103
119
 
104
- // helper
105
- function fillInputs(start, end) {
106
- gteq_input.val(formatDate(start, el_opts));
107
- if (el_opts.date_to_human_readable) {
108
- end.setTime(end.getTime() - 1000);
109
- }
120
+ // A wrapper holding both inputs (a date_range filter) uses its first and
121
+ // last. A Formtastic .datetime_preset_pair is two wrappers with one input
122
+ // each, so the "to" input lives in the next wrapper. Only that class looks
123
+ // there: any other element must not write into an unrelated next field.
124
+ function detectInputs(el, options) {
125
+ var inputs = fieldInputs(el);
126
+ var gteq = inputs[0];
127
+ var lteq = inputs[inputs.length - 1];
128
+ var next = el.nextElementSibling;
129
+ // A lone pair input with no partner gets only the start, not both ends.
130
+ if (inputs.length < 2 && el.classList.contains('datetime_preset_pair')) {
131
+ lteq = (next && fieldInputs(next)[0]) || null;
132
+ }
133
+ return [resolveInput(options.gteq_input) || gteq, resolveInput(options.lteq_input) || lteq];
134
+ }
110
135
 
111
- lteq_input.val(formatDate(end, el_opts));
112
- }
136
+ var closeOpenMenu = function () {};
137
+
138
+ function menuItems(opts) {
139
+ var items = PRESETS.map(function (preset) {
140
+ return { key: preset.key, className: 'btn_' + preset.key, title: preset.title, range: preset.range };
141
+ });
142
+ opts.add_range.forEach(function (range, i) {
143
+ items.push({ key: 'custom_' + i, className: 'btn_date_range_' + i, title: range.title, range: function () {
144
+ return [day(range.start, 0), day(range.end, 0)];
145
+ } });
146
+ });
147
+ return items;
148
+ }
149
+
150
+ function openMenu(toggle, opts, fill) {
151
+ closeOpenMenu();
152
+
153
+ var items = menuItems(opts);
154
+ var menu = document.createElement('div');
155
+ menu.className = 'block_timerange';
156
+ menu.setAttribute('data-date-range-preset-menu', '');
157
+ menu.setAttribute('role', 'menu');
158
+
159
+ items.forEach(function (item) {
160
+ var row = document.createElement('div');
161
+ var button = document.createElement('span');
162
+ button.className = item.className;
163
+ button.setAttribute('data-date-range-preset', item.key);
164
+ button.setAttribute('role', 'menuitem');
165
+ button.tabIndex = 0;
166
+ button.textContent = item.title;
167
+ row.appendChild(button);
168
+ menu.appendChild(row);
169
+ });
170
+
171
+ var box = toggle.getBoundingClientRect();
172
+ menu.style.minWidth = box.width + 'px';
173
+ menu.style.top = (box.top + window.scrollY) + 'px';
174
+ menu.style.left = (box.left + window.scrollX) + 'px';
113
175
 
114
- $this.on('click.dateRangeExtPreset', '.btn_timerange', function(e) {
115
- unbindClickEventBlockTimerange();
116
- e.stopPropagation();
176
+ function choose(target) {
177
+ var button = target.closest('[data-date-range-preset]');
178
+ if (!button) { return; }
179
+ var key = button.getAttribute('data-date-range-preset');
180
+ var item = items.filter(function (it) { return it.key === key; })[0];
181
+ closeOpenMenu();
182
+ fill(item.range(shiftedNow(opts)));
183
+ }
184
+
185
+ menu.addEventListener('click', function (e) { choose(e.target); });
186
+ menu.addEventListener('keydown', function (e) {
187
+ if (e.key === 'Enter' || e.key === ' ') {
188
+ e.preventDefault();
189
+ choose(e.target);
190
+ toggle.focus();
191
+ } else if (e.key === 'Escape') {
192
+ closeOpenMenu();
193
+ toggle.focus();
194
+ } else if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
117
195
  e.preventDefault();
196
+ var buttons = Array.prototype.slice.call(menu.querySelectorAll('[data-date-range-preset]'));
197
+ var step = e.key === 'ArrowDown' ? 1 : -1;
198
+ var at = buttons.indexOf(document.activeElement);
199
+ // With no preset focused, ArrowUp starts from the bottom.
200
+ if (at === -1) { at = step === 1 ? -1 : 0; }
201
+ buttons[(at + step + buttons.length) % buttons.length].focus();
202
+ }
203
+ });
204
+
205
+ // Tabbing out of the menu closes it. A null relatedTarget is a click on
206
+ // something unfocusable, which onOutsideClick already handles.
207
+ menu.addEventListener('focusout', function (e) {
208
+ if (e.relatedTarget && !menu.contains(e.relatedTarget)) { closeOpenMenu(); }
209
+ });
210
+
211
+ // No stopPropagation: this listener only watches for a click that should
212
+ // close the menu. Active Admin delegates Clear Filters and the has_many
213
+ // buttons from <document>, so swallowing the event would break them.
214
+ function onOutsideClick(e) {
215
+ if (!menu.contains(e.target)) { closeOpenMenu(); }
216
+ }
217
+
218
+ closeOpenMenu = function () {
219
+ menu.remove();
220
+ document.body.removeEventListener('click', onOutsideClick);
221
+ toggle.setAttribute('aria-expanded', 'false');
222
+ closeOpenMenu = function () {};
223
+ };
224
+
225
+ // Append and bind in the same tick, so the presets are live as soon as
226
+ // the menu is in the document.
227
+ document.body.appendChild(menu);
228
+ document.body.addEventListener('click', onOutsideClick);
229
+
230
+ // A link at the right edge of a sidebar would push the menu off screen.
231
+ var overflow = menu.getBoundingClientRect().right - document.documentElement.clientWidth;
232
+ if (overflow > 0) { menu.style.left = Math.max(0, box.left + window.scrollX - overflow) + 'px'; }
233
+ toggle.setAttribute('aria-expanded', 'true');
234
+
235
+ // The menu sits at the end of <body>, out of the tab order near the link.
236
+ var first = menu.querySelector('[data-date-range-preset]');
237
+ if (first) { first.focus(); }
238
+ }
239
+
240
+ // Read at click time: on Active Admin 4 the module, and so the auto-init,
241
+ // runs before a host module that imports it can set defaults.
242
+ function currentOptions(el, options) {
243
+ // api.defaults, so a host that replaces the whole object is still heard.
244
+ var opts = Object.assign({}, api.defaults, options);
245
+ opts.add_range = opts.add_range || [];
246
+
247
+ // The attribute is authoritative in both directions when present.
248
+ var showTime = el.getAttribute('data-show-time');
249
+ if (showTime !== null) { opts.show_time = showTime === 'true'; }
250
+ return opts;
251
+ }
252
+
253
+ function initElement(el, options) {
254
+ // Re-initialising replaces the wiring instead of adding to it, so a host
255
+ // call with options after the auto-init wins. The listener lives on the
256
+ // link, so dropping the old link drops the old wiring with it.
257
+ el.querySelectorAll('[data-date-range-preset-toggle]').forEach(function (link) { link.remove(); });
258
+
259
+ var inputs = detectInputs(el, options);
260
+ var gteq = inputs[0];
261
+ var lteq = inputs[1];
262
+
263
+ var toggle = document.createElement('a');
264
+ toggle.href = '#';
265
+ toggle.className = 'btn_timerange';
266
+ toggle.textContent = 'Set range';
267
+ toggle.setAttribute('data-date-range-preset-toggle', '');
268
+ toggle.setAttribute('aria-haspopup', 'menu');
269
+ toggle.setAttribute('aria-expanded', 'false');
270
+
271
+ var label = el.querySelector('label');
272
+ if (label) {
273
+ label.classList.add('datetime_preset_filter_label');
274
+ label.appendChild(toggle);
275
+ } else {
276
+ el.insertBefore(toggle, el.firstChild);
277
+ }
118
278
 
119
- let additional_items_html = '';
120
- opts.add_range.forEach(function(el, i) {
121
- return additional_items_html += '<div><span class="btn_date_range_' + i + '">' + el['title'] + '</span></div>';
122
- });
123
-
124
- // Bind in the same tick the popup is appended. Active Admin 3 ships
125
- // jQuery 3, which rebuilt .ready() on top of a Deferred whose .then
126
- // schedules through setTimeout, so handlers attached inside it landed
127
- // a macrotask late and the popup was on screen but inert until then.
128
- // On a non-document collection the method is deprecated anyway.
129
- let container = $('<div style="min-width: '+e.target.offsetWidth+'px; top: '+(e.target.offsetTop)+'px; left: '+(e.target.offsetLeft)+'px" class="block_timerange">' +
130
- '<div><span class="btn_today">Today</span></div>' +
131
- '<div><span class="btn_yesterday">Yesterday</span></div>' +
132
- '<div><span class="btn_week">This Week</span></div>' +
133
- '<div><span class="btn_month">This Month</span></div>' +
134
- '<div><span class="btn_last_week">Last Week</span></div>' +
135
- '<div><span class="btn_last_month">Last Month</span></div>' +
136
- additional_items_html +
137
- '</div>'
138
- ).appendTo('body');
139
-
140
- // additional ranges
141
- opts.add_range.forEach(function(el, i) {
142
- container.on('click.CalendarRangeSet', '.btn_date_range_' + i, function(e) {
143
- unbindClickEventBlockTimerange();
144
- let start = new Date(el['start'].getFullYear(), el['start'].getMonth(), el['start'].getDate());
145
- let end = new Date(el['end'].getFullYear(), el['end'].getMonth(), el['end'].getDate());
146
- fillInputs(start, end)
147
- });
148
- });
149
-
150
- // Today
151
- container.on('click.CalendarRangeSet', '.btn_today', function(e) {
152
- unbindClickEventBlockTimerange();
153
- let start = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate());
154
- let end = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate() + 1);
155
- fillInputs(start, end);
156
- });
157
-
158
- // Yesterday
159
- container.on('click.CalendarRangeSet', '.btn_yesterday', function(e) {
160
- unbindClickEventBlockTimerange();
161
- let start = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate() - 1);
162
- let end = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate());
163
- fillInputs(start, end);
164
- });
165
-
166
- // Week
167
- container.on('click.CalendarRangeSet', '.btn_week', function(e) {
168
- unbindClickEventBlockTimerange();
169
- let start = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate() - days_since_monday(datetime));
170
- let end = new Date(start.getFullYear(), start.getMonth(), start.getDate() + 7);
171
- fillInputs(start, end);
172
- });
173
-
174
- // Month
175
- container.on('click.CalendarRangeSet', '.btn_month', function(e) {
176
- unbindClickEventBlockTimerange();
177
- let start = new Date(datetime.getFullYear(), datetime.getMonth(), 1);
178
- let end = new Date(datetime.getFullYear(), datetime.getMonth() + 1, 1);
179
- fillInputs(start, end);
180
- });
181
-
182
- // Last Week
183
- container.on('click.CalendarRangeSet', '.btn_last_week', function(e) {
184
- unbindClickEventBlockTimerange();
185
- let end = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate() - days_since_monday(datetime));
186
- let start = new Date(end.getFullYear(), end.getMonth(), end.getDate() - 7);
187
- fillInputs(start, end);
188
- });
189
-
190
- // Last Month
191
- container.on('click.CalendarRangeSet', '.btn_last_month', function(e) {
192
- unbindClickEventBlockTimerange();
193
- let end = new Date(datetime.getFullYear(), datetime.getMonth(), 1);
194
- let start = new Date(end.getFullYear(), end.getMonth() - 1, 1);
195
- fillInputs(start, end);
196
- });
197
-
198
- // Outer
199
- // No stopPropagation here: this listener only watches for a click
200
- // that should close the popup. Active Admin delegates Clear Filters
201
- // and the has_many buttons from <document>, which is upstream of
202
- // <body>, so swallowing the event would break them for as long as
203
- // the popup is open.
204
- $('body').on('click.CalendarRangeSet', function(e) {
205
- if ($(e.target).closest('.block_timerange').length == 0) {
206
- unbindClickEventBlockTimerange();
207
- }
208
- });
279
+ toggle.addEventListener('click', function (e) {
280
+ e.preventDefault();
281
+ e.stopPropagation();
282
+ var opts = currentOptions(el, options);
283
+ openMenu(toggle, opts, function (range) {
284
+ var end = range[1];
285
+ if (opts.date_to_human_readable) { end = new Date(end.getTime() - 1000); }
286
+ if (gteq) { setValue(gteq, formatFor(gteq, range[0], opts)); }
287
+ if (lteq) { setValue(lteq, formatFor(lteq, end, opts)); }
209
288
  });
210
289
  });
211
290
  }
212
291
 
213
- $.fn.date_range_ext_preset.defaults = {
214
- // Manual global time shift, from UTC can be +/- number
215
- hours_offset: 0,
292
+ function toElements(target) {
293
+ if (typeof target === 'string') { return Array.prototype.slice.call(document.querySelectorAll(target)); }
294
+ if (target instanceof Element) { return [target]; }
295
+ return Array.prototype.slice.call(target || []);
296
+ }
216
297
 
217
- // date_to_human_readable = true, then "date_to" consider as including full day without last second
218
- // For example Today will be:
219
- // true
220
- // 2015-06-10 - 2015-06-10
221
- // 2015-06-10 00:00:00 - 2015-06-10 23:59:59
222
- // false
223
- // 2015-06-10 - 2015-06-11
224
- // 2015-06-10 00:00:00 - 2015-06-11 00:00:00
225
- date_to_human_readable: false,
298
+ // target: a CSS selector, an Element, or a list of Elements.
299
+ function init(target, options) {
300
+ var elements = toElements(target);
301
+ elements.forEach(function (el) { initElement(el, options || {}); });
302
+ return elements;
303
+ }
226
304
 
227
- // Display time or not: 2015-06-10 vs 2015-06-10 00:00:00
228
- show_time: false,
305
+ var api = { defaults: defaults, init: init };
306
+ window.ActiveAdminDateRangePreset = api;
229
307
 
230
- // Array of addition ranges
231
- // example:
232
- // {
233
- // title: 'Last 30 days',
234
- // start: new Date().setDate((new Date()).getDate() - 30)
235
- // end: new Date()
236
- // }
237
- add_range: []
308
+ function autoInit() {
309
+ init('.datetime_preset_pair');
238
310
  }
239
- });
240
311
 
241
- // jQuery 3 removed $(document).on('ready'), so this must stay $(fn).
242
- $(function() {
243
- // Init in forms
244
- $('.datetime_preset_pair').date_range_ext_preset();
245
- });
312
+ if (document.readyState === 'loading') {
313
+ document.addEventListener('DOMContentLoaded', autoInit);
314
+ } else {
315
+ autoInit();
316
+ }
317
+ })();
@@ -0,0 +1,63 @@
1
+ /* Plain CSS: Sprockets serves it to Active Admin 3 and a Tailwind entry can
2
+ @import it on Active Admin 4. Dark mode follows Active Admin 4's .dark class. */
3
+
4
+ form label.datetime_preset_filter_label .btn_timerange {
5
+ float: right;
6
+ margin: -2px 8px 0 0;
7
+ text-decoration: none;
8
+ border-bottom: 1px dashed;
9
+ line-height: 1.4em;
10
+ }
11
+
12
+ form label.datetime_preset_filter_label .btn_timerange:hover {
13
+ border-bottom: 0 none;
14
+ }
15
+
16
+ /* A form pair gets Active Admin's full label column, wide enough that the
17
+ float above parks the link far from the inputs it drives. Put it on its own
18
+ line under the label text; `display: table` keeps it shrink-to-fit. Sidebar
19
+ filters are divs, not lis, and keep the float. */
20
+ li.datetime_preset_pair > label.datetime_preset_filter_label .btn_timerange {
21
+ float: none;
22
+ display: table;
23
+ margin: 2px 0 0 0;
24
+ }
25
+
26
+ .block_timerange {
27
+ position: absolute;
28
+ z-index: 50;
29
+ display: block;
30
+ border: 1px solid #000;
31
+ padding: 5px 10px;
32
+ text-align: center;
33
+ background-color: #f4f4f4;
34
+ }
35
+
36
+ .block_timerange > div {
37
+ margin-top: 10px;
38
+ }
39
+
40
+ .block_timerange > div:last-child {
41
+ margin-bottom: 10px;
42
+ }
43
+
44
+ .block_timerange > div span {
45
+ color: #2e86cc;
46
+ cursor: pointer;
47
+ text-decoration: none;
48
+ font-size: 14px;
49
+ border-bottom: 1px dashed;
50
+ }
51
+
52
+ .block_timerange > div span:hover {
53
+ border-bottom: 0 none;
54
+ }
55
+
56
+ .block_timerange:where(.dark, .dark *) {
57
+ border-color: #4b5563;
58
+ background-color: #1f2937;
59
+ }
60
+
61
+ .block_timerange:where(.dark, .dark *) > div span {
62
+ color: #60a5fa;
63
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin_date_range_preset
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gena M.
@@ -13,16 +13,22 @@ dependencies:
13
13
  name: activeadmin
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
18
  version: '3.2'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 5.0.0.a
19
22
  type: :runtime
20
23
  prerelease: false
21
24
  version_requirements: !ruby/object:Gem::Requirement
22
25
  requirements:
23
- - - "~>"
26
+ - - ">="
24
27
  - !ruby/object:Gem::Version
25
28
  version: '3.2'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: 5.0.0.a
26
32
  - !ruby/object:Gem::Dependency
27
33
  name: railties
28
34
  requirement: !ruby/object:Gem::Requirement
@@ -61,10 +67,11 @@ extra_rdoc_files: []
61
67
  files:
62
68
  - LICENSE.txt
63
69
  - README.md
70
+ - config/importmap.rb
64
71
  - lib/active_admin_date_range_preset.rb
65
72
  - lib/active_admin_date_range_preset/version.rb
66
73
  - vendor/assets/javascripts/active_admin_date_range_preset.js
67
- - vendor/assets/stylesheets/active_admin_date_range_preset.scss
74
+ - vendor/assets/stylesheets/active_admin_date_range_preset.css
68
75
  homepage: https://github.com/workgena/active_admin_date_range_preset
69
76
  licenses:
70
77
  - MIT
@@ -1,50 +0,0 @@
1
- form label.datetime_preset_filter_label .btn_timerange {
2
- float: right;
3
- margin: -2px 8px 0 0;
4
- text-decoration: none;
5
- border-bottom: 1px dashed;
6
- line-height: 1.4em;
7
- &:hover {
8
- border-bottom: 0 none;
9
- }
10
- }
11
-
12
- // A form pair gets Active Admin's full label column, which is wide enough
13
- // that the float above parks the link at the far right of it, away from the
14
- // inputs it drives. Put it on its own line under the label text instead.
15
- // `display: table` keeps it shrink-to-fit, so the dashed underline stays
16
- // under the words rather than stretching the whole column.
17
- //
18
- // The sidebar filter keeps the float: there the label and the link share a
19
- // narrow panel and right alignment is what the plugin has always shown.
20
- .datetime_preset_pair > label.datetime_preset_filter_label .btn_timerange {
21
- float: none;
22
- display: table;
23
- margin: 2px 0 0 0;
24
- }
25
-
26
- .block_timerange {
27
- position: absolute;
28
- display: block;
29
- border: 1px solid #000;
30
- padding: 5px 10px 5px 10px;
31
- text-align: center;
32
- background-color: #f4f4f4;
33
- >div {
34
- margin-top: 10px;
35
- &:last-child {
36
- margin-bottom: 10px;
37
- }
38
- span {
39
- color: #2e86cc;
40
- cursor: pointer;
41
- text-decoration: none;
42
- font-size: 14px;
43
- border-bottom: 1px dashed;
44
- &:hover {
45
- border-bottom: 0 none;
46
- }
47
- }
48
- }
49
- }
50
-