radiant-event_calendar-extension 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.1.0
@@ -2,8 +2,14 @@ class Admin::EventsController < Admin::ResourceController
2
2
  paginate_models :per_page => 20
3
3
 
4
4
  def load_models
5
- finder = params[:all] ? Event.all : Event.future_and_current
6
- self.models = finder.paginate(pagination_parameters)
5
+ pp = pagination_parameters
6
+ unless params[:p]
7
+ first_event = Event.future_and_current.first
8
+ i = Event.all.index(first_event)
9
+ p = (i / pp[:per_page].to_i) + 1
10
+ pp[:page] = p if p && p > 1
11
+ end
12
+ self.models = Event.paginate(pp)
7
13
  end
8
14
 
9
15
  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 ical.refresh
19
- flash[:notice] = ical.calendar.name + " calendar refreshed from iCal subscription ."
18
+ if events = ical.refresh
19
+ flash[:notice] = ical.calendar.name + " calendar refreshed from iCal subscription."
20
20
  else
21
21
  flash[:notice] = "Error parsing " + ical.calendar.name + " calendar from iCal subscription."
22
22
  end
@@ -5,7 +5,7 @@ class EventsController < SiteController
5
5
  helper_method :url_for_date, :url_for_month, :url_without_period, :calendar_parameters, :month_name, :short_month_name, :day_names
6
6
  before_filter :numerical_parameters
7
7
 
8
- radiant_layout { |controller| controller.layout_for :event_calendar }
8
+ radiant_layout { Radiant::Config['event_calendar.layout'] }
9
9
  no_login_required
10
10
 
11
11
  # delivers designated lists of events in minimal formats
data/app/models/event.rb CHANGED
@@ -123,6 +123,22 @@ class Event < ActiveRecord::Base
123
123
  calendar.slug if calendar
124
124
  end
125
125
 
126
+ def location
127
+ if event_venue
128
+ event_venue.to_s
129
+ else
130
+ read_attribute(:location)
131
+ end
132
+ end
133
+
134
+ def address
135
+ event_venue.address if event_venue
136
+ end
137
+
138
+ def postcode
139
+ event_venue.postcode if event_venue
140
+ end
141
+
126
142
  def description_paragraph
127
143
  if description =~ /\<p/
128
144
  description
@@ -142,19 +158,7 @@ class Event < ActiveRecord::Base
142
158
  def occurrence?
143
159
  !master?
144
160
  end
145
-
146
- def location
147
- event_venue ? event_venue.to_s : read_attribute(:location)
148
- end
149
161
 
150
- def address
151
- event_venue ? event_venue.address : read_attribute(:location)
152
- end
153
-
154
- def postcode
155
- event_venue ? event_venue.postcode : read_attribute(:postcode)
156
- end
157
-
158
162
  def date
159
163
  start_date.to_datetime.strftime(date_format)
160
164
  end
@@ -285,6 +289,10 @@ class Event < ActiveRecord::Base
285
289
  def continuing?
286
290
  end_date && start_date < Time.now && end_date > Time.now
287
291
  end
292
+
293
+ def finished?
294
+ start_date < Time.now && (!end_date || end_date < Time.now)
295
+ end
288
296
 
289
297
  def editable?
290
298
  status != Status[:imported]
@@ -332,7 +340,6 @@ class Event < ActiveRecord::Base
332
340
  :uuid => cal_event.uid,
333
341
  :title => cal_event.summary,
334
342
  :description => cal_event.description,
335
- :location => cal_event.location,
336
343
  :url => cal_event.url,
337
344
  :start_date => cal_event.dtstart,
338
345
  :end_date => cal_event.dtend,
@@ -340,6 +347,7 @@ class Event < ActiveRecord::Base
340
347
  :created_at => cal_event.dtstamp
341
348
  })
342
349
  event.status = Status[:imported]
350
+ event.set_venue_from_location(cal_event.location)
343
351
  cal_event.rrule.each { |rule| event.add_recurrence(rule) }
344
352
  event
345
353
  rescue => error
@@ -348,23 +356,31 @@ class Event < ActiveRecord::Base
348
356
  end
349
357
 
350
358
  def update_from(cal_event)
359
+ #TODO handle and merge local updates
351
360
  self.update_attributes({
352
361
  :title => cal_event.summary,
353
362
  :description => cal_event.description,
354
- :location => cal_event.location,
355
363
  :url => cal_event.url,
356
364
  :start_date => cal_event.dtstart,
357
365
  :end_date => cal_event.dtend,
358
366
  :all_day => !cal_event.dtstart.is_a?(DateTime)
359
367
  })
360
368
  self.status = Status[:imported]
