base de l'application

* Affichage des ressources
* Affichage des évènements
* Affichage des réservations
* Partie d'administration protégée
This commit is contained in:
François Vaux 2010-07-23 16:35:50 +02:00
parent 8ff914cb5a
commit 8d3dad9b8c
87 changed files with 13975 additions and 0 deletions

10
Rakefile Normal file
View file

@ -0,0 +1,10 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'

View file

@ -0,0 +1,10 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
# Scrub sensitive parameters from your log
# filter_parameter_logging :password
end

View file

@ -0,0 +1,2 @@
class BookingsController < ApplicationController
end

View file

@ -0,0 +1,37 @@
class EventsController < ApplicationController
# GET /:key/event/:id/edit
def edit
end
# POST /:key/event/add
def create
@item = Item.find_by_key(params[:key])
dates = params[:event].delete(:dates)
e = Event.new(params[:event].merge(:item => @item))
if e.valid?
dates = extract_dates(dates)
p dates
else
flash[:errors] = ""
e.errors.each do |attr,msg|
flash[:errors] += "<li>#{msg}</li>"
end
redirect_to item_path(:key => @item.key)
end
end
# PUT /:key/event/:id
def update
end
# DELETE /:key/event/:id
def delete
end
private
def extract_dates(text)
text.each_line.to_a
end
end

View file

@ -0,0 +1,53 @@
class ItemsController < ApplicationController
before_filter :set_date
# GET /
def index
render :action => 'public_index' unless session[:authorized]
@items = Item.find(:all, :include => [:events])
end
# GET /:key
def show
@item = Item.find_by_key(params[:key])
end
# GET /new
def new
end
# GET /:key/edit
def edit
render :action => 'public_edit' unless session[:authorized]
end
# POST /
def create
end
# PUT /:key
def update
end
# DELETE /:key
def delete
end
# GET /authentify
def authentify
if params[:secret] == ADMIN_SECRET_KEY
session[:authorized] = true
end
redirect_to '/'
end
private
def set_date
@date = begin
Date.strptime(params[:date], '%d/%m/%Y')
rescue ArgumentError, TypeError
Date.today
end
end
end

View file

@ -0,0 +1,3 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end

View file

@ -0,0 +1,2 @@
module BookingsHelper
end

View file

@ -0,0 +1,2 @@
module EventsHelper
end

View file

@ -0,0 +1,13 @@
module ItemHelper
def default_dates
[ @date.strftime('%d/%m/%Y'), hour(+0), hour(+1) ].join(' ')
end
def hour(hdelta)
t = Time.now + (hdelta*3600)
q = ((t.min / 60.0) * 4).ceil / 4.0 * 60
hour = (q == 60 ? t.hour + 1 : t.hour).round
min = (q == 60 ? 0 : q ).round
"%02d:%02d" % [hour, min]
end
end

View file

@ -0,0 +1,2 @@
module ItemsHelper
end

18
app/models/booking.rb Normal file
View file

@ -0,0 +1,18 @@
class Booking < ActiveRecord::Base
UNIT = 100 / 24.0 / 4
belongs_to :event
def margin_for(date, offset)
quarter = [0, 15, 30, 45].index(((start_at.min/15.0).round * 15) % 60)
(start_at.hour * 4*UNIT) + (quarter * UNIT) - offset
end
def width_for(date)
(length/3600.0 * 4*UNIT) + ((length/60.0%60) * UNIT)
end
def length
end_at - start_at
end
end

25
app/models/event.rb Normal file
View file

@ -0,0 +1,25 @@
class Event < ActiveRecord::Base
TAG_RE = /\[[^]]+\]/
belongs_to :item
has_many :bookings
validates_presence_of :title, :message => "Le titre ne peut pas être vide"
validates_length_of :title, :within => 4...140,
:message => "Le titre doit faire entre 4 et 140 caractères"
def generate_color
digest = Digest::MD5.hexdigest(title =~ TAG_RE ? $~.to_s : self.title)
self.color = "##{digest[0...6]}"
end
def upcoming_bookings
self.bookings.
find(:all, :conditions => ['start_at >= ?', Date.today.at_midnight])
end
def anchor
'event-%s' % id.to_s(16)
end
end

