schedulable 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5965f8d54d74a2e9dc9a3637bdac730fac29861
|
4
|
+
data.tar.gz: ee86cfa84c07e0ae273ae3d70e76f811cfb28a3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8cc72da05d83051a102e51fbc3a2ef5378e8f0d3529a1f715c7110820ccd361f28f2d7c638c5cb2b20b98e33db6adcd27f5f22ac621096905ee6ce79067486b
|
7
|
+
data.tar.gz: 49e83fe2ecaf68a9cbc12e361ec19c2c913447991c983d4e5afa0e57d12970bb327510a48f7ea84f3a3e87b2d21d002900dd84bfa87bfb134955bc1889ab82c9
|
@@ -64,8 +64,8 @@ class ScheduleInput < SimpleForm::Inputs::Base
|
|
64
64
|
weekdays.reduce(''.html_safe) do | content, weekday |
|
65
65
|
content << template.content_tag("div", nil, style: 'display: table-row') do
|
66
66
|
template.content_tag("span", day_labels[weekday] || weekday, style: 'display: table-cell') <<
|
67
|
-
db.collection_check_boxes(weekday.to_sym, [1, 2, 3, 4, -1], lambda { |i| i} , lambda { |i| " ".html_safe}, checked: db.object.send(weekday), item_wrapper_tag: nil) do |cb|
|
68
|
-
template.content_tag("span",
|
67
|
+
db.collection_check_boxes(weekday.to_sym, [1, 2, 3, 4, -1], lambda { |i| i} , lambda { |i| " ".html_safe}, boolean_style: :inline, label: false, checked: db.object.send(weekday), inline_label: false, item_wrapper_tag: nil) do |cb|
|
68
|
+
template.content_tag("span", style: 'display: table-cell; text-align: center;') { cb.check_box(class: "check_box") }
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -62,10 +62,15 @@ module Schedulable
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
define_method "build_#{occurrences_association}_after_update" do
|
66
|
+
schedule = self.send(name)
|
67
|
+
if schedule.changes.any?
|
68
|
+
self.send("build_#{occurrences_association}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
65
72
|
define_method "build_#{occurrences_association}" do
|
66
73
|
|
67
|
-
puts 'build occurrences...'
|
68
|
-
|
69
74
|
# build occurrences for events
|
70
75
|
|
71
76
|
schedule = self.send(name)
|
@@ -87,9 +92,8 @@ module Schedulable
|
|
87
92
|
max_count = terminating && schedule.remaining_occurrences.any? ? [max_count, schedule.remaining_occurrences.count].min : max_count
|
88
93
|
|
89
94
|
if schedule.rule != 'singular'
|
90
|
-
|
91
95
|
# Get schedule occurrences
|
92
|
-
all_occurrences = schedule.
|
96
|
+
all_occurrences = schedule.occurrences_between(Time.now, max_date.to_time)
|
93
97
|
occurrences = []
|
94
98
|
# Filter valid dates
|
95
99
|
all_occurrences.each_with_index do |occurrence_date, index|
|
@@ -101,15 +105,23 @@ module Schedulable
|
|
101
105
|
end
|
102
106
|
end
|
103
107
|
end
|
104
|
-
|
105
108
|
else
|
106
|
-
|
109
|
+
# Get Singular occurrence
|
110
|
+
d = schedule.date
|
111
|
+
t = schedule.time
|
112
|
+
dt = d + t.seconds_since_midnight.seconds
|
113
|
+
singular_date_time = (d + t.seconds_since_midnight.seconds).to_datetime
|
107
114
|
occurrences = [singular_date_time]
|
108
115
|
end
|
109
|
-
|
116
|
+
|
110
117
|
# Build occurrences
|
111
118
|
update_mode = Schedulable.config.update_mode || :datetime
|
112
119
|
|
120
|
+
# Always use index as base for singular events
|
121
|
+
if schedule.rule == 'singular'
|
122
|
+
update_mode = :index
|
123
|
+
end
|
124
|
+
|
113
125
|
# Get existing remaining records
|
114
126
|
occurrences_records = schedulable.send("remaining_#{occurrences_association}")
|
115
127
|
|
@@ -118,7 +130,6 @@ module Schedulable
|
|
118
130
|
occurrences.each_with_index do |occurrence, index|
|
119
131
|
|
120
132
|
# Pull an existing record
|
121
|
-
|
122
133
|
if update_mode == :index
|
123
134
|
existing_records = [occurrences_records[index]]
|
124
135
|
elsif update_mode == :datetime
|
@@ -133,13 +144,13 @@ module Schedulable
|
|
133
144
|
# Overwrite existing records
|
134
145
|
existing_records.each do |existing_record|
|
135
146
|
if !occurrences_records.update(existing_record.id, date: occurrence.to_datetime)
|
136
|
-
puts '
|
147
|
+
puts 'An error occurred while saving an existing occurrence record'
|
137
148
|
end
|
138
149
|
end
|
139
150
|
else
|
140
151
|
# Create new record
|
141
152
|
if !occurrences_records.create(date: occurrence.to_datetime)
|
142
|
-
puts '
|
153
|
+
puts 'An error occurred while creating an occurrence record'
|
143
154
|
end
|
144
155
|
end
|
145
156
|
end
|
data/lib/schedulable/schedule.rb
CHANGED
@@ -7,7 +7,7 @@ module Schedulable
|
|
7
7
|
|
8
8
|
belongs_to :schedulable, polymorphic: true
|
9
9
|
|
10
|
-
after_initialize :
|
10
|
+
after_initialize :update_schedule
|
11
11
|
before_save :update_schedule
|
12
12
|
|
13
13
|
validates_presence_of :rule
|
@@ -25,7 +25,7 @@ module Schedulable
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def method_missing(meth, *args, &block)
|
28
|
-
if @schedule
|
28
|
+
if @schedule.present? && @schedule.respond_to?(meth)
|
29
29
|
@schedule.send(meth, *args, &block)
|
30
30
|
end
|
31
31
|
end
|
@@ -35,13 +35,17 @@ module Schedulable
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def update_schedule()
|
38
|
+
|
39
|
+
self.rule||= "singular"
|
40
|
+
self.interval||= 1
|
41
|
+
self.count||= 0
|
38
42
|
|
39
|
-
|
40
|
-
if self.time
|
41
|
-
|
43
|
+
time = Date.today.to_time
|
44
|
+
if self.time.present?
|
45
|
+
time = time + self.time.seconds_since_midnight.seconds
|
42
46
|
end
|
43
|
-
|
44
|
-
@schedule = IceCube::Schedule.new(
|
47
|
+
|
48
|
+
@schedule = IceCube::Schedule.new(time)
|
45
49
|
|
46
50
|
if self.rule && self.rule != 'singular'
|
47
51
|
|
@@ -98,18 +102,6 @@ module Schedulable
|
|
98
102
|
errors.add(:day_of_week, :empty)
|
99
103
|
end
|
100
104
|
end
|
101
|
-
|
102
|
-
|
103
|
-
def init_schedule()
|
104
|
-
|
105
|
-
self.rule||= "singular"
|
106
|
-
self.interval||= 1
|
107
|
-
self.count||= 0
|
108
|
-
|
109
|
-
@schedule = IceCube::Schedule.new(date)
|
110
|
-
|
111
|
-
self.update_schedule()
|
112
|
-
end
|
113
105
|
end
|
114
106
|
end
|
115
107
|
end
|
data/lib/schedulable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schedulable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Nowrotek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|