Skip to content

Commit 49d8109

Browse files
author
Gena Maly
committed
Readme
1 parent cd67c5f commit 49d8109

File tree

4 files changed

+119
-2
lines changed

4 files changed

+119
-2
lines changed

README.md

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ This is how it looks like
88

99
![Step 2](/screen/step_2.jpg)
1010

11+
![Form 1](/screen/step_2_1.png)
12+
13+
![Form 2](/screen/step_2_2.png)
14+
1115
## Installation
1216

1317
Add this line to your application's Gemfile:
@@ -55,6 +59,64 @@ By default inputs are filled with date("yyyy-mm-dd"). If you need time add
5559
```data: { show_time: 'true' }```
5660

5761

62+
## Using with ActiveAdminDatetimepicker
63+
64+
If you use GEM https://github.com/activeadmin-plugins/active_admin_datetimepicker
65+
and want apply this plugin to filter-inputs for this gem you need:
66+
67+
First apply ActiveAdminDatetimepicker to any filters your need
68+
69+
```ruby
70+
filter :time_start, as: :date_time_range
71+
```
72+
73+
In active_admin.js
74+
75+
Add following lines to JavaScript
76+
77+
```javascript
78+
$(document).on('ready', function(){
79+
$('form.filter_form div.filter_date_time_range').date_range_ext_preset();
80+
});
81+
```
82+
83+
Now all you "date_time_range" inputs has button "Set rage"
84+
85+
86+
## Custom usage
87+
88+
You can assign "Set range" almost to any input-text-pair filters/forms.
89+
For example, you have complex form where input-pairs are not close to each other and not standard.
90+
91+
```javascript
92+
$(document).on('ready', function(){
93+
$('.any_jquery_selector').date_range_ext_preset({
94+
lteq_input: '.jquery_selector_to_first_input',
95+
gteq_input: '.jquery_selector_to_second_input'
96+
});
97+
});
98+
```
99+
".any_jquery_selector" is pointed to place where button "Set rage" will appear.
100+
Set lteq_input and gteq_input to point to inputs if they not near main selector.
101+
102+
103+
## Global and local settings
104+
105+
There are several settings, which can be set globally or locally.
106+
107+
Example how to set settings for only specific inputs
108+
109+
```javascript
110+
$('.any_jquery_selector').date_range_ext_preset({
111+
setting_name: "setting_value"
112+
});
113+
```
114+
Example how to set global settings. Write it before $(document).on('ready')
115+
116+
```javascript
117+
$.fn.date_range_ext_preset.defaults.setting_name = "setting_value"
118+
```
119+
58120
You can set global defaults in your active_admin.js like this:
59121

60122
```javascript
@@ -69,4 +131,59 @@ $.fn.date_range_ext_preset.defaults.date_to_human_readable = true
69131
$.fn.date_range_ext_preset.defaults.show_time = true
70132
```
71133

72-
Set dafaults before $(document).on('ready')
134+
### date_to_human_readable
135+
136+
value: true/false
137+
138+
default: false
139+
140+
This options changes second date to include full date-time of the day, like normal human thinks about time ranges.
141+
Today true : 2015-06-12 - 2015-06-12
142+
Today false: 2015-06-12 - 2015-06-13
143+
144+
When normal human say "2015-06-12" hi means "2015-06-12 23:59:59"
145+
But default behavior in programming is "2015-06-12" = "2015-06-12 00:00:00"
146+
Be careful with this options. Cause if you change it to "true" you will also need to change your server-side scripts to search "humanize-way".
147+
148+
### show_time
149+
150+
value: true/false
151+
152+
default: false
153+
154+
If true then will show date and time, usually it will be 00:00:00
155+
156+
### hours_offset
157+
158+
values: positive or negative integer
159+
160+
default: 0
161+
162+
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:
163+
164+
Example:
165+
```javascript
166+
$.fn.date_range_ext_preset.defaults.hours_offset = +3
167+
// or
168+
$.fn.date_range_ext_preset.defaults.hours_offset = -3
169+
```
170+
171+
### inject_method
172+
173+
value: 'wrap' or 'append'
174+
175+
This is how button "Set rage" will be added to DOM-tree. Play with it to choose best place.
176+
177+
178+
179+
180+
181+
182+
183+
184+
185+
186+
187+
188+
189+

lib/active_admin_date_range_preset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "activeadmin"
2-
require "active_admin_datetimepicker/version"
2+
require "active_admin_date_range_preset/version"
33

44
module ActiveAdminDateRangePreset
55
module Rails

screen/step_2_1.png

16 KB
Loading

screen/step_2_2.png

20.2 KB
Loading

0 commit comments

Comments
 (0)