39
app/models/item.rb Normal file
View file

@ -0,0 +1,39 @@
class Item < ActiveRecord::Base
has_many :events
has_many :bookings, :through => :events
validates_presence_of :name, :email
before_create :regenerate_key
def self.find_by_key(*args)
super(*args) or raise NotFound
end
class NotFound < StandardError; end
# Create a random string (128 ^ 32 possibilities)
def regenerate_key
string = Array.new(32) { rand(128).chr }.join
self.key = Digest::MD5.hexdigest(string)
end
def upcoming_events
self.events.map(&:upcoming_bookings).flatten.map(&:event)
end
def bookings_for(date)
bookings_between(date, date)
end
def bookings_between(lower, upper)
bookings_range(lower.at_midnight, 1.day.since(upper).at_midnight - 1)
end
private
def bookings_range(lower, upper)
self.bookings.find :all,
:conditions => ['start_at >= ? AND end_at <= ?', lower, upper]
end
end

View file

@ -0,0 +1,5 @@
<li class="booking">
De <%= booking.start_at.strftime('%H:%M') %>
à <%= booking.end_at.strftime('%H:%M') %>
le <%= booking.start_at.strftime('%d/%m/%Y') %>
</li>

View file

@ -0,0 +1,7 @@
<li class="event">
<h3 style="background-color: <%= event.color %>"><%=h event.title %></h3>
<p><%=h event.details %></p>
<ul class="booking-list">
<%= render :partial => 'bookings/booking', :collection => event.upcoming_bookings %>
</ul>
</li>

View file

@ -0,0 +1,111 @@
<div id="day-view">
<table id="monthly-calendar">
<thead>
<tr class="cal-nav">
<th colspan="7">
<a href="?date=<%= 1.month.until(now).strftime('%d/%m/%Y')
%>" class="cal-prev" title="Mois précédent">«</a>
<strong><%= now.strftime('%B %Y') %></strong>
<a href="?date=<%= 1.month.since(now).strftime('%d/%m/%Y')
%>" class="cal-next" title="Mois suivant">»</a>
</th>
</tr>
<tr class="cal-head">
<th>lun</th> <th>mar</th> <th>mer</th> <th>jeu</th>
<th>ven</th> <th>sam</th> <th>dim</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="7">
<form action="" method="get">
<p>
<input type="text" name="date" value="<%= now.strftime('%d/%m/%Y') %>" />
<input type="submit" value="Go" /><br />
<a href="?date=<%= Date.today.strftime('%d/%m/%Y') %>">Aujourd'hui</a>
</p>
</form>
</td>
</tr>
</tfoot>
<tbody>
<tr><%
first = Date.civil(now.year, now.month, 1)
last = Date.civil(now.year, now.month, -1)
wday = 1
current = 1
# Initial padding, if needed
while wday != first.wday %>
<td></td> <%
wday = (wday + 1) % 7
end
# Day cells
while current <= last.mday %>
<td<%= ' class="current-day"' if current == now.day
%>><a href="?date=<%= now.strftime('%02d/%%m/%%Y' % current) %>"><%=
current
%></a></td><%
# Next row after every sunday
if (wday % 7).zero? %>
</tr>
<tr><%
end
wday = (wday + 1) % 7
current += 1
end
# Fill the remaining space
until ((wday-1) % 7).zero? %>
<td></td><%
wday += 1
end %>
</tr>
</tbody>
</table>
<table id="booking-calendar">
<thead>
<tr>
<td></td>
<th>00:00</th> <th>02:00</th> <th>04:00</th>
<th>06:00</th> <th>08:00</th> <th>10:00</th>
<th>12:00</th> <th>14:00</th> <th>16:00</th>
<th>18:00</th> <th>20:00</th> <th>22:00</th>
</tr>
</thead>
<tbody>
<%
7.times do |offset|
current_day = offset.days.since(now)
bookings = @item.bookings_for(current_day)
offset, m, w = 0.0, 0.0, 0.0
%>
<tr<%= ' class="calendar-now"' if current_day == now %>>
<th><%= current_day.strftime('%a %d/%m') %></th>
<td class="calendar-day" colspan="12"><%
bookings.each do |booking| %>
<a class="calendar-booking" href="#<%= booking.event.anchor %>"
style="background-color: <%=
booking.event.color
%>; margin-left: <%=
m = booking.margin_for(current_day, offset)
m + 0.15
%>%; width: <%=
w = booking.width_for(current_day)
%>%;"><span><%= booking.event.title %></span></a><%
offset += m if booking == bookings.first
offset += w
end
%>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>

