Skip to content

bcalloway/rails-calendar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scheduling Calendar

A Rails plugin that creates the ability to add specific events to a calendar and assign them to categories. On the frontend, a calendar listing will be displayed along with a mini-calendar widget with events highlighted, as well as a filter-by-category form. Calendar can be exported in iCal format, or subscribed to.

NOTE: This is a work in progress and currently exists as a set of sample files to add to an existing project. A gem might be created in the future.

Features

  • Add/Edit/Delete calendar event for a specific date or date range
  • Assign calendar event to a category (program)
  • Add/Edit/Delete categories (programs)
  • Export calendar events as an iCal file
  • Subscribe to entire calendar
  • Subscribe to a specific category or categories
  • Decent test coverage using Shoulda, Mocha, and Factory Girl

What’s Included

  • jRails jQuery javascript libraries
  • SASS stylesheets for skinning the backend and frontend of the calendar
  • Admin and Application layouts
  • Supporting images for the tool
  • Database migration file
  • All necessary models, controllers, and helpers
  • All necessary views

Requirements

Gems

Be sure to vendor the following gems by inserting these lines into your environment.rb file:


  config.gem 'RedCloth',
             :lib => 'redcloth' 
  config.gem 'will_paginate', 
             :lib => 'will_paginate', 
             :source => 'http://gemcutter.org'
  config.gem 'haml',
             :source => 'http://gemcutter.org'
  config.gem 'formtastic',
             :source => 'http://gemcutter.org'
  config.gem 'searchlogic',
             :lib => 'searchlogic',
             :source => 'http://gemcutter.org'
  config.gem 'icalendar'

To run the included tests, place this in config/environments/test.rb:


config.gem ‘mocha’
config.gem ‘factory_girl’,
:lib => ‘factory_girl’,
:source => ‘http://gemcutter.org’
config.gem ‘shoulda’,
:lib => ‘shoulda’,
:source => ‘http://gemcutter.org’

require ‘factory_girl’ require ‘mocha’

Then run


  sudo rake gems:install
  rake gems:unpack

To setup formtastic, be sure to run the following generator:


  script/generate formtastic

Plugins

  • calendar_helper

Run script/plugin install git://github.com/topfunky/calendar_helper.git

Routes

Add these to routes.rb
Note: for calendar routes, params[:id] is the current date in the following format, 2009-01-14


  map.resources :programs
  map.resources :calendars
  map.connect  '/admin/calendars/:id', :controller => 'calendars', :action => 'index'
  map.connect  '/daily_event/:id', :controller => 'calendars', :action => 'daily_list'
  map.connect '/calendar/:id', :controller => 'calendars', :action => 'calendar_list'
  map.connect '/calendars/:id', :controller => 'calendars', :action => 'show'
  map.connect '/filter/calendar/:id', :controller => 'calendars', :action => 'filter'
  map.connect '/subscribe', :controller => 'calendars', :action => 'subscribe'
  map.connect '/subscribe_selected/:id/:program', :controller => 'calendars', :action => 'subscribe_selected'
  map.connect '/events/:id', :controller => 'calendars', :action => 'export_events'
  map.connect '/daily_events/:id', :controller => 'calendars', :action => 'export_daily_events'
  map.connect '/events/:id/:program', :controller => 'calendars', :action => 'export_selected_events'
  map.connect '/event/:id', :controller => 'calendars', :action => 'export_event'

How to Use

Out of the box, this provides both admin views and frontend views. There is no authentication built-in so you are free to choose one to protect the admin panel.

In your application layout, reference these stylesheets and javascripts:


  = stylesheet_link_tag 'formtastic', 'screen', 'calendar', 'facebox', :media => 'all', :cache => true
  = javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js', 'facebox', 'base', :cache => true

In your admin layout, reference these stylesheets and javascripts.


  = stylesheet_link_tag 'formtastic', :media => 'all', :cache => 'admin/all'
  = stylesheet_link_tag 'http://jqueryui.com/latest/themes/base/ui.all.css'

= javascript_include_tag ‘http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js’, ‘http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js’, ‘admin’, ‘http://jqueryui.com/latest/ui/ui.datepicker.js’

As an alternative, you can use the included admin layout which has it’s own theme supplied.

To access the calendar list view in the frontend, create a link like so:


= link_to "Calendar", "calendar/#{Time.now.strftime('%Y-%m-%d')}"

There is also a view named calendar.html.haml with will produce a standard calendar monthly view. To use this instead of the default list view, change the calendar_list action in calendars_controller.rb from this:


def calendar_list
  @events = Calendar.current_events(params[:id])
  @daily_events = @events.group_by { |d| d.start_date }

respond_to do |format| format.html{ render :layout => ‘application’ } end

end

to this:


def calendar_list
  @events = Calendar.current_events(params[:id])
  @daily_events = @events.group_by { |d| d.start_date }

respond_to do |format| format.html{ render :layout => ‘application’, :template => ‘calendars/calendar.html.haml’ } end

end

Check the routes.rb file for a better understanding on how to user other routes.

License

Copyright © 2009 Brandon Calloway, released under the MIT license

About

A set of files to use in order to add a category-based calendar to an existing Rails project

Resources

License

Stars

Watchers

Forks

Packages

No packages published