nautilus-like folders-files list view #252

This commit is contained in:
Karel Picman 2016-04-21 14:16:07 +02:00
parent e727fa2769
commit c49881dbf9
58 changed files with 1639 additions and 1189 deletions

View File

@ -40,94 +40,99 @@ class DmsfController < ApplicationController
@force_file_unlock_allowed = User.current.allowed_to?(:force_file_unlock, @project) @force_file_unlock_allowed = User.current.allowed_to?(:force_file_unlock, @project)
@workflows_available = DmsfWorkflow.where(['project_id = ? OR project_id IS NULL', @project.id]).count > 0 @workflows_available = DmsfWorkflow.where(['project_id = ? OR project_id IS NULL', @project.id]).count > 0
@file_approval_allowed = User.current.allowed_to?(:file_approval, @project) @file_approval_allowed = User.current.allowed_to?(:file_approval, @project)
@tree_view = (User.current.pref[:dmsf_tree_view] == '1') && (!%w(atom xml json).include?(params[:format]))
unless @folder if @tree_view
if params[:custom_field_id].present? && params[:custom_value].present?
@subfolders = []
DmsfFolder.where(:project_id => @project.id).visible.each do |f|
f.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@subfolders << f
break
end
end
end
end
@files = []
DmsfFile.where(:project_id => @project.id).visible.each do |f|
r = f.last_revision
if r
r.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@files << f
break
end
end
end
end
end
@dir_links = []
DmsfLink.where(:project_id => @project.id, :target_type => DmsfFolder.model_name.to_s).visible.each do |l|
l.target_folder.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@dir_links << l
break
end
end
end
end
@file_links = []
DmsfLink.where(:project_id => @project.id, :target_type => DmsfFile.model_name.to_s).visible.each do |l|
r = l.target_file.last_revision if l.target_file
if r
r.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@file_links << l
break
end
end
end
end
end
@url_links = []
DmsfLink.where(:project_id => @project.id, :target_type => 'DmsfUrl').visible.each do |l|
r = l.target_file.last_revision if l.target_file
if r
r.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@file_links << l
break
end
end
end
end
end
else
@subfolders = @project.dmsf_folders.visible
@files = @project.dmsf_files.visible
@dir_links = @project.folder_links.visible
@file_links = @project.file_links.visible
@url_links = @project.url_links.visible
end
@locked_for_user = false @locked_for_user = false
else else
unless @folder
if params[:custom_field_id].present? && params[:custom_value].present?
@subfolders = []
DmsfFolder.where(:project_id => @project.id).visible.each do |f|
f.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@subfolders << f
break
end
end
end
end
@files = []
DmsfFile.where(:project_id => @project.id).visible.each do |f|
r = f.last_revision
if r
r.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@files << f
break
end
end
end
end
end
@dir_links = []
DmsfLink.where(:project_id => @project.id, :target_type => DmsfFolder.model_name.to_s).visible.each do |l|
l.target_folder.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@dir_links << l
break
end
end
end
end
@file_links = []
DmsfLink.where(:project_id => @project.id, :target_type => DmsfFile.model_name.to_s).visible.each do |l|
r = l.target_file.last_revision if l.target_file
if r
r.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@file_links << l
break
end
end
end
end
end
@url_links = []
DmsfLink.where(:project_id => @project.id, :target_type => 'DmsfUrl').visible.each do |l|
r = l.target_file.last_revision if l.target_file
if r
r.custom_field_values.each do |v|
if v.custom_field_id == params[:custom_field_id].to_i
if v.custom_field.compare_values?(v.value, params[:custom_value])
@file_links << l
break
end
end
end
end
end
else
@subfolders = @project.dmsf_folders.visible
@files = @project.dmsf_files.visible
@dir_links = @project.folder_links.visible
@file_links = @project.file_links.visible
@url_links = @project.url_links.visible
end
@locked_for_user = false
else
if @folder.deleted? if @folder.deleted?
render_404 render_404
return return
end
@subfolders = @folder.dmsf_folders.visible
@files = @folder.dmsf_files.visible
@dir_links = @folder.folder_links.visible
@file_links = @folder.file_links.visible
@url_links = @folder.url_links.visible
@locked_for_user = @folder.locked_for_user?
end end
@subfolders = @folder.subfolders.visible
@files = @folder.files.visible
@dir_links = @folder.folder_links.visible
@file_links = @folder.file_links.visible
@url_links = @folder.url_links.visible
@locked_for_user = @folder.locked_for_user?
end end
@ajax_upload_size = Setting.plugin_redmine_dmsf['dmsf_max_ajax_upload_filesize'].present? ? Setting.plugin_redmine_dmsf['dmsf_max_ajax_upload_filesize'] : 100 @ajax_upload_size = Setting.plugin_redmine_dmsf['dmsf_max_ajax_upload_filesize'].present? ? Setting.plugin_redmine_dmsf['dmsf_max_ajax_upload_filesize'] : 100
@ -293,7 +298,7 @@ class DmsfController < ApplicationController
end end
def edit def edit
@parent = @folder.folder @parent = @folder.dmsf_folder
@pathfolder = copy_folder(@folder) @pathfolder = copy_folder(@folder)
@force_file_unlock_allowed = User.current.allowed_to?(:force_file_unlock, @project) @force_file_unlock_allowed = User.current.allowed_to?(:force_file_unlock, @project)
end end
@ -333,7 +338,7 @@ class DmsfController < ApplicationController
if commit if commit
redirect_to :back redirect_to :back
else else
redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder.folder) redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder.dmsf_folder)
end end
end end
@ -448,7 +453,7 @@ class DmsfController < ApplicationController
log_activity(f, 'emailing zip') log_activity(f, 'emailing zip')
audit = DmsfFileRevisionAccess.new audit = DmsfFileRevisionAccess.new
audit.user = User.current audit.user = User.current
audit.revision = f.last_revision audit.dmsf_file_revision = f.last_revision
audit.action = DmsfFileRevisionAccess::EmailAction audit.action = DmsfFileRevisionAccess::EmailAction
audit.save! audit.save!
end end
@ -475,7 +480,7 @@ class DmsfController < ApplicationController
log_activity(f, 'download zip') log_activity(f, 'download zip')
audit = DmsfFileRevisionAccess.new audit = DmsfFileRevisionAccess.new
audit.user = User.current audit.user = User.current
audit.revision = f.last_revision audit.dmsf_file_revision = f.last_revision
audit.action = DmsfFileRevisionAccess::DownloadAction audit.action = DmsfFileRevisionAccess::DownloadAction
audit.save! audit.save!
end end
@ -497,7 +502,7 @@ class DmsfController < ApplicationController
selected_folders.each do |selected_folder_id| selected_folders.each do |selected_folder_id|
folder = DmsfFolder.visible.find_by_id selected_folder_id folder = DmsfFolder.visible.find_by_id selected_folder_id
if folder if folder
zip.add_folder(folder, member, (folder.folder.dmsf_path_str if folder.folder)) zip.add_folder(folder, member, (folder.dmsf_folder.dmsf_path_str if folder.dmsf_folder))
else else
raise FileNotFound raise FileNotFound
end end
@ -512,7 +517,7 @@ class DmsfController < ApplicationController
unless (file.project == @project) || User.current.allowed_to?(:view_dmsf_files, file.project) unless (file.project == @project) || User.current.allowed_to?(:view_dmsf_files, file.project)
raise DmsfAccessError raise DmsfAccessError
end end
zip.add_file(file, member, (file.folder.dmsf_path_str if file.folder)) if file zip.add_file(file, member, (file.dmsf_folder.dmsf_path_str if file.dmsf_folder)) if file
end end
end end
max_files = Setting.plugin_redmine_dmsf['dmsf_max_file_download'].to_i max_files = Setting.plugin_redmine_dmsf['dmsf_max_file_download'].to_i
@ -565,6 +570,7 @@ class DmsfController < ApplicationController
if folder if folder
unless folder.delete commit unless folder.delete commit
flash[:error] = folder.errors.full_messages.to_sentence flash[:error] = folder.errors.full_messages.to_sentence
return
end end
elsif !commit elsif !commit
raise FileNotFound raise FileNotFound

View File

@ -39,14 +39,14 @@ class DmsfFilesController < ApplicationController
@revision = @file.last_revision @revision = @file.last_revision
else else
@revision = DmsfFileRevision.find(params[:download].to_i) @revision = DmsfFileRevision.find(params[:download].to_i)
raise DmsfAccessError if @revision.file != @file raise DmsfAccessError if @revision.dmsf_file != @file
end end
check_project(@revision.file) check_project(@revision.dmsf_file)
raise ActionController::MissingFile if @file.deleted? raise ActionController::MissingFile if @file.deleted?
log_activity('downloaded') log_activity('downloaded')
access = DmsfFileRevisionAccess.new access = DmsfFileRevisionAccess.new
access.user = User.current access.user = User.current
access.revision = @revision access.dmsf_file_revision = @revision
access.action = DmsfFileRevisionAccess::DownloadAction access.action = DmsfFileRevisionAccess::DownloadAction
access.save! access.save!
member = Member.where(:user_id => User.current.id, :project_id => @file.project.id).first member = Member.where(:user_id => User.current.id, :project_id => @file.project.id).first
@ -71,14 +71,14 @@ class DmsfFilesController < ApplicationController
@revision = @file.last_revision @revision = @file.last_revision
else else
@revision = DmsfFileRevision.find(params[:download].to_i) @revision = DmsfFileRevision.find(params[:download].to_i)
raise DmsfAccessError if @revision.file != @file raise DmsfAccessError if @revision.dmsf_file != @file
end end
check_project(@revision.file) check_project(@revision.dmsf_file)
raise ActionController::MissingFile if @revision.file.deleted? raise ActionController::MissingFile if @revision.dmsf_file.deleted?
log_activity('downloaded') log_activity('downloaded')
access = DmsfFileRevisionAccess.new access = DmsfFileRevisionAccess.new
access.user = User.current access.user = User.current
access.revision = @revision access.dmsf_file_revision = @revision
access.action = DmsfFileRevisionAccess::DownloadAction access.action = DmsfFileRevisionAccess::DownloadAction
access.save! access.save!
member = Member.where(:user_id => User.current.id, :project_id => @file.project.id).first member = Member.where(:user_id => User.current.id, :project_id => @file.project.id).first
@ -99,7 +99,7 @@ class DmsfFilesController < ApplicationController
@revision = @file.last_revision @revision = @file.last_revision
@file_delete_allowed = User.current.allowed_to?(:file_delete, @project) @file_delete_allowed = User.current.allowed_to?(:file_delete, @project)
@file_manipulation_allowed = User.current.allowed_to?(:file_manipulation, @project) @file_manipulation_allowed = User.current.allowed_to?(:file_manipulation, @project)
@revision_pages = Paginator.new @file.revisions.visible.count, params['per_page'] ? params['per_page'].to_i : 25, params['page'] @revision_pages = Paginator.new @file.dmsf_file_revisions.visible.count, params['per_page'] ? params['per_page'].to_i : 25, params['page']
respond_to do |format| respond_to do |format|
format.html { format.html {
@ -120,7 +120,7 @@ class DmsfFilesController < ApplicationController
revision.description = params[:dmsf_file_revision][:description] revision.description = params[:dmsf_file_revision][:description]
revision.comment = params[:dmsf_file_revision][:comment] revision.comment = params[:dmsf_file_revision][:comment]
revision.file = @file revision.dmsf_file = @file
last_revision = @file.last_revision last_revision = @file.last_revision
revision.source_revision = last_revision revision.source_revision = last_revision
revision.user = User.current revision.user = User.current
@ -233,7 +233,7 @@ class DmsfFilesController < ApplicationController
if commit if commit
redirect_to :back redirect_to :back
else else
redirect_to dmsf_folder_path(:id => @project, :folder_id => @file.folder) redirect_to dmsf_folder_path(:id => @project, :folder_id => @file.dmsf_folder)
end end
end end
@ -318,7 +318,7 @@ class DmsfFilesController < ApplicationController
def find_revision def find_revision
@revision = DmsfFileRevision.visible.find params[:id] @revision = DmsfFileRevision.visible.find params[:id]
@file = @revision.file @file = @revision.dmsf_file
@project = @file.project @project = @file.project
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404

View File

@ -36,7 +36,7 @@ class DmsfFilesCopyController < ApplicationController
end end
@target_folder = DmsfFolder.visible.find(params[:target_folder_id]) unless params[:target_folder_id].blank? @target_folder = DmsfFolder.visible.find(params[:target_folder_id]) unless params[:target_folder_id].blank?
@target_folder ||= @file.folder if @target_project == @project @target_folder ||= @file.dmsf_folder if @target_project == @project
render :layout => !request.xhr? render :layout => !request.xhr?
end end
@ -52,8 +52,8 @@ class DmsfFilesCopyController < ApplicationController
raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project) raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project)
end end
if (@target_folder && @target_folder == @file.folder) || if (@target_folder && @target_folder == @file.dmsf_folder) ||
(@target_folder.nil? && @file.folder.nil? && @target_project == @file.project) (@target_folder.nil? && @file.dmsf_folder.nil? && @target_project == @file.project)
flash[:error] = l(:error_target_folder_same) flash[:error] = l(:error_target_folder_same)
redirect_to :action => 'new', :id => @file, :target_project_id => @target_project, :target_folder_id => @target_folder redirect_to :action => 'new', :id => @file, :target_project_id => @target_project, :target_folder_id => @target_folder
return return
@ -84,8 +84,8 @@ class DmsfFilesCopyController < ApplicationController
raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project) raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project)
end end
if (@target_folder && @target_folder == @file.folder) || if (@target_folder && @target_folder == @file.dmsf_folder) ||
(@target_folder.nil? && @file.folder.nil? && @target_project == @file.project) (@target_folder.nil? && @file.dmsf_folder.nil? && @target_project == @file.project)
flash[:error] = l(:error_target_folder_same) flash[:error] = l(:error_target_folder_same)
redirect_to :action => 'new', :id => @file, :target_project_id => @target_project, :target_folder_id => @target_folder redirect_to :action => 'new', :id => @file, :target_project_id => @target_project, :target_folder_id => @target_folder
return return

View File

@ -34,7 +34,7 @@ class DmsfFoldersCopyController < ApplicationController
end end
@target_folder = DmsfFolder.visible.find(params[:target_folder_id]) unless params[:target_folder_id].blank? @target_folder = DmsfFolder.visible.find(params[:target_folder_id]) unless params[:target_folder_id].blank?
@target_folder ||= @folder.folder if @target_project == @project @target_folder ||= @folder.dmsf_folder if @target_project == @project
render :layout => !request.xhr? render :layout => !request.xhr?
end end
@ -50,8 +50,8 @@ class DmsfFoldersCopyController < ApplicationController
raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project) raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project)
end end
if (@target_folder && @target_folder == @folder.folder) || if (@target_folder && @target_folder == @folder.dmsf_folder) ||
(@target_folder.nil? && @folder.folder.nil? && @target_project == @folder.project) (@target_folder.nil? && @folder.dmsf_folder.nil? && @target_project == @folder.project)
flash[:error] = l(:error_target_folder_same) flash[:error] = l(:error_target_folder_same)
redirect_to :action => 'new', :id => @folder, :target_project_id => @target_project, :target_folder_id => @target_folder redirect_to :action => 'new', :id => @folder, :target_project_id => @target_project, :target_folder_id => @target_folder
return return