View file

@ -0,0 +1,27 @@
<li class="item">
<h2><%= item.name %></h2>
<p>
<span class="key"><%=
link_to item.key, item_path(:key => item.key)
%></span>
&lt;<span class="email"><%=
link_to item.email, "mailto:#{item.email}"
%></span>&gt;
<span class="edit">
<%= link_to "Éditer", edit_item_path(:key => item.key) %>
</span>
</p>
<ul class="event-list">
<% if item.upcoming_events.empty? %>
<li>Aucun évènement à venir</li>
<% else %>
<li>Évènements à venir :</li>
<%= render :partial => 'events/event', :collection => item.upcoming_events %>
<% end %>
</ul>
<p class="timestamps">
<%= item.created_at.localtime.strftime('Créé le %d/%m/%Y à %Hh%M') %>
</p>
</li>

View file

@ -0,0 +1,14 @@
<select name="<%= name %>_hour" id="event-<%= name %>-hour">
<% (0..23).each do |i| -%>
<option value="<%= i %>" <%=
'selected="selected"' if i == hour
%>><%= "%02d" % i %>h</option>
<% end -%>
</select>
<select name="<%= name %>_min" id="event-<%= name %>-min">
<% (0..59).step(15) do |i| -%>
<option value="<%= i %>" <%=
'selected="selected"' if i == min
%>><%= "%02d" % i %></option>
<% end -%>
</select>

View file

@ -0,0 +1,5 @@
<h1>EvoResa</h1>
<ul id="item-list">
<%= render :partial => 'item', :collection => @items %>
</ul>

View file

@ -0,0 +1,6 @@
<h1>EvoResa</h1>
<div id="content-page">
<p>Vous devez être authentifié pour éditer une ressource.</p>
</div>

View file

@ -0,0 +1,5 @@
<h1>EvoResa</h1>
<div id="content-page">
<p>L'accès à une ressource nécessite une clé.</p>
</div>

View file

@ -0,0 +1,60 @@
<% content_for :title do %>
<%= @item.name %> /
<% end %>
<h1><%= @item.name %></h1>
<%= render :partial => 'calendar', :locals => { :now => @date } %>
<div id="actions">
<div id="booking-form">
<h2>Réserver</h2>
<% if flash[:errors] %>
<ul class="errors">
<%= flash[:errors] %>
</ul>
<% end %>
<% form_for :event, :url => add_event_path(:key => @item.key) do |f| %>
<p>
<%= f.label :title, "Titre :" %>
<%= f.text_field :title %>
<span class="form-field-info">140 caractères maximum</span>
</p>
<p>
<%= f.label :details, "Détails :" %>
<%= f.text_area :details, :rows => 5, :cols => 20 %>
</p>
<p>
<%= f.label :dates, "Dates :" %>
<%= text_area_tag 'event[dates]', default_dates, :rows => 5, :cols => 20 %>
<span class="form-field-info">Une date par ligne</span>
</p>
<p>
<%= f.submit "Valider" %>
</p>
<% end %>
</div>
<ul id="event-list">
<% upper = 6.days.since(@date)
@item.bookings_between(@date, upper).map(&:event).uniq.each do |event| %>
<li class="event" id="<%= event.anchor %>">
<strong style="background-color: <%= event.color %>;">
<%=h event.title %>
<a href="#" class="top-anchor">↑</a>
</strong>
<span class="details">
<%=h event.details %>
<br />
</span>
<ul class="booking-list">
<%=
render :partial => 'bookings/booking',
:collection => event.item.bookings_between(@date, upper)
%>
</ul>
<p class="edit">
<%= link_to 'Éditer', edit_event_path(:key => @item.key, :id => event.id) %>
</p>
</li>
<% end %>
</div>

View file

