10 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | = Google Calendar Plugin For Redmine
2 |
3 | REQUIRES: TZInfo GEM (http://tzinfo.rubyforge.org/)
4 |
5 | A plugin to allow users to create a new Redmine tab and embed a Google Calendar using Google Embeddable Calendar iframe.
6 |
7 | http://www.google.com/calendar/embed/EmbedHelper_en.html
8 |
9 | To install from git:
10 |
11 | (Git Version < 1.5.3)
12 | $ cd {RAILS_ROOT}/vendor/plugins
13 | $ git clone git://github.com/mully/redmine_google_calendar.git
14 |
15 | (Git Version >= 1.5.3 -- Because the "git-rails" gem uses Git Submodules introduced in ver. 1.5.3)
16 | $ sudo gem install git-rails
17 | $ git-rails install git://github.com/mully/redmine_google_calendar.git
18 |
19 |
--------------------------------------------------------------------------------
/init.rb:
--------------------------------------------------------------------------------
1 | # redMine - project management software
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang
3 | #
4 | # This program is free software; you can redistribute it and/or
5 | # modify it under the terms of the GNU General Public License
6 | # as published by the Free Software Foundation; either version 2
7 | # of the License, or (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program; if not, write to the Free Software
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 |
18 | require 'redmine'
19 |
20 | RAILS_DEFAULT_LOGGER.info 'Google Calendar'
21 |
22 | # Redmine ticket emailer plugin
23 | Redmine::Plugin.register :redmine_google_calendar do
24 | name 'Google Calendar Plugin'
25 | author 'Jim Mulholland'
26 | description 'A plugin to allow users to add a new tab with an embedded Google Calendar Iframe.'
27 | version '0.1.0'
28 |
29 | # The data necessary to log into your email server.
30 | # For this first rev, I am assuming you have an IMAP server
31 | settings :default => {'iframe_text' => ''}, :partial => 'settings/settings'
32 |
33 | # This plugin adds a project module
34 | # It can be enabled/disabled at project level (Project settings -> Modules)
35 | project_module :google_calendar do
36 | # This permission has to be explicitly given
37 | # It will be listed on the permissions screen
38 | permission :view_google_calendar_tab, {:google_calendar => :show}
39 | end
40 |
41 | # A new item is added to the project menu
42 | menu :project_menu, :google_calendar, :controller => 'google_calendar', :action => 'show'
43 | end
44 |
45 | Rails::Plugin.class_eval do
46 | def reloadable!
47 | load_paths.each { |p| Dependencies.load_once_paths.delete(p) }
48 | end
49 | end
50 |
51 | reloadable!
52 |
--------------------------------------------------------------------------------
/app/controllers/google_calendar_controller.rb:
--------------------------------------------------------------------------------
1 | # iframe_tab_controller.rb
2 | #
3 | # Copyright 2008 Jim Mulholland
4 | #
5 | # This program is free software; you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation; either version 2 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 | # MA 02110-1301, USA.
19 |
20 | require 'tzinfo'
21 |
22 | class GoogleCalendarController < ApplicationController
23 | layout 'base'
24 | before_filter :find_project, :authorize
25 |
26 | def show
27 | @iframe_text = IframeText.get_iframe_text(@project)
28 |
29 | unless User.current.time_zone.nil?
30 | time_zone = tzinfo_from_offset(User.current.time_zone.utc_offset)
31 |
32 | #If "pvttk" string is not in the iframe, this is a public calendar
33 | if @iframe_text[/pvttk/].nil?
34 | #Substitute in the current timezone for public calendar
35 | @iframe_text.sub!(/ctz=\S*"/, "ctz=#{time_zone.name}\"")
36 | else
37 | #Substitute in the current timezone for private calendar
38 | @iframe_text.sub!(/ctz=\S*&/, "ctz=#{time_zone.name}&")
39 | end
40 | end
41 | end
42 |
43 |
44 | private
45 | def find_project
46 | @project = Project.find(params[:id])
47 | rescue ActiveRecord::RecordNotFound
48 | render_404
49 | end
50 |
51 | def tzinfo_from_offset(offset_in_seconds)
52 |
53 | #Search For US Timezones First
54 | us = TZInfo::Country.get('US')
55 |
56 | us.zone_info.each do |tz|
57 | if tz.timezone.current_period.utc_offset.to_i == offset_in_seconds
58 | return tz.timezone
59 | end
60 | end
61 |
62 | TZInfo::Timezone.all.each do |tz2|
63 | if tz2.current_period.utc_offset.to_i == offset_in_seconds
64 | return tz2
65 | end
66 | end
67 | return nil
68 | end
69 | end
70 |
71 |
--------------------------------------------------------------------------------