View File

@ -53,7 +53,7 @@ class DmsfLinksController < ApplicationController
if file if file
folder = DmsfFolder.find_by_id params[:dmsf_link][:target_folder_id] folder = DmsfFolder.find_by_id params[:dmsf_link][:target_folder_id]
if (folder && (folder.project_id == @dmsf_link.target_project_id) && folder.files.include?(file)) || folder.nil? if (folder && (folder.project_id == @dmsf_link.target_project_id) && folder.dmsf_files.include?(file)) || folder.nil?
@dmsf_link.name = file.title @dmsf_link.name = file.title
end end
end end

View File

@ -149,7 +149,7 @@ class DmsfUploadController < ApplicationController
file = DmsfFile.new file = DmsfFile.new
file.project = @project file.project = @project
file.name = name file.name = name
file.folder = @folder file.dmsf_folder = @folder
file.notification = Setting.plugin_redmine_dmsf[:dmsf_default_notifications].present? file.notification = Setting.plugin_redmine_dmsf[:dmsf_default_notifications].present?
new_revision.minor_version = 0 new_revision.minor_version = 0
new_revision.major_version = 0 new_revision.major_version = 0
@ -172,7 +172,7 @@ class DmsfUploadController < ApplicationController
commited_disk_filepath = "#{DmsfHelper.temp_dir}/#{commited_file[:disk_filename].gsub(/[\/\\]/,'')}" commited_disk_filepath = "#{DmsfHelper.temp_dir}/#{commited_file[:disk_filename].gsub(/[\/\\]/,'')}"
new_revision.file = file new_revision.dmsf_file = file
new_revision.user = User.current new_revision.user = User.current
new_revision.name = name new_revision.name = name
new_revision.title = commited_file[:title] new_revision.title = commited_file[:title]

View File

@ -47,10 +47,9 @@ class DmsfWorkflowsController < ApplicationController
revision = DmsfFileRevision.find_by_id params[:dmsf_file_revision_id] revision = DmsfFileRevision.find_by_id params[:dmsf_file_revision_id]
if revision if revision
if @dmsf_workflow.try_finish revision, action, (params[:step_action].to_i / 10) if @dmsf_workflow.try_finish revision, action, (params[:step_action].to_i / 10)
file = DmsfFile.joins(:revisions).where(:dmsf_file_revisions => {:id => revision.id}).first if revision.dmsf_file
if file
begin begin
file.unlock! true revision.dmsf_file.unlock! true
rescue DmsfLockError => e rescue DmsfLockError => e
flash[:info] = e.message flash[:info] = e.message
end end
@ -389,7 +388,7 @@ private
@project = @dmsf_workflow.project @project = @dmsf_workflow.project
else # Global workflow else # Global workflow
revision = DmsfFileRevision.find_by_id params[:dmsf_file_revision_id] revision = DmsfFileRevision.find_by_id params[:dmsf_file_revision_id]
@project = revision.file.project if revision && revision.file @project = revision.dmsf_file.project if revision && revision.dmsf_file
end end
else else
if params[:dmsf_workflow] if params[:dmsf_workflow]

View File

@ -69,14 +69,49 @@ module DmsfHelper
def self.to_time(obj) def self.to_time(obj)
#Right, enough of bugs, let's try a better approach here. #Right, enough of bugs, let's try a better approach here.
return if !obj return unless obj
return obj.to_time(ActiveRecord::Base.default_timezone) if obj.is_a?(String) return obj.to_time(ActiveRecord::Base.default_timezone) if obj.is_a?(String)
# Why can't Mysql::Time conform to time object? - without a utc? method it breaks redmine's # Why can't Mysql::Time conform to time object? - without a utc? method it breaks redmine's
# rendering method, so we convert it to string, and back into time - not the most efficient # rendering method, so we convert it to string, and back into time - not the most efficient
# of methods - however seems functional. Not sure if MySQL # of methods - however seems functional. Not sure if MySQL
return obj.to_s.to_time(ActiveRecord::Base.default_timezone) if obj.class.name == 'Mysql::Time' (obj.class.name == 'Mysql::Time') ? obj.to_s.to_time(ActiveRecord::Base.default_timezone) : obj
return obj end
def self.dmsf_tree(parent, obj, tree = nil)
tree ||= []
# Folders && files && links
nodes = obj.dmsf_folders.visible + obj.dmsf_links.visible + obj.dmsf_files.visible
# Alphabetical and type sort
nodes.sort! do |x, y|
if ((x.is_a?(DmsfFolder) || (x.is_a?(DmsfLink) && x.is_folder?)) &&
(y.is_a?(DmsfFile) || (y.is_a?(DmsfLink) && y.is_file?)))
-1
elsif ((x.is_a?(DmsfFile) || (x.is_a?(DmsfLink) && x.is_file?)) &&
(y.is_a?(DmsfFolder) || (y.is_a?(DmsfLink) && y.is_folder?)))
1
else
x.title.downcase <=> y.title.downcase
end
end
# Create the tree
nodes.each do |node|
local_parent = node.dmsf_folder
level = 0
while local_parent && (local_parent != parent)
level += 1
local_parent = local_parent.dmsf_folder
end
position = tree.size
# Files of the same parent and on the same level have the same position
if position > 0 && tree[-1][1] == level &&
(tree[-1][0].is_a?(DmsfFile) || (tree[-1][0].is_a?(DmsfLink) && tree[-1][0].is_file?))
position = tree[-1][2]
end
tree << [node, level, position]
self.dmsf_tree(parent, node, tree) if node.is_a?(DmsfFolder)
end
tree
end end
end end

View File

@ -33,17 +33,15 @@ class DmsfFile < ActiveRecord::Base
include RedmineDmsf::Lockable include RedmineDmsf::Lockable
belongs_to :project belongs_to :project
belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id' belongs_to :dmsf_folder
belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id' belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
has_many :revisions, -> { order("#{DmsfFileRevision.table_name}.major_version DESC, #{DmsfFileRevision.table_name}.minor_version DESC, #{DmsfFileRevision.table_name}.updated_at DESC") }, has_many :dmsf_file_revisions, -> { order("#{DmsfFileRevision.table_name}.major_version DESC, #{DmsfFileRevision.table_name}.minor_version DESC, #{DmsfFileRevision.table_name}.updated_at DESC") },
:class_name => 'DmsfFileRevision', :foreign_key => 'dmsf_file_id',
:dependent => :destroy :dependent => :destroy
has_many :locks, -> { where(entity_type: 0).order("#{DmsfLock.table_name}.updated_at DESC") }, has_many :locks, -> { where(entity_type: 0).order("#{DmsfLock.table_name}.updated_at DESC") },
:class_name => 'DmsfLock', :foreign_key => 'entity_id', :dependent => :destroy :class_name => 'DmsfLock', :foreign_key => 'entity_id', :dependent => :destroy
has_many :referenced_links, -> { where target_type: DmsfFile.model_name.to_s}, has_many :referenced_links, -> { where target_type: DmsfFile.model_name.to_s},
:class_name => 'DmsfLink', :foreign_key => 'target_id', :dependent => :destroy :class_name => 'DmsfLink', :foreign_key => 'target_id', :dependent => :destroy
accepts_nested_attributes_for :revisions, :locks, :referenced_links, :project
STATUS_DELETED = 1 STATUS_DELETED = 1
STATUS_ACTIVE = 0 STATUS_ACTIVE = 0
@ -58,7 +56,7 @@ class DmsfFile < ActiveRecord::Base
validate :validates_name_uniqueness validate :validates_name_uniqueness
def validates_name_uniqueness def validates_name_uniqueness
existing_file = DmsfFile.visible.find_file_by_name(self.project, self.folder, self.name) existing_file = DmsfFile.visible.find_file_by_name(self.project, self.dmsf_folder, self.name)
errors.add(:name, l('activerecord.errors.messages.taken')) unless errors.add(:name, l('activerecord.errors.messages.taken')) unless
existing_file.nil? || existing_file.id == self.id existing_file.nil? || existing_file.id == self.id
end end
@ -96,11 +94,12 @@ class DmsfFile < ActiveRecord::Base
@@storage_path = nil @@storage_path = nil
def self.storage_path def self.storage_path
path = Setting.plugin_redmine_dmsf['dmsf_storage_directory'].strip if Setting.plugin_redmine_dmsf['dmsf_storage_directory'].present? return @@storage_path if @@storage_path.present?
path = Setting.plugin_redmine_dmsf['dmsf_storage_directory']
path = Pathname(Redmine::Configuration['attachments_storage_path']).join('dmsf') if path.blank? && Redmine::Configuration['attachments_storage_path'].present? path = Pathname(Redmine::Configuration['attachments_storage_path']).join('dmsf') if path.blank? && Redmine::Configuration['attachments_storage_path'].present?
path = Rails.root.join('files/dmsf').to_s if path.blank? path = Rails.root.join('files/dmsf').to_s if path.blank?
DmsfFile.storage_path = path if path != @@storage_path path.strip if path
@@storage_path path
end end
# Lets introduce a write for storage path, that way we can also # Lets introduce a write for storage path, that way we can also
@ -123,7 +122,7 @@ class DmsfFile < ActiveRecord::Base
def last_revision def last_revision
unless @last_revision unless @last_revision
@last_revision = self.deleted? ? self.revisions.first : self.revisions.visible.first @last_revision = self.deleted? ? self.dmsf_file_revisions.first : self.dmsf_file_revisions.visible.first
end end
@last_revision @last_revision
end end
@ -144,7 +143,7 @@ class DmsfFile < ActiveRecord::Base
end end
begin begin
# Revisions and links of a deleted file SHOULD be deleted too # Revisions and links of a deleted file SHOULD be deleted too
self.revisions.each { |r| r.delete(commit, true) } self.dmsf_file_revisions.each { |r| r.delete(commit, true) }
if commit if commit
self.destroy self.destroy
else else
@ -160,11 +159,11 @@ class DmsfFile < ActiveRecord::Base
end end
def restore def restore
if self.dmsf_folder_id && (self.folder.nil? || self.folder.deleted?) if self.dmsf_folder_id && (self.dmsf_folder.nil? || self.dmsf_folder.deleted?)
errors[:base] << l(:error_parent_folder) errors[:base] << l(:error_parent_folder)
return false return false
end end
self.revisions.each { |r| r.restore } self.dmsf_file_revisions.each { |r| r.restore }
self.deleted = STATUS_ACTIVE self.deleted = STATUS_ACTIVE
self.deleted_by_user = nil self.deleted_by_user = nil
save save
@ -191,7 +190,7 @@ class DmsfFile < ActiveRecord::Base
end end
def dmsf_path def dmsf_path
path = self.folder.nil? ? [] : self.folder.dmsf_path path = self.dmsf_folder ? self.dmsf_folder.dmsf_path : []
path.push(self) path.push(self)
path path
end end
@ -202,8 +201,8 @@ class DmsfFile < ActiveRecord::Base
def notify? def notify?
return true if self.notification return true if self.notification
return true if folder && folder.notify? return true if self.dmsf_folder && delf.dmsf_folder.notify?
return true if !folder && self.project.dmsf_notification return true if !self.dmsf_folder && self.project.dmsf_notification
return false return false
end end
@ -236,7 +235,7 @@ class DmsfFile < ActiveRecord::Base
# If the target project differs from the source project we must physically move the disk files # If the target project differs from the source project we must physically move the disk files
if self.project != project if self.project != project
self.revisions.all.each do |rev| self.dmsf_file_revisions.all.each do |rev|
if File.exist? rev.disk_file(self.project) if File.exist? rev.disk_file(self.project)
FileUtils.mv rev.disk_file(self.project), rev.disk_file(project) FileUtils.mv rev.disk_file(self.project), rev.disk_file(project)
end end
@ -244,9 +243,9 @@ class DmsfFile < ActiveRecord::Base
end end
self.project = project self.project = project
self.folder = folder self.dmsf_folder = folder
new_revision = self.last_revision.clone new_revision = self.last_revision.clone
new_revision.file = self new_revision.dmsf_file = self
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 = [] new_revision.custom_values = []
@ -261,7 +260,7 @@ class DmsfFile < ActiveRecord::Base
# If the target project differs from the source project we must physically move the disk files # If the target project differs from the source project we must physically move the disk files
if self.project != project if self.project != project
self.revisions.all.each do |rev| self.dmsf_file_revisions.all.each do |rev|
if File.exist? rev.disk_file(self.project) if File.exist? rev.disk_file(self.project)
FileUtils.cp rev.disk_file(self.project), rev.disk_file(project) FileUtils.cp rev.disk_file(self.project), rev.disk_file(project)
end end
@ -269,14 +268,14 @@ class DmsfFile < ActiveRecord::Base
end end
file = DmsfFile.new file = DmsfFile.new
file.folder = folder file.dmsf_folder = folder
file.project = project file.project = project
file.name = self.name file.name = self.name
file.notification = Setting.plugin_redmine_dmsf['dmsf_default_notifications'].present? file.notification = Setting.plugin_redmine_dmsf['dmsf_default_notifications'].present?
if file.save && self.last_revision if file.save && self.last_revision
new_revision = self.last_revision.clone new_revision = self.last_revision.clone
new_revision.file = file new_revision.dmsf_file = file
new_revision.comment = l(:comment_copied_from, :source => "#{self.project.identifier}: #{self.dmsf_path_str}") new_revision.comment = l(:comment_copied_from, :source => "#{self.project.identifier}: #{self.dmsf_path_str}")
new_revision.custom_values = [] new_revision.custom_values = []

View File

