radiant-event_calendar-extension 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/README.md +0 -2
  2. data/VERSION +1 -1
  3. data/app/controllers/admin/events_controller.rb +12 -3
  4. data/app/controllers/admin/icals_controller.rb +2 -2
  5. data/app/models/calendar.rb +1 -1
  6. data/app/models/event.rb +13 -5
  7. data/app/models/ical.rb +15 -5
  8. data/app/views/admin/calendars/edit.html.haml +3 -0
  9. data/app/views/admin/calendars/index.html.haml +3 -0
  10. data/app/views/admin/calendars/new.html.haml +4 -1
  11. data/app/views/admin/event_venues/_event_venue.html.haml +4 -3
  12. data/app/views/admin/event_venues/_form.html.haml +1 -1
  13. data/app/views/admin/event_venues/edit.html.haml +3 -0
  14. data/app/views/admin/event_venues/index.html.haml +3 -0
  15. data/app/views/admin/event_venues/new.html.haml +4 -0
  16. data/app/views/admin/event_venues/remove.html.haml +30 -8
  17. data/app/views/admin/events/_event.html.haml +5 -13
  18. data/app/views/admin/events/_form.html.haml +3 -3
  19. data/app/views/admin/events/edit.html.haml +3 -0
  20. data/app/views/admin/events/index.html.haml +28 -2
  21. data/app/views/admin/events/new.html.haml +3 -0
  22. data/app/views/admin/events/remove.html.haml +11 -6
  23. data/app/views/events/_event.html.haml +2 -4
  24. data/config/routes.rb +2 -2
  25. data/event_calendar_extension.rb +1 -1
  26. data/pkg/radiant-event_calendar-extension-1.1.0.gem +0 -0
  27. data/public/stylesheets/sass/admin/event_calendar.sass +229 -216
  28. data/radiant-event_calendar-extension.gemspec +2 -4
  29. metadata +4 -6
  30. data/public/stylesheets/sass/admin/modules/_grid.sass +0 -56
  31. data/public/stylesheets/sass/constants.sass +0 -80
  32. data/public/stylesheets/sass/event_calendar.sass +0 -279
data/README.md CHANGED
@@ -72,8 +72,6 @@ The events controller uses `share_layouts` to define various page parts that you
72
72
  * `pagination` is the usual will_paginate block.
73
73
  * `faceting` here only gives the option to remove any date filters that have been applied. If you add the `taggable_events` extension it gets more useful.
74
74
 
75
- You will find minimal styling of some of these parts in `/stylesheets/sass/calendar.sass`,
76
-
77
75
  Set the config entry `event_calendar.layout` to the name of your layout and point a browser at /calendar to see what you've got.
78
76
 
79
77
  Here's a basic sample layout that should just work:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -1,15 +1,24 @@
1
1
  class Admin::EventsController < Admin::ResourceController
2
2
  paginate_models :per_page => 20
3
+ prepend_before_filter :get_venue
3
4
 
4
5
  def load_models
5
6
  pp = pagination_parameters
7
+ finder = @event_venue ? Event.at_venue(@event_venue) : Event.scoped
6
8
  unless params[:p]
7
- first_event = Event.future_and_current.first
8
- i = Event.all.index(first_event)
9
+ first_event = finder.future_and_current.first
10
+ i = finder.index(first_event) || 0 # if there are no future events we revert to the first page
9
11
  p = (i / pp[:per_page].to_i) + 1
10
12
  pp[:page] = p if p && p > 1
11
13
  end
12
- self.models = Event.paginate(pp)
14
+ self.models = finder.paginate(pp)
15
+ end
16
+
17
+ protected
18
+
19
+ def get_venue
20
+ @event_venue = EventVenue.find_by_id(params[:event_venue_id]) if params[:event_venue_id]
21
+ Rails.logger.warn "@event_venue is #{@event_venue.inspect}"
13
22
  end
14
23
 
15
24
  end
@@ -15,8 +15,8 @@ class Admin::IcalsController < Admin::ResourceController
15
15
 
16
16
  def refresh
17
17
  ical = Ical.find(params[:id])
18
- if events = ical.refresh
19
- flash[:notice] = ical.calendar.name + " calendar refreshed from iCal subscription."
18
+ if response = ical.refresh
19
+ flash[:notice] = ical.calendar.name + " calendar refreshed. #{response}"
20
20
  else
21
21
  flash[:notice] = "Error parsing " + ical.calendar.name + " calendar from iCal subscription."
22
22
  end
