diff --git a/lib/redmine_dmsf/patches/attachable_patch.rb b/lib/redmine_dmsf/patches/attachable_patch.rb index 4a3b2a63..f1d6f406 100644 --- a/lib/redmine_dmsf/patches/attachable_patch.rb +++ b/lib/redmine_dmsf/patches/attachable_patch.rb @@ -22,28 +22,15 @@ module RedmineDmsf module Patches module AttachablePatch - def self.included(base) - base.send(:include, InstanceMethods) - base.class_eval do - unloadable - alias_method_chain :has_attachments?, :has_attachments_dms - end + ################################################################################################################## + # Overriden methods + + def has_attachments? + super || (defined?(self.dmsf_files) && self.dmsf_files.any?) end - module InstanceMethods - - def has_attachments_with_has_attachments_dms? - has_attachments_without_has_attachments_dms? || (defined?(self.dmsf_files) && self.dmsf_files.any?) - end - - end end end end - # Apply the patch - Rails.configuration.to_prepare do - unless Redmine::Acts::Attachable::InstanceMethods.included_modules.include?(RedmineDmsf::Patches::AttachablePatch) - Redmine::Acts::Attachable::InstanceMethods.send(:include, RedmineDmsf::Patches::AttachablePatch) - end - end +Redmine::Acts::Attachable::InstanceMethods.send(:prepend, RedmineDmsf::Patches::AttachablePatch) diff --git a/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb b/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb index f90bc612..86235c3a 100644 --- a/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb +++ b/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb @@ -20,47 +20,31 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require_dependency 'custom_fields_helper' - module RedmineDmsf module Patches module CustomFieldsHelperPatch - def self.included(base) - base.send(:include, InstanceMethods) - base.class_eval do - unloadable - - alias_method_chain :render_custom_fields_tabs, :render_custom_tab - alias_method_chain :custom_field_type_options, :custom_tab_options + + ################################################################################################################## + # Overridden methods + + def render_custom_fields_tabs(types) + cf = {:name => 'DmsfFileRevisionCustomField', :partial => 'custom_fields/index', :label => :dmsf} + unless CustomFieldsHelper::CUSTOM_FIELDS_TABS.index { |f| f[:name] == cf[:name] } + CustomFieldsHelper::CUSTOM_FIELDS_TABS << cf end + super(types) end - module InstanceMethods - - def render_custom_fields_tabs_with_render_custom_tab(types) - cf = {:name => 'DmsfFileRevisionCustomField', :partial => 'custom_fields/index', :label => :dmsf} - unless CustomFieldsHelper::CUSTOM_FIELDS_TABS.index { |f| f[:name] == cf[:name] } - CustomFieldsHelper::CUSTOM_FIELDS_TABS << cf - end - render_custom_fields_tabs_without_render_custom_tab(types) + def custom_field_type_options + cf = {:name => 'DmsfFileRevisionCustomField', :partial => 'custom_fields/index', :label => :dmsf} + unless CustomFieldsHelper::CUSTOM_FIELDS_TABS.index { |f| f[:name] == cf[:name] } + CustomFieldsHelper::CUSTOM_FIELDS_TABS << cf end - - def custom_field_type_options_with_custom_tab_options - cf = {:name => 'DmsfFileRevisionCustomField', :partial => 'custom_fields/index', :label => :dmsf} - unless CustomFieldsHelper::CUSTOM_FIELDS_TABS.index { |f| f[:name] == cf[:name] } - CustomFieldsHelper::CUSTOM_FIELDS_TABS << cf - end - custom_field_type_options_without_custom_tab_options - end - + super end + end end end -# Apply the patch -Rails.configuration.to_prepare do - unless CustomFieldsHelper.included_modules.include?(RedmineDmsf::Patches::CustomFieldsHelperPatch) - CustomFieldsHelper.send(:include, RedmineDmsf::Patches::CustomFieldsHelperPatch) - end -end \ No newline at end of file +CustomFieldsHelper.send(:prepend, RedmineDmsf::Patches::CustomFieldsHelperPatch) diff --git a/lib/redmine_dmsf/patches/project_patch.rb b/lib/redmine_dmsf/patches/project_patch.rb index 841efad8..dae6b715 100644 --- a/lib/redmine_dmsf/patches/project_patch.rb +++ b/lib/redmine_dmsf/patches/project_patch.rb @@ -24,106 +24,94 @@ module RedmineDmsf module Patches module ProjectPatch - def self.included(base) # :nodoc: - base.send(:include, InstanceMethods) - base.send :include, Redmine::NestedSet::Traversing - base.class_eval do - unloadable - alias_method_chain :copy, :dmsf + ################################################################################################################## + # Overridden methods - has_many :dmsf_files, -> { where(dmsf_folder_id: nil).order(:name) }, - :class_name => 'DmsfFile', :foreign_key => 'project_id', :dependent => :destroy - has_many :dmsf_folders, ->{ where(:dmsf_folder_id => nil).order(:title) }, - :class_name => 'DmsfFolder', :foreign_key => 'project_id', :dependent => :destroy - has_many :dmsf_workflows, :dependent => :destroy - has_many :folder_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfFolder' }, - :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy - has_many :file_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfFile' }, - :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy - has_many :url_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfUrl' }, - :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy - has_many :dmsf_links, -> { where dmsf_folder_id: nil }, - :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy - - before_save :set_default_dmsf_notification - - validates_length_of :dmsf_description, :maximum => 65535 - - Project.const_set(:ATTACHABLE_DMS_AND_ATTACHMENTS, 1) - Project.const_set(:ATTACHABLE_ATTACHMENTS, 2) + def copy(project, options={}) + super(project, options) + project = project.is_a?(Project) ? project : Project.find(project) + to_be_copied = %w(dmsf approval_workflows) + to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil? + if save + to_be_copied.each do |name| + send "copy_#{name}", project + end + save end end - module InstanceMethods + ################################################################################################################## + # New methods - def set_default_dmsf_notification - if self.new_record? - if !self.dmsf_notification && (Setting.plugin_redmine_dmsf['dmsf_default_notifications'] == '1') - self.dmsf_notification = true - end + Project.include Redmine::NestedSet::Traversing + + Project.has_many :dmsf_files, -> { where(dmsf_folder_id: nil).order(:name) }, + :class_name => 'DmsfFile', :foreign_key => 'project_id', :dependent => :destroy + Project.has_many :dmsf_folders, ->{ where(:dmsf_folder_id => nil).order(:title) }, + :class_name => 'DmsfFolder', :foreign_key => 'project_id', :dependent => :destroy + Project.has_many :dmsf_workflows, :dependent => :destroy + Project.has_many :folder_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfFolder' }, + :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy + Project.has_many :file_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfFile' }, + :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy + Project.has_many :url_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfUrl' }, + :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy + Project.has_many :dmsf_links, -> { where dmsf_folder_id: nil }, + :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy + + Project.before_save :set_default_dmsf_notification + + Project.validates_length_of :dmsf_description, :maximum => 65535 + + Project.const_set(:ATTACHABLE_DMS_AND_ATTACHMENTS, 1) + Project.const_set(:ATTACHABLE_ATTACHMENTS, 2) + + def set_default_dmsf_notification + if self.new_record? + if !self.dmsf_notification && (Setting.plugin_redmine_dmsf['dmsf_default_notifications'] == '1') + self.dmsf_notification = true end end + end - def dmsf_count - file_count = self.dmsf_files.visible.count + self.file_links.visible.count - folder_count = self.dmsf_folders.visible.count + self.folder_links.visible.count - self.dmsf_folders.visible.each do |f| - file_count += f.deep_file_count - folder_count += f.deep_folder_count - end - { :files => file_count, :folders => folder_count } + def dmsf_count + file_count = self.dmsf_files.visible.count + self.file_links.visible.count + folder_count = self.dmsf_folders.visible.count + self.folder_links.visible.count + self.dmsf_folders.visible.each do |f| + file_count += f.deep_file_count + folder_count += f.deep_folder_count end + { :files => file_count, :folders => folder_count } + end - def copy_with_dmsf(project, options={}) - copy_without_dmsf(project, options) - - project = project.is_a?(Project) ? project : Project.find(project) - - to_be_copied = %w(dmsf approval_workflows) - to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil? - - if save - to_be_copied.each do |name| - send "copy_#{name}", project - end - save - end - + # Simple yet effective approach to copying things + def copy_dmsf(project) + project.dmsf_folders.visible.each do |f| + f.copy_to(self, nil) end - - # Simple yet effective approach to copying things - def copy_dmsf(project) - project.dmsf_folders.visible.each do |f| - f.copy_to(self, nil) - end - project.dmsf_files.visible.each do |f| - f.copy_to(self, nil) - end - project.folder_links.visible.each do |l| - l.copy_to(self, nil) - end - project.file_links.visible.each do |l| - l.copy_to(self, nil) - end - project.url_links.visible.each do |l| - l.copy_to(self, nil) - end + project.dmsf_files.visible.each do |f| + f.copy_to(self, nil) end + project.folder_links.visible.each do |l| + l.copy_to(self, nil) + end + project.file_links.visible.each do |l| + l.copy_to(self, nil) + end + project.url_links.visible.each do |l| + l.copy_to(self, nil) + end + end - def copy_approval_workflows(project) - project.dmsf_workflows.each do |wf| - wf.copy_to self - end + def copy_approval_workflows(project) + project.dmsf_workflows.each do |wf| + wf.copy_to self end end end + end end -# Apply patch -Rails.configuration.to_prepare do - unless Project.included_modules.include?(RedmineDmsf::Patches::ProjectPatch) - Project.send(:include, RedmineDmsf::Patches::ProjectPatch) - end -end +Project.send(:prepend, RedmineDmsf::Patches::ProjectPatch) diff --git a/lib/redmine_dmsf/patches/project_tabs_extended.rb b/lib/redmine_dmsf/patches/project_tabs_extended.rb index 341a2078..4008f4ba 100644 --- a/lib/redmine_dmsf/patches/project_tabs_extended.rb +++ b/lib/redmine_dmsf/patches/project_tabs_extended.rb @@ -18,45 +18,27 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require_dependency 'projects_helper' - module RedmineDmsf module Patches module ProjectTabsExtended - def self.included(base) - base.extend(ClassMethods) - base.send(:include, InstanceMethods) - base.class_eval do - unloadable - alias_method_chain :project_settings_tabs, :dmsf - end - end - - module ClassMethods - end - - module InstanceMethods - - def project_settings_tabs_with_dmsf - tabs = project_settings_tabs_without_dmsf - dmsf_tabs = [ - {:name => 'dmsf', :action => {:controller => 'dmsf_state', :action => 'user_pref_save'}, :partial => 'dmsf_state/user_pref', :label => :menu_dmsf}, - {:name => 'dmsf_workflow', :action => {:controller => 'dmsf_workflows', :action => 'index'}, :partial => 'dmsf_workflows/main', :label => :label_dmsf_workflow_plural} - ] - tabs.concat(dmsf_tabs.select {|dmsf_tab| User.current.allowed_to?(dmsf_tab[:action], @project)}) - return tabs - end + ################################################################################################################## + # Overridden methods + def project_settings_tabs + tabs = super + dmsf_tabs = [ + {:name => 'dmsf', :action => {:controller => 'dmsf_state', :action => 'user_pref_save'}, + :partial => 'dmsf_state/user_pref', :label => :menu_dmsf}, + {:name => 'dmsf_workflow', :action => {:controller => 'dmsf_workflows', :action => 'index'}, + :partial => 'dmsf_workflows/main', :label => :label_dmsf_workflow_plural} + ] + tabs.concat(dmsf_tabs.select {|dmsf_tab| User.current.allowed_to?(dmsf_tab[:action], @project)}) + return tabs end end end end -# Apply patch -Rails.configuration.to_prepare do - unless ProjectsHelper.included_modules.include?(RedmineDmsf::Patches::ProjectTabsExtended) - ProjectsHelper.send(:include, RedmineDmsf::Patches::ProjectTabsExtended) - end -end \ No newline at end of file +ProjectsHelper.send(:prepend, RedmineDmsf::Patches::ProjectTabsExtended)