combined_time_select 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -2
- data/combined_time_select.gemspec +1 -1
- data/lib/combined_time_select.rb +78 -90
- data/lib/combined_time_select/version.rb +1 -1
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5df1e72bff11080a5c031e5f4fb0517ab42834be
|
4
|
+
data.tar.gz: 14f8139529a2c494321c5b6ab3ae825f4569f291
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e1eea77be8282504e903895de1ac18e81118dc588589ff61963debd08e8a58bcef6a9ec18683b8e45dcc483a8aba1e1d88032eaadbc496d19afc71291e194c1
|
7
|
+
data.tar.gz: f713604c08235aa016fef23176055842433aa917c391986f94cde57b828d1bd3c6cb473f39a0135bb7416c3b9e13e585b7a90f71c588e46e017af7135ad3c598
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
Combined Time Select
|
2
2
|
====================
|
3
3
|
|
4
|
+
Compatible with Rails 5+
|
5
|
+
|
4
6
|
Written by [Chris Oliver](http://excid3.com) [@excid3](https://twitter.com/excid3).
|
5
7
|
|
6
8
|
This is a small gem for creating Google Calendar style 12 hour AM/PM
|
7
|
-
time_select fields for Rails
|
9
|
+
time_select fields for Rails. It's based off of [simple_time_select](https://github.com/tamoyal/simple_time_select) by tamoyal.
|
8
10
|
|
9
11
|
![combined_time_select](http://f.cl.ly/items/1945331M3W1h0f1K3I2v/Screen%20Shot%202011-12-23%20at%2012.08.37%20AM.png)
|
10
12
|
|
@@ -15,7 +17,7 @@ Installation
|
|
15
17
|
|
16
18
|
Just add this into your Gemfile followed by a bundle install:
|
17
19
|
|
18
|
-
gem "combined_time_select", "~>
|
20
|
+
gem "combined_time_select", "~> 2.0.0"
|
19
21
|
|
20
22
|
Usage
|
21
23
|
-----
|
@@ -45,6 +47,8 @@ This will create a combined time select starting at 10:30 AM and going till
|
|
45
47
|
value for the start_time attribute on the object this form was created
|
46
48
|
for.
|
47
49
|
|
50
|
+
Because `combined_time_select` overrides the time_select method to provide you the combined time fields, there is no need to designate a method when using libraries such as Formtastic. You will, however, need to disable the built in hour and minute labels by indicating `:labels => false` (though you can still give your individual field a label with `:label => "Label Name"`) and to add in the am/pm designation for a 12 hour clock by indicating `:ampm => true`.
|
51
|
+
|
48
52
|
On the controller side, we need to parse this attribute before we create
|
49
53
|
a new object. combined_time_select provides a nice method for this
|
50
54
|
called parse_time_select!. You can use this in your create action just
|
data/lib/combined_time_select.rb
CHANGED
@@ -1,114 +1,102 @@
|
|
1
1
|
require "combined_time_select/version"
|
2
2
|
|
3
3
|
module CombinedTimeSelect
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module DateTimeSelectorWithSimpleTimeSelect
|
5
|
+
def select_minute
|
6
|
+
return super unless @options[:combined].eql? true
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
def parse_time_select!(attribute)
|
11
|
-
self[attribute] = Time.zone.parse("#{self["#{attribute}(1i)"]}-#{self["#{attribute}(2i)"]}-#{self["#{attribute}(3i)"]} #{self["#{attribute}(5i)"]}")
|
12
|
-
(1..5).each { |i| self.delete "#{attribute}(#{i}i)" }
|
13
|
-
self
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
8
|
+
# Although this is a datetime select, we only care about the time. Assume that the date will
|
9
|
+
# be set by some other control, and the date represented here will be overriden
|
17
10
|
|
11
|
+
val_minutes = @datetime.kind_of?(Time) ? @datetime.min + @datetime.hour*60 : @datetime
|
18
12
|
|
19
|
-
|
20
|
-
class DateTimeSelector
|
21
|
-
def select_minute_with_simple_time_select
|
22
|
-
return select_minute_without_simple_time_select unless @options[:combined].eql? true
|
13
|
+
@options[:time_separator] = ""
|
23
14
|
|
24
|
-
|
25
|
-
|
15
|
+
# Default is 15 minute intervals
|
16
|
+
minute_interval = @options.fetch(:minute_interval, 15)
|
26
17
|
|
27
|
-
|
18
|
+
start_minute = 0
|
19
|
+
end_minute = 1439
|
28
20
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end_minute = 1439
|
36
|
-
|
37
|
-
# @options[:start_hour] should be specified in military
|
38
|
-
# i.e. 0-23
|
39
|
-
if @options[:start_hour]
|
40
|
-
start_minute = @options[:start_hour] * 60
|
41
|
-
start_minute += @options.fetch(:start_minute, 0)
|
42
|
-
end
|
21
|
+
# @options[:start_hour] should be specified in military
|
22
|
+
# i.e. 0-23
|
23
|
+
if @options[:start_hour]
|
24
|
+
start_minute = @options[:start_hour] * 60
|
25
|
+
start_minute += @options.fetch(:start_minute, 0)
|
26
|
+
end
|
43
27
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
28
|
+
# @options[:end_hour] should be specified in military
|
29
|
+
# i.e. 0-23
|
30
|
+
if @options[:end_hour]
|
31
|
+
end_minute = (@options[:end_hour] * 60) + @options.fetch(:end_minute, 59)
|
32
|
+
end
|
49
33
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
34
|
+
if @options[:use_hidden] || @options[:discard_minute]
|
35
|
+
build_hidden(:minute, val)
|
36
|
+
else
|
37
|
+
minute_options = []
|
38
|
+
start_minute.upto(end_minute) do |minute|
|
39
|
+
if minute%minute_interval == 0
|
40
|
+
ampm = minute < 720 ? ' AM' : ' PM'
|
41
|
+
hour = minute/60
|
42
|
+
minute_padded = zero_pad_num(minute%60)
|
43
|
+
hour_padded = zero_pad_num(hour)
|
44
|
+
ampm_hour = ampm_hour(hour)
|
45
|
+
|
46
|
+
val = "#{hour_padded}:#{minute_padded}:00"
|
47
|
+
|
48
|
+
option_text = @options[:ampm] ? "#{ampm_hour}:#{minute_padded}#{ampm}" : "#{hour_padded}:#{minute_padded}"
|
49
|
+
minute_options << ((val_minutes == minute) ?
|
50
|
+
%(<option value="#{val}" selected="selected">#{option_text}</option>\n) :
|
51
|
+
%(<option value="#{val}">#{option_text}</option>\n)
|
52
|
+
)
|
70
53
|
end
|
71
|
-
build_select(:minute, minute_options.join(' '))
|
72
54
|
end
|
55
|
+
build_select(:minute, minute_options.join(' '))
|
73
56
|
end
|
74
|
-
|
57
|
+
end
|
75
58
|
|
59
|
+
def select_hour
|
60
|
+
return super unless @options[:combined].eql? true
|
61
|
+
# Don't build the hour select
|
62
|
+
#build_hidden(:hour, val)
|
63
|
+
end
|
76
64
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
alias_method_chain :select_hour, :simple_time_select
|
65
|
+
def select_second
|
66
|
+
return super unless @options[:combined].eql? true
|
67
|
+
# Don't build the seconds select
|
68
|
+
#build_hidden(:second, val)
|
69
|
+
end
|
83
70
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
alias_method_chain :select_second, :simple_time_select
|
71
|
+
def select_year
|
72
|
+
return super unless @options[:combined].eql? true
|
73
|
+
# Don't build the year select
|
74
|
+
#build_hidden(:year, val)
|
75
|
+
end
|
90
76
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
alias_method_chain :select_year, :simple_time_select
|
77
|
+
def select_month
|
78
|
+
return super unless @options[:combined].eql? true
|
79
|
+
# Don't build the month select
|
80
|
+
#build_hidden(:month, val)
|
81
|
+
end
|
97
82
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
83
|
+
def select_day
|
84
|
+
return super unless @options[:combined].eql? true
|
85
|
+
# Don't build the day select
|
86
|
+
#build_hidden(:day, val)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
104
90
|
|
105
|
-
|
106
|
-
return select_day_without_simple_time_select unless @options[:combined].eql? true
|
107
|
-
# Don't build the day select
|
108
|
-
#build_hidden(:day, val)
|
109
|
-
end
|
110
|
-
alias_method_chain :select_day, :simple_time_select
|
91
|
+
ActionView::Helpers::DateTimeSelector.send(:prepend, CombinedTimeSelect::DateTimeSelectorWithSimpleTimeSelect)
|
111
92
|
|
93
|
+
module ActionController
|
94
|
+
class Parameters
|
95
|
+
def parse_time_select!(attribute)
|
96
|
+
self[attribute] = Time.zone.parse("#{self["#{attribute}(1i)"]}-#{self["#{attribute}(2i)"]}-#{self["#{attribute}(3i)"]} #{self["#{attribute}(5i)"]}")
|
97
|
+
(1..5).each { |i| self.delete "#{attribute}(#{i}i)" }
|
98
|
+
self
|
99
|
+
end
|
112
100
|
end
|
113
101
|
end
|
114
102
|
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: combined_time_select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.0.0
|
27
41
|
description: Generates a time_select field like Google calendar.
|
28
42
|
email:
|
29
43
|
- excid3@gmail.com
|
@@ -31,7 +45,7 @@ executables: []
|
|
31
45
|
extensions: []
|
32
46
|
extra_rdoc_files: []
|
33
47
|
files:
|
34
|
-
- .gitignore
|
48
|
+
- ".gitignore"
|
35
49
|
- CHANGELOG.md
|
36
50
|
- Gemfile
|
37
51
|
- LICENSE
|
@@ -49,17 +63,17 @@ require_paths:
|
|
49
63
|
- lib
|
50
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- -
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
70
|
requirements:
|
57
|
-
- -
|
71
|
+
- - ">="
|
58
72
|
- !ruby/object:Gem::Version
|
59
73
|
version: '0'
|
60
74
|
requirements: []
|
61
75
|
rubyforge_project: combined_time_select
|
62
|
-
rubygems_version: 2.
|
76
|
+
rubygems_version: 2.6.11
|
63
77
|
signing_key:
|
64
78
|
specification_version: 4
|
65
79
|
summary: A Rails time_select like Google Calendar with combined hour and minute time_select
|