From 076f840eee6a9fca615be083e585dc1ce04ae4f5 Mon Sep 17 00:00:00 2001 From: Daniel Munn Date: Wed, 9 Jan 2013 23:55:20 +0000 Subject: [PATCH] Resolves pull request #84 --- app/models/dmsf_file.rb | 14 ++++++---- app/models/dmsf_folder.rb | 19 +++++++++++++ config/routes.rb | 2 ++ init.rb | 8 +++--- lib/redmine_dmsf/patches/project_patch.rb | 34 ++++++++++++++++++++++- 5 files changed, 67 insertions(+), 10 deletions(-) diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 517a23c0..7ee6b244 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -354,7 +354,7 @@ class DmsfFile < ActiveRecord::Base next if dmsf_attrs.length == 0 || id_attribute == 0 next unless results.select{|f| f.id.to_s == id_attribute}.empty? - dmsf_file = DmsfFile.where(limit_options[:conditions]).where(:id => id_attribute, :deleted => false).first + dmsf_file = DmsfFile.where(limit_options[:conditions]).where(:id => dmsf_attrs[2], :deleted => false).first if !dmsf_file.nil? if options[:offset] @@ -368,10 +368,14 @@ class DmsfFile < ActiveRecord::Base allowed = User.current.allowed_to?(:view_dmsf_files, dmsf_file.project) project_included = false project_included = true if projects.nil? - if !project_included - projects.each {|x| - project_included = true if x[:id] == dmsf_file.project.id - } + unless project_included + projects.each do |x| + if x.is_a?(ActiveRecord::Relation) + project_included = x.first.id == dmsf_file.project.id + else + project_included = x[:id] == dmsf_file.project.id + end + end end if (allowed && project_included) diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index b68859e0..8ab595e2 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -144,6 +144,25 @@ class DmsfFolder < ActiveRecord::Base self.subfolders.visible.each {|subfolder| file_count += subfolder.deep_file_count} file_count end + + def deep_folder_count + folder_count = self.subfolders.length + self.subfolders.each {|subfolder| folder_count += subfolder.deep_folder_count} + folder_count + end + + def self.project_deep_folder_count(project) + subfolders = self.project_root_folders(project) + folder_count = subfolders.length + subfolders.each{|subfolder| folder_count += subfolder.deep_folder_count} + folder_count + end + + def self.project_deep_file_count(project) + file_count = DmsfFile.project_root_files(project).length + self.project_root_folders(project).each{|subfolder| file_count += subfolder.deep_file_count} + file_count + end def deep_folder_count folder_count = self.subfolders.length diff --git a/config/routes.rb b/config/routes.rb index 5d00a4c3..31b9c45f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -70,6 +70,8 @@ RedmineApp::Application.routes.draw do get '/dmsf/files/:id/download', :controller => 'dmsf_files', :action => 'show', :download => '' #Otherwise will not route nil download param get '/dmsf/files/:id/download/:download', :controller => 'dmsf_files', :action => 'show' get '/dmsf/files/:id', :controller => 'dmsf_files', :action => 'show' + # Just to keep backward compatibility of external url links + get '/dmsf_files/:id', :controller => 'dmsf_files', :action => 'show' # # files_copy controller diff --git a/init.rb b/init.rb index 8bdfb9eb..6334174b 100644 --- a/init.rb +++ b/init.rb @@ -72,7 +72,7 @@ Redmine::Plugin.register :redmine_dmsf do unless entry.nil? || entry.deleted title = args[1] ? args[1] : entry.title revision = args[2] ? args[2] : "" - return link_to "#{title}", :controller => "dmsf_files", :action => "show", :id => entry, :download => revision + return link_to "#{title}", :controller => "dmsf_files", :action => "show", :id => entry, :download => revision, :only_path => false end nil end @@ -85,13 +85,13 @@ Redmine::Plugin.register :redmine_dmsf do macro :dmsff do |obj, args| if args.length < 1 - return link_to l(:link_documents), :controller => "dmsf", :action => "show", :id => @project + return link_to l(:link_documents), :controller => "dmsf", :action => "show", :id => @project, :only_path => false else entry_id = args[0].strip entry = DmsfFolder.find(entry_id) unless entry.nil? title = args[1] ? args[1] : entry.title - return link_to "#{title}", :controller => "dmsf", :action => "show", :id => entry.project, :folder_id => entry + return link_to "#{title}", :controller => "dmsf", :action => "show", :id => entry.project, :folder_id => entry, :only_path => false end end nil @@ -109,7 +109,7 @@ Redmine::Plugin.register :redmine_dmsf do entry = DmsfFile.find(entry_id) unless entry.nil? || entry.deleted title = args[1] ? args[1] : entry.title - return link_to "#{title}", :controller => "dmsf_files", :action => "show", :id => entry + return link_to "#{title}", :controller => "dmsf_files", :action => "show", :id => entry, :only_path => false end nil end diff --git a/lib/redmine_dmsf/patches/project_patch.rb b/lib/redmine_dmsf/patches/project_patch.rb index 224f6f0f..a7f3c95b 100644 --- a/lib/redmine_dmsf/patches/project_patch.rb +++ b/lib/redmine_dmsf/patches/project_patch.rb @@ -1,6 +1,6 @@ # Redmine plugin for Document Management System "Features" # -# Copyright (C) 2011 Vít Jonáš +# Copyright (C) 2011 V�t Jon� # Copyright (C) 2012 Daniel Munn # # This program is free software; you can redistribute it and/or @@ -28,6 +28,7 @@ module RedmineDmsf base.extend(ClassMethods) base.class_eval do unloadable +<<<<<<< HEAD alias_method_chain :copy, :dmsf has_many :dmsf_files, :class_name => "DmsfFile", :foreign_key => "project_id", :conditions => { :dmsf_folder_id => nil } @@ -36,6 +37,10 @@ module RedmineDmsf end +======= + alias_method_chain :copy, :dmsf_copy + end +>>>>>>> d4e19db3410db4cae44a55b0e8c022a6fd82e9fa end module ClassMethods @@ -45,6 +50,7 @@ module RedmineDmsf def all_dmsf_custom_fields @all_dmsf_custom_fields ||= (DmsfFileRevisionCustomField.for_all).uniq.sort # + dmsf_file_revision_custom_fields).uniq.sort end +<<<<<<< HEAD def dmsf_count file_count = DmsfFile.visible.project_root_files(self).count @@ -79,6 +85,32 @@ module RedmineDmsf f.copy_to(self, nil) } end +======= + + def copy_with_dmsf_copy(project, options={}) + project = project.is_a?(Project) ? project : Project.find(project) + + to_be_copied = %w(wiki versions issue_categories issues members queries boards dmsf) + to_be_copied = to_be_copied & options[:only].to_a unless options[:only].nil? + + Project.transaction do + if save + reload + to_be_copied.each do |name| + send "copy_#{name}", project + end + Redmine::Hook.call_hook(:model_project_copy_before_save, :source_project => project, :destination_project => self) + save + end + end + end + + # Copies DMSF from +project+ + def copy_dmsf(project) + DmsfFolder.project_root_folders(project).each{|subfolder| subfolder.copy_to(self, nil)} + DmsfFile.project_root_files(project).each{|file| file.copy_to(self, nil)} + end +>>>>>>> d4e19db3410db4cae44a55b0e8c022a6fd82e9fa end end end