From b1b529cec83b20d09c9018ba64d21822417337bf Mon Sep 17 00:00:00 2001 From: friflaj Date: Tue, 8 Jun 2010 22:36:40 +0200 Subject: [PATCH] iCalendar support --- app/controllers/backlogs_controller.rb | 96 +++++++++++++++++++ .../backlogs/_view_issues_sidebar.html.erb | 3 +- config/locales/en.yml | 5 + config/locales/nl.yml | 4 + config/routes.rb | 1 + init.rb | 1 + lib/backlogs_hooks.rb | 1 + 7 files changed, 110 insertions(+), 1 deletion(-) diff --git a/app/controllers/backlogs_controller.rb b/app/controllers/backlogs_controller.rb index db54284169..e23c0fcdd4 100755 --- a/app/controllers/backlogs_controller.rb +++ b/app/controllers/backlogs_controller.rb @@ -1,6 +1,8 @@ include StoriesHelper include BacklogMenuHelper +require 'icalendar' + class BacklogsController < ApplicationController unloadable @@ -196,6 +198,100 @@ class BacklogsController < ApplicationController send_data(cards.pdf.render, :filename => 'cards.pdf', :disposition => 'attachment', :type => 'application/pdf') end + def calendar + cal = Icalendar::Calendar.new + + # current + future sprints + Sprint.find(:all, :conditions => ["not sprint_start_date is null and not effective_date is null and project_id = ? and effective_date >= ?", @project.id, Date.today]).each {|sprint| + cal.event do + dtstart sprint.sprint_start_date + dtend sprint.effective_date + summary l(:event_sprint_summary, { :project => @project.name, :summary => sprint.name } ) + description l(:event_sprint_description, { + :summary => sprint.name, + :description => sprint.description, + :url => url_for({ + :controller => 'backlogs', + :only_path => false, + :action => 'select_issues', + :project_id => @project.id, + :sprint_id => sprint.id + }) + }) + klass 'PRIVATE' + transp 'TRANSPARENT' + end + } + + open_issues = " + #{IssueStatus.table_name}.is_closed = ? + and tracker_id in (?) + and fixed_version_id in ( + select id + from versions + where project_id = ? + and status = 'open' + and not sprint_start_date is null + and effective_date >= ? + ) + " + open_issues_and_impediments = " + (assigned_to_id is null or assigned_to_id = ?) + and + ( + (#{open_issues}) + or + ( #{IssueStatus.table_name}.is_closed = ? + and #{Issue.table_name}.id in ( + select issue_from_id + from issue_relations + join issues on issues.id = issue_to_id and relation_type = 'blocks' + where #{open_issues}) + ) + ) + " + + conditions = [open_issues_and_impediments] + # me or none + conditions << User.current.id + + # open stories/tasks + conditions << false + conditions << Story.trackers + [Task.tracker] + conditions << @project.id + conditions << Date.today + + # open impediments... + conditions << false + + # ... for open stories/tasks + conditions << false + conditions << Story.trackers + [Task.tracker] + conditions << @project.id + conditions << Date.today + + issues = Issue.find(:all, :include => :status, :conditions => conditions).each {|issue| + cal.todo do + summary l(:todo_issue_summary, { :type => issue.tracker.name, :summary => issue.subject } ) + description l(:todo_issue_description, { + :summary => issue.subject, + :description => issue.description, + :url => url_for({ + :controller => 'issues', + :only_path => false, + :action => 'show', + :id => issue.id + }) + }) + klass 'PRIVATE' + category issue.tracker.name + transp 'TRANSPARENT' + end + } + + send_data(cal.to_ical, :filename => "#{@project.identifier}.ics", :disposition => 'attachment', :type => 'text/calendar') + end + private def find_project diff --git a/app/views/backlogs/_view_issues_sidebar.html.erb b/app/views/backlogs/_view_issues_sidebar.html.erb index b6e28030b4..2f47b30a05 100755 --- a/app/views/backlogs/_view_issues_sidebar.html.erb +++ b/app/views/backlogs/_view_issues_sidebar.html.erb @@ -11,7 +11,7 @@ <% end %> <% end %> -

<%= l(:backlogs_product_backlog) %>

+

<%= project.name %>

<%= link_to(l(:backlogs_product_backlog), { :controller => 'backlogs', :action => 'select_issues', @@ -22,6 +22,7 @@ :action => 'product_backlog_cards', :project_id => project.id }) %>
+ <%= l(:label_calendar) %>
<% if sprint && sprint.has_burndown %>

<%= l(:label_sprint_name, {:name => sprint.name}) %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index 22f7de8e20..b5d4ee76ef 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -64,3 +64,8 @@ en: label_backlogs_unconfigured: "You have not configured Backlogs yet. Please go to {{administration}} > {{plugins}}, then click on the {{configure}} link for this plugin. Once you have set the fields, come back to this page to start using the tool." label_sprint_velocity: "Velocity {{velocity}}, based on {{sprints}} sprints with an average {{days}} days" + + event_sprint_summary: "{{project}}: {{summary}}" + event_sprint_description: "{{summary}}: {{url}}\n{{description}}" + todo_issue_summary: "{{type}}: {{summary}}" + todo_issue_description: "{{summary}}: {{url}}\n{{description}}" diff --git a/config/locales/nl.yml b/config/locales/nl.yml index ed6d7fb6e1..a4a76e59c3 100755 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -57,3 +57,7 @@ nl: label_scrum_statistics: Scrum statistieken label_stories: Stories label_sprint_velocity: "Velocity {{velocity}}, berekend over {{sprints}} sprints met gemiddeld {{days}} dagen" + event_sprint_summary: "{{project}}: {{summary}}" + event_sprint_description: "{{summary}}: {{url}}\n{{description}}" + todo_issue_summary: "{{type}}: {{summary}}" + todo_issue_description: "{{summary}}: {{url}}\n{{description}}" diff --git a/config/routes.rb b/config/routes.rb index f341a42bc9..0a322c25de 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,5 +5,6 @@ ActionController::Routing::Routes.draw do |map| map.connect 'backlogs/:project_id/:sprint_id/wiki', :controller => 'backlogs', :action => 'wiki' map.connect 'backlogs/:project_id/:sprint_id/cards', :controller => 'backlogs', :action => 'taskboard_cards' map.connect 'backlogs/:project_id/cards', :controller => 'backlogs', :action => 'product_backlog_cards' + map.connect 'backlogs/:project_id/calendar', :controller => 'backlogs', :action => 'calendar' end diff --git a/init.rb b/init.rb index a0bbb9f7ad..8f29fae4d1 100755 --- a/init.rb +++ b/init.rb @@ -57,6 +57,7 @@ Redmine::Plugin.register :redmine_backlogs do :select_issues, :taskboard_cards, :product_backlog_cards, + :calendar, :burndown ], :stories => [ :index ], :tasks => [ :index ], diff --git a/lib/backlogs_hooks.rb b/lib/backlogs_hooks.rb index 4744a653b3..63c180efdd 100755 --- a/lib/backlogs_hooks.rb +++ b/lib/backlogs_hooks.rb @@ -9,6 +9,7 @@ module BacklogsPlugin locals[:sprints] = Sprint.open_sprints(context[:project]) locals[:project] = context[:project] locals[:sprint] = nil + locals[:webcal] = (context[:request].ssl? ? 'webcals' : 'webcal') q = context[:request].session[:query] if q