@ -21,14 +21,12 @@
class DmsfFileRevision < ActiveRecord::Base class DmsfFileRevision < ActiveRecord::Base
unloadable unloadable
belongs_to :file, :class_name => 'DmsfFile', :foreign_key => 'dmsf_file_id' belongs_to :dmsf_file
belongs_to :source_revision, :class_name => 'DmsfFileRevision', :foreign_key => 'source_dmsf_file_revision_id' belongs_to :source_revision, :class_name => 'DmsfFileRevision', :foreign_key => 'source_dmsf_file_revision_id'
belongs_to :user belongs_to :user
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 :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
has_many :access, :class_name => 'DmsfFileRevisionAccess', :foreign_key => 'dmsf_file_revision_id', :dependent => :destroy has_many :dmsf_file_revision_access, :dependent => :destroy
has_many :dmsf_workflow_step_assignment, :dependent => :destroy has_many :dmsf_workflow_step_assignment, :dependent => :destroy
accepts_nested_attributes_for :access, :dmsf_workflow_step_assignment, :file, :user
STATUS_DELETED = 1 STATUS_DELETED = 1
STATUS_ACTIVE = 0 STATUS_ACTIVE = 0
@ -37,8 +35,8 @@ class DmsfFileRevision < ActiveRecord::Base
scope :deleted, -> { where(:deleted => STATUS_DELETED) } scope :deleted, -> { where(:deleted => STATUS_DELETED) }
acts_as_customizable acts_as_customizable
acts_as_event :title => Proc.new {|o| "#{l(:label_dmsf_updated)}: #{o.file.dmsf_path_str}"}, acts_as_event :title => Proc.new {|o| "#{l(:label_dmsf_updated)}: #{o.dmsf_file.dmsf_path_str}"},
:url => Proc.new {|o| {:controller => 'dmsf_files', :action => 'show', :id => o.file}}, :url => Proc.new {|o| {:controller => 'dmsf_files', :action => 'show', :id => o.dmsf_file}},
:datetime => Proc.new {|o| o.updated_at }, :datetime => Proc.new {|o| o.updated_at },
:description => Proc.new {|o| o.comment }, :description => Proc.new {|o| o.comment },
:author => Proc.new {|o| o.user } :author => Proc.new {|o| o.user }
@ -58,11 +56,11 @@ class DmsfFileRevision < ActiveRecord::Base
:message => l(:error_contains_invalid_character) :message => l(:error_contains_invalid_character)
def project def project
self.file.project if self.file self.dmsf_file.project if self.dmsf_file
end end
def folder def folder
self.file.folder if self.file self.dmsf_file.dmsf_folder if self.dmsf_file
end end
def self.remove_extension(filename) def self.remove_extension(filename)
@ -74,11 +72,11 @@ class DmsfFileRevision < ActiveRecord::Base
end end
def delete(commit = false, force = true) def delete(commit = false, force = true)
if self.file.locked_for_user? if self.dmsf_file.locked_for_user?
errors[:base] << l(:error_file_is_locked) errors[:base] << l(:error_file_is_locked)
return false return false
end end
if !commit && (!force && (self.file.revisions.length <= 1)) if !commit && (!force && (self.dmsf_file.dmsf_file_revisions.length <= 1))
errors[:base] << l(:error_at_least_one_revision_must_be_present) errors[:base] << l(:error_at_least_one_revision_must_be_present)
return false return false
end end
@ -122,7 +120,7 @@ class DmsfFileRevision < ActiveRecord::Base
# custom SQL into a temporary object # custom SQL into a temporary object
# #
def access_grouped def access_grouped
access.select('user_id, COUNT(*) AS count, MIN(created_at) AS first_at, MAX(created_at) AS last_at').group('user_id') self.dmsf_file_revision_access.select('user_id, COUNT(*) AS count, MIN(created_at) AS first_at, MAX(created_at) AS last_at').group('user_id')
end end
def version def version
@ -130,9 +128,9 @@ class DmsfFileRevision < ActiveRecord::Base
end end
def disk_file(project = nil) def disk_file(project = nil)
project = self.file.project unless project project = self.dmsf_file.project unless project
storage_base = DmsfFile.storage_path.dup storage_base = DmsfFile.storage_path.dup
if self.file && project if self.dmsf_file && project
project_base = project.identifier.gsub(/[^\w\.\-]/,'_') project_base = project.identifier.gsub(/[^\w\.\-]/,'_')
storage_base << "/p_#{project_base}" storage_base << "/p_#{project_base}"
end end
@ -149,7 +147,7 @@ class DmsfFileRevision < ActiveRecord::Base
def clone def clone
new_revision = DmsfFileRevision.new new_revision = DmsfFileRevision.new
new_revision.file = self.file new_revision.dmsf_file = self.dmsf_file
new_revision.disk_filename = self.disk_filename new_revision.disk_filename = self.disk_filename
new_revision.size = self.size new_revision.size = self.size
new_revision.mime_type = self.mime_type new_revision.mime_type = self.mime_type
@ -223,13 +221,13 @@ class DmsfFileRevision < ActiveRecord::Base
end end
def new_storage_filename def new_storage_filename
raise DmsfAccessError, 'File id is not set' unless self.file.id raise DmsfAccessError, 'File id is not set' unless self.dmsf_file.id
filename = DmsfHelper.sanitize_filename(self.name) filename = DmsfHelper.sanitize_filename(self.name)
timestamp = DateTime.now.strftime("%y%m%d%H%M%S") timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
while File.exist?(File.join(DmsfFile.storage_path, "#{timestamp}_#{self.file.id}_#{filename}")) while File.exist?(File.join(DmsfFile.storage_path, "#{timestamp}_#{self.dmsf_file.id}_#{filename}"))
timestamp.succ! timestamp.succ!
end end
"#{timestamp}_#{self.file.id}_#{filename}" "#{timestamp}_#{self.dmsf_file.id}_#{filename}"
end end
def copy_file_content(open_file) def copy_file_content(open_file)
@ -262,7 +260,7 @@ class DmsfFileRevision < ActiveRecord::Base
format.sub!('%f', filename) format.sub!('%f', filename)
format.sub!('%d', self.updated_at.strftime('%Y%m%d%H%M%S')) format.sub!('%d', self.updated_at.strftime('%Y%m%d%H%M%S'))
format.sub!('%v', self.version) format.sub!('%v', self.version)
format.sub!('%i', self.file.id.to_s) format.sub!('%i', self.dmsf_file.id.to_s)
format.sub!('%r', self.id.to_s) format.sub!('%r', self.id.to_s)
format + ext format + ext
end end

View File

@ -1,3 +1,5 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features" # Redmine plugin for Document Management System "Features"
# #
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com> # Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
@ -18,20 +20,20 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class DmsfFileRevisionAccess < ActiveRecord::Base class DmsfFileRevisionAccess < ActiveRecord::Base
unloadable unloadable
belongs_to :revision, :class_name => 'DmsfFileRevision', :foreign_key => 'dmsf_file_revision_id' belongs_to :dmsf_file_revision
belongs_to :user belongs_to :user
delegate :project, :to => :revision, :allow_nil => false delegate :project, :to => :revision, :allow_nil => false
delegate :file, :to => :revision, :allow_nil => false delegate :file, :to => :revision, :allow_nil => false
accepts_nested_attributes_for :user, :revision
DownloadAction = 0 DownloadAction = 0
EmailAction = 1 EmailAction = 1
acts_as_event :title => Proc.new {|o| "#{l(:label_dmsf_downloaded)}: #{o.file.dmsf_path_str}"}, acts_as_event :title => Proc.new {|o| "#{l(:label_dmsf_downloaded)}: #{o.dmsf_file.dmsf_path_str}"},
:url => Proc.new {|o| {:controller => 'dmsf_files', :action => 'show', :id => o.file}}, :url => Proc.new {|o| {:controller => 'dmsf_files', :action => 'show', :id => o.dmsf_file}},
:datetime => Proc.new {|o| o.updated_at }, :datetime => Proc.new {|o| o.updated_at },
:description => Proc.new {|o| o.revision.comment }, :description => Proc.new {|o| o.dmsf_file_revision.comment },
:author => Proc.new {|o| o.user } :author => Proc.new {|o| o.user }
acts_as_activity_provider :type => 'dmsf_file_revision_accesses', acts_as_activity_provider :type => 'dmsf_file_revision_accesses',

View File

@ -1,7 +1,9 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features" # Redmine plugin for Document Management System "Features"
# #
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com> # Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2013 Karel Picman <karel.picman@kontron.com> # Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License

View File

@ -28,25 +28,23 @@ class DmsfFolder < ActiveRecord::Base
@@invalid_characters = /\A[^\/\\\?":<>]*\z/ @@invalid_characters = /\A[^\/\\\?":<>]*\z/
belongs_to :project belongs_to :project
belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id' belongs_to :dmsf_folder
belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id' belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
belongs_to :user belongs_to :user
has_many :subfolders, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id', has_many :dmsf_folders, :dependent => :destroy
:dependent => :destroy has_many :dmsf_files, :dependent => :destroy
has_many :files, :class_name => 'DmsfFile', :foreign_key => 'dmsf_folder_id',
:dependent => :destroy
has_many :folder_links, -> { where :target_type => 'DmsfFolder' }, has_many :folder_links, -> { where :target_type => 'DmsfFolder' },
:class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id', :dependent => :destroy :class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id', :dependent => :destroy
has_many :file_links, -> { where :target_type => 'DmsfFile' }, has_many :file_links, -> { where :target_type => 'DmsfFile' },
:class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id', :dependent => :destroy :class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id', :dependent => :destroy
has_many :url_links, -> { where :target_type => 'DmsfUrl' }, has_many :url_links, -> { where :target_type => 'DmsfUrl' },
:class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id', :dependent => :destroy :class_name => 'DmsfLink', :foreign_key => 'dmsf_folder_id', :dependent => :destroy
has_many :dmsf_links, :dependent => :destroy
has_many :referenced_links, -> { where :target_type => 'DmsfFolder' }, has_many :referenced_links, -> { where :target_type => 'DmsfFolder' },
:class_name => 'DmsfLink', :foreign_key => 'target_id', :dependent => :destroy :class_name => 'DmsfLink', :foreign_key => 'target_id', :dependent => :destroy
has_many :locks, -> { where(entity_type: 1).order("#{DmsfLock.table_name}.updated_at DESC") }, has_many :locks, -> { where(entity_type: 1).order("#{DmsfLock.table_name}.updated_at DESC") },
:class_name => 'DmsfLock', :foreign_key => 'entity_id', :dependent => :destroy :class_name => 'DmsfLock', :foreign_key => 'entity_id', :dependent => :destroy
accepts_nested_attributes_for :user, :project, :folder, :subfolders, :files, :folder_links, :file_links, :url_links, :referenced_links, :locks
STATUS_DELETED = 1 STATUS_DELETED = 1
STATUS_ACTIVE = 0 STATUS_ACTIVE = 0
@ -87,13 +85,13 @@ class DmsfFolder < ActiveRecord::Base
def check_cycle def check_cycle
folders = [] folders = []
self.subfolders.each {|f| folders.push(f)} self.dmsf_folders.each {|f| folders.push(f)}
folders.each do |folder| self.dmsf_folders.each do |folder|
if folder == self.folder if folder == self.dmsf_folder
errors.add(:folder, l(:error_create_cycle_in_folder_dependency)) errors.add(:folder, l(:error_create_cycle_in_folder_dependency))
return false return false
end end
folder.subfolders.each {|f| folders.push(f)} folder.dmsf_folders.each {|f| folders.push(f)}
end end
return true return true
end end
@ -110,7 +108,7 @@ class DmsfFolder < ActiveRecord::Base
if self.locked? if self.locked?
errors[:base] << l(:error_folder_is_locked) errors[:base] << l(:error_folder_is_locked)
return false return false
elsif !self.subfolders.visible.empty? || !self.files.visible.empty? elsif !self.dmsf_folders.visible.empty? || !self.dmsf_files.visible.empty?
errors[:base] << l(:error_folder_is_not_empty) errors[:base] << l(:error_folder_is_not_empty)
return false return false
end end
@ -128,7 +126,7 @@ class DmsfFolder < ActiveRecord::Base
end end
def restore def restore
if self.dmsf_folder_id && (self.folder.nil? || self.folder.deleted?) if self.dmsf_folder_id && (self.dmsf_folder.nil? || self.dmsf_folder.deleted?)
errors[:base] << l(:error_parent_folder) errors[:base] << l(:error_parent_folder)
return false return false
end end
@ -142,7 +140,7 @@ class DmsfFolder < ActiveRecord::Base
path = [] path = []
while folder while folder
path.unshift(folder) path.unshift(folder)
folder = folder.folder folder = folder.dmsf_folder
end end
path path
end end
@ -155,8 +153,8 @@ class DmsfFolder < ActiveRecord::Base
def notify? def notify?
return true if self.notification return true if self.notification
return true if folder && folder.notify? return true if self.dmsf_folder && self.dmsf_folder.notify?
return true if !folder && self.project.dmsf_notification return true if !self.dmsf_folder && self.project.dmsf_notification
return false return false
end end
@ -197,21 +195,21 @@ class DmsfFolder < ActiveRecord::Base
end end
def deep_file_count def deep_file_count
file_count = self.files.visible.count file_count = self.dmsf_files.visible.count
self.subfolders.visible.each {|subfolder| file_count += subfolder.deep_file_count} self.dmsf_folders.visible.each { |subfolder| file_count += subfolder.deep_file_count }
file_count + self.file_links.visible.count file_count + self.file_links.visible.count + self.url_links.visible.count
end end
def deep_folder_count def deep_folder_count
folder_count = self.subfolders.visible.count folder_count = self.dmsf_folders.visible.count
self.subfolders.visible.each {|subfolder| folder_count += subfolder.deep_folder_count} self.dmsf_folders.visible.each { |subfolder| folder_count += subfolder.deep_folder_count }
folder_count + self.folder_links.visible.count folder_count + self.folder_links.visible.count
end end
def deep_size def deep_size
size = 0 size = 0
self.files.visible.each {|file| size += file.size} self.dmsf_files.visible.each {|file| size += file.size}
self.subfolders.visible.each {|subfolder| size += subfolder.deep_size} self.dmsf_folders.visible.each {|subfolder| size += subfolder.deep_size}
size size
end end
@ -228,7 +226,7 @@ class DmsfFolder < ActiveRecord::Base
def copy_to(project, folder) def copy_to(project, folder)
new_folder = DmsfFolder.new new_folder = DmsfFolder.new
new_folder.folder = folder ? folder : nil new_folder.dmsf_folder = folder ? folder : nil
new_folder.project = folder ? folder.project : project new_folder.project = folder ? folder.project : project
new_folder.title = self.title new_folder.title = self.title
new_folder.description = self.description new_folder.description = self.description
@ -241,11 +239,11 @@ class DmsfFolder < ActiveRecord::Base
return new_folder unless new_folder.save return new_folder unless new_folder.save
self.files.visible.each do |f| self.dmsf_files.visible.each do |f|
f.copy_to project, new_folder f.copy_to project, new_folder
end end
self.subfolders.visible.each do |s| self.dmsf_folders.visible.each do |s|
s.copy_to project, new_folder s.copy_to project, new_folder
end end
@ -271,10 +269,10 @@ class DmsfFolder < ActiveRecord::Base
def modified def modified
last_update = updated_at last_update = updated_at
subfolders.each do |subfolder| dmsf_folders.each do |subfolder|
last_update = subfolder.updated_at if subfolder.updated_at > last_update last_update = subfolder.updated_at if subfolder.updated_at > last_update
end end
files.each do |file| dmsf_files.each do |file|
last_update = file.updated_at if file.updated_at > last_update last_update = file.updated_at if file.updated_at > last_update
end end
folder_links.each do |folder_link| folder_links.each do |folder_link|
@ -291,8 +289,8 @@ class DmsfFolder < ActiveRecord::Base
# Number of items in the folder # Number of items in the folder
def items def items
subfolders.visible.count + dmsf_folders.visible.count +
files.visible.count + dmsf_files.visible.count +
folder_links.visible.count + folder_links.visible.count +
file_links.visible.count + file_links.visible.count +
url_links.visible.count url_links.visible.count
@ -301,7 +299,7 @@ class DmsfFolder < ActiveRecord::Base
private private
def self.directory_subtree(tree, folder, level, current_folder) def self.directory_subtree(tree, folder, level, current_folder)
folder.subfolders.visible.each do |subfolder| folder.dmsf_folders.visible.each do |subfolder|
unless subfolder == current_folder unless subfolder == current_folder
tree.push(["#{'...' * level}#{subfolder.title}", subfolder.id]) tree.push(["#{'...' * level}#{subfolder.title}", subfolder.id])
directory_subtree(tree, subfolder, level + 1, current_folder) directory_subtree(tree, subfolder, level + 1, current_folder)

View File

