Utilisation de la dernière version de simple_calendar

recurrent
echarp 9 years ago
parent 20b8c11c66
commit 3873317c24
  1. 3
      Gemfile
  2. 13
      Gemfile.lock
  3. 5
      app/assets/javascripts/events.js.coffee
  4. 42
      app/assets/stylesheets/events.css.sass
  5. 11
      app/controllers/events_controller.rb
  6. 16
      app/models/event.rb
  7. 43
      app/views/events/index.html.haml

@ -63,8 +63,7 @@ gem 'email_validator'
# To display a patched diff for event descriptions
gem 'differ'
gem 'simple_calendar', github: 'echarp/simple_calendar'
#gem 'simple_calendar', github: 'excid3/simple_calendar', branch: '1.0'
gem 'simple_calendar'
# Markdown display
gem 'redcarpet'

@ -1,10 +1,3 @@
GIT
remote: git://github.com/echarp/simple_calendar.git
revision: 415838f60847068bc29459f5a275c04d4db05ee9
specs:
simple_calendar (0.1.9)
rails (>= 3.0)
GIT
remote: git://github.com/gregbell/active_admin.git
revision: 0e0b3694bace985f355135f9628ea7918c3695d2
@ -110,7 +103,7 @@ GEM
activemodel
erubis (2.7.0)
eventmachine (1.0.3)
execjs (2.2.0)
execjs (2.2.1)
fastercsv (1.5.5)
ffi (1.9.3)
font-awesome-rails (4.1.0.0)
@ -250,6 +243,8 @@ GEM
json (~> 1.8)
rdoc (~> 4.0, < 5.0)
sexp_processor (4.4.3)
simple_calendar (1.1.3)
rails (>= 3.0)
slim (2.0.2)
temple (~> 0.6.6)
tilt (>= 1.3.3, < 2.1)
@ -319,7 +314,7 @@ DEPENDENCIES
redcarpet
sass-rails (~> 4.0.1)
sdoc (~> 0.4.0)
simple_calendar!
simple_calendar
spring
therubyracer
turbolinks

@ -1,8 +1,3 @@
$(document).ready ->
$('form.region_selector select').change ->
this.form.submit()
$('main form.region_selector + h2').each ->
selector = $(this)
year = selector.html().substr selector.html().search(/\d{4}</), 4
selector.html selector.html().replace(/\d{4}</, '<a class="year_selector" href="?year='+year+'">'+year+'</a><')

@ -3,31 +3,34 @@
form.region_selector
width: 98%
position: absolute
margin-top: 2.5em
margin: 2.45em 0.4em
label
display: none
main form.region_selector + h2
width: 100%
header.calendar-header
font-size: 1.5em
margin-top: 1em
font-weight: bolder
margin-bottom: 0.1em
&.year
margin-top: 1em
margin-bottom: 2.55em
a
margin: 0
a
margin: 0 6px
font-weight: normal
&.previous-month
margin-right: 8px
&.next-month
margin-left: 8px
// For whole year calendar
main form.region_selector + h2 + h2
padding: 0.26em 0 0
font-size: 1.2em
margin-bottom: 0.8em
table.calendar + h2
margin: 1em
font-size: 1.2em
&.year_selector
margin: 0
font-size: normal
&.month_selector
display: block
font-size: 0.8em
font-weight: bolder
margin-bottom: -2.1em
table.calendar
body.events.index table
width: 90%
margin-top: 3.5em
tr
@ -56,7 +59,7 @@ table.calendar
.day_number
font-size: 0.8em
margin-top: -1px
&.not-current-month
&.prev-month, &.next-month
border: none
background-color: #ededed
.day_number
@ -89,6 +92,7 @@ table.calendar
color: #444
margin: 0
padding: 0
margin-top: 0.38em
.event
font-size: smaller

@ -12,11 +12,16 @@ class EventsController < ApplicationController
respond_to do |format|
format.html {
if (params[:year] and !params[:month])
if params[:year]
# Whole year calendar
@events = @events.year params[:year]
@events = @events.year params[:year].to_i
else
@events = @events.month(params[:year] || Date.today.year, params[:month] || Date.today.month)
if params[:start_date]
start_date = Date.parse params[:start_date]
else
start_date = Date.today
end
@events = @events.month start_date.change day: 1
end
}

@ -1,4 +1,6 @@
class Event < ActiveRecord::Base
extend SimpleCalendar
belongs_to :region, foreign_key: 'region'
has_many :notes
has_one :related_city, foreign_key: :name, primary_key: :city, class_name: City
@ -14,16 +16,16 @@ class Event < ActiveRecord::Base
scope :future, -> { where('end_time >= now()').order(start_time: :asc) }
scope :future_30, -> {
where('start_time >= now() and end_time <= ?', Date.today + 30)
.order(:start_time)
.order :start_time
}
scope :year, -> year {
where 'end_time >= ? and start_time < ?',
"#{year}-1-1", "#{year.to_i+1}-1-1"
where '? <= end_time and start_time <= ?',
Date.new(year, 1, 1).beginning_of_week, Date.new(year, 12, 31).end_of_week
}
scope :month, -> year, month {
where 'end_time >= ? and start_time <= ?',
"#{year}-#{month.to_i-1}-23",
"#{month == '12' ? year.to_i+1 : year}-#{month == '12' ? 1 : month.to_i+1}-7"
scope :month, -> start_date {
where '? <= end_time and start_time <= ?',
start_date.beginning_of_week,
start_date.next_month.end_of_week
}
scope :region, -> region { where 'region = ? or locality', region }
scope :tag, -> tag { where 'tags like ?', "%#{tag}%" }

@ -1,41 +1,48 @@
%form.region_selector
- if (params[:month])
= hidden_field_tag :month, params[:month]
- if (params[:year])
- if params[:start_date]
= hidden_field_tag :start_date, params[:start_date]
- if params[:year]
= hidden_field_tag :year, params[:year]
= label_tag :region, Region.model_name.human
= select_tag :region,
options_from_collection_for_select(Region.all, 'id', 'name', params[:region]),
prompt: t('.all_regions')
- if (params[:year] and !params[:month])
- if params[:year]
-# Whole year calendar
%h2
- params[:year] ||= Date.today.year
%header.calendar-header.year
= link_to '<<', "?year=#{params[:year].to_i-1}"
= params[:year]
= link_to '>>', "?year=#{params[:year].to_i+1}"
- (1..12).each do |i|
- params[:month] = i
- params[:start_date] = "#{params[:year]}-#{i}-01"
= calendar @events, { prev_text: '', next_text: '', start_day: :monday,
params: { region: params[:region], tag: params[:tag] } } do |event|
= month_calendar events: @events,
title: -> (start_date) { raw link_to I18n.t('date.month_names')[start_date.month]+' '+params[:year], root_url( start_date: start_date), class: 'month_selector' },
previous_link: -> (param, date_range) { },
next_link: -> (param, date_range) { } do |date, events|
.day_number= date.day
%ul.events
- events.select { |e| e.start_time.to_date <= date and date <= e.end_time.to_date }.sort_by { |e| e.city }.each do |event|
%li.event
= link_to event do
%strong= event.city.gsub('-', ' ')
= event.title
- else
= month_calendar events: @events,
title: -> (start_date) { raw "#{I18n.t('date.month_names')[start_date.month]} #{link_to start_date.year, root_url( year: start_date.year), class: 'year_selector'}" },
previous_link: -> (param, date_range) { link_to '<<', { param => date_range.first - 1.day } },
next_link: -> (param, date_range) { link_to '>>', { param => date_range.last + 1.day } } do |date, events|
.day_number= date.day
%ul.events
- events.select { |e| e.start_time.to_date <= date and date <= e.end_time.to_date }.sort_by { |e| e.city }.each do |event|
%li.event
= link_to event do
%strong= event.city.gsub('-', ' ')
= event.title
- else
= calendar @events, { prev_text: '<<', next_text: '>>', start_day: :monday,
params: { region: params[:region], tag: params[:tag] } } do |event|
%ul.events
%li.event
= link_to event do
%strong= event.city.gsub('-', ' ')
= event.title
.formats
=t '.calendar_in'
= link_to('rss', events_url(:rss, tag: params[:tag]))+','

Loading…
Cancel
Save