@ -0,0 +1,18 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%= stylesheet_link_tag "reset-min", "main" %>
<title><%= yield :title %> EvoResa</title>
</head>
<body>
<%= yield %>
<p id="footer">
propulsé par EvoResa
<a id="help" href="#" title="Aide d'EvoResa">Aide</a>
</p>
</body>
</html>

110
config/boot.rb Normal file
View file

@ -0,0 +1,110 @@
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
module Rails
class << self
def boot!
unless booted?
preinitialize
pick_boot.run
end
end
def booted?
defined? Rails::Initializer
end
def pick_boot
(vendor_rails? ? VendorBoot : GemBoot).new
end
def vendor_rails?
File.exist?("#{RAILS_ROOT}/vendor/rails")
end
def preinitialize
load(preinitializer_path) if File.exist?(preinitializer_path)
end
def preinitializer_path
"#{RAILS_ROOT}/config/preinitializer.rb"
end
end
class Boot
def run
load_initializer
Rails::Initializer.run(:set_load_path)
end
end
class VendorBoot < Boot
def load_initializer
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
Rails::Initializer.run(:install_gem_spec_stubs)
Rails::GemDependency.add_frozen_gem_path
end
end
class GemBoot < Boot
def load_initializer
self.class.load_rubygems
load_rails_gem
require 'initializer'
end
def load_rails_gem
if version = self.class.gem_version
gem 'rails', version
else
gem 'rails'
end
rescue Gem::LoadError => load_error
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
exit 1
end
class << self
def rubygems_version
Gem::RubyGemsVersion rescue nil
end
def gem_version
if defined? RAILS_GEM_VERSION
RAILS_GEM_VERSION
elsif ENV.include?('RAILS_GEM_VERSION')
ENV['RAILS_GEM_VERSION']
else
parse_gem_version(read_environment_rb)
end
end
def load_rubygems
min_version = '1.3.2'
require 'rubygems'
unless rubygems_version >= min_version
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
exit 1
end
rescue LoadError
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
exit 1
end
def parse_gem_version(text)
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
end
private
def read_environment_rb
File.read("#{RAILS_ROOT}/config/environment.rb")
end
end
end
end
# All that for this:
Rails.boot!

22
config/database.yml Normal file
View file

@ -0,0 +1,22 @@
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000

52
config/environment.rb Normal file
View file

@ -0,0 +1,52 @@
# Be sure to restart your server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{RAILS_ROOT}/extras )
# Specify gems that this application depends on and have them installed with rake gems:install
# config.gem "bj"
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
# config.gem "sqlite3-ruby", :lib => "sqlite3"
# config.gem "aws-s3", :lib => "aws/s3"
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Skip frameworks you're not going to use. To use Rails without a database,
# you must remove the Active Record framework.
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names.
config.time_zone = 'UTC'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
# config.i18n.default_locale = :de
end
# Local options
Date::MONTHNAMES = [nil,
'Janvier', 'Février', 'Mars', 'Avril',
'Mai', 'Juin', 'Juillet', 'Août',
'Septembre', 'Octobre', 'Novembre', 'Décembre'
]
Date::ABBR_DAYNAMES = %w(dim lun mar mer jeu ven sam)
ADMIN_SECRET_KEY = 'ee7ebb0a6e3ce158407baf986811a3a2'

View file

@ -0,0 +1,17 @@
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false

View file

@ -0,0 +1,28 @@
# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.action_view.cache_template_loading = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!

View file

@ -0,0 +1,28 @@
# Settings specified here will take precedence over those in config/environment.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_view.cache_template_loading = true
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql

View file

@ -0,0 +1,7 @@
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
# Rails.backtrace_cleaner.remove_silencers!

View file

@ -0,0 +1,10 @@
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end

View file

@ -0,0 +1,5 @@
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone

View file

@ -0,0 +1,21 @@
# Be sure to restart your server when you modify this file.
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
if defined?(ActiveRecord)
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Store the full class name (including module namespace) in STI type column.
ActiveRecord::Base.store_full_sti_class = true
end
ActionController::Routing.generate_best_match = false
# Use ISO 8601 format for JSON serialized times and dates.
ActiveSupport.use_standard_json_time_format = true
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
# if you're including raw json in an HTML page.
ActiveSupport.escape_html_entities_in_json = false

View file