@@ -53,5 +53,5 @@ class Calendar < ActiveRecord::Base
53
53
  def to_ical
54
54
  self.to_ri_cal.to_s
55
55
  end
56
-
56
+
57
57
  end
data/app/models/event.rb CHANGED
@@ -13,7 +13,7 @@ class Event < ActiveRecord::Base
13
13
 
14
14
  belongs_to :master, :class_name => 'Event'
15
15
  has_many :occurrences, :class_name => 'Event', :foreign_key => 'master_id', :dependent => :destroy
16
- has_many :recurrence_rules, :class_name => 'EventRecurrenceRule', :dependent => :destroy, :conditions => {:active => 1}
16
+ has_many :recurrence_rules, :class_name => 'EventRecurrenceRule', :dependent => :destroy, :conditions => {:active => true}
17
17
  accepts_nested_attributes_for :recurrence_rules, :allow_destroy => true, :reject_if => lambda { |attributes| attributes['active'].to_s != '1' }
18
18
 
19
19
  validates_presence_of :uuid, :title, :start_date, :status_id
@@ -65,6 +65,14 @@ class Event < ActiveRecord::Base
65
65
 
66
66
  named_scope :by_end_date, { :order => "end_date ASC" }
67
67
 
68
+ named_scope :at_venue, lambda { |venue| # EventVenue object
69
+ { :conditions => ["event_venue_id = ?", venue.id] }
70
+ }
71
+
72
+ named_scope :except_these, lambda { |uuids| # array of uuid strings
73
+ { :conditions => ["uuid not in (#{uuids.map{'?'}.join(',')})", *uuids] }
74
+ }
75
+
68
76
  def self.in_the_last(period) # seconds. eg calendar.occurrences.in_the_last(1.week)
69
77
  finish = Time.now
70
78
  start = finish - period
@@ -183,6 +191,10 @@ class Event < ActiveRecord::Base
183
191
  start_date.mday
184
192
  end
185
193
 
194
+ def mday_padded
195
+ "%02d" % mday
196
+ end
197
+
186
198
  def short_date
187
199
  start_date.to_datetime.strftime(short_date_format)
188
200
  end
@@ -418,8 +430,4 @@ protected
418
430
  Radiant::Config['event_calendar.round_time_format'] || "%-1I%p"
419
431
  end
420
432
 
421
- def dates_are_in_order
422
-
423
- end
424
-
425
433
  end
data/app/models/ical.rb CHANGED
@@ -5,6 +5,7 @@ require 'date'
5
5
  require 'ftools'
6
6
 
7
7
  class Ical < ActiveRecord::Base
8
+ include ActionView::Helpers::TextHelper
8
9
  belongs_to :calendar
9
10
  validates_presence_of :url
10
11
  has_site if respond_to? :has_site
@@ -45,7 +46,8 @@ class Ical < ActiveRecord::Base
45
46
  begin
46
47
  Ical.transaction do
47
48
  self.last_refresh_count = 0
48
- event_count = 0
49
+ count = { :created => 0, :updated => 0, :deleted => 0 }
50
+ uuids_seen = []
49
51
  File.open(thisfile, "r") do |file|
50
52
  components = RiCal.parse(file)
51
53
  cal = components.first
@@ -53,22 +55,30 @@ class Ical < ActiveRecord::Base
53
55
  if event = Event.find_by_uuid(cal_event.uid)
54
56
  if cal_event.dtstamp > event.updated_at
55
57
  affected.push event.update_from(cal_event)
58
+ count[:updated] += 1
56
59
  else
57
60
  end
58
- event_count += 1
59
61
  else
60
62
  event = Event.create_from(cal_event)
61
63
  event.site = self.calendar.site if event.respond_to? :site=
62
64
  self.calendar.events << event
63
65
  event.save!
64
- affected.push event
66
+ count[:created] += 1
65
67
  end
68
+ uuids_seen.push(cal_event.uid)
66
69
  end
67
70
  end
68
- self.last_refresh_count = event_count
71
+ self.last_refresh_count = uuids_seen.length
69
72
  self.last_refresh_date = Time.now.utc
70
73
  self.save!
71
- affected
74
+
75
+ self.calendar.events.except_these(uuids_seen).each do |event|
76
+ event.destroy
77
+ count[:deleted] += 1
78
+ end
79
+ response = [:created, :updated, :deleted].collect { |counter|
80
+ "#{pluralize(count[counter], 'event')} #{counter}. "
81
+ }.join('')
72
82
  end
73
83
  rescue => error
