2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-30 17:41:13 -04:00
|
|
|
module BlameHelper
|
2021-11-24 10:14:19 -05:00
|
|
|
BODY_FONT_SIZE = "0.875rem"
|
|
|
|
COMMIT_LINE_HEIGHT = 3 # 150% * 2 lines of text
|
|
|
|
COMMIT_PADDING = "10px" # 5px from both top and bottom
|
|
|
|
COMMIT_BLOCK_HEIGHT_EXP = "(#{BODY_FONT_SIZE} * #{COMMIT_LINE_HEIGHT}) + #{COMMIT_PADDING}"
|
|
|
|
CODE_LINE_HEIGHT = 1.1875
|
|
|
|
CODE_PADDING = "20px" # 10px from both top and bottom
|
|
|
|
|
2016-10-30 17:41:13 -04:00
|
|
|
def age_map_duration(blame_groups, project)
|
|
|
|
now = Time.zone.now
|
|
|
|
start_date = blame_groups.map { |blame_group| blame_group[:commit].committed_date }
|
|
|
|
.append(project.created_at).min
|
|
|
|
|
|
|
|
{
|
|
|
|
now: now,
|
|
|
|
started_days_ago: (now - start_date).to_i / 1.day
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def age_map_class(commit_date, duration)
|
2017-08-24 10:50:47 -04:00
|
|
|
if duration[:started_days_ago] == 0
|
|
|
|
"blame-commit-age-0"
|
|
|
|
else
|
|
|
|
commit_date_days_ago = (duration[:now] - commit_date).to_i / 1.day
|
|
|
|
# Numbers 0 to 10 come from this calculation, but only commits on the oldest
|
|
|
|
# day get number 10 (all other numbers can be multiple days), so the range
|
|
|
|
# is normalized to 0-9
|
|
|
|
age_group = [(10 * commit_date_days_ago) / duration[:started_days_ago], 9].min
|
|
|
|
"blame-commit-age-#{age_group}"
|
|
|
|
end
|
2016-10-30 17:41:13 -04:00
|
|
|
end
|
2021-11-24 10:14:19 -05:00
|
|
|
|
|
|
|
def intrinsic_row_css(line_count)
|
|
|
|
# using rems here because the size of the row depends on the text size
|
|
|
|
# which can be customized via user agent styles and browser preferences
|
|
|
|
total_line_height_exp = "#{line_count * CODE_LINE_HEIGHT}rem + #{CODE_PADDING}"
|
|
|
|
row_height_exp = line_count == 1 ? COMMIT_BLOCK_HEIGHT_EXP : total_line_height_exp
|
|
|
|
"contain-intrinsic-size: 1px calc(#{row_height_exp})"
|
|
|
|
end
|
2016-10-30 17:41:13 -04:00
|
|
|
end
|