active_admin_datetimepicker 2.1.0 → 2.3.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 +4 -4
- data/README.md +64 -0
- data/app/assets/stylesheets/active_admin_datetimepicker.scss +156 -0
- data/config/initializers/active_admin_datetimepicker.rb +11 -2
- data/lib/active_admin_datetimepicker/base.rb +82 -4
- data/lib/active_admin_datetimepicker/inputs/filters/date_time_range_input.rb +33 -4
- data/lib/active_admin_datetimepicker/version.rb +1 -1
- data/lib/active_admin_datetimepicker.rb +11 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1e644517745842200b47507077f8a036c9f546cbdf520cdf032f68b3b3fa3526
|
|
4
|
+
data.tar.gz: c93eb424cc31fd240a759d763db274fbdaa13e737d02026957715a1c03701c13
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f54ad3394010f7dcdc6ea7f148bc11ec299b71171394c933d36949234736513f4bcdf58e1c0fec6f4d07e3bf23b04f85f65bdac72d3083a70b78dafe8f6bee3
|
|
7
|
+
data.tar.gz: e003821ff3320c6ead3d802cab1787f9bf758ea9179c3c48d385a9592d2051d3d8c64cc7456cbe7a803ff686da06286c253812b5383d4fd88b00ac5cb2a98a00
|
data/README.md
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
Adds XDSoft's DateTime picker as a `date_time_picker` input for forms, and `date_time_range` for filters.
|
|
10
10
|
|
|
11
|
+
On ActiveAdmin 4 the same inputs render the browser's native date and time controls instead; see [ActiveAdmin 4](#activeadmin-4).
|
|
12
|
+
|
|
11
13
|