74
84
  logger.error "RiCal parse error with: #{self.calendar.name}: #{error}."
@@ -1,3 +1,6 @@
1
+ - @page_title = @calendar.name
2
+ - @page_title += ' - Calendar - ' + default_page_title
3
+
1
4
  - include_stylesheet('admin/event_calendar')
2
5
 
3
6
  - render_region :main do |main|
@@ -1,3 +1,6 @@
1
+ - @page_title = 'Calendars'
2
+ - @page_title += ' - Calendar - ' + default_page_title
3
+
1
4
  - include_stylesheet 'admin/event_calendar'
2
5
  = render_region :top
3
6
 
@@ -1,4 +1,7 @@
1
- - include_stylesheet('admin/calendar')
1
+ - @page_title = 'New calendar'
2
+ - @page_title += ' - Calendar - ' + default_page_title
3
+
4
+ - include_stylesheet('admin/event_calendar')
2
5
 
3
6
  - render_region :main do |main|
4
7
  - main.edit_header do
@@ -5,7 +5,7 @@
5
5
  %h3.title
6
6
  = link_to event_venue.title, edit_admin_event_venue_url(event_venue)
7
7
  %p.description
8
- = truncate(event_venue.description, 128)
8
+ = link_to "#{event_venue.events.count} #{pluralize(event_venue.events.count, 'event')}", admin_event_venue_events_url(event_venue)
9
9
  - tbody.location_cell do
10
10
  %td.location
11
11
  = event_venue.address
@@ -14,5 +14,6 @@
14
14
  - if event_venue.url
15
15
  = link_to truncate(event_venue.url, 48), event_venue.url
16
16
  - tbody.modify_cell do
17
- %td.remove
18
- = link_to 'remove', remove_admin_event_venue_url(event_venue)
17
+ %td.actions
18
+ - confirmation = "Are you sure you want to delete entirely the event venue '#{event_venue.title}'?"
19
+ = link_to image('minus') + ' remove', remove_admin_event_venue_url(event_venue), :class => 'action'
@@ -43,6 +43,6 @@
43
43
  This is only required if your address is unusual or you want these events to show on a map in a particular place.
44
44
 
45
45
  %p.url
46
- = f.label :url, "Venue url"
46
+ = f.label :url, "Location url"
47
47
  = f.text_field :url, :class => 'textbox'
48
48
 
@@ -1,3 +1,6 @@
1
+ - @page_title = @event_venue.title
2
+ - @page_title += ' - Calendar - ' + default_page_title
3
+
1
4
  - include_stylesheet "admin/event_calendar"
2
5
  - include_javascript "admin/event_calendar"
3
6
  - if defined? TinyMceFilter
@@ -1,3 +1,6 @@
1
+ - @page_title = 'Locations'
2
+ - @page_title += ' - Calendar - ' + default_page_title
3
+
1
4
  - include_stylesheet "admin/event_calendar"
2
5
 
3
6
  #event_venues_table.outset
@@ -1,5 +1,9 @@
1
+ - @page_title = 'Add a location'
2
+ - @page_title += ' - Calendar - ' + default_page_title
3
+
1
4
  - include_stylesheet "admin/event_calendar"
2
5
  - include_javascript "admin/event_calendar"
6
+
3
7
  - if defined? TinyMceFilter
4
8
  - include_javascript "tiny_mce/tiny_mce"
5
9
  - include_javascript "tiny_mce/tiny_mce_settings"
@@ -1,17 +1,39 @@
1
- %h1 Remove event
1
+ - include_stylesheet "admin/event_calendar"
2
+
3
+ %h1 Remove location
2
4
 
3
5
  %p
4
6
  Are you sure you want to
5
7
  %strong.warning
6
8
  remove permanently
7
- the following event?
9
+ the location
10
+ = link_to @event_venue.title + '?', edit_admin_event_venue_url(@event_venue)
8
11
 
9
- %table.index#events
10
- %tbody
11
- = render :partial => 'event', :object => @event
12
+ - if @event_venue.events.any?
13
+ %br
14
+ It is associated with
15
+ = @event_venue.events.count
16
+ = pluralize(@event_venue.events.count, 'event')
17
+ that will remain in the calendar without a location:
18
+ - else
19
+ It has no events.
12
20
 
13
- - form_for [:admin, @event], :html => {:method => :delete} do
21
+ - if @event_venue.events.any?
22
+ %ul
23
+ - @event_venue.events.each do |event|
24
+ %li
25
+ = link_to event.title, edit_admin_event_url(event)
26
+ %span.note
27
+ = event.summarize_start
28
+
29
+ - form_for [:admin, @event_venue], :html => {:method => :delete} do
14
30
  %p.buttons
