ICS_Support__3.patch

SÅ‚awek Goszcz, 2009-09-07 10:43

Download (3.05 KB)

View differences:

redmine/app/controllers/application.rb 2009-09-04 14:55:52.000000000 +0200
17 17

  
18 18
require 'uri'
19 19
require 'cgi'
20
require 'icalendar'
20 21

  
21 22
class ApplicationController < ActionController::Base
22 23
  layout 'base'
......
163 164
    render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
164 165
  end
165 166
  
167
#EDIT
168
def render_ics(items, options={})
169
	cal = Icalendar::Calendar.new
170
	items.each { |i| 
171
		event = Icalendar::Event.new
172
		event.dtstart     =  i.start_date
173
		event.dtend       =  i.due_date
174
		if i.is_a? Issue
175
			event.summary     =  i.subject
176
		else
177
			event.summary     =  "V. " + i.name
178
		end
179
      
180
		if !i.description.nil?
181
			event.description = i.description
182
		end
183
		cal.add_event(event)
184
	}
185
	@cal_string = cal.to_ical 
186
	render :template => "common/calendar.ics.erb", :layout => false , :content_type => Mime::ICS
187
end
188
  
189
  
166 190
  def self.accept_key_auth(*actions)
167 191
    actions = actions.flatten.map(&:to_s)
168 192
    write_inheritable_attribute('accept_key_auth_actions', actions)
redmine/app/controllers/issues_controller.rb 2009-09-04 14:50:42.000000000 +0200
366 366
    retrieve_query
367 367
    if @query.valid?
368 368
      events = []
369
	  #EDIT
370
	  if (request.format == Mime::ICS)
371
	        @calendar.startdt = @project.created_on.to_s(:db)
372
	  end
369 373
      events += Issue.find(:all, 
370 374
                           :include => [:tracker, :status, :assigned_to, :priority, :project], 
371 375
                           :conditions => ["(#{@query.statement}) AND ((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
......
376 380
      @calendar.events = events
377 381
    end
378 382
    
379
    render :layout => false if request.xhr?
383
    #render :layout => false if request.xhr?
384
	#EDIT
385
	respond_to do |format|
386
		format.html { render :layout => false if request.xhr? }
387
		format.ics  { render_ics(events) }
388
	end  
380 389
  end
381 390
  
382 391
  def context_menu
redmine/app/views/common/calendar.ics.erb 2009-09-04 14:59:00.000000000 +0200
1
<%= @cal_string %>
redmine/lib/redmine/helpers/calendar.rb 2009-09-04 14:39:59.000000000 +0200
45 45
        end
46 46
      end
47 47
      
48
	  def startdt=(dt)
49
		@startdt = dt
50
	  end
51
	  
48 52
      # Sets calendar events
49 53
      def events=(events)
50 54
        @events = events