|
|
12
14
|
|
|
13
15
|
## Installation
|
|
@@ -89,6 +91,40 @@ The `date_time_picker` input accepts many of the options available to the standa
|
|
|
89
91
|
end
|
|
90
92
|
```
|
|
91
93
|
|
|
94
|
+
## ActiveAdmin 4
|
|
95
|
+
|
|
96
|
+
ActiveAdmin 4 ships without jQuery and Sprockets, so on ActiveAdmin 4 the gem
|
|
97
|
+
does not load the XDSoft picker. The `date_time_picker` input and the
|
|
98
|
+
`date_time_range` filter render native `<input type="datetime-local">` fields
|
|
99
|
+
(`type="date"` for a `date` column), styled by ActiveAdmin itself. There is no
|
|
100
|
+
JavaScript or CSS to install: skip the Sprockets and NPM steps above.
|
|
101
|
+
|
|
102
|
+
Values use the HTML format, `YYYY-MM-DDTHH:MM` (`YYYY-MM-DD` for date fields).
|
|
103
|
+
`ActiveAdminDatetimepicker::Base.format` applies to ActiveAdmin 3 only.
|
|
104
|
+
|
|
105
|
+
Only these `datepicker_options` (and `default_datetime_picker_options`) have a
|
|
106
|
+
native equivalent and are applied on ActiveAdmin 4. Everything else is ignored.
|
|
107
|
+
|
|
108
|
+
| Option | Native attribute |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| `min_date`, `min_date_time` | `min` |
|
|
111
|
+
| `max_date`, `max_date_time` | `max` |
|
|
112
|
+
| `step` (minutes) | `step` (seconds, `datetime-local` only) |
|
|
113
|
+
|
|
114
|
+
`min`/`max` must be absolute dates (a `Date`, `Time` or a string like
|
|
115
|
+
`"2024-01-31"`); relative values such as `"+3D"` are dropped. An explicit
|
|
116
|
+
`input_html: { min: ... }` wins over the mapped value.
|
|
117
|
+
|
|
118
|
+
Unlike the XDSoft picker, the browser enforces `min`, `max` and `step` when the
|
|
119
|
+
form is submitted. A stored value outside the range, or off the step (10:07 with
|
|
120
|
+
`step: 15`), blocks the save until it is changed.
|
|
121
|
+
|
|
122
|
+
The markup carries `data-*` hooks for tests and other plugins:
|
|
123
|
+
|
|
124
|
+
- every input: `data-datetimepicker-input`
|
|
125
|
+
- the filter wrapper: `data-datetimepicker-range` (on ActiveAdmin 4 it also keeps the `filter_date_time_range` class)
|
|
126
|
+
- the filter inputs: `data-datetimepicker-range-input="from"` and `"to"`
|
|
127
|
+
|
|
92
128
|
## Override behaviour in initializer
|
|
93
129
|
|
|
94
130
|
```ruby
|
|
@@ -118,6 +154,34 @@ ActiveAdminDatetimepicker::Base.format = "%d/%m/%Y %H:%M" # Ruby format
|
|
|
118
154
|
|
|
119
155
|
See [the datetimepicker documentation for more details](http://xdsoft.net/jqplugins/datetimepicker/).
|
|
120
156
|
|
|
157
|
+
## Theming
|
|
158
|
+
|
|
159
|
+
### Accent color
|
|
160
|
+
|
|
161
|
+
The upstream XDSoft stylesheet hardcodes a bright blue (`#33aaff`) on the
|
|
162
|
+
selected/current day, the current time slot and "today". This gem exposes that
|
|
163
|
+
color as a single SCSS variable so you can recolor the whole picker without
|
|
164
|
+
`!important` overrides. Set it **before** importing the gem; the default keeps
|
|
165
|
+
the original blue, so existing apps are unaffected:
|
|
166
|
+
|
|
167
|
+
```scss
|
|
168
|
+
$aa-datetimepicker-accent-color: #38678b; // your brand color
|
|
169
|
+
@import "active_admin_datetimepicker";
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Dark mode
|
|
173
|
+
|
|
174
|
+
The picker follows the host's dark theme using the same triggers as
|
|
175
|
+
[`active_admin_theme`](https://github.com/activeadmin-plugins/active_admin_theme):
|
|
176
|
+
the OS `prefers-color-scheme: dark` preference and an explicit
|
|
177
|
+
`html[data-theme="dark"]`. Under either, the picker adopts XDSoft's built-in
|
|
178
|
+
`.xdsoft_dark` skin (its orange current/today, dark surfaces). A page pinned
|
|
179
|
+
with `html[data-theme="light"]` always stays light. No configuration is needed;
|
|
180
|
+
it works out of the box once the gem's stylesheet is imported.
|
|
181
|
+
|
|
182
|
+
Note: in dark mode the current/today cells use XDSoft's built-in dark skin
|
|
183
|
+
colors, not `$aa-datetimepicker-accent-color`.
|
|
184
|
+
|
|
121
185
|
|
|
122
186
|
## Contributing
|
|
123
187
|
|
|
@@ -45,3 +45,159 @@ div.xdsoft_datetimepicker {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
|
|
49
|
+
// --- Configurable accent color ---------------------------------------------
|
|
50
|
+
// Upstream xdsoft hardcodes a bright blue (#33aaff) on the selected/current day,
|
|
51
|
+
// the current time slot and "today". There is no vendor variable for it, so host
|
|
52
|
+
// apps used to resort to !important overrides. Expose it two ways:
|
|
53
|
+
//
|
|
54
|
+
// * `$aa-datetimepicker-accent-color` — a compile-time SCSS variable, set it
|
|
55
|
+
// before importing this gem.
|
|
56
|
+
// * `--aa-datetimepicker-accent` — a runtime CSS custom property. Prefer this
|
|
57
|
+
// in sprockets apps: a SCSS variable set in the host manifest does NOT reach
|
|
58
|
+
// this gem's partial across a sprockets `@import` (separate compilation
|
|
59
|
+
// scope), whereas a CSS custom property flows through the cascade regardless.
|
|
60
|
+
// Set it on `:root` (or `html[data-theme=...]` for per-mode values).
|
|
61
|
+
//
|
|
62
|
+
// Both default to the original blue, so existing apps see no change unless they
|
|
63
|
+
// opt in. The CSS property wins when set; otherwise it falls back to the SCSS
|
|
64
|
+
// variable's value.
|
|
65
|
+
$aa-datetimepicker-accent-color: #33aaff !default;
|
|
66
|
+
$-aa-dtp-accent: var(--aa-datetimepicker-accent, #{$aa-datetimepicker-accent-color});
|
|
67
|
+
|
|
68
|
+
// Dark-mode surface/text/border, same idea as the accent: runtime CSS custom
|
|
69
|
+
// properties so a themed host can bind the picker to its own dark palette
|
|
70
|
+
// (e.g. `--aa-datetimepicker-surface: var(--aa-surface)`), with fallbacks that
|
|
71
|
+
// are a soft dark rather than pure black so the picker is usable out of the box.
|
|
72
|
+
$-aa-dtp-surface: var(--aa-datetimepicker-surface, #1f242a);
|
|
73
|
+
$-aa-dtp-surface-2: var(--aa-datetimepicker-surface-2, #262c33);
|
|
74
|
+
$-aa-dtp-text: var(--aa-datetimepicker-text, #cfd3d8);
|
|
75
|
+
$-aa-dtp-text-muted: var(--aa-datetimepicker-text-muted, #8a9099);
|
|
76
|
+
$-aa-dtp-border: var(--aa-datetimepicker-border, #3a4048);
|
|
77
|
+
$-aa-dtp-hover: var(--aa-datetimepicker-hover, #2e353d);
|
|
78
|
+
|
|
79
|
+
div.xdsoft_datetimepicker {
|
|
80
|
+
.xdsoft_label > .xdsoft_select > div > .xdsoft_option.xdsoft_current,
|
|
81
|
+
.xdsoft_calendar td.xdsoft_current,
|
|
82
|
+
.xdsoft_timepicker .xdsoft_time_box > div > div.xdsoft_current {
|
|
83
|
+
background: $-aa-dtp-accent;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// "today" is a text color, not a fill
|
|
87
|
+
.xdsoft_calendar td.xdsoft_today {
|
|
88
|
+
color: $-aa-dtp-accent;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// When today is also the selected cell, its accent fill needs light text
|
|
92
|
+
// (otherwise accent-on-accent hides the number).
|
|
93
|
+
.xdsoft_calendar td.xdsoft_today.xdsoft_current {
|
|
94
|
+
color: #fff;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.xdsoft_calendar td.xdsoft_current.xdsoft_disabled:hover,
|
|
98
|
+
.xdsoft_timepicker .xdsoft_time_box > div > div.xdsoft_current.xdsoft_disabled:hover {
|
|
99
|
+
background: $-aa-dtp-accent !important;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
// --- Dark mode -------------------------------------------------------------
|
|
105
|
+
// Follow the host's dark theme using the same triggers active_admin_theme uses:
|
|
106
|
+
// the OS `prefers-color-scheme` preference (unless the page is pinned light) and
|
|
107
|
+
// an explicit `html[data-theme="dark"]`. Rather than invent new dark colors we
|
|
108
|
+
// reuse xdsoft's own built-in `.xdsoft_dark` skin, re-scoped onto
|
|
109
|
+
// `.xdsoft_datetimepicker` directly (the picker is appended to <body>, so it can
|
|
110
|
+
// never carry the `.xdsoft_dark` class on its own). A `[data-theme="light"]`
|
|
111
|
+
// page always stays light.
|
|
112
|
+
@mixin aa-datetimepicker-dark {
|
|
113
|
+
.xdsoft_datetimepicker {
|
|
114
|
+
box-shadow: 0 5px 15px -5px rgba(0, 0, 0, 0.6);
|
|
115
|
+
background: $-aa-dtp-surface;
|
|
116
|
+
border: 1px solid $-aa-dtp-border;
|
|
117
|
+
color: $-aa-dtp-text;
|
|
118
|
+
|
|
119
|
+
.xdsoft_timepicker .xdsoft_time_box {
|
|
120
|
+
border: 1px solid $-aa-dtp-border;
|
|
121
|
+
}
|
|
122
|
+
.xdsoft_timepicker .xdsoft_time_box > div > div {
|
|
123
|
+
background: $-aa-dtp-surface;
|
|
124
|
+
border-top: 1px solid $-aa-dtp-border;
|
|
125
|
+
color: $-aa-dtp-text;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.xdsoft_label {
|
|
129
|
+
background-color: $-aa-dtp-surface;
|
|
130
|
+
}
|
|
131
|
+
.xdsoft_label > .xdsoft_select {
|
|
132
|
+
border: 1px solid $-aa-dtp-border;
|
|
133
|
+
background: $-aa-dtp-surface;
|
|
134
|
+
}
|
|
135
|
+
.xdsoft_label > .xdsoft_select > div > .xdsoft_option:hover {
|
|
136
|
+
color: $-aa-dtp-text;
|
|
137
|
+
background: $-aa-dtp-hover;
|
|
138
|
+
}
|
|
139
|
+
.xdsoft_label > .xdsoft_select > div > .xdsoft_option.xdsoft_current {
|
|
140
|
+
background: $-aa-dtp-accent;
|
|
141
|
+
box-shadow: none;
|
|
142
|
+
color: #fff;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.xdsoft_calendar td,
|
|
146
|
+
.xdsoft_calendar th {
|
|
147
|
+
background: $-aa-dtp-surface;
|
|
148
|
+
border: 1px solid $-aa-dtp-border;
|
|
149
|
+
color: $-aa-dtp-text;
|
|
150
|
+
}
|
|
151
|
+
.xdsoft_calendar th {
|
|
152
|
+
background: $-aa-dtp-surface-2;
|
|
153
|
+
color: $-aa-dtp-text-muted;
|
|
154
|
+
}
|
|
155
|
+
.xdsoft_calendar td.xdsoft_other_month,
|
|
156
|
+
.xdsoft_calendar td.xdsoft_disabled {
|
|
157
|
+
color: $-aa-dtp-text-muted;
|
|
158
|
+
}
|
|
159
|
+
.xdsoft_calendar td.xdsoft_today {
|
|
160
|
+
color: $-aa-dtp-accent;
|
|
161
|
+
}
|
|
162
|
+
.xdsoft_calendar td.xdsoft_default,
|
|
163
|
+
.xdsoft_calendar td.xdsoft_current,
|
|
164
|
+
.xdsoft_timepicker .xdsoft_time_box > div > div.xdsoft_current {
|
|
165
|
+
background: $-aa-dtp-accent;
|
|
166
|
+
box-shadow: none;
|
|
167
|
+
color: #fff;
|
|
168
|
+
}
|
|
169
|
+
.xdsoft_calendar td:hover:not(.xdsoft_current),
|
|
170
|
+
.xdsoft_timepicker .xdsoft_time_box > div > div:hover:not(.xdsoft_current) {
|
|
171
|
+
color: $-aa-dtp-text !important;
|
|
172
|
+
background: $-aa-dtp-hover !important;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.xdsoft_scrollbar > .xdsoft_scroller {
|
|
176
|
+
background: $-aa-dtp-border !important;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Month prev/next, the "today" home button and the time-column up/down
|
|
180
|
+
// scrollers are a dark PNG sprite with no vendor variable — on the dark
|
|
181
|
+
// surface they disappear. Invert so the arrows read as light icons. The
|
|
182
|
+
// time scrollers also carry .xdsoft_prev/.xdsoft_next, so they're covered.
|
|
183
|
+
.xdsoft_prev,
|
|
184
|
+
.xdsoft_next,
|
|
185
|
+
.xdsoft_today_button {
|
|
186
|
+
filter: invert(1);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.xdsoft_copyright {
|
|
190
|
+
color: $-aa-dtp-text-muted !important;
|
|
191
|
+
a { color: $-aa-dtp-text !important; }
|
|
192
|
+
a:hover { color: $-aa-dtp-text-muted !important; }
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// OS preference, unless the user explicitly chose light
|
|
198
|
+
@media (prefers-color-scheme: dark) {
|
|
199
|
+
html:not([data-theme="light"]) { @include aa-datetimepicker-dark; }
|
|
200
|
+
}
|
|
201
|
+
// Explicit user choice always wins
|
|
202
|
+
html[data-theme="dark"] { @include aa-datetimepicker-dark; }
|
|
203
|
+
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
# ActiveAdmin 4 submits native datetime-local values ("2024-01-31T10:00").
|
|
2
|
+
# Typed columns cast them to times; for an untyped ransacker the value stays a
|
|
3
|
+
# string, so the "T" is swapped for the space the database compares against.
|
|
4
|
+
iso_to_db = lambda do |value|
|
|
5
|
+
value.is_a?(String) ? value.sub(/\A(\d{4}-\d{2}-\d{2})T(?=\d{2}:\d{2})/, '\1 ') : value
|
|
6
|
+
end
|
|
7
|
+
|
|
1
8
|
Ransack.configure do |config|
|
|
2
9
|
config.add_predicate 'gteq_datetime_picker',
|
|
3
|
-
arel_predicate: 'gteq'
|
|
10
|
+
arel_predicate: 'gteq',
|
|
11
|
+
formatter: iso_to_db
|
|
4
12
|
|
|
5
13
|
config.add_predicate 'lteq_datetime_picker',
|
|
6
|
-
arel_predicate: 'lt'
|
|
14
|
+
arel_predicate: 'lt',
|
|
15
|
+
formatter: iso_to_db
|
|
7
16
|
end
|
|
@@ -5,6 +5,12 @@ module ActiveAdminDatetimepicker
|
|
|
5
5
|
mattr_accessor :format
|
|
6
6
|
@@format = '%Y-%m-%d %H:%M'
|
|
7
7
|
|
|
8
|
+
# Value formats the browser accepts for native inputs (HTML spec), used on ActiveAdmin 4.
|
|
9
|
+
NATIVE_FORMATS = {
|
|
10
|
+
'datetime-local' => '%Y-%m-%dT%H:%M',
|
|
11
|
+
'date' => '%Y-%m-%d'
|
|
12
|
+
}.freeze
|
|
13
|
+
|
|
8
14
|
def html_class
|
|
9
15
|
'date-time-picker'
|
|
10
16
|
end
|
|
@@ -17,9 +23,14 @@ module ActiveAdminDatetimepicker
|
|
|
17
23
|
super().tap do |options|
|
|
18
24
|
options[:class] = [self.options[:class], html_class].compact.join(' ')
|
|
19
25
|
options[:data] ||= input_html_data
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
if ActiveAdminDatetimepicker.aa_v4?
|
|
27
|
+
native_input_html_options(options, input_name)
|
|
28
|
+
else
|
|
29
|
+
options[:data].merge!(datepicker_options: datetime_picker_options)
|
|
30
|
+
options[:value] = input_value(input_name)
|
|
31
|
+
options[:maxlength] = 19
|
|
32
|
+
end
|
|
33
|
+
options[:data].merge!(datetimepicker_input: true)
|
|
23
34
|
options[:placeholder] = placeholder unless placeholder.nil?
|
|
24
35
|
end
|
|
25
36
|
end
|
|
@@ -45,8 +56,76 @@ module ActiveAdminDatetimepicker
|
|
|
45
56
|
end
|
|
46
57
|
end
|
|
47
58
|
|
|
59
|
+
# A date column gets a date-only control; datetime columns and
|
|
60
|
+
# ransackers without a column get a date and time control.
|
|
61
|
+
def native_input_type
|
|
62
|
+
date_column? ? 'date' : 'datetime-local'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Covers DB columns and attributes declared with the Attributes API.
|
|
66
|
+
def date_column?
|
|
67
|
+
return column.type == :date if column&.type
|
|
68
|
+
|
|
69
|
+
object.class.respond_to?(:attribute_types) && object.class.attribute_types[method.to_s]&.type == :date
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Stored strings are parsed as leniently as input_value does on ActiveAdmin 3,
|
|
73
|
+
# so a non-ISO value is not blanked and wiped on save.
|
|
74
|
+
def native_input_value(input_name = nil)
|
|
75
|
+
format_native(object.public_send(input_name || method), strict: false)
|
|
76
|
+
end
|
|
77
|
+
|
|
48
78
|
protected
|
|
49
79
|
|
|
80
|
+
def native_input_html_options(options, input_name)
|
|
81
|
+
options[:type] = native_input_type
|
|
82
|
+
options[:value] = native_input_value(input_name)
|
|
83
|
+
options.delete(:maxlength)
|
|
84
|
+
options.delete(:size)
|
|
85
|
+
native_picker_attributes.each { |name, value| options[name] = value unless options.key?(name) }
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Only the xdsoft options with a native equivalent are mapped; the rest
|
|
89
|
+
# configure the jQuery widget, which ActiveAdmin 4 pages do not load.
|
|
90
|
+
def native_picker_attributes
|
|
91
|
+
picker_options = datetime_picker_options.transform_keys { |k| k.to_s.camelcase(:lower) }
|
|
92
|
+
attributes = {}
|
|
93
|
+
min = format_native(picker_options['minDateTime']) || native_day_bound(picker_options['minDate'], '00:00')
|
|
94
|
+
max = format_native(picker_options['maxDateTime']) || native_day_bound(picker_options['maxDate'], '23:59')
|
|
95
|
+
attributes[:min] = min if min
|
|
96
|
+
attributes[:max] = max if max
|
|
97
|
+
step = picker_options['step'].to_i
|
|
98
|
+
# xdsoft counts the step in minutes, the HTML attribute in seconds.
|
|
99
|
+
attributes[:step] = step * 60 if step > 0 && native_input_type == 'datetime-local'
|
|
100
|
+
attributes
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# xdsoft's minDate and maxDate are whole days, so a datetime-local bound
|
|
104
|
+
# starts at 00:00 of the first day and ends at 23:59 of the last.
|
|
105
|
+
def native_day_bound(value, time)
|
|
106
|
+
bound = format_native(value)
|
|
107
|
+
bound && native_input_type == 'datetime-local' ? "#{bound[0, 10]}T#{time}" : bound
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def format_native(value, strict: true)
|
|
111
|
+
value = value.call if value.respond_to?(:call)
|
|
112
|
+
return nil if value.blank?
|
|
113
|
+
if value.respond_to?(:strftime)
|
|
114
|
+
# Times are shown in the app's zone, like the record values.
|
|
115
|
+
value = value.in_time_zone if value.is_a?(Time) || value.is_a?(DateTime)
|
|
116
|
+
else
|
|
117
|
+
# Relative xdsoft values such as "+3D" have no native equivalent.
|
|
118
|
+
return nil if strict && !value.to_s.match?(%r{\A\d{4}[-/]\d{1,2}[-/]\d{1,2}})
|
|
119
|
+
# A string with an offset names an instant; one without is local wall-clock time.
|
|
120
|
+
offset = Date._parse(value.to_s).key?(:offset)
|
|
121
|
+
value = DateTime.parse(value.to_s)
|
|
122
|
+
value = value.in_time_zone if offset
|
|
123
|
+
end
|
|
124
|
+
value.strftime(NATIVE_FORMATS.fetch(native_input_type))
|
|
125
|
+
rescue ArgumentError
|
|
126
|
+
nil
|
|
127
|
+
end
|
|
128
|
+
|
|
50
129
|
def _default_datetime_picker_options
|
|
51
130
|
res = default_datetime_picker_options.map do |k, v|
|
|
52
131
|
if v.respond_to?(:call) || v.is_a?(Proc)
|
|
@@ -59,4 +138,3 @@ module ActiveAdminDatetimepicker
|
|
|
59
138
|
end
|
|
60
139
|
end
|
|
61
140
|
end
|
|
62
|
-
|
|
@@ -5,6 +5,29 @@ module ActiveAdmin
|
|
|
5
5
|
include Base
|
|
6
6
|
include ActiveAdminDatetimepicker::Base
|
|
7
7
|
|
|
8
|
+
# ActiveAdmin 4's DateRangeInput renders date_field pairs, which drop
|
|
9
|
+
# the time; this keeps its markup but emits native datetime fields.
|
|
10
|
+
def to_html
|
|
11
|
+
return super unless ActiveAdminDatetimepicker.aa_v4?
|
|
12
|
+
|
|
13
|
+
input_wrapping do
|
|
14
|
+
[ label_html,
|
|
15
|
+
'<div class="filters-form-input-group">',
|
|
16
|
+
builder.text_field(gt_input_name, input_html_options_for(gt_input_name, gt_input_placeholder)),
|
|
17
|
+
builder.text_field(lt_input_name, input_html_options_for(lt_input_name, lt_input_placeholder)),
|
|
18
|
+
'</div>'
|
|
19
|
+
].join("\n").html_safe
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def wrapper_html_options
|
|
24
|
+
super.tap do |options|
|
|
25
|
+
# ActiveAdmin 4 dropped the filter_<as> class that active_admin_date_range_preset looks for.
|
|
26
|
+
options[:class] = "#{options[:class]} filter_date_time_range" if ActiveAdminDatetimepicker.aa_v4?
|
|
27
|
+
options[:data] = (options[:data] || {}).merge(datetimepicker_range: true)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
8
31
|
def input_html_options(input_name = gt_input_name, placeholder = gt_input_placeholder)
|
|
9
32
|
super.tap do |options|
|
|
10
33
|
options[:class] = html_class
|
|
@@ -13,16 +36,22 @@ module ActiveAdmin
|
|
|
13
36
|
|
|
14
37
|
# This method is for compatibility for ActiveAdmin 2.6
|
|
15
38
|
def input_html_options_for(input_name, placeholder)
|
|
16
|
-
|
|
17
|
-
|
|
39
|
+
options = super
|
|
40
|
+
value = ActiveAdminDatetimepicker.aa_v4? ? native_input_value(input_name) : input_value(input_name)
|
|
41
|
+
bound = input_name == gt_input_name ? 'from' : 'to'
|
|
42
|
+
options.merge(
|
|
43
|
+
placeholder: placeholder,
|
|
44
|
+
value: value,
|
|
45
|
+
data: (options[:data] || {}).merge(datetimepicker_range_input: bound)
|
|
46
|
+
)
|
|
18
47
|
end
|
|
19
48
|
|
|
20
49
|
def gt_input_name
|
|
21
|
-
|
|
50
|
+
date_column? ? super : "#{method}_gteq_datetime_picker"
|
|
22
51
|
end
|
|
23
52
|
|
|
24
53
|
def lt_input_name
|
|
25
|
-
|
|
54
|
+
date_column? ? super : "#{method}_lteq_datetime_picker"
|
|
26
55
|
end
|
|
27
56
|
|
|
28
57
|
end
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
require 'activeadmin'
|
|
2
|
+
|
|
3
|
+
module ActiveAdminDatetimepicker
|
|
4
|
+
# ActiveAdmin 4 drops jQuery and Sprockets, so the plugin renders native
|
|
5
|
+
# date/time inputs there instead of the xdsoft picker.
|
|
6
|
+
def self.aa_v4?
|
|
7
|
+
return @aa_v4 if defined?(@aa_v4)
|
|
8
|
+
|
|
9
|
+
@aa_v4 = Gem::Version.new(ActiveAdmin::VERSION) >= Gem::Version.new('4.0.0.beta1')
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
2
13
|
require 'active_admin_datetimepicker/version'
|
|
3
14
|
require 'active_admin_datetimepicker/base'
|
|
4
15
|
require 'active_admin_datetimepicker/inputs/date_time_picker_input'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_admin_datetimepicker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Igor Fedoronchuk
|
|
@@ -18,7 +18,7 @@ dependencies:
|
|
|
18
18
|
version: '3.0'
|
|
19
19
|
- - "<"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version:
|
|
21
|
+
version: 5.0.0.a
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -28,8 +28,9 @@ dependencies:
|
|
|
28
28
|
version: '3.0'
|
|
29
29
|
- - "<"
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
|
-
version:
|
|
32
|
-
description: Integrate jQuery xdan datetimepicker plugin to ActiveAdmin
|
|
31
|
+
version: 5.0.0.a
|
|
32
|
+
description: Integrate jQuery xdan datetimepicker plugin to ActiveAdmin 3, native
|
|
33
|
+
date and time inputs on ActiveAdmin 4
|
|
33
34
|
email:
|
|
34
35
|
- fedoronchuk@gmail.com
|
|
35
36
|
executables: []
|