mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-05 19:34:34 +08:00
Refactor StringUtility#to_filesystems_compatible_filename [SCI-2641]
This commit is contained in:
parent
1575da6edb
commit
aa30cf6130
3 changed files with 13 additions and 26 deletions
|
@ -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}/" \
|
||||
|
|
|
@ -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(/\.*$/, '')
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue