#1290 formatted title

This commit is contained in:
karel.picman@lbcfree.net 2021-09-21 10:59:38 +02:00
parent 45fdd94fb4
commit b15c3eef10
5 changed files with 16 additions and 22 deletions

View File

@ -62,15 +62,10 @@ class DmsfFilesController < ApplicationController
access.action = DmsfFileRevisionAccess::DownloadAction access.action = DmsfFileRevisionAccess::DownloadAction
access.save! access.save!
member = Member.find_by(user_id: User.current.id, project_id: @file.project.id) 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 # IE has got a tendency to cache files
expires_in(0.year, 'must-revalidate' => true) expires_in(0.year, 'must-revalidate' => true)
send_file @revision.disk_file, 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, type: @revision.detect_content_type,
disposition: params[:disposition].present? ? params[:disposition] : @revision.dmsf_file.disposition disposition: params[:disposition].present? ? params[:disposition] : @revision.dmsf_file.disposition
rescue DmsfAccessError => e rescue DmsfAccessError => e

View File

@ -154,7 +154,10 @@ module DmsfQueriesHelper
tag = "<span class=\"dmsf-expander\"></span>".html_safe + tag tag = "<span class=\"dmsf-expander\"></span>".html_safe + tag
end end
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' when 'url-link'
if item&.deleted? if item&.deleted?
tag = content_tag('span', value, class: 'icon dmsf-icon-link') tag = content_tag('span', value, class: 'icon dmsf-icon-link')

View File

@ -453,12 +453,7 @@ class DmsfFile < ActiveRecord::Base
def display_name def display_name
member = Member.find_by(user_id: User.current.id, project_id: project_id) 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? fname = formatted_name(member)
title_format = member.dmsf_title_format
else
title_format = Setting.plugin_redmine_dmsf['dmsf_global_title_format']
end
fname = formatted_name(title_format)
if fname.length > 50 if fname.length > 50
return "#{fname[0, 25]}...#{fname[-25, 25]}" return "#{fname[0, 25]}...#{fname[-25, 25]}"
end end
@ -511,9 +506,9 @@ class DmsfFile < ActiveRecord::Base
result result
end end
def formatted_name(format) def formatted_name(member)
if last_revision if last_revision
last_revision.formatted_name(format) last_revision.formatted_name(member)
else else
name name
end end

View File

@ -301,7 +301,12 @@ class DmsfFileRevision < ActiveRecord::Base
parts.size == 2 ? parts[0].to_i * 1000 + parts[1].to_i : 0 parts.size == 2 ? parts[0].to_i * 1000 + parts[1].to_i : 0
end 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? return name if format.blank?
if name =~ /(.*)(\..*)$/ if name =~ /(.*)(\..*)$/
filename = $1 filename = $1

View File

@ -52,11 +52,7 @@ module RedmineDmsf
end end
string_path = file.dmsf_folder.nil? ? '' : (file.dmsf_folder.dmsf_path_str + File::SEPARATOR) 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 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)
string_path += file.formatted_name(member.dmsf_title_format)
else
string_path += file.formatted_name(Setting.plugin_redmine_dmsf['dmsf_global_title_format'])
end
zip_entry = ::Zip::Entry.new(@zip_file, string_path, nil, nil, nil, nil, nil, nil, zip_entry = ::Zip::Entry.new(@zip_file, string_path, nil, nil, nil, nil, nil, nil,
::Zip::DOSTime.at(file.last_revision.updated_at)) ::Zip::DOSTime.at(file.last_revision.updated_at))
@zip_file.put_next_entry(zip_entry) @zip_file.put_next_entry(zip_entry)
@ -84,5 +80,5 @@ module RedmineDmsf
end end
end end
end end