15
- %input.button{:type=>"submit", :value=>"Delete event"}/
31
+ %input.button{:type=>"submit", :value=>"Delete location"}
16
32
  or
17
- = link_to 'Cancel', admin_events_url
33
+ = link_to 'Cancel', admin_event_venues_url
34
+
35
+ #actions
36
+ %ul
37
+ %li= link_to "event list", admin_events_url
38
+ %li= link_to "calendar list", admin_calendars_url
39
+ %li= link_to "venue list", admin_event_venues_url
@@ -9,18 +9,13 @@
9
9
  %td.datemark
10
10
  %a{:href => admin_event_url(master_event), :class => event.occurrence? ? 'occurrence' : 'master'}
11
11
  %span.month= Date::ABBR_MONTHNAMES[event.start_date.month]
12
- %span.day= event.start_date.mday
12
+ %span.day= event.mday_padded
13
13
  - tbody.title_cell do
14
14
  %td.event
15
15
  %h3.title
16
16
  = link_to event.title, edit_admin_event_url(master_event), :class => event.occurrence? ? 'occurrence' : 'master'
17
17
  %p.description
18
- = truncate(event.description, 128)
19
- - unless event.keywords.blank?
20
- %p.keywords
21
- %strong
22
- tags:
23
- = event.keywords
18
+ = truncate(event.description, :length => 128)
24
19
  - tbody.calendar_cell do
25
20
  %td.calendar
26
21
  = link_to event.calendar.name, admin_calendar_url(event.calendar) if event.calendar
@@ -30,13 +25,10 @@
30
25
  - tbody.location_cell do
31
26
  %td.location
32
27
  - if event.event_venue
33
- = event.event_venue.title
28
+ = link_to event.event_venue.title, edit_admin_event_venue_url(event.event_venue)
34
29
  - tbody.modify_cell do
35
- %td.remove
30
+ %td.actions
36
31
  - if event.editable?
37
32
  - confirmation = "Are you sure you want to delete entirely the event '#{event.title}'"
38
33
  - confirmation << " and all its recurrences" if event.recurs?
39
- = link_to "remove", admin_event_url(event.master || event), :confirm => "#{confirmation}?", :method => 'delete'
40
- - else
41
- %span.ineditable{:title => "subscribed events can't be removed here"}
42
- remove
34
+ = link_to image('minus') + ' remove', remove_admin_event_url(event.master || event), :class => 'action'
@@ -86,7 +86,7 @@
86
86
 
87
87
  - form_bottom.edit_venue do
88
88
  - toggle_precedence = %w{venue new_venue}
89
- - toggle_precedence.reverse! if @venues.empty? || @event.event_venue.new_record?
89
+ - toggle_precedence.reverse! if @venues.empty?
90
90
 
91
91
  - if imported
92
92
  - f.fields_for :event_venue, @event.event_venue do |ef|
@@ -96,13 +96,13 @@
96
96
  -if @venues.any?
97
97
  #venue.main
98
98
  %p#existing_venue
99
- = f.label :event_venue_id, "Choose a place"
99
+ = f.label :event_venue_id, "Choose a location"
100
100
  = f.select :event_venue_id, @venues.map {|v| [v.title, v.id]}, {:include_blank => true}, :class => 'textbox', :disabled => imported
101
101
  - if imported
102
102
  = link_to "edit this location", admin_event_venue_url(@event.event_venue)
103
103
  to add title, description and directions
104
104
  - else
105
- = link_to "add a new place", new_admin_event_venue_url, :class => 'swapper', :rel => "toggle[#{toggle_precedence.join(',')}]"
105
+ = link_to "add a new location", new_admin_event_venue_url, :class => 'swapper', :rel => "toggle[#{toggle_precedence.join(',')}]"
106
106
  #new_venue
107
107
  - @event.build_event_venue unless @event.event_venue
108
108
  - f.fields_for :event_venue, @event.event_venue do |ef|
@@ -1,3 +1,6 @@
1
+ - @page_title = @event.title
2
+ - @page_title += ' - Calendar - ' + default_page_title
3
+
1
4
  - include_stylesheet "admin/event_calendar"
2
5
  - include_javascript "admin/event_calendar"
3
6
 
@@ -1,8 +1,34 @@
1
+ - @page_title = 'Events'
2
+ - @page_title += " at #{@event_venue.title}" if @event_venue
3
+ - @page_title += ' - Calendar - ' + default_page_title
4
+
1
5
  - include_stylesheet "admin/event_calendar"