@ -133,7 +133,7 @@ class DmsfLink < ActiveRecord::Base
end end
def restore def restore
if self.dmsf_folder_id && (self.folder.nil? || self.folder.deleted?) if self.dmsf_folder_id && (self.dmsf_folder.nil? || self.dmsf_folder.deleted?)
errors[:base] << l(:error_parent_folder) errors[:base] << l(:error_parent_folder)
return false return false
end end
@ -142,4 +142,12 @@ class DmsfLink < ActiveRecord::Base
save(:validate => false) save(:validate => false)
end end
def is_folder?
self.target_type == 'DmsfFolder'
end
def is_file?
!is_folder?
end
end end

View File

@ -29,7 +29,6 @@ class DmsfLock < ActiveRecord::Base
belongs_to :user belongs_to :user
# At the moment apparently we're only supporting a write lock? # At the moment apparently we're only supporting a write lock?
as_enum :lock_type, [:type_write, :type_other] as_enum :lock_type, [:type_write, :type_other]
as_enum :lock_scope, [:scope_exclusive, :scope_shared] as_enum :lock_scope, [:scope_exclusive, :scope_shared]

View File

@ -66,8 +66,8 @@ class DmsfMailer < Mailer
def workflow_notification(user, workflow, revision, subject_id, text1_id, text2_id, notice = nil) def workflow_notification(user, workflow, revision, subject_id, text1_id, text2_id, notice = nil)
if user && workflow && revision if user && workflow && revision
if revision.file && revision.file.project if revision.dmsf_file && revision.dmsf_file.project
@project = revision.file.project @project = revision.dmsf_file.project
redmine_headers 'Project' => @project.identifier redmine_headers 'Project' => @project.identifier
end end
set_language_if_valid user.language set_language_if_valid user.language
@ -75,7 +75,7 @@ class DmsfMailer < Mailer
message_id workflow message_id workflow
@workflow = workflow @workflow = workflow
@revision = revision @revision = revision
@text1 = l(text1_id, :name => workflow.name, :filename => revision.file.name, :notice => notice) @text1 = l(text1_id, :name => workflow.name, :filename => revision.dmsf_file.name, :notice => notice)
@text2 = l(text2_id) @text2 = l(text2_id)
@notice = notice @notice = notice
mail :to => user.mail, mail :to => user.mail,

View File

@ -1,8 +1,10 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features" # Redmine plugin for Document Management System "Features"
# #
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com> # Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk> # Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-14 Karel Pičman <karel.picman@kontron.com> # Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
@ -73,7 +75,11 @@ class DmsfUpload
@major_version = 0 @major_version = 0
@minor_version = 0 @minor_version = 0
@workflow = nil @workflow = nil
@custom_values = DmsfFileRevision.new(:file => DmsfFile.new(:project => @project)).custom_field_values file = DmsfFile.new
file.project = @project
revision = DmsfFileRevision.new
revision.dmsf_file = file
@custom_values = revision.custom_field_values
else else
last_revision = file.last_revision last_revision = file.last_revision
@title = last_revision.title @title = last_revision.title

View File

@ -2,7 +2,7 @@
# #
# Redmine plugin for Document Management System "Features" # Redmine plugin for Document Management System "Features"
# #
# Copyright (C) 2011-15 Karel Pičman <karel.picman@kontron.com> # Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License

View File

@ -2,7 +2,7 @@
# #
# Redmine plugin for Document Management System "Features" # Redmine plugin for Document Management System "Features"
# #
# Copyright (C) 2011-15 Karel Pičman <karel.picman@kontron.com> # Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
@ -28,8 +28,6 @@ class DmsfWorkflowStepAction < ActiveRecord::Base
validates :author_id, :presence => true validates :author_id, :presence => true
validates_uniqueness_of :dmsf_workflow_step_assignment_id, :scope => [:action], :unless => lambda {self.action == DmsfWorkflowStepAction::ACTION_DELEGATE} validates_uniqueness_of :dmsf_workflow_step_assignment_id, :scope => [:action], :unless => lambda {self.action == DmsfWorkflowStepAction::ACTION_DELEGATE}
attr_accessible :dmsf_workflow_step_assignment_id, :action, :note
ACTION_APPROVE = 1 ACTION_APPROVE = 1
ACTION_REJECT = 2 ACTION_REJECT = 2
ACTION_DELEGATE = 3 ACTION_DELEGATE = 3

View File

@ -2,7 +2,7 @@
# #
# Redmine plugin for Document Management System "Features" # Redmine plugin for Document Management System "Features"
# #
# Copyright (C) 2011-15 Karel Pičman <karel.picman@kontron.com> # Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
@ -26,8 +26,6 @@ class DmsfWorkflowStepAssignment < ActiveRecord::Base
validates :dmsf_workflow_step_id, :dmsf_file_revision_id, :presence => true validates :dmsf_workflow_step_id, :dmsf_file_revision_id, :presence => true
validates_uniqueness_of :dmsf_workflow_step_id, :scope => [:dmsf_file_revision_id] validates_uniqueness_of :dmsf_workflow_step_id, :scope => [:dmsf_file_revision_id]
attr_accessible :dmsf_workflow_step_id, :user_id, :dmsf_file_revision_id
def add?(dmsf_file_revision_id) def add?(dmsf_file_revision_id)
if self.dmsf_file_revision_id == dmsf_file_revision_id if self.dmsf_file_revision_id == dmsf_file_revision_id
add = true add = true

View File

@ -26,6 +26,9 @@
<td class="dmsf_checkbox"><%= check_box_tag(name, id, false, <td class="dmsf_checkbox"><%= check_box_tag(name, id, false,
:title => l(:title_check_for_zip_download_or_email), :id => "subfolder_#{id}") %></td> :title => l(:title_check_for_zip_download_or_email), :id => "subfolder_#{id}") %></td>
<td class="dmsf_title"> <td class="dmsf_title">
<% if @tree_view %>
<span class='dmsf_expander' <%= onclick.html_safe %>></span>
<% end %>
<%= link_to(h(title), <%= link_to(h(title),
dmsf_folder_path(:id => project, :folder_id => subfolder), dmsf_folder_path(:id => project, :folder_id => subfolder),
:class => 'icon icon-folder') %> :class => 'icon icon-folder') %>
@ -106,7 +109,7 @@
<% end %> <% end %>
<% end %> <% end %>
</td> </td>
<td class="dmsf_invisible">0</td> <td class="dmsf_invisible"><%= position %></td>
<td class="dmsf_invisible">0</td> <td class="dmsf_invisible">0</td>
<td class="dmsf_invisible"><%= subfolder.modified.to_i if subfolder %></td> <td class="dmsf_invisible"><%= subfolder.modified.to_i if subfolder %></td>
<td class="dmsf_invisible">0</td> <td class="dmsf_invisible">0</td>

View File

@ -25,6 +25,9 @@
<td class="dmsf_checkbox"><%= check_box_tag(name, id, false, <td class="dmsf_checkbox"><%= check_box_tag(name, id, false,
:title => l(:title_check_for_zip_download_or_email), :id => "file_#{id}") %></td> :title => l(:title_check_for_zip_download_or_email), :id => "file_#{id}") %></td>
<td class="dmsf_title"> <td class="dmsf_title">
<% if @tree_view %>
<span class='dmsf_expander' <%= onclick.html_safe %>></span>
<% end %>
<% file_view_url = url_for({:controller => :dmsf_files, :action => 'view', :id => file}) %> <% file_view_url = url_for({:controller => :dmsf_files, :action => 'view', :id => file}) %>
<%= link_to(h(title), <%= link_to(h(title),
file_view_url, file_view_url,
@ -33,6 +36,7 @@
:title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version), :title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version),
'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_view_url}") %> 'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_view_url}") %>
<div class="dmsf_filename" title="<%= l(:title_filename_for_download)%>"><%= h(link ? link.path : file.display_name) %></div> <div class="dmsf_filename" title="<%= l(:title_filename_for_download)%>"><%= h(link ? link.path : file.display_name) %></div>
<%= '</span>'.html_safe if @tree_view %>
</td> </td>
<td class="dmsf_size"><%= number_to_human_size(file.last_revision.size) %></td> <td class="dmsf_size"><%= number_to_human_size(file.last_revision.size) %></td>
<td class="dmsf_modified"> <td class="dmsf_modified">
@ -174,7 +178,7 @@
<% end %> <% end %>
<% end %> <% end %>
</td> </td>
<td class="dmsf_invisible">1</td> <td class="dmsf_invisible"><%= position %></td>
<td class="dmsf_invisible"><%= file.last_revision.size %></td> <td class="dmsf_invisible"><%= file.last_revision.size %></td>
<td class="dmsf_invisible"><%= file.last_revision.updated_at.to_i %></td> <td class="dmsf_invisible"><%= file.last_revision.updated_at.to_i %></td>
<td class="dmsf_invisible"><%= file.last_revision.iversion %></td> <td class="dmsf_invisible"><%= file.last_revision.iversion %></td>

View File

@ -0,0 +1,118 @@
<%
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
%>
<table class="display list dmsf_list" id="browser">
<thead>
<tr>
<th class="dmsf_checkbox dmsf_th">
<input id="check_all_entries" title="<%= l(:title_check_uncheck_all_for_zip_download_or_email) %>" type="checkbox" />
</th>
<th class ="dmsf_th"><%= l(:link_title) %></th>
<th class ="dmsf_th"><%= l(:link_size) %></th>
<th class ="dmsf_th"><%= l(:link_modified) %></th>
<th title="<%= l(:label_version) %>" class ="dmsf_th"><%= l(:link_ver) %></th>
<th class ="dmsf_th"><%= l(:link_workflow) %></th>
<th class ="dmsf_th"><%= l(:link_author) %></th>
<th class ="dmsf_th"></th>
<th class="dmsf_invisible"></th>
<th class="dmsf_invisible"></th>
<th class="dmsf_invisible"></th>
<th class="dmsf_invisible"></th>
</tr>
</thead>
<tbody>
<% @subfolders.each do |subfolder| %>
<tr class="dir">
<%= render(:partial => 'dir',
:locals => {
:project => @project,
:subfolder => subfolder,
:link => nil,
:id => subfolder.id,
:name => 'subfolders[]',
:title => subfolder.title,
:position => 0 }) %>
</tr>
<% end %>
<% @dir_links.each do |link| %>
<% unless link.target_project %>
<% Rails.logger.error "Error: dmsf_link id #{link.id} has no target!" %>
<% next %>
<% end %>
<tr class="dmsf_gray">
<%= render(:partial => 'dir',
:locals => {
:project => link.target_project,
:subfolder => link.target_folder,
:link => link,
:id => link.id,
:name => 'dir_links[]',
:title => link.name,
:position => 0}) %>
</tr>
<% end %>
<% @files.each do |file| %>
<% unless file.last_revision %>
<% Rails.logger.error "Error: dmsf_file id #{file.id} has no revision!" %>
<% next %>
<% end %>
<tr class="file">
<%= render(:partial => 'file', :locals => {
:project => @project,
:file => file,
:link => nil,
:id => file.id,
:name => 'files[]',
:title => file.title,
:position => 1 }) %>
</tr>
<% end %>
<% @file_links.each do |link| %>
<% unless link.target_file.last_revision %>
<% Rails.logger.error "Error: dmsf_file id #{link.target_id} has no revision!" %>
<% next %>
<% end %>
<tr class="dmsf_gray">
<%= render(:partial => 'file', :locals => {
:project => link.target_project,
:file => link.target_file,
:link => link,
:id => link.id,
:name => 'file_links[]',
:title => link.name,
:position => 1}) %>
</tr>
<% end %>
<% @url_links.each do |link| %>
<tr class="dmsf_gray">
<%= render(:partial => 'url', :locals => {
:project => link.target_project,
:file => link.target_file,
:link => link,
:id => link.id,
:name => 'file_links[]',
:title => link.name,
:position => 1}) %>
</tr>
<% end %>
</tbody>
</table>

View File

@ -0,0 +1,138 @@
<%
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
%>
<table class="display list dmsf_list" id="browser">
<thead>
<tr>
<th class="dmsf_checkbox dmsf_th">
<input id="check_all_entries" title="<%= l(:title_check_uncheck_all_for_zip_download_or_email) %>" type="checkbox" />
</th>
<th class ="dmsf_th"><%= l(:link_title) %></th>
<th class ="dmsf_th"><%= l(:link_size) %></th>
<th class ="dmsf_th"><%= l(:link_modified) %></th>
<th title="<%= l(:label_version) %>" class ="dmsf_th"><%= l(:link_ver) %></th>
<th class ="dmsf_th"><%= l(:link_workflow) %></th>
<th class ="dmsf_th"><%= l(:link_author) %></th>
<th class ="dmsf_th"></th>
<th class="dmsf_invisible"></th>
<th class="dmsf_invisible"></th>
<th class="dmsf_invisible"></th>
<th class="dmsf_invisible"></th>
</tr>
</thead>
<tbody>
<% parent = @folder ? @folder : @project %>
<% DmsfHelper.dmsf_tree(parent, parent).each do |obj, level, position| %>
<% classes = "dmsf_tree idnt-#{level}" %>
<% if obj.is_a?(DmsfFolder) && ((obj.dmsf_folders.visible.count > 0) || (obj.dmsf_files.visible.count > 0) || (obj.dmsf_links.visible.count > 0)) %>
<% classes += ' idnt dmsf_collapsed' %>
<% id = "id='#{obj.id}span'".html_safe %>
<% onclick = "onclick=\"dmsf_toggle('#{obj.id}','#{obj.id}span')\"" %>
<% else %>
<% classes += ' dmsf_child' %>
<% onclick = '' %>
<% end %>
<% classes += ' dmsf_hidden' if obj.dmsf_folder && obj.dmsf_folder != @folder %>
<% parent = obj.dmsf_folder %>
<% while parent %>
<% classes += " #{parent.id}" %>
<% parent = parent.dmsf_folder %>
<% end %>
<% if obj.is_a? DmsfFolder %>
<tr <%= id %> class="dir <%= classes %>">
<%= render(:partial => 'dir',
:locals => {
:project => @project,
:subfolder => obj,
:link => nil,
:id => obj.id,
:name => 'subfolders[]',
:title => obj.title,
:onclick => onclick,
:position => position}) %>
</tr>
<% elsif obj.is_a?(DmsfLink) && (obj.target_type == 'DmsfFolder') %>
<% unless obj.target_project %>
<% Rails.logger.error "Error: dmsf_link id #{obj.id} has no target!" %>
<% next %>
<% end %>
<tr <%= id %> class="dmsf_gray <%= classes %>">
<%= render(:partial => 'dir',
:locals => {
:project => obj.target_project,
:subfolder => obj.target_folder,
:link => obj,
:id => obj.id,
:name => 'dir_links[]',
:title => obj.name,
:onclick => onclick,
:position => position}) %>
</tr>
<% elsif obj.is_a?(DmsfFile) %>
<% unless obj.last_revision %>
<% Rails.logger.error "Error: dmsf_file id #{obj.id} has no revision!" %>
<% next %>
<% end %>
<tr <%= id %> class="file <%= classes %>">
<%= render(:partial => 'file', :locals => {
:project => @project,
:file => obj,
:link => nil,
:id => obj.id,
:name => 'files[]',
:title => obj.title,
:onclick => onclick,
:position => position}) %>
</tr>
<% elsif obj.is_a?(DmsfLink) && (obj.target_type == 'DmsfFile') %>
<% unless obj.target_file.last_revision %>
<% Rails.logger.error "Error: dmsf_file id #{obj.target_id} has no revision!" %>
<% next %>
<% end %>
<tr <%= id %> class="dmsf_gray <%= classes %>">
<%= render(:partial => 'file', :locals => {
:project => obj.target_project,
:file => obj.target_file,
:link => obj,
:id => obj.id,
:name => 'file_links[]',
:title => obj.name,
:onclick => onclick,
:position => position}) %>
</tr>
<% elsif obj.is_a?(DmsfLink) && (obj.target_type == 'DmsfUrl') %>
<tr <%= id %> class="dmsf_gray <%= classes %>">
<%= render(:partial => 'url', :locals => {
:project => obj.target_project,
:file => obj.target_file,
:link => obj,
:id => obj.id,
:name => 'file_links[]',
:title => obj.name,
:onclick => onclick,
:position => position}) %>
</tr>
<% end %>
<% end %>
</tbody>
</table>

