diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index 239602208..54e1ca2d6 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -71,12 +71,7 @@ module ReportsHelper suffix = '.csv' name.empty? ? 'Table' : name end - obj_name = to_filesystems_compatible_filename( - obj_name.truncate( - Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH, - omission: '' - ) - ) + obj_name = to_filesystems_compatible_filename(obj_name) obj_name += "_Step#{parent.position + 1}#{suffix}" obj_folder_name = 'Protocol attachments' parent_module = if parent.protocol.present? @@ -95,29 +90,16 @@ module ReportsHelper suffix = '.csv' name.empty? ? 'Table' : name end - obj_name = to_filesystems_compatible_filename( - obj_name.truncate( - Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH, - omission: '' - ) - ) + obj_name = to_filesystems_compatible_filename(obj_name) obj_name += suffix obj_folder_name = 'Results attachments' parent_module = parent end - parent_module_name = to_filesystems_compatible_filename( - parent_module.name.truncate( - Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH, - omission: '' - ) - ) - parent_exp_name = to_filesystems_compatible_filename( - parent_module.experiment.name.truncate( - Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH, - omission: '' - ) - ) + parent_module_name = + to_filesystems_compatible_filename(parent_module.name) + parent_exp_name = + to_filesystems_compatible_filename(parent_module.experiment.name) locals[:filename] = obj_name locals[:path] = "#{parent_exp_name}/#{parent_module_name}/" \ diff --git a/app/helpers/string_utility.rb b/app/helpers/string_utility.rb index 5d43c13d6..20985efcf 100644 --- a/app/helpers/string_utility.rb +++ b/app/helpers/string_utility.rb @@ -12,6 +12,10 @@ module StringUtility end def to_filesystems_compatible_filename(file_or_folder_name) + file_or_folder_name = file_or_folder_name.truncate( + Constants::EXPORTED_FILENAME_TRUNCATION_LENGTH, + omission: '' + ) file_or_folder_name.strip .sub(/^[.-]*/, '') .sub(/\.*$/, '') diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 7d3093157..e133da3ba 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -25,8 +25,9 @@ class Constants DROPDOWN_TEXT_MAX_LENGTH = 15 # Max characters for filenames, after which they get truncated FILENAME_TRUNCATION_LENGTH = 50 - # Max characters for exported files' names, after which they get truncated - EXPORTED_FILE_NAME_TRUNCATION_LENGTH = 20 + # Max characters for exported files' names and folders, after which they get + # truncated + EXPORTED_FILENAME_TRUNCATION_LENGTH = 20 USER_INITIALS_MAX_LENGTH = 4 # Password 'key stretching' factor