diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index c22528e3..07dfe002 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -26,7 +26,9 @@ class DmsfController < ApplicationController verify :method => :post, :only => [:delete_entries, :create, :save, :delete, :save_root, :notify_activate, :notify_deactivate], :render => { :nothing => true, :status => :method_not_allowed } - + + helper :all + def show if @folder.nil? @subfolders = DmsfFolder.project_root_folders(@project) diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index 19580d46..9c774ff3 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -28,6 +28,8 @@ class DmsfFilesController < ApplicationController verify :method => :post, :only => [:create_revision, :delete_revision, :delete, :lock, :unlock, :notify_activate, :notify_deactivate], :render => { :nothing => true, :status => :method_not_allowed } + helper :all + def show # download is put here to provide more clear and usable links if params.has_key?(:download) diff --git a/app/controllers/dmsf_files_copy_controller.rb b/app/controllers/dmsf_files_copy_controller.rb index 728be22b..806075ff 100644 --- a/app/controllers/dmsf_files_copy_controller.rb +++ b/app/controllers/dmsf_files_copy_controller.rb @@ -26,6 +26,8 @@ class DmsfFilesCopyController < ApplicationController verify :method => :post, :only => [:create, :move], :render => { :nothing => true, :status => :method_not_allowed } + helper :all + def new @target_project = DmsfFile.allowed_target_projects_on_copy.detect {|p| p.id.to_s == params[:target_project_id]} if params[:target_project_id] @target_project ||= @project if User.current.allowed_to?(:file_manipulation, @project) diff --git a/app/controllers/dmsf_state_controller.rb b/app/controllers/dmsf_state_controller.rb index ce9859b9..5f4a15fa 100644 --- a/app/controllers/dmsf_state_controller.rb +++ b/app/controllers/dmsf_state_controller.rb @@ -26,6 +26,8 @@ class DmsfStateController < ApplicationController verify :method => :post, :only => [:user_pref_save], :render => { :nothing => true, :status => :method_not_allowed } + helper :all + def user_pref_save member = @project.members.find(:first, :conditions => {:user_id => User.current.id}) if member diff --git a/app/controllers/dmsf_upload_controller.rb b/app/controllers/dmsf_upload_controller.rb index dc927638..a6ef0c61 100644 --- a/app/controllers/dmsf_upload_controller.rb +++ b/app/controllers/dmsf_upload_controller.rb @@ -27,7 +27,9 @@ class DmsfUploadController < ApplicationController verify :method => :post, :only => [:upload_files, :upload_file, :commit_files], :render => { :nothing => true, :status => :method_not_allowed } - + + helper :all + def upload_files uploaded_files = params[:uploaded_files] @uploads = [] @@ -141,6 +143,14 @@ class DmsfUploadController < ApplicationController File.delete(commited_disk_filepath) files.push(file) + + unless commited_file["dmsf_file_revision"].blank? + commited_file["dmsf_file_revision"]["custom_field_values"].each do |v| + cv = CustomValue.find(:first, :conditions => ["customized_id = " + new_revision.id.to_s + " AND custom_field_id = " + v[0]]) + cv.value = v[1] + cv.save + end + end else failed_uploads.push(commited_file) end @@ -183,4 +193,4 @@ class DmsfUploadController < ApplicationController end end -end \ No newline at end of file +end diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index eaa45812..a7c001ce 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -90,6 +90,9 @@ class DmsfFile < ActiveRecord::Base return false end if Setting.plugin_redmine_dmsf["dmsf_really_delete_files"] + CustomValue.find(:all, :conditions => "customized_id = " + self.id.to_s).each do |v| + v.destroy + end self.revisions.each {|r| r.delete(true)} self.destroy else @@ -186,7 +189,22 @@ class DmsfFile < ActiveRecord::Base end projects end - + + # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields + def available_custom_fields + search_project = nil + if self.project.present? + search_project = self.project + elsif self.project_id.present? + search_project = Project.find(self.project_id) + end + if search_project + search_project.all_dmsf_custom_fields + else + DmsfFileRevisionCustomField.all + end + end + def move_to(project, folder) if self.locked_for_user? errors.add_to_base(l(:error_file_is_locked)) @@ -197,7 +215,19 @@ class DmsfFile < ActiveRecord::Base new_revision.folder = folder ? folder : nil new_revision.project = folder ? folder.project : project - new_revision.comment = l(:comment_moved_from, :source => "#{self.project.identifier}:#{self.dmsf_path_str}") + new_revision.comment = l(:comment_moved_from, :source => "#{self.project.identifier}:#{self.dmsf_path_str}") + + new_revision.custom_values = [] + temp_custom_values = self.last_revision.custom_values.select{|cv| new_revision.project.all_dmsf_custom_fields.include?(cv.custom_field)}.map(&:clone) + new_revision.custom_values = temp_custom_values + + #add default value for CFs not existing + present_custom_fields = new_revision.custom_values.collect(&:custom_field).uniq + Project.find(new_revision.project_id).all_dmsf_custom_fields.each do |cf| + unless present_custom_fields.include?(cf) + new_revision.custom_values << CustomValue.new({:custom_field => cf, :value => cf.default_value}) + end + end self.folder = new_revision.folder self.project = new_revision.project @@ -212,14 +242,30 @@ class DmsfFile < ActiveRecord::Base file.name = self.name file.notification = !Setting.plugin_redmine_dmsf["dmsf_default_notifications"].blank? - new_revision = self.last_revision.clone - - new_revision.file = file - new_revision.folder = folder ? folder : nil - new_revision.project = folder ? folder.project : project - new_revision.comment = l(:comment_copied_from, :source => "#{self.project.identifier}:#{self.dmsf_path_str}") - - new_revision.save if file.save + if file.save + new_revision = self.last_revision.clone + + new_revision.file = file + new_revision.folder = folder ? folder : nil + new_revision.project = folder ? folder.project : project + new_revision.comment = l(:comment_copied_from, :source => "#{self.project.identifier}: #{self.dmsf_path_str}") + + new_revision.custom_values = [] + temp_custom_values = self.last_revision.custom_values.select{|cv| new_revision.project.all_dmsf_custom_fields.include?(cv.custom_field)}.map(&:clone) + new_revision.custom_values = temp_custom_values + + #add default value for CFs not existing + present_custom_fields = new_revision.custom_values.collect(&:custom_field).uniq + new_revision.project.all_dmsf_custom_fields.each do |cf| + unless present_custom_fields.include?(cf) + new_revision.custom_values << CustomValue.new({:custom_field => cf, :value => cf.default_value}) + end + end + + unless new_revision.save + file.delete + end + end return file end diff --git a/app/models/dmsf_file_revision.rb b/app/models/dmsf_file_revision.rb index 663dee40..bbc63bb9 100644 --- a/app/models/dmsf_file_revision.rb +++ b/app/models/dmsf_file_revision.rb @@ -24,7 +24,9 @@ class DmsfFileRevision < ActiveRecord::Base belongs_to :folder, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id" belongs_to :deleted_by_user, :class_name => "User", :foreign_key => "deleted_by_user_id" belongs_to :project - + + acts_as_customizable + acts_as_event :title => Proc.new {|o| "#{l(:label_dmsf_updated)}: #{o.file.dmsf_path_str}"}, :url => Proc.new {|o| {:controller => 'dmsf_files', :action => 'show', :id => o.file}}, :datetime => Proc.new {|o| o.updated_at }, @@ -77,6 +79,9 @@ class DmsfFileRevision < ActiveRecord::Base ["disk_filename = :filename", {:filename => self.disk_filename}]) File.delete(self.disk_file) if dependent.length <= 1 && File.exist?(self.disk_file) DmsfFileRevisionAccess.find(:all, :conditions => ["dmsf_file_revision_id = ?", self.id]).each {|a| a.destroy} + CustomValue.find(:all, :conditions => "customized_id = " + self.id.to_s).each do |v| + v.destroy + end self.destroy else self.deleted = true @@ -128,7 +133,9 @@ class DmsfFileRevision < ActiveRecord::Base new_revision.name = self.name new_revision.folder = self.folder - + + new_revision.custom_values = self.custom_values.map(&:clone) + return new_revision end @@ -202,5 +209,20 @@ class DmsfFileRevision < ActiveRecord::Base end end end - + + # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields + def available_custom_fields + search_project = nil + if self.project.present? + search_project = self.project + elsif self.project_id.present? + search_project = Project.find(self.project_id) + end + if search_project + search_project.all_dmsf_custom_fields + else + DmsfFileRevisionCustomField.all + end + end + end \ No newline at end of file diff --git a/app/models/dmsf_file_revision_custom_field.rb b/app/models/dmsf_file_revision_custom_field.rb new file mode 100644 index 00000000..30d28ec3 --- /dev/null +++ b/app/models/dmsf_file_revision_custom_field.rb @@ -0,0 +1,13 @@ +class DmsfFileRevisionCustomField < CustomField + unloadable + has_and_belongs_to_many :projects, :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :foreign_key => "custom_field_id" + + def initialize(attributes = nil) + super + self.searchable = true + end + + def type_name + :DMSF_custom_field + end +end \ No newline at end of file diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index b0dc0ff8..38425468 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -27,7 +27,9 @@ class DmsfFolder < ActiveRecord::Base has_many :subfolders, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id", :order => "title ASC" has_many :files, :class_name => "DmsfFile", :foreign_key => "dmsf_folder_id", :conditions => { :deleted => false } - belongs_to :user + belongs_to :user + + acts_as_customizable validates_presence_of :title validates_uniqueness_of :title, :scope => [:dmsf_folder_id, :project_id] @@ -152,6 +154,19 @@ 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) + + new_folder.custom_values = temp_custom_values + + #add default value for CFs not existing + present_custom_fields = new_folder.custom_values.collect(&:custom_field).uniq + new_folder.project.all_dmsf_custom_fields.each do |cf| + unless present_custom_fields.include?(cf) + new_folder.custom_values << CustomValue.new({:custom_field => cf, :value => cf.default_value}) + end + end return new_folder unless new_folder.save @@ -164,7 +179,22 @@ class DmsfFolder < ActiveRecord::Base end return new_folder - end + end + + # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields + def available_custom_fields + search_project = nil + if self.project.present? + search_project = self.project + elsif self.project_id.present? + search_project = Project.find(self.project_id) + end + if search_project + search_project.all_dmsf_custom_fields + else + DmsfFileRevisionCustomField.all + end + end # To fullfill searchable module expectations def self.search(tokens, projects=nil, options={}) diff --git a/app/views/dmsf/_custom_fields.html.erb b/app/views/dmsf/_custom_fields.html.erb new file mode 100644 index 00000000..1fa7de3d --- /dev/null +++ b/app/views/dmsf/_custom_fields.html.erb @@ -0,0 +1,9 @@ +<% unless object.nil? %> +
<%= custom_field_tag_with_label(:dmsf_folder, value) %>
+ <% end %> <%= submit_tag(create ? l(:submit_create) : l(:submit_save)) %> <% end %> diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index 9b7c7732..aa8bae89 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -19,10 +19,12 @@ <%= render(:partial => 'path', :locals => {:path => path}) %> -- <%= label_tag("dmsf_file_revision_comment", l(:label_comment) + ":") %> -
<%= custom_field_tag_with_label(:dmsf_file_revision, value) %>
+ <% end %> +<%= label_tag("", l(:label_comment) + ":") %> <%= h(revision.comment) %> diff --git a/app/views/dmsf_state/_user_pref.html.erb b/app/views/dmsf_state/_user_pref.html.erb index 1c276329..80747fdc 100644 --- a/app/views/dmsf_state/_user_pref.html.erb +++ b/app/views/dmsf_state/_user_pref.html.erb @@ -14,6 +14,24 @@ :selected => mail_notification)) %> <%= submit_tag(l(:submit_save), :title => l(:title_save_preferences)) %> + <% end %> + + <% form_for :project, @project, :url => project_path(@project), :html => {:method=>:post} do %> + <% custom_fields = DmsfFileRevisionCustomField.find(:all) %> + <% unless custom_fields.empty? %> +
+ <% end %> + + <%= submit_tag(l(:submit_save), :title => l(:title_save_preferences)) %> <% end %> diff --git a/app/views/dmsf_upload/_upload_file.html.erb b/app/views/dmsf_upload/_upload_file.html.erb index 2a90abb8..3264915a 100644 --- a/app/views/dmsf_upload/_upload_file.html.erb +++ b/app/views/dmsf_upload/_upload_file.html.erb @@ -66,6 +66,11 @@ end<%= custom_field_tag_with_label("commited_files[#{i}][dmsf_file_revision]", value) %>
+ <% end %><%= label_tag("commited_files[#{i}][comment]", l(:label_comment) + ":") %>
+ <%= label_tag("dmsf_file_revision_comment", l(:label_comment) + ":") %> +