View File

@ -22,13 +22,17 @@
<td class="dmsf_checkbox"></td> <td class="dmsf_checkbox"></td>
<td class="dmsf_title"> <td class="dmsf_title">
<% if @tree_view %>
<span class='dmsf_expander' <%= onclick.html_safe %>></span>
<% end %>
<%= link_to(h(title), <%= link_to(h(title),
link.external_url, link.external_url,
:target => '_blank', :target => '_blank',
:class => 'icon dmsf_icon-link') %> :class => 'icon dmsf_icon-link') %>
<div class="dmsf_filename" title="<%= l(:label_target_folder)%>"> <div class="dmsf_filename" title="<%= l(:label_target_folder) %>">
<%= link.external_url %> <%= link.external_url %>
</div> </div>
<%= '</span>'.html_safe if @tree_view %>
</td> </td>
<td class="dmsf_size"></td> <td class="dmsf_size"></td>
<td class="dmsf_modified"><%= format_time(link.updated_at) %></td> <td class="dmsf_modified"><%= format_time(link.updated_at) %></td>
@ -49,7 +53,7 @@
<span class="icon"></span> <span class="icon"></span>
<% end %> <% end %>
</td> </td>
<td class="dmsf_invisible">1</td> <td class="dmsf_invisible"><%= position %> </td>
<td class="dmsf_invisible"></td> <td class="dmsf_invisible"></td>
<td class="dmsf_invisible">link.updated_at.to_i</td> <td class="dmsf_invisible">link.updated_at.to_i</td>
<td class="dmsf_invisible"></td> <td class="dmsf_invisible"></td>

View File

@ -101,97 +101,11 @@
</div> </div>
<% end %> <% end %>
<div class="autoscroll"> <div class="autoscroll">
<table class="display list dmsf_list" id="browser"> <% if @tree_view %>
<thead> <%= render(:partial => 'tree_view') %>
<tr> <% else %>
<th class="dmsf_checkbox dmsf_th"> <%= render(:partial => 'list_view') %>
<input id="check_all_entries" title="<%= l(:title_check_uncheck_all_for_zip_download_or_email) %>" type="checkbox" />
</th>
<th class ="dmsf_th"><%= l(:link_title) %></th>
<th class ="dmsf_th"><%= l(:link_size) %></th>
<th class ="dmsf_th"><%= l(:link_modified) %></th>
<th title="<%= l(:label_version) %>" class ="dmsf_th"><%= l(:link_ver) %></th>
<th class ="dmsf_th"><%= l(:link_workflow) %></th>
<th class ="dmsf_th"><%= l(:link_author) %></th>
<th class ="dmsf_th"></th>
<th class="dmsf_invisible"></th>
<th class="dmsf_invisible"></th>
<th class="dmsf_invisible"></th>
<th class="dmsf_invisible"></th>
</tr>
</thead>
<tbody>
<% @subfolders.each do |subfolder| %>
<tr class="dir">
<%= render(:partial => 'dir',
:locals => {
:project => @project,
:subfolder => subfolder,
:link => nil,
:id => subfolder.id,
:name => 'subfolders[]',
:title => subfolder.title }) %>
</tr>
<% end %>
<% @dir_links.each do |link| %>
<% unless link.target_project %>
<% Rails.logger.error "Error: dmsf_link id #{link.id} has no target!" %>
<% next %>
<% end %> <% end %>
<tr class="dmsf_gray">
<%= render(:partial => 'dir',
:locals => {
:project => link.target_project,
:subfolder => link.target_folder,
:link => link,
:id => link.id,
:name => 'dir_links[]',
:title => link.name }) %>
</tr>
<% end %>
<% @files.each do |file| %>
<% unless file.last_revision %>
<% Rails.logger.error "Error: dmsf_file id #{file.id} has no revision!" %>
<% next %>
<% end %>
<tr class="file">
<%= render(:partial => 'file', :locals => {
:project => @project,
:file => file,
:link => nil,
:id => file.id,
:name => 'files[]',
:title => file.title }) %>
</tr>
<% end %>
<% @file_links.each do |link| %>
<% unless link.target_file.last_revision %>
<% Rails.logger.error "Error: dmsf_file id #{link.target_id} has no revision!" %>
<% next %>
<% end %>
<tr class="dmsf_gray">
<%= render(:partial => 'file', :locals => {
:project => link.target_project,
:file => link.target_file,
:link => link,
:id => link.id,
:name => 'file_links[]',
:title => link.name }) %>
</tr>
<% end %>
<% @url_links.each do |link| %>
<tr class="dmsf_gray">
<%= render(:partial => 'url', :locals => {
:project => link.target_project,
:file => link.target_file,
:link => link,
:id => link.id,
:name => 'file_links[]',
:title => link.name }) %>
</tr>
<% end %>
</tbody>
</table>
</div> </div>
<% end %> <% end %>
@ -228,15 +142,15 @@
$('#browser').dataTable({ $('#browser').dataTable({
'bJQueryUI': true, 'bJQueryUI': true,
'oLanguage': { 'oLanguage': {
'sUrl': "<%= plugin_asset_path(:redmine_dmsf, 'javascripts', sUrl) %>" 'sUrl': "<%= plugin_asset_path(:redmine_dmsf, 'javascripts', sUrl) %>"
}, },
'bAutoWidth': false, 'bAutoWidth': false,
'bPaginate': false, 'bPaginate': false,
'aaSorting': [[1,'asc']], 'aaSorting': [[1, 'asc']],
'aaSortingFixed': [[8,'asc']], 'aaSortingFixed': [[ 8, 'asc']],
'aoColumnDefs': [ 'aoColumnDefs': [
{ 'bSearchable': false, 'aTargets': [0, 7, 8, 9] }, { 'bSearchable': false, 'aTargets': [0, 7, 8, 9, 10, 11] },
{ 'bSortable': false, 'aTargets': [0, 7, 8] }, { 'bSortable': false, 'aTargets': [0, 7] },
{ 'iDataSort': 9, 'aTargets': [ 2 ] }, { 'iDataSort': 9, 'aTargets': [ 2 ] },
{ 'iDataSort': 10, 'aTargets': [ 3 ] }, { 'iDataSort': 10, 'aTargets': [ 3 ] },
{ 'iDataSort': 11, 'aTargets': [ 4 ] } { 'iDataSort': 11, 'aTargets': [ 4 ] }
@ -245,7 +159,15 @@
jQuery('div.dmsf_controls').prependTo(jQuery('#browser_wrapper div.fg-toolbar')[0]); jQuery('div.dmsf_controls').prependTo(jQuery('#browser_wrapper div.fg-toolbar')[0]);
}, },
'fnInfoCallback': function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) { 'fnInfoCallback': function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
return "<%= l(:label_number_of_folders)%>: <%= @subfolders.count + @dir_links.count %>, <%= l(:label_number_of_documents)%>: <%= @files.count + @file_links.count + @url_links.count %>"; <% if @tree_view %>
<% if @folder %>
return "<%= "#{l(:label_number_of_folders)}: #{@folder.deep_folder_count} #{l(:label_number_of_documents)}: #{@folder.deep_file_count}" %>";
<% else %>
return "<%= "#{l(:label_number_of_folders)}: #{DmsfFolder.visible.where(:project_id => @project.id).count + DmsfLink.visible.where(:project_id => @project.id, :target_type => 'DmsfFolder').count}, #{l(:label_number_of_documents)}: #{DmsfFile.visible.where(:project_id => @project.id).count + DmsfLink.visible.where(:project_id => @project.id, :target_type => 'DmsfFile').count + DmsfLink.visible.where(:project_id => @project.id, :target_type => 'DmsfUrl').count}" %>";
<% end %>
<% else %>
return "<%= "#{l(:label_number_of_folders)}: #{@subfolders.count + @dir_links.count}, #{l(:label_number_of_documents)}: #{@files.count + @file_links.count + @url_links.count}" %>";
<% end %>
} }
}); });

View File

