Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
311 additions
and
109 deletions.
There are no files selected for viewing
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 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 file was deleted.
Oops, something went wrong.
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 file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class RecurringEventsController < ApplicationController | ||
before_action :set_recurring_event, only: [:show, :edit, :update, :destroy] | ||
|
||
def index | ||
@recurring_events = RecurringEvent.all | ||
end | ||
|
||
def show | ||
end | ||
|
||
def new | ||
@recurring_event = RecurringEvent.new | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def create | ||
@recurring_event = RecurringEvent.new(recurring_event_params) | ||
@recurring_event.save | ||
end | ||
|
||
def update | ||
if params[:event] | ||
@recurring_event.update(anchor: params[:event][:start]) | ||
else | ||
@recurring_event.update(recurring_event_params) | ||
end | ||
end | ||
|
||
def destroy | ||
@recurring_event.destroy | ||
end | ||
|
||
private | ||
|
||
def set_recurring_event | ||
@recurring_event = RecurringEvent.find(params[:id]) | ||
end | ||
|
||
def recurring_event_params | ||
params.require(:recurring_event).permit(:title, :anchor, :frequency, :color) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module RecurringEventsHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# == Schema Information | ||
# | ||
# Table name: recurring_events | ||
# | ||
# id :integer not null, primary key | ||
# title :string | ||
# anchor :date | ||
# frequency :integer default(0) | ||
# color :string | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
|
||
class RecurringEvent < ApplicationRecord | ||
enum frequency: { weekly: 0, biweekly: 1, monthly: 2, annually: 3 } | ||
|
||
validates :anchor, presence: true | ||
validates :frequency, presence: true | ||
|
||
def schedule | ||
@schedule ||= begin | ||
schedule = IceCube::Schedule.new(now = anchor) | ||
case frequency | ||
when 'weekly' | ||
schedule.add_recurrence_rule IceCube::Rule.weekly(1) | ||
when 'biweekly' | ||
schedule.add_recurrence_rule IceCube::Rule.weekly(2) | ||
when 'monthly' | ||
schedule.add_recurrence_rule IceCube::Rule.monthly(1) | ||
when 'annually' | ||
schedule.add_recurrence_rule IceCube::Rule.yearly(1) | ||
end | ||
schedule | ||
end | ||
end | ||
|
||
def events(start_date, end_date) | ||
start_frequency = start_date ? start_date.to_date : Date.today - 1.year | ||
end_frequency = end_date ? end_date.to_date : Date.today + 1.year | ||
schedule.occurrences_between(start_frequency, end_frequency) | ||
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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
$('.calendar').fullCalendar('removeEvents', [<%= @event.id %>]) | ||
$('.calendar').fullCalendar('removeEvents', '<%= "event_#{@event.id}" %>') | ||
$('.modal').modal('hide'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
$('.modal-backdrop').hide(); | ||
$('#remote_container').html('<%= j render "new" %>'); | ||
$('#new_event').modal('show'); | ||
|
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="modal fade" id="edit_recurring_event"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | ||
<h4 class="modal-title">Edit Recurring Event</h4> | ||
</div> | ||
<div class="modal-body"> | ||
<%= render 'form', recurring_event: @recurring_event %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<%= simple_form_for @recurring_event, remote: true do |f| %> | ||
<div class="form-inputs"> | ||
<%= f.input :title %> | ||
<%= f.input :anchor, input_html: { class: "form-control input-sm" } %> | ||
<%= f.input :frequency, as: :select, collection: RecurringEvent.frequencies.keys, input_html: { class: "form-control input-sm" } %> | ||
<%= f.input :color, as: :select, collection: [['Black','black'], ['Green','green'], ['Red','red']] %> | ||
</div> | ||
|
||
<div class="form-actions"> | ||
<%= f.button :submit %> | ||
<%= link_to 'New Event', | ||
new_event_path, | ||
class: 'btn btn-default', | ||
remote: true if @recurring_event.new_record? %> | ||
<%= link_to 'Delete', | ||
@recurring_event, | ||
method: :delete, | ||
class: 'btn btn-danger', | ||
data: { confirm: 'Are you sure?' }, | ||
remote: true unless @recurring_event.new_record? %> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="modal fade" id="new_recurring_event"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | ||
<h4 class="modal-title">Create New Recurring Event</h4> | ||
</div> | ||
<div class="modal-body"> | ||
<%= render 'form', recurring_event: @recurring_event %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
events = recurring_event.events(params[:start], params[:end]) | ||
json.array! events do |event| | ||
json.id "recurring_#{recurring_event.id}" | ||
json.title recurring_event.title | ||
json.start event.strftime('%Y-%m-%d') | ||
json.end (event + 1.day).strftime('%Y-%m-%d') | ||
|
||
json.color recurring_event.color unless recurring_event.color.blank? | ||
json.allDay true | ||
|
||
json.update_url recurring_event_path(recurring_event, method: :patch) | ||
json.edit_url edit_recurring_event_path(recurring_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$('.calendar').fullCalendar( | ||
'renderEvents', | ||
$.parseJSON("<%=j render(@recurring_event, format: :json).html_safe %>"), | ||
true | ||
); | ||
$('.modal').modal('hide'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$('.calendar').fullCalendar('removeEvents', '<%= "recurring_#{@recurring_event.id}" %>'); | ||
$('.modal').modal('hide'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$('#remote_container').html('<%= j render "edit" %>'); | ||
$('#edit_recurring_event').modal('show'); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
json.partial! @recurring_events, | ||
partial: 'recurring_events/recurring_event', | ||
as: :recurring_event |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
$('.modal-backdrop').hide(); | ||
$('#remote_container').html('<%= j render "new" %>'); | ||
$('#new_recurring_event').modal('show'); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
$('.calendar').fullCalendar('removeEvents', '<%= "recurring_#{@recurring_event.id}" %>'); | ||
$('.calendar').fullCalendar( | ||
'renderEvents', | ||
$.parseJSON("<%= j render(@recurring_event, format: :json).html_safe %>"), | ||
true | ||
); | ||
$('.modal').modal('hide'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
Rails.application.routes.draw do | ||
resources :recurring_events | ||
resources :events | ||
root 'visitors#index' | ||
|
||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# rails g model recurring_event title anchor:date frequency:integer color | ||
|
||
class CreateRecurringEvents < ActiveRecord::Migration[5.0] | ||
def change | ||
create_table :recurring_events do |t| | ||
t.string :title | ||
t.date :anchor | ||
t.integer :frequency, limit: 1, default: 0 | ||
t.string :color | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Oops, something went wrong.