2
6
 
3
7
  #events_table.outset
4
8
  %table#events.index{:cellspacing=>"0", :border=>"0", :cellpadding=>"0"}
5
- = render :partial => 'list_head'
9
+ %thead
10
+ %tr
11
+ - render_region :thead do |thead|
12
+ - thead.date_header do
13
+ %th.date
14
+ - thead.title_header do
15
+ %th.event
16
+ %strong
17
+ Events
18
+ - if @event_venue
19
+ at
20
+ = @event_venue.title
21
+ = link_to "(show all)", admin_events_url
22
+ - thead.calendar_header do
23
+ %th.calendar Calendar
24
+ - thead.time_header do
25
+ %th.date Time
26
+ - thead.location_header do
27
+ %th.location Location
28
+ - thead.keywords_header do
29
+ %th.keywords Keywords
30
+ - thead.modify_header do
31
+ %th.modify Modify
6
32
 
7
33
  %tbody
8
34
  - if @events.any?
@@ -11,7 +37,7 @@
11
37
  - else
12
38
  %tr
13
39
  %td.note{:colspan => admin.event.index.tbody.length}
14
- No events coming up
40
+ No events to display
15
41
 
16
42
  - render_region :bottom do |bottom|
17
43
  - bottom.buttons do
@@ -1,3 +1,6 @@
1
+ - @page_title = 'Add an event'
2
+ - @page_title += ' - Calendar - ' + default_page_title
3
+
1
4
  - include_stylesheet "admin/event_calendar"
2
5
  - include_javascript "admin/event_calendar"
3
6
 
@@ -1,17 +1,22 @@
1
- %h1 Remove event
1
+ %h1 Delete event
2
2
 
3
3
  %p
4
4
  Are you sure you want to
5
5
  %strong.warning
6
6
  remove permanently
7
- the following event?
7
+ the event
8
+ = link_to(@event.title, edit_admin_event_url(@event)) + '?'
9
+
8
10
 
9
- %table.index#events
10
- %tbody
11
- = render :partial => 'event', :object => @event
12
11
 
13
12
  - form_for [:admin, @event], :html => {:method => :delete} do
14
13
  %p.buttons
15
14
  %input.button{:type=>"submit", :value=>"Delete event"}/
16
15
  or
17
- = link_to 'Cancel', admin_events_url
16
+ = link_to 'Cancel', admin_events_url
17
+
18
+ #actions
19
+ %ul
20
+ %li= link_to "event list", admin_events_url
21
+ %li= link_to "calendar list", admin_calendars_url
22
+ %li= link_to "venue list", admin_event_venues_url
@@ -10,16 +10,14 @@
10
10
  - unless no_date
11
11
  .datemark
12
12
  .mon= event.short_month
13
- .dom= event.mday
13
+ .dom= event.mday_padded
14
14
  .summary
15
15
  %h2
16
16
  - if event.url
17
17
  = link_to event.title, event.url, :class => 'title'
18
18
  - else
19
19
  = event.title
20
- - event.attached_tags.each do |tag|
21
- %span.tag
22
- = tag.name
20
+ = event.keywords
23
21
 
24
22
  %p.practicalities
25
23
  = event.summarize_start
data/config/routes.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  ActionController::Routing::Routes.draw do |map|
2
2
  map.namespace :admin, :path_prefix => '/admin/event_calendar' do |cal|
3
- cal.resources :calendars
3
+ cal.resources :calendars, :member => {:remove => :get}
4
4
  cal.resources :icals, :collection => {:refresh_all => :any}, :member => {:refresh => :put}
5
5
  cal.resources :events, :member => {:remove => :get}
6
- cal.resources :event_venues, :member => {:remove => :get}
6
+ cal.resources :event_venues, :member => {:remove => :get}, :has_many => :events
7
7
  cal.calendars_home '/', :controller => 'events', :action => 'index'
8
8
  end
9
9
  map.calendar "/calendar.:format", :controller => 'events', :action => 'index'
@@ -1,5 +1,5 @@
1
1
  class EventCalendarExtension < Radiant::Extension
2
- version "1.0.1"
2
+ version "1.1.1"
3
3
  description "An event calendar extension that administers events locally or draws them from any ical or CalDAV publishers (Google Calendar, .Mac, Darwin Calendar Server, etc.)"
4
4
  url "http://github.com/radiant/radiant-event_calendar-extension"
5
5