@ -46,7 +46,7 @@
:class => 'icon dmsf_icon-notification-off') %> :class => 'icon dmsf_icon-notification-off') %>
<% end %> <% end %>
<%= link_to(l(:label_link_to), <%= link_to(l(:label_link_to),
new_dmsf_link_path(:project_id => @project.id, :dmsf_folder_id => @file.folder ? @file.folder.id : nil, :dmsf_file_id => @file.id, :type => 'link_to'), new_dmsf_link_path(:project_id => @project.id, :dmsf_folder_id => @file.dmsf_folder ? @file.dmsf_folder.id : nil, :dmsf_file_id => @file.id, :type => 'link_to'),
:title => l(:title_create_link), :title => l(:title_create_link),
:class => 'icon dmsf_icon-link') %> :class => 'icon dmsf_icon-link') %>
<%= link_to("#{l(:button_copy)}/#{l(:button_move)}", copy_file_path(:id => @file), <%= link_to("#{l(:button_copy)}/#{l(:button_move)}", copy_file_path(:id => @file),
@ -76,7 +76,7 @@
</div> </div>
<h3><%= l(:heading_revisions) %></h3> <h3><%= l(:heading_revisions) %></h3>
<% @file.revisions.visible[@revision_pages.offset, @revision_pages.per_page].each do |revision| %> <% @file.dmsf_file_revisions.visible[@revision_pages.offset, @revision_pages.per_page].each do |revision| %>
<div class="dmsf_revision_box tabular dataTables_wrapper"> <div class="dmsf_revision_box tabular dataTables_wrapper">
<div class="fg-toolbar ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"> <div class="fg-toolbar ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix">
<div class="dataTables_lenght"> <div class="dataTables_lenght">
@ -90,7 +90,7 @@
<%= link_to image_tag('rev_delete.png', :plugin => 'redmine_dmsf'), <%= link_to image_tag('rev_delete.png', :plugin => 'redmine_dmsf'),
delete_revision_path(revision), delete_revision_path(revision),
:data => {:confirm => l(:text_are_you_sure)}, :data => {:confirm => l(:text_are_you_sure)},
:title => l(:title_delete_revision) if @file_delete_allowed && (@file.revisions.visible.count > 1) %> :title => l(:title_delete_revision) if @file_delete_allowed && (@file.dmsf_file_revisions.visible.count > 1) %>
</div> </div>
<i><%= l(:info_revision, :rev => revision.id) %></i> <i><%= l(:info_revision, :rev => revision.id) %></i>
<%= (revision.source_revision.nil? ? l(:label_created) : l(:label_changed)).downcase %> <%= (revision.source_revision.nil? ? l(:label_created) : l(:label_changed)).downcase %>
@ -109,7 +109,7 @@
<div class="splitcontentright"> <div class="splitcontentright">
<p> <p>
<%= label_tag('', l(:label_file)) %> <%= label_tag('', l(:label_file)) %>
<%= ("#{h(revision.file.folder.dmsf_path_str)}/") if revision.file.folder %><%= h(revision.name) %> <%= ("#{h(revision.dmsf_file.dmsf_folder.dmsf_path_str)}/") if revision.dmsf_file.dmsf_folder %><%= h(revision.name) %>
</p> </p>
</div> </div>
</div> </div>
@ -170,7 +170,7 @@
<br/> <br/>
<% end %> <% end %>
<span class="pagination"><%= pagination_links_full @revision_pages, @file.revisions.visible.count %></span> <span class="pagination"><%= pagination_links_full @revision_pages, @file.dmsf_file_revisions.visible.count %></span>
<% <%
url = 'jquery.dataTables/en.json' url = 'jquery.dataTables/en.json'

View File

@ -25,7 +25,7 @@
<% html_title(l(:dmsf)) %> <% html_title(l(:dmsf)) %>
<%= render(:partial => '/dmsf/path', <%= render(:partial => '/dmsf/path',
:locals => {:folder => @file.folder, :filename => @file.title, :locals => {:folder => @file.dmsf_folder, :filename => @file.title,
:title => "#{l(:button_copy)}/#{l(:button_move)}"}) %> :title => "#{l(:button_copy)}/#{l(:button_move)}"}) %>
<% if DmsfFile.allowed_target_projects_on_copy.present? %> <% if DmsfFile.allowed_target_projects_on_copy.present? %>

View File

@ -69,7 +69,7 @@
<p> <p>
<% if @target_folder_id %> <% if @target_folder_id %>
<% folder = DmsfFolder.find_by_id @target_folder_id %> <% folder = DmsfFolder.find_by_id @target_folder_id %>
<% files = folder.files.visible if folder %> <% files = folder.dmsf_files.visible if folder %>
<% else %> <% else %>
<% files = @dmsf_link.target_project.dmsf_files.visible if @dmsf_link.target_project %> <% files = @dmsf_link.target_project.dmsf_files.visible if @dmsf_link.target_project %>
<% end %> <% end %>

View File

@ -1,8 +1,11 @@
<%# Redmine plugin for Document Management System "Features" <%
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
# #
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com> # Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk> # Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-15 Karel Pičman <karel.picman@kontron.com> # Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
@ -21,21 +24,27 @@
<%= textilizable(@body) %> <%= textilizable(@body) %>
<% if @links_only == '1' %> <% if @links_only == '1' %>
<% folders = [] %>
<% files = [] %>
<% if @folders.present? %> <% if @folders.present? %>
<% JSON.parse(@folders).each do |id| %> <% JSON.parse(@folders).each do |id| %>
<% folder = DmsfFolder.find_by_id id %> <% folder = DmsfFolder.find_by_id id %>
<% if folder %> <% if folder %>
<% folder.folder_tree.each do |name, i| %> <% folder.folder_tree.each do |name, i| %>
<% dir = DmsfFolder.find_by_id i %> <% dir = DmsfFolder.find_by_id i %>
<% if dir %> <% if dir && !folders.include?(dir) %>
<br/> <br/>
<%= link_to(h(dir.dmsf_path_str), dmsf_folder_path(:id => dir.project_id, :folder_id => dir.id, :only_path => false)) %> <%= link_to(h(dir.dmsf_path_str), dmsf_folder_path(:id => dir.project_id, :folder_id => dir.id, :only_path => false)) %>
<br/><br/> <br/><br/>
<% dir.files.each do |file| %> <% dir.dmsf_files.each do |file| %>
<%= link_to(h(file.title), dmsf_file_url(file)) %> <% unless files.include?(file) %>
&nbsp;(<%= link_to(h(file.name), dmsf_file_url(file, :download => '')) %>) <%= link_to(h(file.title), dmsf_file_url(file)) %>
<br/> &nbsp;(<%= link_to(h(file.name), dmsf_file_url(file, :download => '')) %>)
<br/>
<% files << file %>
<% end %>
<% end %> <% end %>
<% folders << dir %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
@ -45,11 +54,13 @@
<br/> <br/>
<% JSON.parse(@files).each do |id| %> <% JSON.parse(@files).each do |id| %>
<% file = DmsfFile.find_by_id id %> <% file = DmsfFile.find_by_id id %>
<% if file %> <% if file && !files.include?(file) %>
<%= link_to(h(file.title), dmsf_file_url(file)) %> <%= link_to(h(file.title), dmsf_file_url(file)) %>
&nbsp;(<%= link_to(h(file.name), dmsf_file_url(file, :download => '')) %>) &nbsp;(<%= link_to(h(file.name), dmsf_file_url(file, :download => '')) %>)
<br/> <br/>
<% files << file %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

View File

@ -1,8 +1,11 @@
<%# Redmine plugin for Document Management System "Features" <%
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
# #
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com> # Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk> # Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-15 Karel Pičman <karel.picman@kontron.com> # Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
@ -21,16 +24,21 @@
<%= @body %> <%= @body %>
<% if @links_only == '1' %> <% if @links_only == '1' %>
<% folders = [] %>
<% files = [] %>
<% if @folders.present? %> <% if @folders.present? %>
<% JSON.parse(@folders).each do |id| %> <% JSON.parse(@folders).each do |id| %>
<% folder = DmsfFolder.find_by_id id %> <% folder = DmsfFolder.find_by_id id %>
<% if folder %> <% if folder && !folders.include?(folder) %>
<% folder.folder_tree.each do |name, i| %> <% folder.folder_tree.each do |name, i| %>
<% dir = DmsfFolder.find_by_id i %> <% dir = DmsfFolder.find_by_id i %>
<% if dir %> <% if dir %>
<%= dir.dmsf_path_str %> <%= dir.dmsf_path_str %>
<% dir.files.each do |file| %> <% dir.dmsf_files.each do |file| %>
<%= dmsf_file_url(file, :download => '') %> <% unless files.include?(file) %>
<%= dmsf_file_url(file, :download => '') %>
<% files << file %>
<% end %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
@ -40,8 +48,9 @@
<% if @files.present? %> <% if @files.present? %>
<% JSON.parse(@files).each do |id| %> <% JSON.parse(@files).each do |id| %>
<% file = DmsfFile.find_by_id id %> <% file = DmsfFile.find_by_id id %>
<% if file %> <% if file && !files.include?(file) %>
<%= dmsf_file_url(file, :download => '') %> <%= dmsf_file_url(file, :download => '') %>
<% files << file %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

View File

@ -22,11 +22,11 @@
</p> </p>
<p> <p>
<%= @text2 %> <%= @text2 %>
<% unless @revision.file.folder %> <% unless @revision.dmsf_file.dmsf_folder %>
<%= link_to l(:link_documents), <%= link_to l(:link_documents),
dmsf_folder_url(:id => @revision.file.project) %> dmsf_folder_url(:id => @revision.dmsf_file.project) %>
<% else %> <% else %>
<%= link_to @revision.file.folder.title, <%= link_to @revision.dmsf_file.dmsf_folder.title,
dmsf_folder_url(:id => @revision.file.project, :folder_id => @revision.file.folder) %> dmsf_folder_url(:id => @revision.dmsf_file.project, :folder_id => @revision.dmsf_file.dmsf_folder) %>
<% end %>. <% end %>.
</p> </p>

View File

@ -18,8 +18,8 @@
<%= @user.name %>, <%= @user.name %>,
<%= @text1 %> <%= @text1 %>
<% unless @revision.file.folder %> <% unless @revision.dmsf_file.dmsf_folder %>
<%= @text2 %> <%= dmsf_folder_url(:id => @revision.file.project) %>. <%= @text2 %> <%= dmsf_folder_url(:id => @revision.dmsf_file.project) %>.
<% else %> <% else %>
<%= @text2 %> <%= dmsf_folder_url(:id => @revision.file.project, :folder_id => @revision.file.folder) %>. <%= @text2 %> <%= dmsf_folder_url(:id => @revision.dmsf_file.project, :folder_id => @revision.dmsf_file.dmsf_folder) %>.
<% end %> <% end %>

View File

@ -1,3 +1,25 @@
<%#
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
%>
<%= labelled_fields_for :pref, @user.pref do |pref_fields| %> <%= labelled_fields_for :pref, @user.pref do |pref_fields| %>
<p><%= pref_fields.check_box :dmsf_tree_view %></p> <p><%= pref_fields.check_box :dmsf_tree_view %></p>
<% end %> <% end %>

View File

@ -1,8 +1,11 @@
<%# Redmine plugin for Document Management System "Features" <%#
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
# #
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com> # Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk> # Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-14 Karel Pičman <karel.picman@kontron.com> # Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
@ -16,7 +19,8 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.%> # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
%>
<% if @project.new_record? && @source_project %> <% if @project.new_record? && @source_project %>
<p> <p>

View File

@ -47,9 +47,9 @@
:class => 'icon icon-folder') %> :class => 'icon icon-folder') %>
</td> </td>
<td class="title"> <td class="title">
<% if folder.folder %> <% if folder.dmsf_folder %>
<%= link_to(h(folder.folder.title), <%= link_to(h(folder.dmsf_folder.title),
{:controller => 'dmsf', :action => 'show', :id => folder.project, :folder_id => folder.folder}) %> {:controller => 'dmsf', :action => 'show', :id => folder.project, :folder_id => folder.dmsf_folder}) %>
<% else %> <% else %>
<%= link_to(l(:link_documents), {:controller => 'dmsf', :action => 'show', :id=> folder.project }) %> <%= link_to(l(:link_documents), {:controller => 'dmsf', :action => 'show', :id=> folder.project }) %>
<% end %> <% end %>
@ -67,8 +67,8 @@
:class => "icon icon-file #{DmsfHelper.filetype_css(file.name)}") %> :class => "icon icon-file #{DmsfHelper.filetype_css(file.name)}") %>
</td> </td>
<td class="title"> <td class="title">
<% if file.folder %> <% if file.dmsf_folder %>
<%= link_to(h(file.folder.title), <%= link_to(h(file.dmsf_folder.title),
{:controller => 'dmsf', :action => 'show', :id => file.project, :folder_id => file.folder}) %> {:controller => 'dmsf', :action => 'show', :id => file.project, :folder_id => file.folder}) %>
<% else %> <% else %>
<%= link_to(l(:link_documents), {:controller => 'dmsf', :action => 'show', :id=> file.project }) %> <%= link_to(l(:link_documents), {:controller => 'dmsf', :action => 'show', :id=> file.project }) %>

View File

@ -25,10 +25,10 @@
'dmsf_workflow_step_assignments.user_id = ? AND dmsf_workflow_step_actions.id IS NULL', @user.id).all %> 'dmsf_workflow_step_assignments.user_id = ? AND dmsf_workflow_step_actions.id IS NULL', @user.id).all %>
<% assignments = Array.new %> <% assignments = Array.new %>
<% all_assignments.each do |assignment| %> <% all_assignments.each do |assignment| %>
<% if assignment.dmsf_file_revision.file.last_revision && <% if assignment.dmsf_file_revision.dmsf_file.last_revision &&
!assignment.dmsf_file_revision.file.last_revision.deleted? && !assignment.dmsf_file_revision.dmsf_file.last_revision.deleted? &&
(assignment.dmsf_file_revision.workflow == DmsfWorkflow::STATE_WAITING_FOR_APPROVAL) && (assignment.dmsf_file_revision.workflow == DmsfWorkflow::STATE_WAITING_FOR_APPROVAL) &&
(assignment.dmsf_file_revision == assignment.dmsf_file_revision.file.last_revision) %> (assignment.dmsf_file_revision == assignment.dmsf_file_revision.dmsf_file.last_revision) %>
<% assignments << assignment %> <% assignments << assignment %>
<% end %> <% end %>
<% end %> <% end %>
@ -48,8 +48,8 @@
<% assignments.each do |assignment| %> <% assignments.each do |assignment| %>
<tr id="assignment-<%= assignment.id %>" class="<%= cycle('odd', 'even') %>"> <tr id="assignment-<%= assignment.id %>" class="<%= cycle('odd', 'even') %>">
<td class="project"> <td class="project">
<% if assignment.dmsf_file_revision.file.project %> <% if assignment.dmsf_file_revision.dmsf_file.project %>
<%= link_to_project(assignment.dmsf_file_revision.file.project) %> <%= link_to_project(assignment.dmsf_file_revision.dmsf_file.project) %>
<% end %> <% end %>
</td> </td>
<td> <td>
@ -59,18 +59,18 @@
<% end %> <% end %>
</td> </td>
<td class="title"> <td class="title">
<% if assignment.dmsf_file_revision && assignment.dmsf_file_revision.file %> <% if assignment.dmsf_file_revision && assignment.dmsf_file_revision.dmsf_file %>
<%= link_to(h(assignment.dmsf_file_revision.title), <%= link_to(h(assignment.dmsf_file_revision.title),
{:controller => 'dmsf_files', :action => :show, :id => assignment.dmsf_file_revision.file }) %> {:controller => 'dmsf_files', :action => :show, :id => assignment.dmsf_file_revision.dmsf_file }) %>
<% end %> <% end %>
</td> </td>
<td class="title"> <td class="title">
<% if assignment.dmsf_file_revision %> <% if assignment.dmsf_file_revision %>
<% if assignment.dmsf_file_revision.file.folder %> <% if assignment.dmsf_file_revision.dmsf_file.dmsf_folder %>
<%= link_to(h(assignment.dmsf_file_revision.file.folder.title), <%= link_to(h(assignment.dmsf_file_revision.dmsf_file.dmsf_folder.title),
{:controller => 'dmsf', :action => 'show', :id => assignment.dmsf_file_revision.file.project, :folder_id => assignment.dmsf_file_revision.file.folder}) %> {:controller => 'dmsf', :action => 'show', :id => assignment.dmsf_file_revision.dmsf_file.project, :folder_id => assignment.dmsf_file_revision.dmsf_file.dmsf_folder}) %>
<% elsif assignment.dmsf_file_revision.file.project %> <% elsif assignment.dmsf_file_revision.dmsf_file.project %>
<%= link_to(l(:link_documents), {:controller => 'dmsf', :action => 'show', :id => assignment.dmsf_file_revision.file.project }) %> <%= link_to(l(:link_documents), {:controller => 'dmsf', :action => 'show', :id => assignment.dmsf_file_revision.dmsf_file.project }) %>
<% end %> <% end %>
<% end %> <% end %>
</td> </td>

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

View File

@ -0,0 +1,117 @@
/* encoding: utf-8
*
* Redmine plugin for Document Management System "Features"
*
* Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* Function to allow the projects to show up as a tree */
function dmsf_toggle(EL, PM)
{
var els = document.getElementsByTagName('tr');
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)" + EL + "(\\s|$)");
var cpattern = new RegExp('span');
var expand = new RegExp('dmsf_expanded');
var collapse = new RegExp('dmsf_collapsed');
var hide = new RegExp('dmsf_hidden');
var spanid = PM;
var classid = new RegExp('junk');
var oddeventoggle = 0;
for(i = 0; i < elsLen; i++)
{
if(cpattern.test(els[i].id))
{
var tmpspanid = spanid;
var tmpclassid = classid;
spanid = els[i].id;
classid = spanid;
classid = classid.match(/(\w+)span/)[1];
classid = new RegExp(classid);
if(tmpclassid.test(els[i].className) && (tmpspanid.toString() !== PM.toString()))
{
if(collapse.test(document.getElementById(tmpspanid).className))
{
spanid = tmpspanid;
classid = tmpclassid;
}
}
}
if(pattern.test(els[i].className))
{
var cnames = els[i].className;
cnames = cnames.replace(/dmsf_hidden/g,'');
if(expand.test(document.getElementById(PM).className))
{
cnames += ' dmsf_hidden';
}
else
{
if((spanid.toString() !== PM.toString()) && (classid.test(els[i].className)))
{
if(collapse.test(document.getElementById(spanid).className))
{
cnames += ' dmsf_hidden';
}
}
}
els[i].className = cnames;
}
if(!(hide.test(els[i].className)))
{
var cnames = els[i].className;
cnames = cnames.replace(/odd/g,'');
cnames = cnames.replace(/even/g,'');
if(oddeventoggle === 0)
{
cnames += ' odd';
}
else
{
cnames += ' even';
}
oddeventoggle ^= 1;
els[i].className = cnames;
}
}
if (collapse.test(document.getElementById(PM).className))
{
var cnames = document.getElementById(PM).className;
cnames = cnames.replace(/dmsf_collapsed/,'dmsf_expanded');
document.getElementById(PM).className = cnames;
}
else
{
var cnames = document.getElementById(PM).className;
cnames = cnames.replace(/dmsf_expanded/,'dmsf_collapsed');
document.getElementById(PM).className = cnames;
}
}

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@ -43,7 +43,7 @@
.plupload_logo { .plupload_logo {
width: 40px; width: 40px;
height: 40px; height: 40px;
background: url('../img/plupload.png') no-repeat 0 0; background: url('../images/plupload.png') no-repeat 0 0;
position: absolute; position: absolute;
top: 8px; top: 8px;
left: 8px; left: 8px;
@ -119,7 +119,7 @@
} }
.plupload_thumb_loading { .plupload_thumb_loading {
background: #eee url(../img/loading.gif) center no-repeat; background: #eee url(../images/loading.gif) center no-repeat;
} }
.plupload_thumb_loading .plupload_file_dummy, .plupload_thumb_loading .plupload_file_dummy,

View File

