diff --git a/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb b/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb index d9f3f8bb..fadce7ce 100644 --- a/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb +++ b/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb @@ -22,13 +22,16 @@ require_dependency 'custom_fields_helper' module RedmineDmsf module Patches - module CustomFieldsHelperPatch + module CustomFieldsHelperPatch def self.included(base) base.extend(ClassMethods) base.send(:include, InstanceMethods) base.class_eval do unloadable - if Redmine::VERSION::MAJOR >= 2 && Redmine::VERSION::MINOR >= 5 + if ( + (Redmine::VERSION::MAJOR >= 3) || + (Redmine::VERSION::MAJOR >= 2 && Redmine::VERSION::MINOR >= 5) + ) alias_method_chain :render_custom_fields_tabs, :render_custom_tab alias_method_chain :custom_field_type_options, :custom_tab_options else @@ -37,39 +40,42 @@ module RedmineDmsf end end - module ClassMethods + module ClassMethods end module InstanceMethods - - def custom_fields_tabs_with_custom_tab + + def custom_fields_tabs_with_custom_tab add_cf - custom_fields_tabs_without_custom_tab + custom_fields_tabs_without_custom_tab end - - def render_custom_fields_tabs_with_render_custom_tab(types) + + def render_custom_fields_tabs_with_render_custom_tab(types) add_cf render_custom_fields_tabs_without_render_custom_tab(types) end - def custom_field_type_options_with_custom_tab_options + def custom_field_type_options_with_custom_tab_options add_cf custom_field_type_options_without_custom_tab_options - end - + end + private - + def add_cf cf = {:name => 'DmsfFileRevisionCustomField', :partial => 'custom_fields/index', :label => :dmsf} - if Redmine::VERSION::MAJOR <= 2 && Redmine::VERSION::MINOR < 4 - unless CustomField::CUSTOM_FIELDS_TABS.index { |f| f[:name] == cf[:name] } - CustomField::CUSTOM_FIELDS_TABS << cf - end - else + if ( + (Redmine::VERSION::MAJOR >= 3) || + (Redmine::VERSION::MAJOR >= 2 && Redmine::VERSION::MINOR >= 5) + ) unless CustomFieldsHelper::CUSTOM_FIELDS_TABS.index { |f| f[:name] == cf[:name] } - CustomFieldsHelper::CUSTOM_FIELDS_TABS << cf - end - end + CustomFieldsHelper::CUSTOM_FIELDS_TABS << cf + else + unless CustomField::CUSTOM_FIELDS_TABS.index { |f| f[:name] == cf[:name] } + CustomField::CUSTOM_FIELDS_TABS << cf + end + end + end end end end diff --git a/lib/redmine_dmsf/patches/project_patch.rb b/lib/redmine_dmsf/patches/project_patch.rb index 16dfed55..15efdb59 100644 --- a/lib/redmine_dmsf/patches/project_patch.rb +++ b/lib/redmine_dmsf/patches/project_patch.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# +# # Redmine plugin for Document Management System "Features" # # Copyright (C) 2011 Vít Jonáš @@ -27,30 +27,45 @@ module RedmineDmsf module ProjectPatch def self.included(base) # :nodoc: - base.send(:include, InstanceMethods) + base.send(:include, InstanceMethods) base.class_eval do unloadable alias_method_chain :copy, :dmsf - has_many :dmsf_files, :class_name => 'DmsfFile', :foreign_key => 'project_id', - :conditions => { :dmsf_folder_id => nil }, :dependent => :destroy - has_many :dmsf_folders, :class_name => 'DmsfFolder', :foreign_key => 'project_id', - :conditions => {:dmsf_folder_id => nil}, :dependent => :destroy - has_many :dmsf_workflows, :dependent => :destroy - has_many :folder_links, :class_name => 'DmsfLink', :foreign_key => 'project_id', - :conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfFolder' }, - :dependent => :destroy - has_many :file_links, :class_name => 'DmsfLink', :foreign_key => 'project_id', - :conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfFile' }, - :dependent => :destroy - has_many :url_links, :class_name => 'DmsfLink', :foreign_key => 'project_id', - :conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfUrl' }, - :dependent => :destroy + if (Redmine::VERSION::MAJOR >= 3) + has_many :dmsf_files, -> { where dmsf_folder_id: nil}, + :class_name => 'DmsfFile', :foreign_key => 'project_id', :dependent => :destroy + has_many :dmsf_folders, -> {where dmsf_folder_id: nil}, + :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 + else + has_many :dmsf_files, :class_name => 'DmsfFile', :foreign_key => 'project_id', + :conditions => { :dmsf_folder_id => nil }, :dependent => :destroy + has_many :dmsf_folders, :class_name => 'DmsfFolder', :foreign_key => 'project_id', + :conditions => {:dmsf_folder_id => nil}, :dependent => :destroy + has_many :dmsf_workflows, :dependent => :destroy + has_many :folder_links, :class_name => 'DmsfLink', :foreign_key => 'project_id', + :conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfFolder' }, + :dependent => :destroy + has_many :file_links, :class_name => 'DmsfLink', :foreign_key => 'project_id', + :conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfFile' }, + :dependent => :destroy + has_many :url_links, :class_name => 'DmsfLink', :foreign_key => 'project_id', + :conditions => { :dmsf_folder_id => nil, :target_type => 'DmsfUrl' }, + :dependent => :destroy + end end end - + module InstanceMethods - + def dmsf_count file_count = self.dmsf_files.visible.count + self.file_links.count folder_count = self.dmsf_folders.visible.count + self.folder_links.count @@ -87,23 +102,23 @@ module RedmineDmsf f.copy_to(self, nil) end project.folder_links.visible.each do |l| - l.copy_to(self, nil) + l.copy_to(self, nil) end project.file_links.visible.each do |l| - l.copy_to(self, nil) + 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 end end - + end end end @@ -113,4 +128,4 @@ Rails.configuration.to_prepare do unless Project.included_modules.include?(RedmineDmsf::Patches::ProjectPatch) Project.send(:include, RedmineDmsf::Patches::ProjectPatch) end -end \ No newline at end of file +end