active_admin_datetimepicker 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -3
- data/active_admin_datetimepicker.gemspec +26 -0
- data/lib/active_admin_datetimepicker.rb +9 -10
- data/lib/active_admin_datetimepicker/base.rb +59 -0
- data/lib/active_admin_datetimepicker/inputs/date_time_picker_input.rb +2 -23
- data/lib/active_admin_datetimepicker/inputs/filters/date_time_range_input.rb +5 -14
- data/lib/active_admin_datetimepicker/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 340225652c1b7a23d5eb2c44e24ceee530d817e3
|
4
|
+
data.tar.gz: bc69629e0bb5c3d8f96d59a147b6f4faeeb84ac1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55a56f2c56811962a4d2305ec6b8d90c28e57842b8a86e7204f517cf286ea62a47f65a8f69f7be6dbadae51335184648c4c8b79279680b6374c1b4538e70b7e9
|
7
|
+
data.tar.gz: e50bdea210d76f47a8f272d62e9855300c82a2c251166af1b2a6c4adfcbe373e4c9c6edd112d63e42e709bb2477f1bc40780f1342f8895d48f82f232350a29b6
|
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
Adds ability to use XDSoft's DateTime picker as the date_time_picker input for forms, and date_time_range for filters
|
4
4
|
|
5
|
+
|
6
|
+
![ActiveAdminDatetimepicker](https://raw.githubusercontent.com/ActiveAdminPlugins/activeadmin_datetimepicker/master/screen/screen.png "ActiveAdminDatetimepicker")
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
@@ -32,8 +35,8 @@ The `date_time_picker` input accepts many of the options available to the standa
|
|
32
35
|
|
33
36
|
```ruby
|
34
37
|
form do |f|
|
35
|
-
f.input :starts_at, as: :
|
36
|
-
f.input :ends_at, as: :
|
38
|
+
f.input :starts_at, as: :date_time_picker, datepicker_options: { min_date: "2013-10-8", max_date: "+3D" }
|
39
|
+
f.input :ends_at, as: :date_time_picker, datepicker_options: { min_date: 3.days.ago.to_date, max_date: "+1W +5D" }
|
37
40
|
end
|
38
41
|
```
|
39
42
|
|
@@ -41,6 +44,18 @@ end
|
|
41
44
|
filter :created_at, as: :date_time_range
|
42
45
|
```
|
43
46
|
|
47
|
+
|
48
|
+
## Override behaviour in initializer
|
49
|
+
```ruby
|
50
|
+
# This if for front-end javascript side
|
51
|
+
ActiveAdminDatetimepicker::Base.default_datetime_picker_options = {
|
52
|
+
defaultDate: proc { Time.current.strftime("%Y-%m-%d 00:00") }
|
53
|
+
}
|
54
|
+
# This if for backend(Ruby)
|
55
|
+
ActiveAdminDatetimepicker::Base.format = "%Y-%m-%d %H:%M:%S"
|
56
|
+
```
|
57
|
+
|
58
|
+
|
44
59
|
See [the datetimepicker documentation for more details](http://xdsoft.net/jqplugins/datetimepicker/).
|
45
60
|
|
46
61
|
|
@@ -52,7 +67,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
52
67
|
|
53
68
|
## Contributing
|
54
69
|
|
55
|
-
1. Fork it ( https://github.com/
|
70
|
+
1. Fork it ( https://github.com/activeadmin-plugins/activeadmin_datetimepicker/fork )
|
56
71
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
57
72
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
58
73
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'active_admin_datetimepicker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "active_admin_datetimepicker"
|
8
|
+
spec.version = ActiveAdminDatetimepicker::VERSION
|
9
|
+
spec.authors = ["Igor Fedoronchuk"]
|
10
|
+
spec.email = ["fedoronchuk@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{datetimepicker extension for ActiveAdmin}
|
13
|
+
spec.description = %q{Integrate jQuery xdan datetimepicker plugin to ActiveAdmin}
|
14
|
+
spec.homepage = "https://github.com/activeadmin-plugins/activeadmin_datetimepicker"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "bin"
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "xdan-datetimepicker-rails", "~> 2.4"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
|
26
|
+
end
|
@@ -1,14 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'activeadmin'
|
2
|
+
require 'xdan-datetimepicker-rails'
|
3
|
+
require 'active_admin_datetimepicker/version'
|
4
|
+
require 'active_admin_datetimepicker/base'
|
5
|
+
require 'active_admin_datetimepicker/inputs/date_time_picker_input'
|
6
|
+
require 'active_admin_datetimepicker/inputs/filters/date_time_range_input'
|
6
7
|
|
7
8
|
module ActiveAdminDatetimepicker
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
9
|
+
module Rails
|
10
|
+
class Engine < ::Rails::Engine
|
12
11
|
end
|
13
|
-
|
12
|
+
end
|
14
13
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module ActiveAdminDatetimepicker
|
2
|
+
module Base
|
3
|
+
mattr_accessor :default_datetime_picker_options do
|
4
|
+
{}
|
5
|
+
end
|
6
|
+
|
7
|
+
mattr_accessor :format do
|
8
|
+
'%Y-%m-%d %H:%M'
|
9
|
+
end
|
10
|
+
|
11
|
+
def html_class
|
12
|
+
'date-time-picker'
|
13
|
+
end
|
14
|
+
|
15
|
+
def input_html_data
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
|
19
|
+
def input_html_options(input_name = nil)
|
20
|
+
options = {}
|
21
|
+
options[:class] = [self.options[:class], html_class].compact.join(' ')
|
22
|
+
options[:data] ||= input_html_data
|
23
|
+
options[:data].merge!(datepicker_options: datetime_picker_options)
|
24
|
+
options[:value] ||= input_value(input_name)
|
25
|
+
options[:maxlength] = 19
|
26
|
+
options
|
27
|
+
end
|
28
|
+
|
29
|
+
def input_value(input_name = nil)
|
30
|
+
val = object.public_send(input_name || method)
|
31
|
+
return DateTime.new(val.year, val.month, val.day, val.hour, val.min).strftime(format) if val.is_a?(Time)
|
32
|
+
val.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
def datetime_picker_options
|
36
|
+
@datetime_picker_options ||= begin
|
37
|
+
# backport support both :datepicker_options AND :datetime_picker_options
|
38
|
+
options = self.options.fetch(:datepicker_options, {})
|
39
|
+
options = self.options.fetch(:datetime_picker_options, options)
|
40
|
+
options = Hash[options.map { |k, v| [k.to_s.camelcase(:lower), v] }]
|
41
|
+
_default_datetime_picker_options.merge(options)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def _default_datetime_picker_options
|
48
|
+
res = default_datetime_picker_options.map do |k, v|
|
49
|
+
if v.respond_to?(:call) || v.is_a?(Proc)
|
50
|
+
[k, v.call]
|
51
|
+
else
|
52
|
+
[k, v]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
Hash[res]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -1,28 +1,7 @@
|
|
1
1
|
module ActiveAdmin
|
2
2
|
module Inputs
|
3
3
|
class DateTimePickerInput < ::Formtastic::Inputs::StringInput
|
4
|
-
|
5
|
-
super.tap do |options|
|
6
|
-
options[:class] = [options[:class], "date-time-picker"].compact.join(' ')
|
7
|
-
options[:data] ||= {}
|
8
|
-
options[:data].merge! datepicker_options
|
9
|
-
options[:value] ||= value
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def value
|
14
|
-
val = object.send(method)
|
15
|
-
return DateTime.new(val.year, val.month, val.day, val.hour, val.min).strftime("%Y-%m-%d %H:%M") if val.is_a?(Time)
|
16
|
-
return val if val.nil?
|
17
|
-
val.to_s
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
def datepicker_options
|
22
|
-
options = self.options.fetch(:datepicker_options, {})
|
23
|
-
options = Hash[options.map{ |k, v| [k.to_s.camelcase(:lower), v] }]
|
24
|
-
{ datepicker_options: options }
|
25
|
-
end
|
4
|
+
include ActiveAdminDatetimepicker::Base
|
26
5
|
end
|
27
6
|
end
|
28
|
-
end
|
7
|
+
end
|
@@ -3,23 +3,14 @@ module ActiveAdmin
|
|
3
3
|
module Filters
|
4
4
|
class DateTimeRangeInput < DateRangeInput
|
5
5
|
include Base
|
6
|
-
|
7
|
-
def html_class
|
8
|
-
"date-time-picker"
|
9
|
-
end
|
10
|
-
|
11
|
-
def format
|
12
|
-
"%Y-%m-%d %H:%M"
|
13
|
-
end
|
6
|
+
include ActiveAdminDatetimepicker::Base
|
14
7
|
|
15
8
|
def input_html_options(input_name = gt_input_name)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
max: 10,
|
20
|
-
value: current_value.respond_to?(:strftime) ? current_value.strftime(format) : "" }
|
9
|
+
super.tap do |options|
|
10
|
+
options[:class] = html_class
|
11
|
+
end
|
21
12
|
end
|
22
13
|
end
|
23
14
|
end
|
24
15
|
end
|
25
|
-
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_admin_datetimepicker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Fedoronchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xdan-datetimepicker-rails
|
@@ -64,9 +64,11 @@ files:
|
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
|
+
- active_admin_datetimepicker.gemspec
|
67
68
|
- app/assets/javascripts/active_admin_datetimepicker.js.coffee
|
68
69
|
- app/assets/stylesheets/active_admin_datetimepicker.scss
|
69
70
|
- lib/active_admin_datetimepicker.rb
|
71
|
+
- lib/active_admin_datetimepicker/base.rb
|
70
72
|
- lib/active_admin_datetimepicker/inputs/date_time_picker_input.rb
|
71
73
|
- lib/active_admin_datetimepicker/inputs/filters/date_time_range_input.rb
|
72
74
|
- lib/active_admin_datetimepicker/version.rb
|