369
+ self.set_venue_from_location(cal_event.location)
361
370
  cal_event.rrule.each { |rule| self.add_recurrence(rule) }
371
+ self.save!
362
372
  self
363
373
  rescue => error
364
374
  logger.error "Event update error: #{error}."
365
375
  raise
366
376
  end
367
377
 
378
+ def set_venue_from_location(location='')
379
+ unless location.blank?
380
+ self.event_venue = EventVenue.find_by_title(location) || EventVenue.find_or_create_by_location(location)
381
+ end
382
+ end
383
+
368
384
  protected
369
385
 
370
386
  def set_uuid
@@ -1,17 +1,15 @@
1
1
  class EventVenue < ActiveRecord::Base
2
2
  has_many :events, :dependent => :nullify
3
3
  has_site if respond_to? :has_site
4
- validates_presence_of :title, :address
5
4
  default_scope :order => 'title asc'
6
5
 
7
6
  def to_s
8
- %{#{title}, #{address}}
7
+ title
9
8
  end
10
9
 
11
- def location
12
- address
13
- end
14
- def location=(location)
15
- address = location
10
+ # location is the string read in automatically from ical subscriptions
11
+ def title
12
+ read_attribute(:title) || location
16
13
  end
14
+
17
15
  end
data/app/models/ical.rb CHANGED
@@ -13,8 +13,9 @@ class Ical < ActiveRecord::Base
13
13
 
14
14
  def refresh
15
15
  retrieve_file
16
- parse_file
16
+ updated = parse_file
17
17
  logger.info self.calendar.category + "/" + self.calendar.name + " - iCalendar subscription refreshed on " + Time.now.strftime("%m/%d at %H:%M")
18
+ updated
18
19
  end
19
20
 
20
21
  def retrieve_file
@@ -40,6 +41,7 @@ class Ical < ActiveRecord::Base
40
41
  end
41
42
 
42
43
  def parse_file(thisfile=filename)
44
+ affected = []
43
45
  begin
44
46
  Ical.transaction do
45
47
  self.last_refresh_count = 0
@@ -50,7 +52,7 @@ class Ical < ActiveRecord::Base
50
52
  cal.events.each do |cal_event|
51
53
  if event = Event.find_by_uuid(cal_event.uid)
52
54
  if cal_event.dtstamp > event.updated_at
53
- event.update_from(cal_event)
55
+ affected.push event.update_from(cal_event)
54
56
  else
55
57
  end
56
58
  event_count += 1
@@ -59,12 +61,14 @@ class Ical < ActiveRecord::Base
59
61
  event.site = self.calendar.site if event.respond_to? :site=
60
62
  self.calendar.events << event
61
63
  event.save!
64
+ affected.push event
62
65
  end
63
66
  end
64
67
  end
65
68
  self.last_refresh_count = event_count
66
69
  self.last_refresh_date = Time.now.utc
67
70
  self.save!
71
+ affected
68
72
  end
69
73
  rescue => error
70
74
  logger.error "RiCal parse error with: #{self.calendar.name}: #{error}."
@@ -1,50 +1,64 @@
1
+ - @calendar.build_ical unless @calendar.ical
2
+
1
3
  #calendar_form.form-area
2
4
  = render_region :form_top
3
5
  = error_messages_for :calendar
4
6
 
5
- - render_region :form do |form|
6
- - form.edit_name do
7
- .title
8
- %p.calendar_title
9
- = f.label :name
10
- = f.text_field :name, :class => "textbox"
11
- %p.calendar_category
12
- = f.label :category
13
- = f.text_field :category, :class => "textbox"
14
- %p.calendar_slug
15
- = f.label :slug
16
- = f.text_field :slug, :class => "textbox"
17
- %p.note
18
- The category and slug are used create a url in the form /[calendar page]/category/slug showing only the events of this calendar.
19
-
20
- .description
21
- %p.description
22
- = f.label :description, "Description"
23
- = f.text_area 'description', :size => '40x6', :class => "textarea"
24
-
25
- - @calendar.build_ical unless @calendar.ical
26
- - form.edit_ical do
27
-
28
- - f.fields_for :ical do |ical_f|
29
- .ical
7
+ .main
8
+ - render_region :form do |form|
9
+ - form.edit_name do
10
+ .title
11
+ %p.title
12
+ = f.label :name
13
+ = f.text_field :name, :class => "textbox"
14
+
15
+ - form.edit_ical do
16
+ - f.fields_for :ical do |ical_f|
30
17
  %p.url
31
18
  = ical_f.label :url, "Subscription url (optional)"
32
19
  = ical_f.text_field :url, :class => "textbox"
33
- = ical_f.check_box :refresh_interval
34
- = ical_f.label :refresh_interval, 'Refresh automatically?', :class => 'minor'
35
20
 
36
- %p.username
37
- = ical_f.label :username
38
- = ical_f.text_field :username, :class => "textbox"
21
+ .drawer
22
+ .drawer_contents#subscription
23
+
24
+ %div.username
25
+ = ical_f.label :username, 'Username', :class => 'minor'
26
+ = ical_f.text_field :username, :class => "textbox"
39
27
 
40
- %p.password
41
- = ical_f.label :password
42
- = ical_f.text_field :password, :class => "textbox"
28
+ %div.password
29
+ = ical_f.label :password, 'Password', :class => 'minor'
30
+ = ical_f.text_field :password, :class => "textbox"
43
31
 
44
- %p.note
45
- The url should be a complete http(s) address that works in your browser.
32
+ %div.refreshment
33
+ = ical_f.check_box :refresh_interval
34
+ = ical_f.label :refresh_interval, 'Refresh automatically?', :class => 'minor'
35
+
36
+ .drawer_handle
37
+ %a.toggle{:href=>'#subscription', :rel=>"toggle[subscription]", :class=>"more"}
38
+ more
39
+
40
+ - form.edit_filing do
41
+ .filing
42
+ %p.calendar_category
43
+ = f.label :category
44
+ = f.text_field :category, :class => "textbox"
45
+ %p.calendar_slug
46
+ = f.label :slug
47
+ = f.text_field :slug, :class => "textbox"
48
+
49
+ - form.edit_description do
50
+ .description
51
+ %p.description
52
+ = f.label :description, "Description"
53
+ = f.text_area 'description', :size => '40x6', :class => "textarea"
46
54
 
47
55
  - render_region :form_bottom do |form_bottom|
56
+ - form_bottom.edit_metadata do
57
+ .metadata
58
+ %p.keywords
59
+ = f.label :keywords
60
+ = f.text_field :keywords, :class => "textbox"
61
+
48
62
  - form_bottom.edit_timestamp do
49
63
  = updated_stamp @calendar
50
64
 
@@ -4,7 +4,6 @@
4
4
  - main.edit_header do
5
5
  %h1
6
6
  Edit Calendar
7
- = render :partial => 'actions'
8
7
 
9
8
  - main.edit_form do
10
9
  - form_for :calendar, @calendar, :url => admin_calendar_path(@calendar), :html => { :method => "put", :multipart => true } do |f|
@@ -12,7 +12,7 @@
12
12
  - tbody.url_cell do
13
13
  %td.url
14
14
  - if event_venue.url
15
- = link_to event_venue.url
15
+ = link_to truncate(event_venue.url, 48), event_venue.url
16
16
  - tbody.modify_cell do
17
17
  %td.remove
18
18
  = link_to 'remove', remove_admin_event_venue_url(event_venue)
@@ -1,44 +1,48 @@
1
- - include_stylesheet "admin/event_calendar"
2
- - include_javascript "admin/event_calendar"
3
- - if defined? TinyMceFilter
4
- - include_javascript "tiny_mce/tiny_mce"
5
- - include_javascript "tiny_mce/tiny_mce_settings"
6
- - include_javascript "tiny_mce/application"
7
-
8
1
  - or_choose ||= false
9
2
  - event_venue ||= EventVenue.new
10
3
 
11
- .title
12
- %p.venue_title
4
+ .main
5
+ %p.title
13
6
  = f.label :title, "Venue or location title"
14
7
  = f.text_field :title, :class => 'textbox'
15
8
  - if or_choose && @venues.any?
16
9
  = link_to "choose an existing place", '#', :class => 'swapper', :rel => 'toggle[venue,new_venue]'
17
-
18
- %p.note
10
+ - else
11
+ %span.note
12
+ We remember these details for you, so changes here affect every event occurring in this place
13
+
19
14
  - if or_choose && @venues.any?
20
- If you've used this place before, please
21
- = link_to "choose it from the list", '#', :class => 'swapper', :rel => 'toggle[venue,new_venue]'
22
- so that you can update it globally
23
- - else
24
- Next time you add an event you'll be able to choose this venue from a list
15
+ %p.note
16
+ If you've used this place before, please
17
+ = link_to "choose it from the list", '#', :class => 'swapper', :rel => 'toggle[venue,new_venue]'
18
+ so that you can update it globally
19
+
20
+ .metadata
21
+ %p.keywords
22
+ = f.label :keywords
23
+ = f.text_field :keywords, :class => "textbox"
24
+
25
+ .main
26
+ %p.location
27
+ = f.label :location, "Location tag"
28
+ = f.text_field :location, :class => "textbox"
29
+ %span.note
30
+ This is used to recognise the venue in a calendar feed. It can be postcode, grid reference or any distinctive string.
25
31
 
26
- %p.url
27
- = f.label :url, "Venue website"
28
- = f.text_field :url, :class => 'textbox'
32
+ %p.address
33
+ - if defined? TinyMceFilter
34
+ = link_to image('mce', :alt=> 'toolbar icon'), '#', :class => 'toggleMCE', :rel => (@event ? "toggle[event_event_venue_attributes_address]" : "toggle[event_venue_address]")
35
+ = f.label :address, "Address or directions"
36
+ = f.text_area :address, :class => 'textarea'
29
37
 
30
- %p.venue_location
31
- = f.label :address, "Address or location"
32
- = f.text_area :address, :class => 'textarea'
38
+ .metadata
39
+ %p.venue_postcode
40
+ = f.label :postcode, "Postcode or grid reference"
41
+ = f.text_field :postcode, :class => 'textbox place'
42
+ %span.note
43
+ This is only required if your address is unusual or you want these events to show on a map in a particular place.
33
44
 
34
- %p.venue_postcode
35
- = f.label :postcode, "Postcode or grid reference"
36
- = f.text_field :postcode, :class => 'textbox place'
37
- %span.note
38
- This is only required if your address is unusual or you want these events to show on a map in a particular place.
45
+ %p.url
46
+ = f.label :url, "Venue url"
47
+ = f.text_field :url, :class => 'textbox'
39
48
 
40
- %p.venue_description
41
- - if defined? TinyMceFilter
42
- = link_to image('mce', :alt=> 'toolbar icon'), '#', :class => 'toggleMCE', :rel => "toggle[event_venue_#{event_venue.id}_description]"
43
- = f.label :description, "Description"
44
- = f.text_area :description, :class => 'textarea', :id => "event_venue_#{event_venue.id}_description"
@@ -1,4 +1,9 @@
1
- - include_stylesheet "admin/calendar"
1
+ - include_stylesheet "admin/event_calendar"
2
+ - include_javascript "admin/event_calendar"
3
+ - if defined? TinyMceFilter
4
+ - include_javascript "tiny_mce/tiny_mce"
5
+ - include_javascript "tiny_mce/tiny_mce_settings"
6
+ - include_javascript "tiny_mce/application"
2
7
 
3
8
  - render_region :main do |main|
4
9
  - main.edit_header do
@@ -1,4 +1,9 @@
1
- - include_stylesheet "admin/calendar"
1
+ - include_stylesheet "admin/event_calendar"
2
+ - include_javascript "admin/event_calendar"
3
+ - if defined? TinyMceFilter
4
+ - include_javascript "tiny_mce/tiny_mce"
5
+ - include_javascript "tiny_mce/tiny_mce_settings"
6
+ - include_javascript "tiny_mce/application"
2
7
 
3
8
  - render_region :main do |main|
4
9
  - main.edit_header do
@@ -1,25 +1,19 @@
1
1
  - master_event = event.occurrence? ? event.master : event
2
- - cssclass = "node level-1"
2
+ - cssclass = "node"
3
3
  - cssclass << " continuing" if event.continuing?
4
+ - cssclass << " past" if event.finished?
4
5
 
5
6
  %tr{:class => cssclass}
6
7
  - render_region :tbody do |tbody|
7
8
  - tbody.date_cell do
8
9
  %td.datemark
9
- - if event.editable?
10
- %a{:href => admin_event_url(master_event), :class => event.occurrence? ? 'occurrence' : 'master'}
11
- %span.month= Date::ABBR_MONTHNAMES[event.start_date.month]
12
- %span.day= event.start_date.mday
13
- - else
10
+ %a{:href => admin_event_url(master_event), :class => event.occurrence? ? 'occurrence' : 'master'}
14
11
  %span.month= Date::ABBR_MONTHNAMES[event.start_date.month]
15
12
  %span.day= event.start_date.mday
16
13
  - tbody.title_cell do
17
14
  %td.event
18
15
  %h3.title
19
- - if event.editable?
20
- = link_to event.title, edit_admin_event_url(master_event), :class => event.occurrence? ? 'occurrence' : 'master'
21
- - else
22
- = event.title
16
+ = link_to event.title, edit_admin_event_url(master_event), :class => event.occurrence? ? 'occurrence' : 'master'
23
17
  %p.description
24
18
  = truncate(event.description, 128)
25
19
  - unless event.keywords.blank?
@@ -35,7 +29,8 @@
35
29
  = event.summarize_period
36
30
  - tbody.location_cell do
37
31
  %td.location
38
- = event.location
32
+ - if event.event_venue
33
+ = event.event_venue.title
39
34
  - tbody.modify_cell do
40
35
  %td.remove
41
36
  - if event.editable?