Copy DMSF functionality expansion

Data linkup (with dependency destruction)
This commit is contained in:
Daniel Munn 2012-06-22 09:26:45 +01:00
parent bf215f4e4f
commit 82e53e7fdf
9 changed files with 99 additions and 11 deletions

View File

@ -1,8 +1,16 @@
Changelog for Redmine DMSF
==========================
1.4.3: *Not yet released*
-----------------------
* New: Hook into project copy functionality to permit (although not attractively)
functionality for DMSF to be duplicated accross projects
* Update: Project patch defines linkage between DMSF files and DMSF folders.
* Update: Data linkage allowing dependent items to be deleted (project deletion for example)
this needs to be revised as files marked deleted are not affected by this at present
1.4.2: *2012-06-21*
-------------------------
-----------------
* New: Integration test cases for webdav functionality
* Update: Documentation has been converted from Simpletext to Markdown
* Update: Features listed in documentation

View File

@ -30,9 +30,11 @@ class DmsfFile < ActiveRecord::Base
belongs_to :folder, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id"
has_many :revisions, :class_name => "DmsfFileRevision", :foreign_key => "dmsf_file_id",
:order => "major_version DESC, minor_version DESC, updated_at DESC",
:conditions => { :deleted => false }
:conditions => { :deleted => false },
:dependent => :destroy
has_many :locks, :class_name => "DmsfFileLock", :foreign_key => "dmsf_file_id",
:order => "updated_at DESC"
:order => "updated_at DESC",
:dependent => :destroy
belongs_to :deleted_by_user, :class_name => "User", :foreign_key => "deleted_by_user_id"
validates_presence_of :name

View File

@ -24,10 +24,12 @@ class DmsfFolder < ActiveRecord::Base
belongs_to :project
belongs_to :folder, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id"
has_many :subfolders, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id", :order => "title ASC"
has_many :subfolders, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id", :order => "title ASC",
:dependent => :destroy
has_many :files, :class_name => "DmsfFile", :foreign_key => "dmsf_folder_id",
:conditions => { :deleted => false }
belongs_to :user
:conditions => { :deleted => false },
:dependent => :destroy
belongs_to :user
acts_as_customizable
@ -129,6 +131,12 @@ class DmsfFolder < ActiveRecord::Base
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 deep_size
size = 0
self.files.each {|file| size += file.size}
@ -154,7 +162,7 @@ class DmsfFolder < ActiveRecord::Base
new_folder.title = self.title
new_folder.description = self.description
new_folder.user = User.current
#copy only cfs present in destination project
temp_custom_values = self.custom_values.select{|cv| new_folder.project.all_dmsf_custom_fields.include?(cv.custom_field)}.map(&:clone)
@ -166,7 +174,7 @@ class DmsfFolder < ActiveRecord::Base
unless present_custom_fields.include?(cf)
new_folder.custom_values << CustomValue.new({:custom_field => cf, :value => cf.default_value})
end
end
end
return new_folder unless new_folder.save
@ -179,7 +187,7 @@ class DmsfFolder < ActiveRecord::Base
end
return new_folder
end
end
# Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
def available_custom_fields
@ -194,7 +202,7 @@ class DmsfFolder < ActiveRecord::Base
else
DmsfFileRevisionCustomField.all
end
end
end
# To fullfill searchable module expectations
def self.search(tokens, projects=nil, options={})

View File

@ -0,0 +1,5 @@
<% if @project.new_record? %>
<p>
<label class="block"><%= check_box_tag 'only[]', 'dmsf', true %><%= l(:label_dmsf_plural, @source_project.dmsf_count) %></label>
</p>
<% end %>

View File

@ -191,3 +191,4 @@ en:
:parent_directory: "Parent Directory"
:note_webdav: "Webdav once enabled can be found at http://.../dmsf/webdav/"
:label_webdav: "Webdav functionality"
:label_dmsf_plural: "Copy DMSF files and folders (%{files} files in %{folders} folders)"

View File

@ -24,7 +24,7 @@ Redmine::Plugin.register :redmine_dmsf do
name "DMSF"
author "Vit Jonas / Daniel Munn"
description "Document Management System Features"
version "1.4.2 stable"
version "1.4.3 devel"
url "https://github.com/danmunn/redmine_dmsf"
author_url "https://code.google.com/p/redmine-dmsf/"

View File

@ -1,6 +1,10 @@
require 'redmine_dmsf/patches' #plugin patches
require 'redmine_dmsf/webdav' #DAV4Rack implementation
#Hooks
require 'redmine_dmsf/hooks/view_projects_form_hook'
module RedmineDmsf
end

View File

@ -0,0 +1,18 @@
module RedmineDmsf
module Hooks
class ViewProjectsFormHook < Redmine::Hook::ViewListener
include Redmine::I18n
def view_projects_form(context={})
context[:controller].send(:render_to_string, {
:partial => "hooks/redmine_dmsf/view_projects_form",
:locals => context
})
end
end
end
end

View File

@ -26,6 +26,14 @@ module RedmineDmsf
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.extend(ClassMethods)
base.class_eval do
unloadable
alias_method_chain :copy, :dmsf
has_many :files, :class_name => "DmsfFile", :foreign_key => "project_id", :conditions => { :deleted => false, :dmsf_folder_id => nil }, :dependent => :destroy
has_many :folders, :class_name => "DmsfFolder", :foreign_key => "project_id", :dependent => :destroy
end
end
module ClassMethods
@ -35,6 +43,40 @@ module RedmineDmsf
def all_dmsf_custom_fields
@all_dmsf_custom_fields ||= (DmsfFileRevisionCustomField.for_all).uniq.sort # + dmsf_file_revision_custom_fields).uniq.sort
end
def dmsf_count
file_count = DmsfFile.project_root_files(self).count
folder_count = DmsfFolder.project_root_folders(self).count
DmsfFolder.project_root_folders(self).each {|rootfld| file_count += rootfld.deep_file_count; folder_count += rootfld.deep_folder_count }
{: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)
to_be_copied = to_be_copied & options[:only].to_a unless options[:only].nil?
if save
to_be_copied.each do |name|
send "copy_#{name}", project
end
save
end
end
# Simple yet effective approach to copying things
def copy_dmsf(project)
DmsfFile.project_root_files(project).each {|f|
f.copy_to(self, nil)
}
DmsfFolder.project_root_folders(project).each {|f|
f.copy_to(self, nil)
}
end
end
end
end