@ -20,7 +20,6 @@
*/ */
/* DMSF table.list modifications */ /* DMSF table.list modifications */
table.dmsf_list th.dmsf_th { table.dmsf_list th.dmsf_th {
border: none; border: none;
} }
@ -223,3 +222,25 @@ tr.dmsf_gray .icon-file.application-x-gzip { background-image: url(../images/fil
/* Search results */ /* Search results */
dt.dmsf-file { background-image: url(../../../images/document.png); } dt.dmsf-file { background-image: url(../../../images/document.png); }
dt.dmsf-folder { background-image: url(../../../images/folder.png); } dt.dmsf-folder { background-image: url(../../../images/folder.png); }
/* DMSF tree view */
tr.dmsf_hidden { display:none; }
tr.dmsf_tree span.dmsf_expander { cursor: pointer; }
tr.dmsf_tree.dmsf_expanded td.dmsf_title span {
background: url(../images/bullet_arrow_down.png) no-repeat 0 50%;
padding-left: 16px;
}
tr.dmsf_tree.dmsf_child td.dmsf_title span { padding-left: 16px; }
tr.dmsf_tree.dmsf_collapsed td.dmsf_title span {
background: url(../../../images/bullet_arrow_right.png) no-repeat 0 50%;
padding-left: 16px;
}
tr.dmsf_tree.idnt-1 td.dmsf_title {padding-left: 1.5em;}
tr.dmsf_tree.idnt-2 td.dmsf_title {padding-left: 2em;}
tr.dmsf_tree.idnt-3 td.dmsf_title {padding-left: 2.5em;}
tr.dmsf_tree.idnt-4 td.dmsf_title {padding-left: 3em;}
tr.dmsf_tree.idnt-5 td.dmsf_title {padding-left: 3.5em;}
tr.dmsf_tree.idnt-6 td.dmsf_title {padding-left: 4em;}
tr.dmsf_tree.idnt-7 td.dmsf_title {padding-left: 4.5em;}
tr.dmsf_tree.idnt-8 td.dmsf_title {padding-left: 5em;}
tr.dmsf_tree.idnt-9 td.dmsf_title {padding-left: 5.5em;}

View File

@ -26,7 +26,7 @@ cs:
label_dmsf_file_revision_plural: Revize dokumentů label_dmsf_file_revision_plural: Revize dokumentů
label_dmsf_file_revision_access_plural: Přístupy k dokumentům label_dmsf_file_revision_access_plural: Přístupy k dokumentům
warning_no_entries_selected: Není nic vybráno warning_no_entries_selected: Není nic vybráno
error_email_to_must_be_entered: Musí být zadán adresát error_email_to_must_be_entered: Musí být zadán příjemce
warning_file_already_locked: Soubor je již zamčen warning_file_already_locked: Soubor je již zamčen
notice_file_locked: Soubor byl zamčen notice_file_locked: Soubor byl zamčen
warning_file_not_locked: Soubor není zamčen warning_file_not_locked: Soubor není zamčen
@ -34,14 +34,14 @@ cs:
error_only_user_that_locked_file_can_unlock_it: Soubor může být odemčen pouze uživatelem, který ho zamkl error_only_user_that_locked_file_can_unlock_it: Soubor může být odemčen pouze uživatelem, který ho zamkl
error_max_files_exceeded: "Limit pro %{number} najednou stažených souborů je překročen" error_max_files_exceeded: "Limit pro %{number} najednou stažených souborů je překročen"
error_entry_project_does_not_match_current_project: Zadaný projekt neodpovídá aktuálnímu projektu error_entry_project_does_not_match_current_project: Zadaný projekt neodpovídá aktuálnímu projektu
notice_folder_created: Adresář byl vytvořen notice_folder_created: Složka byla vytvořena
error_folder_creation_failed: Vytváření složky selhalo error_folder_creation_failed: Vytváření složky selhalo
error_folder_title_must_be_entered: Musí být zadán název error_folder_title_must_be_entered: Musí být zadán název
notice_folder_deleted: Adresář byl smazán notice_folder_deleted: Složka byla smazána
error_folder_is_not_empty: Adresář není prázdný error_folder_is_not_empty: Složka není prázdná
error_folder_title_is_already_used: Název již existuje error_folder_title_is_already_used: Název již existuje
notice_folder_details_were_saved: Detaily složky byly uloženy notice_folder_details_were_saved: Detaily složky byly uloženy
error_folder_is_locked: Adresář je zamčen error_folder_is_locked: Složka je zamčena
error_file_is_locked: Soubor je zamčen error_file_is_locked: Soubor je zamčen
notice_file_deleted: Soubor byl smazán notice_file_deleted: Soubor byl smazán
error_at_least_one_revision_must_be_present: Musí existovat alespoň jedna revize error_at_least_one_revision_must_be_present: Musí existovat alespoň jedna revize
@ -181,18 +181,18 @@ cs:
heading_access_last: Poslední heading_access_last: Poslední
label_dmsf_updated: Změněno label_dmsf_updated: Změněno
label_dmsf_downloaded: Staženo label_dmsf_downloaded: Staženo
title_total_size_of_all_files: Celková velikost všech souborů v adresáři title_total_size_of_all_files: Celková velikost všech souborů ve složce
project_module_dmsf: DMSF project_module_dmsf: DMSF
warning_no_project_to_copy_file_to: Neexistuje projekt, do kterého můžete kopírovat warning_no_project_to_copy_file_to: Neexistuje projekt, do kterého můžete kopírovat
comment_copied_from: "Zkopírováno z %{source}" comment_copied_from: "Zkopírováno z %{source}"
notice_file_copied: Soubor zkopírován notice_file_copied: Soubor zkopírován
notice_file_moved: Soubor přesunut notice_file_moved: Soubor přesunut
field_target_project: Cílový projekt field_target_project: Cílový projekt
field_target_folder: Cílový adresář field_target_folder: Cílová složka
title_copy_or_move: Kopírovat/Přesunout title_copy_or_move: Kopírovat/Přesunout
label_dmsf_folder_plural: Složky label_dmsf_folder_plural: Složky
comment_moved_from: "Přesunuto z %{source}" comment_moved_from: "Přesunuto z %{source}"
error_target_folder_same: Cílový adresář a projekt jsou stejné jako aktuální error_target_folder_same: Cílový složka a projekt jsou stejné jako aktuální
error_file_cannot_be_moved: Soubor nemůže být přesunut error_file_cannot_be_moved: Soubor nemůže být přesunut
error_file_cannot_be_copied: Soubor nemůže být zkopírován error_file_cannot_be_copied: Soubor nemůže být zkopírován
warning_no_project_to_copy_folder_to: Neexistuje projekt, do kterého můžete kopírovat warning_no_project_to_copy_folder_to: Neexistuje projekt, do kterého můžete kopírovat
@ -205,7 +205,7 @@ cs:
label_maximum_email_filesize: Maximální velikost souboru emailu label_maximum_email_filesize: Maximální velikost souboru emailu
header_minimum_filesize: Chyba souboru. header_minimum_filesize: Chyba souboru.
error_minimum_filesize: "Soubor %{file} má nulovou velikost a nebude přiložen." error_minimum_filesize: "Soubor %{file} má nulovou velikost a nebude přiložen."
parent_directory: Nadřazený adresář parent_directory: Nadřazená složka
note_webdav: "Webdav je po aktivaci k dispozici na %{protocol}://%{domain}/dmsf/webdav/[identifikátor projektu]" note_webdav: "Webdav je po aktivaci k dispozici na %{protocol}://%{domain}/dmsf/webdav/[identifikátor projektu]"
label_webdav: Webdav functionalita label_webdav: Webdav functionalita
label_dmsf_plural: "Kopíruj dokumenty a složky (%{files} souborů v %{folders} složkách)" label_dmsf_plural: "Kopíruj dokumenty a složky (%{files} souborů v %{folders} složkách)"
@ -292,8 +292,8 @@ cs:
label_link_name: Název odkazu label_link_name: Název odkazu
label_link_external_url: URL label_link_external_url: URL
label_target_folder: Cílový adresář label_target_folder: Cílová složka
label_source_folder: Zdrojový adresář label_source_folder: Zdrojová složka
label_target_project: Cílový projekt label_target_project: Cílový projekt
label_source_project: Zdrojový projekt label_source_project: Zdrojový projekt
@ -311,10 +311,10 @@ cs:
link_trash_bin: Koš link_trash_bin: Koš
title_restore: Obnovit title_restore: Obnovit
notice_dmsf_file_restored: Document byl úspěšně obnoven notice_dmsf_file_restored: Document byl úspěšně obnoven
notice_dmsf_folder_restored: Adresář byl úspěšně obnoven notice_dmsf_folder_restored: Složka byla úspěšně obnovena
notice_dmsf_link_restored: Odkaz byl úspěšně obnoven notice_dmsf_link_restored: Odkaz byl úspěšně obnoven
title_restore_checked: Obnov vybrané title_restore_checked: Obnov vybrané
error_parent_folder: Nadřazený adresář neexistuje error_parent_folder: Nadřazená složka neexistuje
error_resource_or_parent_locked: Nelze zamknout - zdrojový nebo nadřazený objekt je zamčený error_resource_or_parent_locked: Nelze zamknout - zdrojový nebo nadřazený objekt je zamčený
error_parent_locked: Nelze zamknout - nadřazený objekt je zamčený error_parent_locked: Nelze zamknout - nadřazený objekt je zamčený
@ -322,7 +322,7 @@ cs:
error_lock_exclusively: Nelze zamknout již zamčený objekt error_lock_exclusively: Nelze zamknout již zamčený objekt
error_unlock_parent_locked: Nelze odemknout - nadřazený objekt je zamčený error_unlock_parent_locked: Nelze odemknout - nadřazený objekt je zamčený
field_dmsf_tree_view: Navigate folders in a tree field_dmsf_tree_view: Zobrazit složky jako stromovou strukturu
my: my:
blocks: blocks:

View File

@ -42,8 +42,8 @@ RedmineApp::Application.routes.draw do
get '/projects/:id/dmsf/unlock', :controller => 'dmsf', :action => 'unlock', :as => 'unlock_dmsf' get '/projects/:id/dmsf/unlock', :controller => 'dmsf', :action => 'unlock', :as => 'unlock_dmsf'
get '/projects/:id/dmsf/', :controller => 'dmsf', :action => 'show', :as => 'dmsf_folder' get '/projects/:id/dmsf/', :controller => 'dmsf', :action => 'show', :as => 'dmsf_folder'
get '/projects/:id/dmsf/new', :controller => 'dmsf', :action => 'new', :as => 'new_dmsf' get '/projects/:id/dmsf/new', :controller => 'dmsf', :action => 'new', :as => 'new_dmsf'
get '/projects/:id/dmsf/edit', :controller=> 'dmsf', :action => 'edit', :as => 'edit_dmsf' get '/projects/:id/dmsf/edit', :controller => 'dmsf', :action => 'edit', :as => 'edit_dmsf'
get '/projects/:id/dmsf/edit/root', :controller=> 'dmsf', :action => 'edit_root', :as => 'edit_root_dmsf' get '/projects/:id/dmsf/edit/root', :controller => 'dmsf', :action => 'edit_root', :as => 'edit_root_dmsf'
get '/projects/:id/dmsf/trash', :controller => 'dmsf', :action => 'trash', :as => 'trash_dmsf' get '/projects/:id/dmsf/trash', :controller => 'dmsf', :action => 'trash', :as => 'trash_dmsf'
get '/projects/:id/dmsf/restore', :controller => 'dmsf', :action => 'restore', :as => 'restore_dmsf' get '/projects/:id/dmsf/restore', :controller => 'dmsf', :action => 'restore', :as => 'restore_dmsf'

View File

@ -31,8 +31,8 @@ class Dmsf120 < ActiveRecord::Migration
add_column :dmsf_file_revisions, :project_id, :integer, :null => true add_column :dmsf_file_revisions, :project_id, :integer, :null => true
DmsfFileRevision.find_each do |revision| DmsfFileRevision.find_each do |revision|
if revision.file if revision.dmsf_file
revision.project_id = revision.file.project.id revision.project_id = revision.dmsf_file.project.id
revision.save revision.save
end end
end end

View File

@ -27,8 +27,8 @@ class RemoveProjectFromRevision < ActiveRecord::Migration
add_column :dmsf_file_revisions, :project_id, :integer, :null => true add_column :dmsf_file_revisions, :project_id, :integer, :null => true
DmsfFileRevision.find_each do |revision| DmsfFileRevision.find_each do |revision|
if revision.file if revision.dmsf_file
revision.project_id = revision.file.project_id revision.project_id = revision.dmsf_file.project_id
revision.save revision.save
end end
end end

View File

@ -30,6 +30,7 @@ class DmsfZip
@zip.chmod(0644) @zip.chmod(0644)
@zip_file = Zip::OutputStream.new(@zip.path) @zip_file = Zip::OutputStream.new(@zip.path)
@files = [] @files = []
@folders = []
end end
def finish def finish
@ -43,24 +44,29 @@ class DmsfZip
end end
def add_file(file, member, root_path = nil) def add_file(file, member, root_path = nil)
string_path = file.folder.nil? ? '' : "#{file.folder.dmsf_path_str}/" unless @files.include?(file)
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path string_path = file.dmsf_folder.nil? ? '' : "#{file.dmsf_folder.dmsf_path_str}/"
string_path += file.formatted_name(member ? member.title_format : nil) string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
@zip_file.put_next_entry(string_path) string_path += file.formatted_name(member ? member.title_format : nil)
File.open(file.last_revision.disk_file, 'rb') do |f| @zip_file.put_next_entry(string_path)
while (buffer = f.read(8192)) File.open(file.last_revision.disk_file, 'rb') do |f|
@zip_file.write(buffer) while (buffer = f.read(8192))
@zip_file.write(buffer)
end
end end
@files << file
end end
@files << file
end end
def add_folder(folder, member, root_path = nil) def add_folder(folder, member, root_path = nil)
string_path = "#{folder.dmsf_path_str}/" unless @folders.include?(folder)
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path string_path = "#{folder.dmsf_path_str}/"
@zip_file.put_next_entry(string_path) string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
folder.subfolders.visible.each { |subfolder| self.add_folder(subfolder, root_path) } @zip_file.put_next_entry(string_path)
folder.files.visible.each { |file| self.add_file(file, member, root_path) } @folders << folder
folder.dmsf_folders.visible.each { |subfolder| self.add_folder(subfolder, root_path) }
folder.dmsf_files.visible.each { |file| self.add_file(file, member, root_path) }
end
end end
end end

View File

@ -25,9 +25,10 @@ module RedmineDmsf
class DmsfViewListener < Redmine::Hook::ViewListener class DmsfViewListener < Redmine::Hook::ViewListener
def view_layouts_base_html_head(context={}) def view_layouts_base_html_head(context={})
"\n".html_safe + stylesheet_link_tag('dmsf', :plugin => :redmine_dmsf) + "\n".html_safe + stylesheet_link_tag('redmine_dmsf.css', :plugin => :redmine_dmsf) +
"\n".html_safe + stylesheet_link_tag('select2.min.css', :plugin => :redmine_dmsf) + "\n".html_safe + stylesheet_link_tag('select2.min.css', :plugin => :redmine_dmsf) +
"\n".html_safe + javascript_include_tag('select2.min.js', :plugin => :redmine_dmsf) "\n".html_safe + javascript_include_tag('select2.min.js', :plugin => :redmine_dmsf) +
"\n".html_safe + javascript_include_tag('redmine_dmsf.js', :plugin => :redmine_dmsf)
end end
end end

View File

@ -4,7 +4,7 @@
# #
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com> # Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk> # Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-15 Karel Pičman <karel.picman@kontron.com> # Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
@ -38,17 +38,17 @@ module RedmineDmsf
end end
end end
if tree if tree
ret = ret | (folder.locks.empty? ? folder.lock : folder.locks) unless folder.nil? ret = ret | (self.dmsf_folder.locks.empty? ? self.dmsf_folder.lock : self.dmsf_folder.locks) if dmsf_folder
end end
return ret return ret
end end
def lock! scope = :scope_exclusive, type = :type_write, expire = nil def lock!(scope = :scope_exclusive, type = :type_write, expire = nil)
# Raise a lock error if entity is locked, but its not at resource level # Raise a lock error if entity is locked, but its not at resource level
existing = locks(false) existing = locks(false)
raise DmsfLockError.new(l(:error_resource_or_parent_locked)) if self.locked? && existing.empty? raise DmsfLockError.new(l(:error_resource_or_parent_locked)) if self.locked? && existing.empty?
unless existing.empty? unless existing.empty?
if existing[0].lock_scope == :scope_shared && scope == :scope_shared if (existing[0].lock_scope == :scope_shared) && (scope == :scope_shared)
# RFC states if an item is exclusively locked and another lock is attempted we reject # RFC states if an item is exclusively locked and another lock is attempted we reject
# if the item is shared locked however, we can always add another lock to it # if the item is shared locked however, we can always add another lock to it
if self.folder.locked? if self.folder.locked?
@ -79,7 +79,7 @@ module RedmineDmsf
return false unless self.locked? return false unless self.locked?
existing = self.lock(true) existing = self.lock(true)
# If its empty its a folder that's locked (not root) # If its empty its a folder that's locked (not root)
(existing.empty? || (!self.folder.nil? && self.folder.locked?)) ? false : true (existing.empty? || (!self.dmsf_folder.nil? && self.dmsf_folder.locked?)) ? false : true
end end
# #
@ -107,7 +107,7 @@ module RedmineDmsf
def unlock!(force_file_unlock_allowed = false) def unlock!(force_file_unlock_allowed = false)
raise DmsfLockError.new(l(:warning_file_not_locked)) unless self.locked? raise DmsfLockError.new(l(:warning_file_not_locked)) unless self.locked?
existing = self.lock(true) existing = self.lock(true)
if existing.empty? || (!self.folder.nil? && self.folder.locked?) #If its empty its a folder thats locked (not root) if existing.empty? || (!self.dmsf_folder.nil? && self.dmsf_folder.locked?) #If its empty its a folder thats locked (not root)
raise DmsfLockError.new(l(:error_unlock_parent_locked)) raise DmsfLockError.new(l(:error_unlock_parent_locked))
else else
# If entity is locked to you, you aren't the lock originator (or named in a shared lock) so deny action # If entity is locked to you, you aren't the lock originator (or named in a shared lock) so deny action

View File

@ -31,7 +31,7 @@ Redmine::WikiFormatting::Macros.register do
revision = file.last_revision revision = file.last_revision
else else
revision = DmsfFileRevision.find(args[2]) revision = DmsfFileRevision.find(args[2])
if revision.file != file if revision.dmsf_file != file
raise ActiveRecord::RecordNotFound raise ActiveRecord::RecordNotFound
end end
end end

View File

@ -44,6 +44,8 @@ module RedmineDmsf
:class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy :class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy
has_many :url_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfUrl' }, has_many :url_links, -> { where dmsf_folder_id: nil, target_type: 'DmsfUrl' },
:class_name => 'DmsfLink', :foreign_key => 'project_id', :dependent => :destroy :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
end end
end end

View File

@ -49,10 +49,10 @@ module RedmineDmsf
unless @childern unless @childern
@children = [] @children = []
if collection? if collection?
folder.subfolders.select(:title).visible.map do |p| folder.dmsf_folders.select(:title).visible.map do |p|
@children.push child(p.title) @children.push child(p.title)
end end
folder.files.select(:name).visible.map do |p| folder.dmsf_files.select(:name).visible.map do |p|
@children.push child(p.name) @children.push child(p.name)
end end
end end
@ -105,7 +105,7 @@ module RedmineDmsf
# Hunt for files parent path # Hunt for files parent path
f = false f = false
if (parent.projectless_path != '/') if (parent.projectless_path != '/')
f = parent.folder if parent.folder f = parent.dmsf_folder if parent.dmsf_folder
else else
f = nil f = nil
end end
@ -199,8 +199,8 @@ module RedmineDmsf
return MethodNotAllowed if exist? # If we already exist, why waste the time trying to save? return MethodNotAllowed if exist? # If we already exist, why waste the time trying to save?
parent_folder = nil parent_folder = nil
if (parent.projectless_path != '/') if (parent.projectless_path != '/')
return Conflict unless parent.folder return Conflict unless parent.dmsf_folder
parent_folder = parent.folder.id parent_folder = parent.dmsf_folder.id
end end
f = DmsfFolder.new f = DmsfFolder.new
f.title = basename f.title = basename
@ -254,8 +254,8 @@ module RedmineDmsf
if(parent.projectless_path == '/') #Project root if(parent.projectless_path == '/') #Project root
folder.dmsf_folder_id = nil folder.dmsf_folder_id = nil
else else
return PreconditionFailed unless parent.exist? && parent.folder return PreconditionFailed unless parent.exist? && parent.dmsf_folder
folder.dmsf_folder_id = parent.folder.id folder.dmsf_folder_id = parent.dmsf_folder.id
end end
folder.title = resource.basename folder.title = resource.basename
folder.save ? Created : PreconditionFailed folder.save ? Created : PreconditionFailed
@ -273,8 +273,8 @@ module RedmineDmsf
if(parent.projectless_path == '/') #Project root if(parent.projectless_path == '/') #Project root
f = nil f = nil
else else
return PreconditionFailed unless parent.exist? && parent.folder return PreconditionFailed unless parent.exist? && parent.dmsf_folder
f = parent.folder f = parent.dmsf_folder
end end
return PreconditionFailed unless exist? && file return PreconditionFailed unless exist? && file
return InternalServerError unless file.move_to(resource.project, f) return InternalServerError unless file.move_to(resource.project, f)
@ -351,7 +351,7 @@ module RedmineDmsf
f = nil f = nil
else else
return PreconditionFailed unless parent.exist? && parent.folder return PreconditionFailed unless parent.exist? && parent.folder
f = parent.folder f = parent.dmsf_folder
end end
return PreconditionFailed unless exist? && file return PreconditionFailed unless exist? && file
return InternalServerError unless file.copy_to(resource.project, f) return InternalServerError unless file.copy_to(resource.project, f)
@ -486,13 +486,13 @@ module RedmineDmsf
f = DmsfFile.new f = DmsfFile.new
f.project = project f.project = project
f.name = basename f.name = basename
f.folder = parent.folder f.dmsf_folder = parent.folder
f.notification = !Setting.plugin_redmine_dmsf['dmsf_default_notifications'].blank? f.notification = !Setting.plugin_redmine_dmsf['dmsf_default_notifications'].blank?
new_revision.minor_version = 0 new_revision.minor_version = 0
new_revision.major_version = 0 new_revision.major_version = 0
end end
new_revision.file = f new_revision.dmsf_file = f
new_revision.user = User.current new_revision.user = User.current
new_revision.name = basename new_revision.name = basename
new_revision.title = DmsfFileRevision.filename_to_title(basename) new_revision.title = DmsfFileRevision.filename_to_title(basename)
@ -570,7 +570,7 @@ module RedmineDmsf
if @request.env['HTTP_RANGE'].nil? if @request.env['HTTP_RANGE'].nil?
access = DmsfFileRevisionAccess.new access = DmsfFileRevisionAccess.new
access.user = User.current access.user = User.current
access.revision = file.last_revision access.dmsf_file_revision = file.last_revision
access.action = DmsfFileRevisionAccess::DownloadAction access.action = DmsfFileRevisionAccess::DownloadAction
access.save! access.save!
end end
@ -583,8 +583,8 @@ module RedmineDmsf
entity = file || folder entity = file || folder
return nil unless entity.locked? return nil unless entity.locked?
if entity.folder && entity.folder.locked? if entity.dmsf_folder && entity.dmsf_folder.locked?
locks = entity.lock.reverse[0].folder.locks(false) # longwinded way of getting base items locks locks = entity.lock.reverse[0].dmsf_folder.locks(false) # longwinded way of getting base items locks
else else
locks = entity.lock(false) locks = entity.lock(false)
end end

View File

@ -40,8 +40,9 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase
@role = Role.find_by_id 1 @role = Role.find_by_id 1
@custom_field = CustomField.find_by_id 21 @custom_field = CustomField.find_by_id 21
@custom_value = CustomValue.find_by_id 21 @custom_value = CustomValue.find_by_id 21
@user_member = User.find_by_id 2
User.current = nil User.current = nil
@request.session[:user_id] = 2 @request.session[:user_id] = @user_member.id
end end
def test_truth def test_truth
@ -55,6 +56,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase
assert_kind_of Role, @role assert_kind_of Role, @role
assert_kind_of CustomField, @custom_field assert_kind_of CustomField, @custom_field
assert_kind_of CustomValue, @custom_value assert_kind_of CustomValue, @custom_value
assert_kind_of User, @user_member
end end
def test_edit_folder_forbidden def test_edit_folder_forbidden
@ -176,4 +178,22 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase
assert_nil flash[:error] assert_nil flash[:error]
end end
def test_show
@role.add_permission! :view_dmsf_files
@role.add_permission! :view_dmsf_folders
get :show, :id => @project.id
assert_response :success
assert_select 'tr.dmsf_tree', :count => 0
end
def test_show_tree_view
@role.add_permission! :view_dmsf_files
@role.add_permission! :view_dmsf_folders
@user_member.pref[:dmsf_tree_view] = '1'
@user_member.preference.save
get :show, :id => @project.id
assert_response :success
assert_select 'tr.dmsf_tree'
end
end end

View File

@ -175,7 +175,7 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase
def test_create def test_create
assert_difference 'DmsfWorkflow.count', +1 do assert_difference 'DmsfWorkflow.count', +1 do
post :create, :dmsf_workflow => {:name => 'wf4'}, :project_id => @project1.id post :create, :dmsf_workflow => {:name => 'wf4', :project_id => @project1.id}
end end
assert_redirected_to settings_project_path(@project1, :tab => 'dmsf_workflow') assert_redirected_to settings_project_path(@project1, :tab => 'dmsf_workflow')
end end

View File

@ -149,7 +149,7 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
@role.add_permission! :file_manipulation @role.add_permission! :file_manipulation
file = DmsfFile.find_file_by_name @project1, nil, 'test.txt' file = DmsfFile.find_file_by_name @project1, nil, 'test.txt'
assert_not_nil file, 'test.txt file not found' assert_not_nil file, 'test.txt file not found'
assert_difference 'file.revisions.count', +1 do assert_difference 'file.dmsf_file_revisions.count', +1 do
put "/dmsf/webdav/#{@project1.identifier}/test.txt", '1234', @jsmith.merge!({:content_type => :text}) put "/dmsf/webdav/#{@project1.identifier}/test.txt", '1234', @jsmith.merge!({:content_type => :text})
assert_response :success # 201 - Created assert_response :success # 201 - Created
end end
@ -163,7 +163,7 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
assert !User.current.anonymous?, 'Current user is not anonymous' assert !User.current.anonymous?, 'Current user is not anonymous'
file = DmsfFile.find_file_by_name @project1, nil, 'test.txt' file = DmsfFile.find_file_by_name @project1, nil, 'test.txt'
assert file.lock!, "File failed to be locked by #{User.current.name}" assert file.lock!, "File failed to be locked by #{User.current.name}"
assert_no_difference 'file.revisions.count' do assert_no_difference 'file.dmsf_file_revisions.count' do
put "/dmsf/webdav/#{@project1.identifier}/test.txt", '1234', @jsmith.merge!({:content_type => :text}) put "/dmsf/webdav/#{@project1.identifier}/test.txt", '1234', @jsmith.merge!({:content_type => :text})
assert_response 423 # Locked assert_response 423 # Locked
end end
@ -177,7 +177,7 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
assert !User.current.anonymous?, 'Current user is not anonymous' assert !User.current.anonymous?, 'Current user is not anonymous'
file = DmsfFile.find_file_by_name @project1, nil, 'test.txt' file = DmsfFile.find_file_by_name @project1, nil, 'test.txt'
assert file.lock!, "File failed to be locked by #{User.current.name}" assert file.lock!, "File failed to be locked by #{User.current.name}"
assert_no_difference 'file.revisions.count' do assert_no_difference 'file.dmsf_file_revisions.count' do
put "/dmsf/webdav/#{@project1.identifier}/test.txt", '1234', @admin.merge!({:content_type => :text}) put "/dmsf/webdav/#{@project1.identifier}/test.txt", '1234', @admin.merge!({:content_type => :text})
assert_response 423 # Locked assert_response 423 # Locked
end end
@ -191,7 +191,7 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
assert !User.current.anonymous?, 'Current user is not anonymous' assert !User.current.anonymous?, 'Current user is not anonymous'
file = DmsfFile.find_file_by_name @project1, nil, 'test.txt' file = DmsfFile.find_file_by_name @project1, nil, 'test.txt'
assert file.lock!, "File failed to be locked by #{User.current.name}" assert file.lock!, "File failed to be locked by #{User.current.name}"
assert_difference 'file.revisions.count', +1 do assert_difference 'file.dmsf_file_revisions.count', +1 do
put "/dmsf/webdav/#{@project1.identifier}/test.txt", '1234', @jsmith.merge!({:content_type => :text}) put "/dmsf/webdav/#{@project1.identifier}/test.txt", '1234', @jsmith.merge!({:content_type => :text})
assert_response :success # 201 - Created assert_response :success # 201 - Created
end end

View File

@ -98,41 +98,41 @@ class DmsfFileTest < RedmineDmsf::Test::UnitTest
end end
def test_delete_restore def test_delete_restore
assert_equal 1, @file4.revisions.visible.count assert_equal 1, @file4.dmsf_file_revisions.visible.count
assert_equal 2, @file4.referenced_links.visible.count assert_equal 2, @file4.referenced_links.visible.count
end end
def test_delete def test_delete
User.current = @admin User.current = @admin
@file4.folder.unlock! @file4.dmsf_folder.unlock!
assert @file4.delete(false), @file4.errors.full_messages.to_sentence assert @file4.delete(false), @file4.errors.full_messages.to_sentence
assert @file4.deleted?, "File #{@file4.name} is not deleted" assert @file4.deleted?, "File #{@file4.name} is not deleted"
assert_equal 0, @file4.revisions.visible.count assert_equal 0, @file4.dmsf_file_revisions.visible.count
# Links should not be deleted # Links should not be deleted
assert_equal 2, @file4.referenced_links.visible.count assert_equal 2, @file4.referenced_links.visible.count
@file4.folder.lock! @file4.dmsf_folder.lock!
end end
def test_restore def test_restore
User.current = @admin User.current = @admin
@file4.folder.unlock! @file4.dmsf_folder.unlock!
assert @file4.delete(false), @file4.errors.full_messages.to_sentence assert @file4.delete(false), @file4.errors.full_messages.to_sentence
@file4.restore @file4.restore
assert !@file4.deleted?, "File #{@file4} hasn't been restored" assert !@file4.deleted?, "File #{@file4} hasn't been restored"
assert_equal 1, @file4.revisions.visible.count assert_equal 1, @file4.dmsf_file_revisions.visible.count
assert_equal 2, @file4.referenced_links.visible.count assert_equal 2, @file4.referenced_links.visible.count
@file4.folder.lock! @file4.dmsf_folder.lock!
end end
def test_destroy def test_destroy
User.current = @admin User.current = @admin
@file4.folder.unlock! @file4.dmsf_folder.unlock!
assert_equal 1, @file4.revisions.visible.count assert_equal 1, @file4.dmsf_file_revisions.visible.count
assert_equal 2, @file4.referenced_links.visible.count assert_equal 2, @file4.referenced_links.visible.count
@file4.delete true @file4.delete true
assert_equal 0, @file4.revisions.count assert_equal 0, @file4.dmsf_file_revisions.count
assert_equal 0, @file4.referenced_links.count assert_equal 0, @file4.referenced_links.count
@file4.folder.lock! @file4.dmsf_folder.lock!
end end
end end