mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-11 06:16:32 +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'
|
suffix = '.csv'
|
||||||
name.empty? ? 'Table' : name
|
name.empty? ? 'Table' : name
|
||||||
end
|
end
|
||||||
obj_name = to_filesystems_compatible_filename(
|
obj_name = to_filesystems_compatible_filename(obj_name)
|
||||||
obj_name.truncate(
|
|
||||||
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
|
|
||||||
omission: ''
|
|
||||||
)
|
|
||||||
)
|
|
||||||
obj_name += "_Step#{parent.position + 1}#{suffix}"
|
obj_name += "_Step#{parent.position + 1}#{suffix}"
|
||||||
obj_folder_name = 'Protocol attachments'
|
obj_folder_name = 'Protocol attachments'
|
||||||
parent_module = if parent.protocol.present?
|
parent_module = if parent.protocol.present?
|
||||||
|
@ -95,29 +90,16 @@ module ReportsHelper
|
||||||
suffix = '.csv'
|
suffix = '.csv'
|
||||||
name.empty? ? 'Table' : name
|
name.empty? ? 'Table' : name
|
||||||
end
|
end
|
||||||
obj_name = to_filesystems_compatible_filename(
|
obj_name = to_filesystems_compatible_filename(obj_name)
|
||||||
obj_name.truncate(
|
|
||||||
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
|
|
||||||
omission: ''
|
|
||||||
)
|
|
||||||
)
|
|
||||||
obj_name += suffix
|
obj_name += suffix
|
||||||
obj_folder_name = 'Results attachments'
|
obj_folder_name = 'Results attachments'
|
||||||
parent_module = parent
|
parent_module = parent
|
||||||
end
|
end
|
||||||
|
|
||||||
parent_module_name = to_filesystems_compatible_filename(
|
parent_module_name =
|
||||||
parent_module.name.truncate(
|
to_filesystems_compatible_filename(parent_module.name)
|
||||||
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
|
parent_exp_name =
|
||||||
omission: ''
|
to_filesystems_compatible_filename(parent_module.experiment.name)
|
||||||
)
|
|
||||||
)
|
|
||||||
parent_exp_name = to_filesystems_compatible_filename(
|
|
||||||
parent_module.experiment.name.truncate(
|
|
||||||
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
|
|
||||||
omission: ''
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
locals[:filename] = obj_name
|
locals[:filename] = obj_name
|
||||||
locals[:path] = "#{parent_exp_name}/#{parent_module_name}/" \
|
locals[:path] = "#{parent_exp_name}/#{parent_module_name}/" \
|
||||||
|
|
|
@ -12,6 +12,10 @@ module StringUtility
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_filesystems_compatible_filename(file_or_folder_name)
|
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
|
file_or_folder_name.strip
|
||||||
.sub(/^[.-]*/, '')
|
.sub(/^[.-]*/, '')
|
||||||
.sub(/\.*$/, '')
|
.sub(/\.*$/, '')
|
||||||
|
|
|
@ -25,8 +25,9 @@ class Constants
|
||||||
DROPDOWN_TEXT_MAX_LENGTH = 15
|
DROPDOWN_TEXT_MAX_LENGTH = 15
|
||||||
# Max characters for filenames, after which they get truncated
|
# Max characters for filenames, after which they get truncated
|
||||||
FILENAME_TRUNCATION_LENGTH = 50
|
FILENAME_TRUNCATION_LENGTH = 50
|
||||||
# Max characters for exported files' names, after which they get truncated
|
# Max characters for exported files' names and folders, after which they get
|
||||||
EXPORTED_FILE_NAME_TRUNCATION_LENGTH = 20
|
# truncated
|
||||||
|
EXPORTED_FILENAME_TRUNCATION_LENGTH = 20
|
||||||
|
|
||||||
USER_INITIALS_MAX_LENGTH = 4
|
USER_INITIALS_MAX_LENGTH = 4
|
||||||
# Password 'key stretching' factor
|
# Password 'key stretching' factor
|
||||||
|
|
Loading…
Add table
Reference in a new issue