Skip to content

Commit

Permalink
Proof of Concept for #35
Browse files Browse the repository at this point in the history
  • Loading branch information
fs5 committed Dec 18, 2021
1 parent 13a88fd commit 44b1608
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
6 changes: 3 additions & 3 deletions app/controllers/i_calendar_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# redmics - redmine ics export plugin
# Copyright (c) 2010-2012 Frank Schwarz, [email protected]
# Copyright (c) 2010-2021 Frank Schwarz, [email protected]
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -73,11 +73,11 @@ def find_optional_query
end

def decode_rendering_settings_from_url
options = [:none, :vevent_full_span, :vevent_end_date, :vevent_start_and_end_date, :vtodo]
options = [:none, :vevent_full_span, :vevent_end_date, :vevent_start_and_end_date, :vtodo, :mega_calendar]
options_summary = [:plain, :status, :ticket_number_and_status]
options_description = [:plain, :url_and_version, :full_no_url, :full]
@rendering = {}
if params[:render_issues] =~ /[0-4]/
if params[:render_issues] =~ /[0-5]/
@rendering[:redmics_icsrender_issues] = options[params[:render_issues].to_i]
end
if params[:render_versions] =~ /[0-3]/
Expand Down
26 changes: 17 additions & 9 deletions app/views/settings/_redmics_settings.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<%# redmics - redmine ics export plugin, Copyright (c) 2010-2011 Frank Schwarz, [email protected] %>
<%# redmics - redmine ics export plugin, Copyright (c) 2010-2021 Frank Schwarz, [email protected] %>
<%
options = ActiveSupport::OrderedHash.new
options[l(:option_settings_rendering_none)] = :none
options[l(:option_settings_rendering_vevent_full_span)] = :vevent_full_span
options[l(:option_settings_rendering_vevent_end_date)] = :vevent_end_date
options[l(:option_settings_rendering_vevent_start_and_end_date)] = :vevent_start_and_end_date
options[l(:option_settings_rendering_vtodo)] = :vtodo
event_options = ActiveSupport::OrderedHash.new
event_options[l(:option_settings_rendering_none)] = :none
event_options[l(:option_settings_rendering_vevent_full_span)] = :vevent_full_span
event_options[l(:option_settings_rendering_vevent_end_date)] = :vevent_end_date
event_options[l(:option_settings_rendering_vevent_start_and_end_date)] = :vevent_start_and_end_date
event_options[l(:option_settings_rendering_vtodo)] = :vtodo
event_options[l(:option_settings_rendering_mega_calendar)] = :mega_calendar if defined?(TicketTime) == 'constant' && TicketTime.class == Class

version_options = ActiveSupport::OrderedHash.new
version_options[l(:option_settings_rendering_none)] = :none
version_options[l(:option_settings_rendering_vevent_full_span)] = :vevent_full_span
version_options[l(:option_settings_rendering_vevent_end_date)] = :vevent_end_date
version_options[l(:option_settings_rendering_vevent_start_and_end_date)] = :vevent_start_and_end_date
version_options[l(:option_settings_rendering_vtodo)] = :vtodo

summary_options = ActiveSupport::OrderedHash.new
summary_options[l(:option_settings_enhance_summary_plain)] = :plain
Expand All @@ -21,11 +29,11 @@
<h3><%= l(:label_settings_rendering_header) %></h3>
<p>
<%= content_tag :label, l(:label_settings_rendering_issues) + ':' %>
<%= select_tag 'settings[redmics_icsrender_issues]', options_for_select(options, @settings[:redmics_icsrender_issues].to_sym) %>
<%= select_tag 'settings[redmics_icsrender_issues]', options_for_select(event_options, @settings[:redmics_icsrender_issues].to_sym) %>
</p>
<p>
<%= content_tag :label, l(:label_settings_rendering_versions) + ':' %>
<%= select_tag 'settings[redmics_icsrender_versions]', options_for_select(options, @settings[:redmics_icsrender_versions].to_sym) %><br/>
<%= select_tag 'settings[redmics_icsrender_versions]', options_for_select(version_options, @settings[:redmics_icsrender_versions].to_sym) %><br/>
</p>
<p>
<%= content_tag :label, l(:label_settings_enhance_summary) + ':' %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ de:
option_settings_rendering_vevent_end_date: ganztägiges Ereignis zum Ende-Datum
option_settings_rendering_vevent_start_and_end_date: ganztägige Ereignisse zum Start- und Ende-Datum
option_settings_rendering_vtodo: Aufgabe
option_settings_rendering_mega_calendar: untertägiges Mega Calendar Ereignis
text_settings_rendering_more_information: Weitere Informationen unter
label_redmics_settings_userprefs: ICS Export
notice_redmics_userprefs_updated: ICS Export Einstellungen wurden erfolgreich aktualisiert
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ en:
option_settings_rendering_vevent_end_date: all-day event for just the end date
option_settings_rendering_vevent_start_and_end_date: all-day event for start and end date
option_settings_rendering_vtodo: todo item
option_settings_rendering_mega_calendar: partial day Mega Calendar event
text_settings_rendering_more_information: For more information see
label_redmics_settings_userprefs: ICS export
notice_redmics_userprefs_updated: ICS export settings have been updated sucessfully
Expand Down
34 changes: 33 additions & 1 deletion lib/redmics/export.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# redmics - redmine ics export plugin
# Copyright (c) 2011 Frank Schwarz, [email protected]
# Copyright (c) 2011-2021 Frank Schwarz, [email protected]
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -182,6 +182,16 @@ def create_issues_renderer(type)
enhance_issue_description(issue, result)
result
}
when :mega_calendar
lambda { |issue|
result = create_issue_vevent_mega_calendar(issue)
apply_issue_common_properties(issue, result)
apply_issue_event_properties(issue, result)
apply_issue_alarm(issue, result) unless @alarm.nil?
enhance_issue_summary(issue, result)
enhance_issue_description(issue, result)
result
}
end
end

Expand Down Expand Up @@ -292,6 +302,16 @@ def create_issue_vtodo(issue)
return [todo]
end

def create_issue_vevent_mega_calendar(issue)
start_date_time, due_date_time = mega_calendar_issue_period(issue)
return [] if start_date_time.nil? || due_date_time.nil?
event = Icalendar::Event.new
event.dtstart = Icalendar::Values::DateTime.new(start_date_time)
event.dtend = Icalendar::Values::DateTime.new(due_date_time)
event.uid = "id:redmics:project:#{issue.project_id}:issue:#{issue.id}@#{Setting.host_name}"
return [event]
end

def apply_issue_common_properties(issue, result)
result.each { |event|
event.summary = "#{issue.subject}" unless event.summary
Expand Down Expand Up @@ -553,6 +573,18 @@ def issue_period(issue)
return [start_date, due_date]
end

def mega_calendar_issue_period(issue)
ticket_time = TicketTime.where(:issue_id => issue.id).first rescue nil
ticket_time_begin = ticket_time.time_begin.strftime(" %H:%M") rescue ' 00:00'
ticket_time_end = ticket_time.time_end.strftime(" %H:%M") rescue ' 24:00'
start_date = issue.start_date
due_date = issue.due_date
return [
(Time.parse(start_date.to_s + ticket_time_begin) unless start_date.nil?),
(Time.parse(due_date.to_s + ticket_time_end) unless due_date.nil?)
]
end

def version_period(version)
return [version.start_date, version.due_date]
end
Expand Down

0 comments on commit 44b1608

Please sign in to comment.