@ -0,0 +1,15 @@
# Be sure to restart your server when you modify this file.
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
ActionController::Base.session = {
:key => '_evoresa2_session',
:secret => 'ef210f24cc7de77bcae2e22eabb805b106142d9ce41ea35fbc76b6b16657014df12e890eb2230847d45fb0f07c9f733db9a788c47eac7d4dcf83a3e862d43003'
}
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rake db:sessions:create")
# ActionController::Base.session_store = :active_record_store

5
config/locales/en.yml Normal file
View file

@ -0,0 +1,5 @@
# Sample localization file for English. Add more files in this directory for other locales.
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
hello: "Hello world"

50
config/routes.rb Normal file
View file

@ -0,0 +1,50 @@
ActionController::Routing::Routes.draw do |map|
map.connect '/authentify/:secret', :controller => 'items', :action => :authentify,
:conditions => { :method => :get }
map.with_options :controller => 'items' do |items|
items.connect '/', :action => :index,
:conditions => { :method => :get }
items.item "/:key", :action => :show,
:conditions => { :method => :get }
items.new_item "/new", :action => :new,
:conditions => { :method => :get }
items.edit_item "/:key/edit", :action => :edit,
:conditions => { :method => :get }
items.connect "/", :action => :create,
:conditions => { :method => :post }
items.connect "/:key", :action => :update,
:conditions => { :method => :put }
items.connect "/:key", :action => :delete,
:conditions => { :method => :delete }
items.with_options :controller => 'events' do |events|
events.edit_event '/:key/event/:id/edit', :action => :edit,
:conditions => { :method => :get }
events.add_event '/:key/event/add', :action => :create,
:conditions => { :method => :post }
events.connect '/:key/event/:id', :action => :update,
:conditions => { :method => :put }
events.connect '/:key/event/:id', :action => :delete,
:conditions => { :method => :delete }
events.with_options :controller => 'bookings' do |bookings|
bookings.edit_booking '/:key/event/:id/booking/:booking_id/edit',
:action => :edit, :conditions => { :method => :get }
bookings.connect '/:key/event/:id/booking/add', :action => :create,
:conditions => { :method => :post }
bookings.connect '/:key/event/:id/booking/:booking_id',
:action => :update, :conditions => { :method => :put }
bookings.connect '/:key/event/:id/booking/:booking_id',
:action => :delete, :conditions => { :method => :delete }
end
end
end
end

BIN
db/development.sqlite3 Normal file

Binary file not shown.

View file

@ -0,0 +1,15 @@
class CreateItems < ActiveRecord::Migration
def self.up
create_table :items do |t|
t.string :name
t.string :email
t.string :key
t.timestamps
end
end
def self.down
drop_table :items
end
end

View file

@ -0,0 +1,16 @@
class CreateEvents < ActiveRecord::Migration
def self.up
create_table :events do |t|
t.string :title
t.text :details
t.references :item
t.string :color
t.timestamps
end
end
def self.down
drop_table :events
end
end

View file

@ -0,0 +1,15 @@
class CreateBookings < ActiveRecord::Migration
def self.up
create_table :bookings do |t|
t.timestamp :start_at
t.timestamp :end_at
t.references :event
t.timestamps
end
end
def self.down
drop_table :bookings
end
end

39
db/schema.rb Normal file
View file

@ -0,0 +1,39 @@
# This file is auto-generated from the current state of the database. Instead of editing this file,
# please use the migrations feature of Active Record to incrementally modify your database, and
# then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
# to create the application database on another system, you should be using db:schema:load, not running
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20100722153250) do
create_table "bookings", :force => true do |t|
t.datetime "start_at"
t.datetime "end_at"
t.integer "event_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "events", :force => true do |t|
t.string "title"
t.text "details"
t.integer "item_id"
t.string "color"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "items", :force => true do |t|
t.string "name"
t.string "email"
t.string "key"
t.datetime "created_at"
t.datetime "updated_at"
end
end

7
db/seeds.rb Normal file
View file

@ -0,0 +1,7 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Major.create(:name => 'Daley', :city => cities.first)

2
doc/README_FOR_APP Normal file
View file

@ -0,0 +1,2 @@
Use this README file to introduce your application and point to useful places in the API for learning more.
Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.

