diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index ff9e2b42..0f6e2afb 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -62,15 +62,10 @@ class DmsfFilesController < ApplicationController access.action = DmsfFileRevisionAccess::DownloadAction access.save! member = Member.find_by(user_id: User.current.id, project_id: @file.project.id) - if member && !member.dmsf_title_format.nil? && !member.dmsf_title_format.empty? - title_format = member.dmsf_title_format - else - title_format = Setting.plugin_redmine_dmsf['dmsf_global_title_format'] - end # IE has got a tendency to cache files expires_in(0.year, 'must-revalidate' => true) send_file @revision.disk_file, - filename: filename_for_content_disposition(@revision.formatted_name(title_format)), + filename: filename_for_content_disposition(@revision.formatted_name(member)), type: @revision.detect_content_type, disposition: params[:disposition].present? ? params[:disposition] : @revision.dmsf_file.disposition rescue DmsfAccessError => e diff --git a/app/helpers/dmsf_queries_helper.rb b/app/helpers/dmsf_queries_helper.rb index 791aa7dc..a0f79ad4 100644 --- a/app/helpers/dmsf_queries_helper.rb +++ b/app/helpers/dmsf_queries_helper.rb @@ -154,7 +154,10 @@ module DmsfQueriesHelper tag = "".html_safe + tag end end - tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:title_filename_for_download)) + member = Member.find_by(user_id: User.current.id, project_id: item.project_id) + revision = DmsfFileRevision.find_by(id: item.customized_id) + filename = revision ? revision.formatted_name(member) : item.filename + tag + content_tag('div', filename, class: 'dmsf-filename', title: l(:title_filename_for_download)) when 'url-link' if item&.deleted? tag = content_tag('span', value, class: 'icon dmsf-icon-link') diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 0960e07e..2b5cf2ca 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -453,12 +453,7 @@ class DmsfFile < ActiveRecord::Base def display_name member = Member.find_by(user_id: User.current.id, project_id: project_id) - if member && !member.dmsf_title_format.nil? && !member.dmsf_title_format.empty? - title_format = member.dmsf_title_format - else - title_format = Setting.plugin_redmine_dmsf['dmsf_global_title_format'] - end - fname = formatted_name(title_format) + fname = formatted_name(member) if fname.length > 50 return "#{fname[0, 25]}...#{fname[-25, 25]}" end @@ -511,9 +506,9 @@ class DmsfFile < ActiveRecord::Base result end - def formatted_name(format) + def formatted_name(member) if last_revision - last_revision.formatted_name(format) + last_revision.formatted_name(member) else name end diff --git a/app/models/dmsf_file_revision.rb b/app/models/dmsf_file_revision.rb index 0e6fb35c..7866cb08 100644 --- a/app/models/dmsf_file_revision.rb +++ b/app/models/dmsf_file_revision.rb @@ -301,7 +301,12 @@ class DmsfFileRevision < ActiveRecord::Base parts.size == 2 ? parts[0].to_i * 1000 + parts[1].to_i : 0 end - def formatted_name(format) + def formatted_name(member) + if member&.dmsf_title_format.present? + format = member.dmsf_title_format + else + format = Setting.plugin_redmine_dmsf['dmsf_global_title_format'] + end return name if format.blank? if name =~ /(.*)(\..*)$/ filename = $1 diff --git a/lib/redmine_dmsf/dmsf_zip.rb b/lib/redmine_dmsf/dmsf_zip.rb index a6789836..63e821fd 100644 --- a/lib/redmine_dmsf/dmsf_zip.rb +++ b/lib/redmine_dmsf/dmsf_zip.rb @@ -52,11 +52,7 @@ module RedmineDmsf end string_path = file.dmsf_folder.nil? ? '' : (file.dmsf_folder.dmsf_path_str + File::SEPARATOR) string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path - if member && !member.dmsf_title_format.nil? && !member.dmsf_title_format.empty? - string_path += file.formatted_name(member.dmsf_title_format) - else - string_path += file.formatted_name(Setting.plugin_redmine_dmsf['dmsf_global_title_format']) - end + string_path += file.formatted_name(member) zip_entry = ::Zip::Entry.new(@zip_file, string_path, nil, nil, nil, nil, nil, nil, ::Zip::DOSTime.at(file.last_revision.updated_at)) @zip_file.put_next_entry(zip_entry) @@ -84,5 +80,5 @@ module RedmineDmsf end - end + end end \ No newline at end of file