Skip to content

Commit

Permalink
Merge pull request #22 from southbridgeio/redmine_5.1_compatibility
Browse files Browse the repository at this point in the history
add compatibility with Redmine 5.1
  • Loading branch information
nevrfl authored Oct 9, 2024
2 parents 54fe166 + 012722f commit f7a8426
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.3.1

* Add compatibility with Redmine 5.1

# 0.3.0

* Add support for bulk-edit
Expand Down
6 changes: 3 additions & 3 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FileUtils.mkdir_p(Rails.root.join('log/issue_open_date')) unless Dir.exist?(Rails.root.join('log/issue_open_date'))

require 'redmine'
require_dependency 'issue_open_date/hook_listener'
require_dependency 'issue_open_date/patches/issue_patch'
require_dependency 'issue_open_date/patches/user_patch'
require_dependency File.dirname(__FILE__) + '/lib/issue_open_date/hook_listener'
require_dependency File.dirname(__FILE__) + '/lib/issue_open_date/patches/issue_patch'
require_dependency File.dirname(__FILE__) + '/lib/issue_open_date/patches/user_patch'

workers_path = File.dirname(__FILE__) + "/app/workers"
ActiveSupport::Dependencies.autoload_paths += [workers_path]
Expand Down
40 changes: 21 additions & 19 deletions lib/issue_open_date/hook_listener.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
class IssueOpenDateHookListener < Redmine::Hook::ViewListener
render_on :view_issues_form_details_bottom, partial: 'issues/open_date_field'
render_on :view_issues_bulk_edit_details_bottom, partial: 'issues/open_date_field_bulk'
render_on :view_issues_show_details_bottom, partial: 'issues/open_date'
render_on :view_my_account, partial: 'my/open_date'
module IssueOpenDate
class HookListener < Redmine::Hook::ViewListener
render_on :view_issues_form_details_bottom, partial: 'issues/open_date_field'
render_on :view_issues_bulk_edit_details_bottom, partial: 'issues/open_date_field_bulk'
render_on :view_issues_show_details_bottom, partial: 'issues/open_date'
render_on :view_my_account, partial: 'my/open_date'

def controller_issues_edit_before_save(context = {})
assign_issue_attributes(context)
end
def controller_issues_edit_before_save(context = {})
assign_issue_attributes(context)
end

def controller_issues_bulk_edit_before_save(context = {})
assign_issue_attributes(context)
end
def controller_issues_bulk_edit_before_save(context = {})
assign_issue_attributes(context)
end

def controller_issues_new_before_save(context = {})
assign_issue_attributes(context)
end
def controller_issues_new_before_save(context = {})
assign_issue_attributes(context)
end

private
private

def assign_issue_attributes(context)
params, issue = context[:params].to_unsafe_h, context[:issue]
Time.use_zone(User.current.time_zone || Time.now.localtime.utc_offset / 3600) do
issue.assign_attributes(params[:issue].slice(*(1..5).map { |i| "open_date(#{i}i)" }))
def assign_issue_attributes(context)
params, issue = context[:params].to_unsafe_h, context[:issue]
Time.use_zone(User.current.time_zone || Time.now.localtime.utc_offset / 3600) do
issue.assign_attributes(params[:issue].slice(*(1..5).map { |i| "open_date(#{i}i)" }))
end
end
end
end
31 changes: 16 additions & 15 deletions lib/issue_open_date/patches/issue_patch.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
module IssueOpenDate
module IssuePatch
def self.included(base) # :nodoc:
base.class_eval do
unloadable
module Patches
module IssuePatch
def self.included(base)
# :nodoc:
base.class_eval do
unloadable

before_save :clear_open_date
before_save :clear_open_date

def open_date
super.in_time_zone(User.current.time_zone) if super
end
def open_date
super.in_time_zone(User.current.time_zone) if super
end

private
private

def clear_open_date
if self.open_date.present? and !self.closed?
self.open_date = nil
def clear_open_date
if self.open_date.present? and !self.closed?
self.open_date = nil
end
end
end

end
end

end
end
Issue.send(:include, IssueOpenDate::IssuePatch)
Issue.send(:include, IssueOpenDate::Patches::IssuePatch)
34 changes: 20 additions & 14 deletions lib/issue_open_date/patches/user_patch.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
User.send(:include,
Module.new do
def self.included(base)
(1..5).each { |i| base.send(:safe_attributes, "issue_open_time(#{i}i)") }
module IssueOpenDate
module Patches
module UserPatch
end
end
end
User.send(:include,
Module.new do
def self.included(base)
(1..5).each { |i| base.send(:safe_attributes, "issue_open_time(#{i}i)") }
end
end
)

User.send(:prepend,
Module.new do
def issue_open_time
time =
begin
tomorrow = Date.tomorrow
super ? super.change(year: tomorrow.year, month: tomorrow.month, day: tomorrow.day) : tomorrow.to_time
end
time_zone ? time.to_datetime.change(offset: time_zone.formatted_offset) : time.to_datetime
end
end
Module.new do
def issue_open_time
time =
begin
tomorrow = Date.tomorrow
super ? super.change(year: tomorrow.year, month: tomorrow.month, day: tomorrow.day) : tomorrow.to_time
end
time_zone ? time.to_datetime.change(offset: time_zone.formatted_offset) : time.to_datetime
end
end
)

0 comments on commit f7a8426

Please sign in to comment.