25
lib/tasks/evoresa.rake Normal file
View file

@ -0,0 +1,25 @@
env_file = File.expand_path('../../../config/environment', __FILE__)
require env_file
namespace :evoresa do
desc "Show the current admin key"
task :show_key do
puts "Current key is: " + ADMIN_SECRET_KEY
puts "Change with rake evoresa:set_key [KEY=<key>]"
end
desc "Set the current admin key"
task :set_key do
require 'digest/md5'
file = env_file + '.rb'
config = File.read(file)
random_key = Digest::MD5.hexdigest(Array.new(32) { rand(128).chr }.join)
new_key = ENV['KEY'] || random_key
config.sub!(/(ADMIN_SECRET_KEY) = '[^']+'/, '\1 = \'' + new_key + "'")
File.open(file, 'w+') {|f| f.write(config) }
puts "The new key is: " + new_key
end
end

4702
log/development.log Normal file
View file

@ -0,0 +1,4702 @@
SQL (0.4ms)  SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'

SQL (0.2ms) select sqlite_version(*)
SQL (8.0ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
SQL (5.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
SQL (0.4ms)  SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'

SQL (0.1ms) SELECT version FROM schema_migrations
Migrating to CreateItems (20100722152749)
SQL (0.6ms) CREATE TABLE "items" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255), "key" varchar(255), "created_at" datetime, "updated_at" datetime) 
SQL (0.2ms) INSERT INTO schema_migrations (version) VALUES ('20100722152749')
Migrating to CreateEvents (20100722153153)
SQL (0.5ms) CREATE TABLE "events" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "details" text, "item_id" integer, "color" varchar(255), "created_at" datetime, "updated_at" datetime) 
SQL (0.1ms) INSERT INTO schema_migrations (version) VALUES ('20100722153153')
Migrating to CreateBookings (20100722153250)
SQL (0.4ms) CREATE TABLE "bookings" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "start_at" datetime, "end_at" datetime, "event_id" integer, "created_at" datetime, "updated_at" datetime) 
SQL (0.2ms) INSERT INTO schema_migrations (version) VALUES ('20100722153250')
SQL (0.5ms)  SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'

SQL (0.3ms) SELECT version FROM schema_migrations
SQL (0.3ms)  SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'

