Skip to content

Commit

Permalink
text ellipsis for work package subject cell
Browse files Browse the repository at this point in the history
  • Loading branch information
as-op committed Nov 28, 2024
1 parent 02dd29f commit 6db6058
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 7 additions & 0 deletions app/models/work_package/pdf_export/common/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ def draw_text_multiline_part(line, text_style, x_position, y_position)
measure_text_height(line, text_style)
end

def ellipsis_if_longer(text, available_width, text_style)
title_text_width = measure_text_width(text, text_style)
return text if title_text_width < available_width

truncate_ellipsis(text, available_width, text_style)
end

def truncate_ellipsis(text, available_width, text_style)
line = text.dup
while line.present? && (measure_text_width("#{line}...", text_style) > available_width)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def table_columns_widths
with_times_column? ? [80, 193, 80, 70, 100] : [80, 270, 70, 100]
end

def table_column_workpackage_text_width
(with_times_column? ? 193 : 270) - 10 # - padding
end

def table_width
table_columns_widths.sum
end
Expand All @@ -131,6 +135,10 @@ def table_columns_span
with_times_column? ? 4 : 3
end

def table_cell_style_font_size
12
end

# rubocop:disable Metrics/AbcSize
def build_table(rows)
pdf.make_table(
Expand All @@ -139,6 +147,7 @@ def build_table(rows)
width: table_width,
column_widths: table_columns_widths,
cell_style: {
size: table_cell_style_font_size,
border_color: "BBBBBB",
border_width: 0.5,
borders: %i[top bottom],
Expand Down Expand Up @@ -185,6 +194,7 @@ def split_group_rows(table_rows)
end
groups
end

# rubocop:enable Metrics/AbcSize

def write_table(user_id, entries)
Expand All @@ -193,8 +203,8 @@ def write_table(user_id, entries)
# for easier handling existing rowspan cells are grouped as one row
grouped_rows = split_group_rows(rows)
# start a new page if the username would be printed alone at the end of the page
pdf.start_new_page if available_space_from_bottom < grouped_rows[0][:height] + grouped_rows[1][:height] + 20
write_user(user_id)
pdf.start_new_page if available_space_from_bottom < grouped_rows[0][:height] + grouped_rows[1][:height] + username_height
write_username(user_id)
write_grouped_tables(grouped_rows)
end

Expand Down Expand Up @@ -266,7 +276,11 @@ def write_heading!
pdf.move_down(2)
end

def write_user(user_id)
def username_height
20 + 10
end

def write_username(user_id)
pdf.formatted_text([{ text: user_name(user_id), size: 20 }])
pdf.move_down(10)
end
Expand All @@ -280,7 +294,8 @@ def activity_name(activity_id)
end

def wp_subject(wp_id)
WorkPackage.find(wp_id).subject
text = WorkPackage.find(wp_id).subject
ellipsis_if_longer(text, table_column_workpackage_text_width, { size: table_cell_style_font_size })
end

def format_duration(hours)
Expand Down

0 comments on commit 6db6058

Please sign in to comment.