Skip to content

Instantly share code, notes, and snippets.

@n-rodriguez
Created August 28, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n-rodriguez/8efa78fc0abb5b5d5da2 to your computer and use it in GitHub Desktop.
Save n-rodriguez/8efa78fc0abb5b5d5da2 to your computer and use it in GitHub Desktop.
Redmine Checklists Loading Patch
diff --git a/init.rb b/init.rb
index 0d3028b..65f949c 100644
--- a/init.rb
+++ b/init.rb
@@ -18,7 +18,7 @@
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
require 'redmine'
-require 'redmine_checklists/redmine_checklists'
+require 'redmine_checklists'
CHECKLISTS_VERSION_NUMBER = '3.1.1'
CHECKLISTS_VERSION_TYPE = "Light version"
diff --git a/lib/redmine_checklists.rb b/lib/redmine_checklists.rb
new file mode 100644
index 0000000..a340de3
--- /dev/null
+++ b/lib/redmine_checklists.rb
@@ -0,0 +1,36 @@
+# This file is a part of Redmine Checklists (redmine_checklists) plugin,
+# issue checklists management plugin for Redmine
+#
+# Copyright (C) 2011-2015 Kirill Bezrukov
+# http://www.redminecrm.com/
+#
+# redmine_checklists is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# redmine_checklists is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
+
+require 'redmine_checklists/hooks/controller_issue_hook'
+require 'redmine_checklists/hooks/views_issues_hook'
+require 'redmine_checklists/hooks/views_layouts_hook'
+
+Rails.configuration.to_prepare do
+ require 'redmine_checklists/patches/issue_patch'
+ require 'redmine_checklists/patches/project_patch'
+ require 'redmine_checklists/patches/issues_controller_patch'
+ require 'redmine_checklists/patches/add_helpers_for_checklists_patch'
+ require 'redmine_checklists/patches/compatibility_patch'
+end
+
+module RedmineChecklists
+
+ def self.settings() Setting[:plugin_redmine_checklists].blank? ? {} : Setting[:plugin_redmine_checklists] end
+
+end
diff --git a/lib/redmine_checklists/patches/add_helpers_for_checklists_patch.rb b/lib/redmine_checklists/patches/add_helpers_for_checklists_patch.rb
index 307b8b7..6bebb6d 100644
--- a/lib/redmine_checklists/patches/add_helpers_for_checklists_patch.rb
+++ b/lib/redmine_checklists/patches/add_helpers_for_checklists_patch.rb
@@ -19,7 +19,6 @@
module RedmineChecklists
module Patches
-
module AddHelpersForChecklistPatch
def self.apply(controller)
controller.send(:helper, 'checklists')
diff --git a/lib/redmine_checklists/patches/issue_patch.rb b/lib/redmine_checklists/patches/issue_patch.rb
index 8c7e451..76db43a 100644
--- a/lib/redmine_checklists/patches/issue_patch.rb
+++ b/lib/redmine_checklists/patches/issue_patch.rb
@@ -21,12 +21,15 @@ require_dependency 'issue'
module RedmineChecklists
module Patches
-
module IssuePatch
- def self.included(base) # :nodoc:
+
+ def self.included(base)
+ base.send(:include, InstanceMethods)
base.class_eval do
- unloadable # Send unloadable so it will not be unloaded in development
+ unloadable
+
attr_reader :copied_from
+
if ActiveRecord::VERSION::MAJOR >= 4
has_many :checklists, lambda { order("#{Checklist.table_name}.position") }, :class_name => "Checklist", :dependent => :destroy, :inverse_of => :issue
else
@@ -37,23 +40,24 @@ module RedmineChecklists
accepts_nested_attributes_for :checklists, :allow_destroy => true, :reject_if => proc { |attrs| attrs["subject"].blank? }
safe_attributes 'checklists_attributes',
- :if => lambda {|issue, user| (user.allowed_to?(:done_checklists, issue.project) ||
- user.allowed_to?(:edit_checklists, issue.project))}
+ :if => lambda { |issue, user| (user.allowed_to?(:done_checklists, issue.project) ||
+ user.allowed_to?(:edit_checklists, issue.project)) }
+ end
+ end
- def copy_checklists(arg)
- issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
- issue.checklists.each{ |checklist| Checklist.create(checklist.attributes.except('id','issue_id').merge(:issue => self)) } if issue
- end
-
+ module InstanceMethods
+
+ def copy_checklists(arg)
+ issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
+ issue.checklists.each{ |checklist| Checklist.create(checklist.attributes.except('id','issue_id').merge(:issue => self)) } if issue
end
+
end
end
-
end
end
-
unless Issue.included_modules.include?(RedmineChecklists::Patches::IssuePatch)
Issue.send(:include, RedmineChecklists::Patches::IssuePatch)
end
diff --git a/lib/redmine_checklists/patches/issues_controller_patch.rb b/lib/redmine_checklists/patches/issues_controller_patch.rb
index 21c35c0..c25339b 100644
--- a/lib/redmine_checklists/patches/issues_controller_patch.rb
+++ b/lib/redmine_checklists/patches/issues_controller_patch.rb
@@ -17,20 +17,18 @@
# You should have received a copy of the GNU General Public License
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
+require_dependency 'issues_controller'
+
module RedmineChecklists
module Patches
-
module IssuesControllerPatch
- def self.included(base) # :nodoc:
+
+ def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
- unloadable # Send unloadable so it will not be unloaded in development
-
+ unloadable
alias_method_chain :build_new_issue_from_params, :checklist
-
end
-
-
end
module InstanceMethods
@@ -53,15 +51,12 @@ module RedmineChecklists
build_new_issue_from_params_without_checklist
end
-
end
end
-
end
end
-
unless IssuesController.included_modules.include?(RedmineChecklists::Patches::IssuesControllerPatch)
IssuesController.send(:include, RedmineChecklists::Patches::IssuesControllerPatch)
end
diff --git a/lib/redmine_checklists/patches/project_patch.rb b/lib/redmine_checklists/patches/project_patch.rb
index d624414..e3f6142 100644
--- a/lib/redmine_checklists/patches/project_patch.rb
+++ b/lib/redmine_checklists/patches/project_patch.rb
@@ -21,14 +21,14 @@ require_dependency 'project'
module RedmineChecklists
module Patches
-
module ProjectPatch
- def self.included(base) # :nodoc:
+
+ def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
- unloadable # Send unloadable so it will not be unloaded in development
- alias_method_chain :copy_issues, :checklist
+ unloadable
+ alias_method_chain :copy_issues, :checklist
end
end
@@ -42,11 +42,9 @@ module RedmineChecklists
end
end
-
end
end
-
unless Project.included_modules.include?(RedmineChecklists::Patches::ProjectPatch)
Project.send(:include, RedmineChecklists::Patches::ProjectPatch)
end
diff --git a/lib/redmine_checklists/redmine_checklists.rb b/lib/redmine_checklists/redmine_checklists.rb
deleted file mode 100644
index 637a23c..0000000
--- a/lib/redmine_checklists/redmine_checklists.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# This file is a part of Redmine Checklists (redmine_checklists) plugin,
-# issue checklists management plugin for Redmine
-#
-# Copyright (C) 2011-2015 Kirill Bezrukov
-# http://www.redminecrm.com/
-#
-# redmine_checklists is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# redmine_checklists is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
-
-Rails.configuration.to_prepare do
- require 'redmine_checklists/hooks/controller_issue_hook'
- require 'redmine_checklists/hooks/views_issues_hook'
- require 'redmine_checklists/hooks/views_layouts_hook'
-
- require 'redmine_checklists/patches/issue_patch'
- require 'redmine_checklists/patches/project_patch'
- require 'redmine_checklists/patches/issues_controller_patch'
- require 'redmine_checklists/patches/add_helpers_for_checklists_patch'
- require 'redmine_checklists/patches/compatibility_patch'
-end
-
-module RedmineChecklists
-
- def self.settings() Setting[:plugin_redmine_checklists].blank? ? {} : Setting[:plugin_redmine_checklists] end
-
-end
-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment