mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 20:05:55 +08:00
adds new string truncation method [fixes SCI-2344]
This commit is contained in:
parent
b277501e6d
commit
0b721d86b1
3 changed files with 20 additions and 1 deletions
|
@ -430,6 +430,7 @@ class ReportsController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
include StringUtility
|
||||||
VisibleProject = Struct.new(:path, :name)
|
VisibleProject = Struct.new(:path, :name)
|
||||||
|
|
||||||
def load_vars
|
def load_vars
|
||||||
|
@ -454,7 +455,8 @@ class ReportsController < ApplicationController
|
||||||
.limit(Constants::SEARCH_LIMIT)
|
.limit(Constants::SEARCH_LIMIT)
|
||||||
.select(:id, :name)
|
.select(:id, :name)
|
||||||
@visible_projects = projects.collect do |project|
|
@visible_projects = projects.collect do |project|
|
||||||
VisibleProject.new(new_project_reports_path(project), project.name)
|
VisibleProject.new(new_project_reports_path(project),
|
||||||
|
ellipsisize(project.name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
13
app/helpers/string_utility.rb
Normal file
13
app/helpers/string_utility.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
module StringUtility
|
||||||
|
def ellipsisize(
|
||||||
|
string,
|
||||||
|
minimum_length = Constants::MAX_NAME_TRUNCATION,
|
||||||
|
edge_length = Constants::MAX_EDGE_LENGTH
|
||||||
|
)
|
||||||
|
length = string.length
|
||||||
|
return string if length < minimum_length || length <= edge_length * 2
|
||||||
|
edge = '.' * edge_length
|
||||||
|
mid_length = length - edge_length * 2
|
||||||
|
string.gsub(/(#{edge}).{#{mid_length},}(#{edge})/, '\1...\2')
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,6 +9,10 @@ class Constants
|
||||||
NAME_MAX_LENGTH = 255
|
NAME_MAX_LENGTH = 255
|
||||||
# Max characters for short text fields, after which they get truncated
|
# Max characters for short text fields, after which they get truncated
|
||||||
NAME_TRUNCATION_LENGTH = 25
|
NAME_TRUNCATION_LENGTH = 25
|
||||||
|
# Max edge length
|
||||||
|
MAX_EDGE_LENGTH = 75
|
||||||
|
# Max character for listing projects in dropdown
|
||||||
|
MAX_NAME_TRUNCATION = 150
|
||||||
# Max characters for short text fields, in dropdownList
|
# Max characters for short text fields, in dropdownList
|
||||||
NAME_TRUNCATION_LENGTH_DROPDOWN = 20
|
NAME_TRUNCATION_LENGTH_DROPDOWN = 20
|
||||||
# Max characters for long text fields
|
# Max characters for long text fields
|
||||||
|
|
Loading…
Add table
Reference in a new issue