activate-admin 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/activate-admin/version.rb +1 -1
- data/lib/datetime_helpers.rb +30 -29
- data/lib/param_helpers.rb +37 -35
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTkwNDU5OWQ0MGE5OGYwMjcxMmQ1NmZmNTk2OGY3NWUyMDg0ZTdmYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTU4OTA4Mzc5ZDI2N2Y1NzdjYjMyYzY3M2QwNWY3ZDZhZWVhN2RiOQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTgwMWU0OWYwMTJmMDQ4NTEyOTY1YTA4N2NiMTUyNjYzNDBmZDVhMGJjYjJk
|
10
|
+
ODY5ZmEyOGFhMDQ2MzE1ZTRjYTc3MGY4MWNhYTE2MWQxYTNlYTQzZWIxZjg2
|
11
|
+
ZjBkODJiYjU3MDdjZmZlZWQyOWE1ODVhNjU4NmY1OTEzMmQwMmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTdjMmFkYjg5NGI0YjA5OWI3Yzk0Nzg3NjA4NzQ1MmFkMDcyNjZhMmQ1Nzkz
|
14
|
+
NGI3Yzc1NmFiZWVhNWY2YjhjZDI5NDNiY2QzN2Y0NWRmZTZlMGRjMGJjYzRi
|
15
|
+
Nzk3N2UzMmMxYzVhNTgzZWFlYTQ1ZDYwNGRmN2Q0OWRkYzBlMmQ=
|
data/lib/datetime_helpers.rb
CHANGED
@@ -1,32 +1,33 @@
|
|
1
|
-
module ActivateAdmin
|
1
|
+
module ActivateAdmin
|
2
|
+
module DatetimeHelpers
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def compact_time_ago(t)
|
22
|
-
d = Time.now - t
|
23
|
-
if d < 1.day
|
24
|
-
time_ago_in_words(t) + ' ago'
|
25
|
-
elsif d < 3.days
|
26
|
-
t.strftime('%A') + " at #{t.to_s(:time)}"
|
27
|
-
else
|
28
|
-
t
|
29
|
-
end
|
30
|
-
end
|
4
|
+
def datetime_select_tags(name, options)
|
5
|
+
v = options[:value] || Time.zone.now
|
6
|
+
c = options[:class]
|
7
|
+
id = options[:id]
|
8
|
+
s = []
|
9
|
+
s << "<style>.datetime select { width: auto }</style>"
|
10
|
+
s << "<span id=\"#{id if id}\" class=\"datetime #{c if c}\">"
|
11
|
+
s << select_tag(:"#{name}[day]", :options => (1..31).to_a, :selected => v.day )
|
12
|
+
s << select_tag(:"#{name}[month]", :options => Date::MONTHNAMES[1..-1].each_with_index.map { |x,i| [x,i+1] }, :selected => v.month)
|
13
|
+
s << select_tag(:"#{name}[year]", :options => (2012..2020).to_a, :selected => v.year )
|
14
|
+
s << '@'
|
15
|
+
s << select_tag(:"#{name}[hour]", :options => (0..23).to_a.map { |x| [x < 10 ? "0#{x}" : x,x] }, :selected => v.hour )
|
16
|
+
s << ':'
|
17
|
+
s << select_tag(:"#{name}[min]", :options => (0..59).to_a.map { |x| [x < 10 ? "0#{x}" : x,x] }, :selected => v.min )
|
18
|
+
s << '</span>'
|
19
|
+
s.join(' ')
|
20
|
+
end
|
31
21
|
|
22
|
+
def compact_time_ago(t)
|
23
|
+
d = Time.now - t
|
24
|
+
if d < 1.day
|
25
|
+
time_ago_in_words(t) + ' ago'
|
26
|
+
elsif d < 3.days
|
27
|
+
t.strftime('%A') + " at #{t.to_s(:time)}"
|
28
|
+
else
|
29
|
+
t
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
32
33
|
end
|
data/lib/param_helpers.rb
CHANGED
@@ -1,41 +1,43 @@
|
|
1
|
-
module ActivateAdmin
|
1
|
+
module ActivateAdmin
|
2
|
+
module ParamHelpers
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def fix_params!
|
5
|
+
datetime_hashes_to_datetimes!(params)
|
6
|
+
file_hashes_to_files!(params)
|
7
|
+
blanks_to_nils!(params)
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
def datetime_hashes_to_datetimes!(hash)
|
11
|
+
hash.each { |k,v|
|
12
|
+
if v.is_a?(Hash) and [:year, :month, :day, :hour, :min].all? { |x| v.has_key?(x.to_s) }
|
13
|
+
hash[k] = Time.zone.local(v[:year].to_i, v[:month].to_i, v[:day].to_i, v[:hour].to_i, v[:min].to_i)
|
14
|
+
elsif v.is_a?(Hash)
|
15
|
+
datetime_hashes_to_datetimes!(v)
|
16
|
+
end
|
17
|
+
}
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
def file_hashes_to_files!(hash)
|
21
|
+
hash.each { |k, v|
|
22
|
+
if v.is_a?(Hash) and v[:tempfile]
|
23
|
+
hash[k] = v[:tempfile]
|
24
|
+
elsif v.is_a?(Hash)
|
25
|
+
file_hashes_to_files!(v)
|
26
|
+
end
|
27
|
+
}
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
30
|
+
def blanks_to_nils!(hash)
|
31
|
+
hash.each { |k,v|
|
32
|
+
if v.blank?
|
33
|
+
hash[k] = nil
|
34
|
+
elsif v.is_a? Array
|
35
|
+
v.each_with_index { |x,i| v[i] = nil if x.blank? }.compact!
|
36
|
+
elsif v.is_a? Hash
|
37
|
+
blanks_to_nils!(v)
|
38
|
+
end
|
39
|
+
}
|
40
|
+
end
|
40
41
|
|
42
|
+
end
|
41
43
|
end
|