rails-scheduler 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,4 +5,4 @@ pkg/
5
5
  test/dummy/db/*.sqlite3
6
6
  test/dummy/log/*.log
7
7
  test/dummy/tmp/
8
- **/**/*.swp
8
+ **.*swp
@@ -14,9 +14,18 @@ Scheduler.form.init = function(form, startDate) {
14
14
  });
15
15
 
16
16
  if (startDate) {
17
+ var weekDay = (startDate.getDay() + 6) % 7; // monday is 0 in Rails
18
+ var weekDayOrder = Math.floor((startDate.getDate() - startDate.getDay() + 6) / 7);
19
+ if (weekDayOrder > 3) {
20
+ weekDayOrder = -1;
21
+ }
22
+
17
23
  // check day of week
18
- dayOfWeek = (startDate.getDay() + 6) % 7; // monday is 0 in Rails
19
- form.find('#event_interval_days_' + dayOfWeek).attr('checked','checked');
24
+ form.find('#event_week_days_' + weekDay).attr('checked','checked');
25
+
26
+ // init day of month
27
+ form.find('#event_week_day_order').val(weekDayOrder);
28
+ form.find('#event_week_day').val(weekDay);
20
29
  }
21
30
  }
22
31
 
@@ -24,5 +33,8 @@ Scheduler.form.showFrequency = function(value) {
24
33
  form = Scheduler.form.current;
25
34
 
26
35
  form.find("#scheduler-options").children("div").hide();
36
+ form.find("#scheduler-options").find("select,input").attr('disabled', 'disabled');
37
+
27
38
  form.find("#scheduler-frequency-" + value ).show();
39
+ form.find("#scheduler-frequency-" + value ).find("select,input").removeAttr('disabled');
28
40
  }
@@ -0,0 +1,25 @@
1
+ module SchedulerHelper
2
+ def frequency_options
3
+ Scheduler::FREQUENCIES.each_with_index.map{ |value, index|
4
+ [ I18n.t("scheduler.frequency.#{ value }.form.option"), index ]
5
+ }
6
+ end
7
+
8
+ def week_day_order_options
9
+ [1, 2, 3, -1 ].map do |d|
10
+ [
11
+ t("scheduler.frequency.monthly.form.week_day_order_option.#{ d }"),
12
+ d
13
+ ]
14
+ end
15
+ end
16
+
17
+ def week_day_options
18
+ 7.times.map do |d|
19
+ [
20
+ l(Date.today.beginning_of_week + d, :format => "%A"),
21
+ d
22
+ ]
23
+ end
24
+ end
25
+ end
@@ -1,6 +1,6 @@
1
1
  <div class="scheduler_form">
2
2
  <%= f.label :frequency %>
3
- <%= f.select :frequency, Scheduler.frequency_options, {}, :class => 'scheduler-frequency' %>
3
+ <%= f.select :frequency, frequency_options, {}, :class => 'scheduler-frequency' %>
4
4
 
5
5
  <div id="scheduler-options">
6
6
  <div id="scheduler-frequency-0">
@@ -19,16 +19,20 @@
19
19
 
20
20
  <div id="scheduler-weekly-days">
21
21
  <% 7.times do |d| %>
22
- <%= check_box_tag "#{ f.object_name }[interval_days][]",
22
+ <%= check_box_tag "#{ f.object_name }[week_days][]",
23
23
  d,
24
- f.object.interval_days.include?(d),
25
- :id => "event_interval_days_#{ d }" %>
24
+ f.object.week_days.include?(d),
25
+ :id => "event_week_days_#{ d }" %>
26
26
  <span><%= I18n.l Date.today.beginning_of_week + d, :format => "%a" %></span>
27
27
  <% end %>
28
28
  </div>
29
29
  </div>
30
30
 
31
31
  <div id="scheduler-frequency-3">
32
- Comming soon..
32
+ <%= raw t('scheduler.frequency.monthly.form.week_day',
33
+ :order_field => f.select(:week_day_order, week_day_order_options),
34
+ :week_field => f.select(:week_day, week_day_options),
35
+ :interval_field => f.number_field(:interval, :size => 1))
36
+ %>
33
37
  </div>
34
38
  </div>
@@ -15,3 +15,9 @@ es:
15
15
  monthly:
16
16
  form:
17
17
  option: "mensual"
18
+ week_day: "El %{order_field} %{week_field} de cada %{interval_field} mes(es)"
19
+ week_day_order_option:
20
+ "1": "primer"
21
+ "2": "segundo"
22
+ "3": "tercer"
23
+ "-1": "último"
@@ -6,6 +6,7 @@ class AddScheduler < ActiveRecord::Migration
6
6
  t.date :start_date
7
7
  t.date :end_date
8
8
  t.integer :frequency, :default => 0
9
+ t.integer :days, :default => 0
9
10
  t.integer :interval
10
11
  t.integer :interval_flag, :default => 0
11
12
  end
@@ -1,11 +1,4 @@
1
1
  module Scheduler
2
2
  FREQUENCIES = [ :one_off, :daily, :weekly, :monthly ]
3
-
4
- class << self
5
- def frequency_options
6
- FREQUENCIES.each_with_index.map{ |value, index|
7
- [ I18n.t("scheduler.frequency.#{ value }.form.option"), index ]
8
- }
9
- end
10
- end
3
+ ORDER = [ :first, :second, :third, :last ]
11
4
  end
@@ -12,7 +12,7 @@ module Scheduler
12
12
  [ :weekly ].include? record.frequency_sym
13
13
  }
14
14
 
15
- validates_numericality_of :interval_flag,
15
+ validates_numericality_of :days,
16
16
  :greater_than => 0,
17
17
  :if => lambda { |record|
18
18
  [ :weekly ].include? record.frequency_sym
@@ -30,24 +30,51 @@ module Scheduler
30
30
  end
31
31
 
32
32
  # Get [ 0, 1, 6 ] (monday, tuesday, sunday) from byte
33
- def interval_days
33
+ def week_days
34
34
  7.times.map{ |i|
35
- interval_flag[i] > 0 ?
35
+ days[i] > 0 ?
36
36
  i :
37
37
  nil
38
38
  }.compact
39
39
  end
40
40
 
41
- def interval_days_sym
42
- interval_days.map{ |d|
41
+ def week_day
42
+ week_days.first
43
+ end
44
+
45
+ def week_days_sym
46
+ week_days.map{ |d|
43
47
  Date::DAYS_INTO_WEEK.invert[d]
44
48
  }
45
49
  end
46
50
 
51
+ def week_day_sym
52
+ week_days_sym.first
53
+ end
54
+
47
55
  # Convert [ 0, 1, 6 ] (monday, tuesday, sunday) to byte
48
- def interval_days= days
49
- self.interval_flag =
50
- days.map{ |d| 2 ** d.to_i }.inject(0, &:+)
56
+ def week_days= ds
57
+ self.days =
58
+ ds.map{ |d| 2 ** d.to_i }.inject(0, &:+)
59
+ end
60
+
61
+ def week_day= day
62
+ self.week_days = Array.wrap(day)
63
+ end
64
+
65
+ def week_day_order
66
+ interval_flag
67
+ end
68
+
69
+ def week_day_order_sym
70
+ index = interval_flag
71
+ index -= 1 if index > 0
72
+
73
+ Scheduler::ORDER[index]
74
+ end
75
+
76
+ def week_day_order= order
77
+ self.interval_flag = order
51
78
  end
52
79
 
53
80
  def recurrence
@@ -57,7 +84,14 @@ module Scheduler
57
84
  :starts => start_date.to_date,
58
85
  :until => end_date.try(:to_date),
59
86
  :interval => interval,
60
- :on => interval_days_sym })
87
+ :on => week_days_sym })
88
+ when :monthly
89
+ Recurrence.new({ :every => :month,
90
+ :starts => start_date.to_date,
91
+ :until => end_date.try(:to_date),
92
+ :interval => interval,
93
+ :on => week_day_order_sym,
94
+ :weekday => week_day_sym })
61
95
  end
62
96
  end
63
97
 
@@ -1,3 +1,3 @@
1
1
  module Scheduler
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-18 00:00:00.000000000Z
12
+ date: 2011-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &69827090 !ruby/object:Gem::Requirement
16
+ requirement: &68372130 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *69827090
24
+ version_requirements: *68372130
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: recurrence
27
- requirement: &69822940 !ruby/object:Gem::Requirement
27
+ requirement: &68371640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.2.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *69822940
35
+ version_requirements: *68371640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mysql2
38
- requirement: &69821950 !ruby/object:Gem::Requirement
38
+ requirement: &68371310 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *69821950
46
+ version_requirements: *68371310
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: factory_girl
49
- requirement: &69821140 !ruby/object:Gem::Requirement
49
+ requirement: &68370910 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *69821140
57
+ version_requirements: *68370910
58
58
  description: ! 'Scheduler support: daily, weekly and montly repetitions'
59
59
  email:
60
60
  - atapiador@dit.upm.es
@@ -69,6 +69,7 @@ files:
69
69
  - README.rdoc
70
70
  - Rakefile
71
71
  - app/assets/javascripts/scheduler.js
72
+ - app/helpers/scheduler_helper.rb
72
73
  - app/views/scheduler/_form.html.erb
73
74
  - config/locales/es.yml
74
75
  - db/migrate/20111204155637_add_scheduler.rb
@@ -133,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
134
  version: '0'
134
135
  segments:
135
136
  - 0
136
- hash: -654998783
137
+ hash: 530319471
137
138
  required_rubygems_version: !ruby/object:Gem::Requirement
138
139
  none: false
139
140
  requirements:
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
143
  version: '0'
143
144
  segments:
144
145
  - 0
145
- hash: -654998783
146
+ hash: 530319471
146
147
  requirements: []
147
148
  rubyforge_project:
148
149
  rubygems_version: 1.8.10