-
-
Save Frank004/6e56771abcf02514b6a3f271f877f8e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this events are on the fly and not store in the database. | |
# you can make some other code to create the record. | |
event.converted_schedule.occurrences_between(event.start_date,event.end_date).each do |date| | |
event_duration_date = (date.to_date + event.duration.days).to_date | |
@events << { | |
title: event.name, | |
event_id: event.id, | |
start: date, | |
end: event_duration_date, | |
description: event.description, | |
allDay: true, | |
color: event.color, | |
} | |
end | |
@events.to_json | |
# you can use something like this to build your event in db's | |
# this example take 1 month only | |
event.converted_schedule.occurrences_between(Time.now,Time.now.end_of_month).each do |e| | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event < ActiveRecord::Base | |
has_many :recurrents, dependent: :destroy | |
#--------------recuring model ------------------------------------------------ | |
include ActiveModel::Validations | |
include ActiveModel::Conversion | |
extend ActiveModel::Naming | |
serialize :schedule, Hash | |
def schedule=(new_schedule) | |
if RecurringSelect.is_valid_rule?(new_schedule) | |
write_attribute(:schedule, RecurringSelect.dirty_hash_to_rule(new_schedule).to_hash) | |
end | |
end | |
def converted_schedule | |
if !self.read_attribute(:schedule).empty? | |
the_schedule = IceCube::Schedule.new( self.start_date ) | |
the_rule = RecurringSelect.dirty_hash_to_rule( self.read_attribute(:schedule) ) | |
if RecurringSelect.is_valid_rule?(the_rule) | |
the_schedule.add_recurrence_rule( the_rule) | |
end | |
the_schedule | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Recurrent < ActiveRecord::Base | |
belongs_to :event | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$('#calendar').fullCalendar({ | |
locale: 'es', | |
events: '/event/'+event_id+'/schedule', | |
eventLimit: 4, | |
header: { | |
left: 'prev,next today', | |
center: 'title', | |
right: 'month,agendaWeek,agendaDay' | |
}, | |
eventRender: function(event, element) { | |
$(element).tooltip({title: "Descripción: " + event.description}); | |
}, | |
loading: function(bool) { | |
if (bool) | |
$('#calendar-loading').show(); | |
else | |
$('#calendar-loading').hide(); | |
}, | |
firstDay: 1, | |
//this section is triggered when the event cell it's clicked | |
selectable: true, | |
selectHelper: true | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<% @event.converted_schedule.next_occurrences(5, DateTime.now).each do |e| %> | |
<li> | |
<%= e.strftime('%d/%b/%Y') if e <= @event.end_date %> | |
</li> | |
<% end %> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey francisco. where do i put the build_event that you provided? it should be in the event model right? and if so, what does recurring model do? thanks man