SQL (0.1ms) PRAGMA index_list("bookings")
SQL (0.1ms) PRAGMA index_list("events")
SQL (0.1ms) PRAGMA index_list("items")
Processing ItemsController#show (for 127.0.0.1 at 2010-07-23 10:01:25) [GET]
ActionView::MissingTemplate (Missing template items/show.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:17:43) [GET]
ActionView::MissingTemplate (Missing template items/index.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#show (for 127.0.0.1 at 2010-07-23 11:18:04) [GET]
Parameters: {"key"=>"authentify"}
ActionView::MissingTemplate (Missing template items/show.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#show (for 127.0.0.1 at 2010-07-23 11:18:35) [GET]
Parameters: {"key"=>"authentify"}
ActionView::MissingTemplate (Missing template items/show.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#show (for 127.0.0.1 at 2010-07-23 11:18:42) [GET]
Parameters: {"key"=>"authentify"}
ActionView::MissingTemplate (Missing template items/show.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#show (for 127.0.0.1 at 2010-07-23 11:18:46) [GET]
Parameters: {"key"=>"authentify"}
ActionView::MissingTemplate (Missing template items/show.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#authentify (for 127.0.0.1 at 2010-07-23 11:19:06) [GET]
Parameters: {"secret"=>"ee7ebb0a6e3ce158407baf986811a3a"}
ActionView::MissingTemplate (Missing template items/authentify.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#authentify (for 127.0.0.1 at 2010-07-23 11:19:32) [GET]
Parameters: {"secret"=>"ee7ebb0a6e3ce158407baf986811a3a"}
Redirected to http://localhost:3000/
Completed in 6ms (DB: 0) | 302 Found [http://localhost/authentify/ee7ebb0a6e3ce158407baf986811a3a]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:19:32) [GET]
ActionView::MissingTemplate (Missing template items/index.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#authentify (for 127.0.0.1 at 2010-07-23 11:19:46) [GET]
Parameters: {"secret"=>"ee7ebb0a6e3ce158407baf986811a3a"}
Redirected to http://localhost:3000/
Completed in 6ms (DB: 0) | 302 Found [http://localhost/authentify/ee7ebb0a6e3ce158407baf986811a3a]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:19:46) [GET]
ActionView::MissingTemplate (Missing template items/index.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#authentify (for 127.0.0.1 at 2010-07-23 11:20:02) [GET]
Parameters: {"secret"=>"ee7ebb0a6e3ce158407baf986811a3a2"}
Redirected to http://localhost:3000/
Completed in 7ms (DB: 0) | 302 Found [http://localhost/authentify/ee7ebb0a6e3ce158407baf986811a3a2]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:20:02) [GET]
ActionView::MissingTemplate (Missing template items/index.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:22:13) [GET]
ActionView::MissingTemplate (Missing template items/index.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:22:15) [GET]
ActionView::MissingTemplate (Missing template items/index.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:22:35) [GET]
ActionView::MissingTemplate (Missing template items/index.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:22:46) [GET]
ActionView::MissingTemplate (Missing template items/index.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#show (for 127.0.0.1 at 2010-07-23 11:23:15) [GET]
Parameters: {"key"=>"j"}
NameError (undefined local variable or method `sessions' for #<ItemsController:0xb66a59bc>):
app/controllers/items_controller.rb:12:in `show'
Rendered rescues/_trace (116.5ms)
Rendered rescues/_request_and_response (5.9ms)
Rendering rescues/layout (internal_server_error)
Processing ItemsController#show (for 127.0.0.1 at 2010-07-23 11:23:23) [GET]
Parameters: {"key"=>"j"}
ActionView::MissingTemplate (Missing template items/show.erb in view path app/views):
Rendering rescues/layout (internal_server_error)
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:23:33) [GET]
ActionView::MissingTemplate (Missing template items/public_index.erb in view path app/views):
app/controllers/items_controller.rb:6:in `index'
Rendering rescues/layout (internal_server_error)
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:23:41) [GET]
Rendering template within layouts/application
Rendering items/public_index
Completed in 90ms (View: 84, DB: 0) | 200 OK [http://localhost/]
Processing ApplicationController#index (for 127.0.0.1 at 2010-07-23 11:23:41) [GET]
ActionController::RoutingError (No route matches "/stylesheets/reset-min.css" with {:method=>:get}):
Rendering rescues/layout (not_found)
Processing ApplicationController#index (for 127.0.0.1 at 2010-07-23 11:23:41) [GET]
ActionController::RoutingError (No route matches "/stylesheets/main.css" with {:method=>:get}):
Rendering rescues/layout (not_found)
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:24:21) [GET]
Rendering template within layouts/application
Rendering items/public_index
Completed in 20ms (View: 13, DB: 0) | 200 OK [http://localhost/]
Processing ApplicationController#index (for 127.0.0.1 at 2010-07-23 11:24:21) [GET]
ActionController::RoutingError (No route matches "/images/help.png" with {:method=>:get}):
Rendering rescues/layout (not_found)
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:25:07) [GET]
Rendering template within layouts/application
Rendering items/public_index
Completed in 21ms (View: 14, DB: 0) | 200 OK [http://localhost/]
Processing ApplicationController#index (for 127.0.0.1 at 2010-07-23 11:25:07) [GET]
ActionController::RoutingError (No route matches "/images/help.png" with {:method=>:get}):
Rendering rescues/layout (not_found)
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:25:37) [GET]
Rendering template within layouts/application
Rendering items/public_index
Completed in 9ms (View: 3, DB: 0) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:25:42) [GET]
Rendering template within layouts/application
Rendering items/public_index
Completed in 19ms (View: 13, DB: 0) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:27:19) [GET]
Rendering template within layouts/application
Rendering items/public_index
Completed in 9ms (View: 3, DB: 0) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:27:31) [GET]
Rendering template within layouts/application
Rendering items/public_index
Completed in 19ms (View: 13, DB: 0) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:27:53) [GET]
Rendering template within layouts/application
Rendering items/public_index
Completed in 19ms (View: 13, DB: 0) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:43:34) [GET]
Rendering template within layouts/application
Rendering items/public_index
Completed in 25ms (View: 13, DB: 0) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:43:54) [GET]
Rendering template within layouts/application
Rendering items/public_index
Completed in 21ms (View: 14, DB: 0) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:45:38) [GET]
Rendering template within layouts/application
Rendering items/public_index
Completed in 20ms (View: 14, DB: 0) | 200 OK [http://localhost/]
Processing ItemsController#authentify (for 127.0.0.1 at 2010-07-23 11:45:44) [GET]
Parameters: {"secret"=>"ee7ebb0a6e3ce158407baf986811a3a2"}
Redirected to http://localhost:3000/
Completed in 7ms (DB: 0) | 302 Found [http://localhost/authentify/ee7ebb0a6e3ce158407baf986811a3a2]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:45:44) [GET]
Rendering template within layouts/application
Rendering items/index
Completed in 21ms (View: 14, DB: 0) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:47:48) [GET]
SyntaxError (/home/madx/dev/evolix/repos/evoresa2/app/models/item.rb:12: syntax error, unexpected tLSHFT, expecting '<' or '\n' or ';'
class NotFound << StandardError; end
^):
app/controllers/items_controller.rb:5:in `index'
Rendered rescues/_trace (121.2ms)
Rendered rescues/_request_and_response (0.8ms)
Rendering rescues/layout (internal_server_error)
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:48:00) [GET]
Item Load (1.3ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Completed in 54ms (View: 13, DB: 1) | 200 OK [http://localhost/]
Item Create (0.9ms) INSERT INTO "items" ("name", "created_at", "updated_at", "key", "email") VALUES('Salle de réunion', '2010-07-23 09:50:34', '2010-07-23 09:50:34', 'df4fac63f77f6896bb09d3b8f01441f7', 'madx@yapok.org')
Item Create (0.6ms) INSERT INTO "items" ("name", "created_at", "updated_at", "key", "email") VALUES('Rétroprojecteur', '2010-07-23 09:50:46', '2010-07-23 09:50:46', 'ea30e7bf781a84c83a5f250f47246b3b', 'madx@yapok.org')
Item Load (1.1ms) SELECT * FROM "items" 
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:50:50) [GET]
Item Load (1.7ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (9.4ms)
Rendered items/_item (0.3ms)
Completed in 44ms (View: 24, DB: 2) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:51:05) [GET]
Item Load (1.7ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (7.1ms)
Rendered items/_item (0.3ms)
Completed in 41ms (View: 21, DB: 2) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:51:37) [GET]
Item Load (1.6ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (7.4ms)
Rendered items/_item (0.3ms)
Completed in 40ms (View: 21, DB: 2) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:51:59) [GET]
Item Load (1.6ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (161.8ms)
Rendered items/_item (0.7ms)
Completed in 194ms (View: 176, DB: 2) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:52:36) [GET]
Item Load (1.6ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (8.0ms)
Rendered items/_item (0.5ms)
Completed in 41ms (View: 22, DB: 2) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:53:02) [GET]
Item Load (1.7ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (8.2ms)
Rendered items/_item (0.5ms)
Completed in 44ms (View: 23, DB: 2) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:53:07) [GET]
Item Load (1.7ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (8.0ms)
Rendered items/_item (0.5ms)
Completed in 51ms (View: 24, DB: 2) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:53:50) [GET]
Item Load (1.8ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (7.5ms)
Rendered items/_item (0.5ms)
Completed in 39ms (View: 13, DB: 2) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:53:51) [GET]
Item Load (1.6ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (6.2ms)
Rendered items/_item (0.5ms)
Completed in 30ms (View: 11, DB: 2) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:54:05) [GET]
Item Load (1.8ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (6.3ms)
Rendered items/_item (0.5ms)
Completed in 30ms (View: 11, DB: 2) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:54:06) [GET]
Item Load (1.6ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (6.5ms)
Rendered items/_item (0.5ms)
Completed in 34ms (View: 11, DB: 2) | 200 OK [http://localhost/]
Processing ItemsController#index (for 127.0.0.1 at 2010-07-23 11:54:07) [GET]
Item Load (1.7ms) SELECT * FROM "items" 
Rendering template within layouts/application
Rendering items/index
Rendered items/_item (6.7ms)
Rendered items/_item (0.5ms)