It is now possible to repeat events using a new méthod: nth day of the month
This commit is contained in:
parent
ab195d28ae
commit
3069dced13
@ -1,10 +1,12 @@
|
|||||||
|
require 'schedule'
|
||||||
|
|
||||||
# This is the central ADL class, where are managed all events
|
# This is the central ADL class, where are managed all events
|
||||||
class Event < ActiveRecord::Base
|
class Event < ActiveRecord::Base
|
||||||
extend SimpleCalendar
|
extend SimpleCalendar
|
||||||
|
include Schedule
|
||||||
strip_attributes
|
strip_attributes
|
||||||
has_paper_trail ignore: [:last_updated, :lock_version, :secret,
|
has_paper_trail ignore: [:last_updated, :lock_version, :secret, :submitter,
|
||||||
:submitter, :decision_time,
|
:decision_time, :latitude, :longitude]
|
||||||
:latitude, :longitude]
|
|
||||||
|
|
||||||
belongs_to :region
|
belongs_to :region
|
||||||
# This is the scheduled first event
|
# This is the scheduled first event
|
||||||
@ -14,7 +16,7 @@ class Event < ActiveRecord::Base
|
|||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validate :end_after_start
|
validate :end_after_start
|
||||||
RULES = %w(daily weekly monthly).freeze
|
RULES = %w(daily weekly monthly monthly_day).freeze
|
||||||
validates :rule, allow_nil: true, inclusion: RULES
|
validates :rule, allow_nil: true, inclusion: RULES
|
||||||
validates :description, presence: true
|
validates :description, presence: true
|
||||||
validates :city, presence: true
|
validates :city, presence: true
|
||||||
@ -94,12 +96,6 @@ class Event < ActiveRecord::Base
|
|||||||
[address, city].compact.join ', '
|
[address, city].compact.join ', '
|
||||||
end
|
end
|
||||||
|
|
||||||
def schedule
|
|
||||||
IceCube::Schedule.new(start_time, end_time: end_time) do |s|
|
|
||||||
s.add_recurrence_rule IceCube::Rule.send(rule).count(repeat + 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def hashtags
|
def hashtags
|
||||||
tags.split.map { |tag| "##{tag.tr('-', '_').camelize :lower}" }
|
tags.split.map { |tag| "##{tag.tr('-', '_').camelize :lower}" }
|
||||||
end
|
end
|
||||||
|
@ -7,4 +7,4 @@
|
|||||||
%strong.city{ title: event.address }= event.city
|
%strong.city{ title: event.address }= event.city
|
||||||
= event.title
|
= event.title
|
||||||
- if event.repeat > 0
|
- if event.repeat > 0
|
||||||
%em.fa.fa-repeat(title="#{event.repeat} - #{t event.rule, scope: 'activerecord.attributes.event.rule_values'}")
|
%em.fa.fa-repeat{ title: event.schedule }
|
||||||
|
@ -118,9 +118,10 @@
|
|||||||
- if @event.repeat > 0
|
- if @event.repeat > 0
|
||||||
%h3
|
%h3
|
||||||
%em.fa.fa-repeat
|
%em.fa.fa-repeat
|
||||||
= t @event.rule, scope: 'activerecord.attributes.event.rule_values'
|
= @event.schedule
|
||||||
|
|
||||||
%ul
|
- if @event.moderated?
|
||||||
%li= link_to_unless_current @event.event || @event, @event.event || @event
|
%ul
|
||||||
- (@event.event || @event).events.each do |e|
|
%li= link_to_unless_current @event.event || @event, @event.event || @event
|
||||||
%li= link_to_unless_current e, e
|
- (@event.event || @event).events.each do |e|
|
||||||
|
%li= link_to_unless_current e, e
|
||||||
|
@ -69,6 +69,7 @@ en:
|
|||||||
daily: Daily
|
daily: Daily
|
||||||
weekly: Weekly
|
weekly: Weekly
|
||||||
monthly: Monthly
|
monthly: Monthly
|
||||||
|
monthly_day: Nth day of the month
|
||||||
yearly: Yearly
|
yearly: Yearly
|
||||||
description: Description
|
description: Description
|
||||||
place_name: Place name
|
place_name: Place name
|
||||||
|
@ -69,6 +69,7 @@ fr:
|
|||||||
daily: Journalière
|
daily: Journalière
|
||||||
weekly: Hebdomadaire
|
weekly: Hebdomadaire
|
||||||
monthly: Mensuelle
|
monthly: Mensuelle
|
||||||
|
monthly_day: Nème jour du mois
|
||||||
yearly: Annuelle
|
yearly: Annuelle
|
||||||
description: Description
|
description: Description
|
||||||
place_name: Nom du lieu
|
place_name: Nom du lieu
|
||||||
|
20
lib/schedule.rb
Normal file
20
lib/schedule.rb
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# The code to manage adl scheduling. Repeat events, is managed here
|
||||||
|
module Schedule
|
||||||
|
def schedule
|
||||||
|
IceCube::Schedule.new start_time, end_time: end_time do |s|
|
||||||
|
s.add_recurrence_rule prepare_schedule.count repeat + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def prepare_schedule
|
||||||
|
rule ||= 'daily'
|
||||||
|
r = IceCube::Rule.send rule.split('_').first
|
||||||
|
if rule == 'monthly_day'
|
||||||
|
r.day_of_week start_time.wday => [start_time.day / 7 + 1]
|
||||||
|
else
|
||||||
|
r
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user