summaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
authorJeff Stubler <brunsa2@gmail.com>2016-10-30 16:41:13 -0500
committerJeff Stubler <brunsa2@gmail.com>2017-06-14 09:17:26 -0500
commit477d975a6786c00b642fe273e36061a94c39225b (patch)
treeb5b85d7c04a9464c79375ef94e9aa62ff137132f /app/helpers
parenta1695253215534539ea17794a8696212c5454b82 (diff)
downloadgitlab-ce-477d975a6786c00b642fe273e36061a94c39225b.tar.gz
Add blame view age map
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/blame_helper.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/helpers/blame_helper.rb b/app/helpers/blame_helper.rb
new file mode 100644
index 00000000000..d1dc4d94560
--- /dev/null
+++ b/app/helpers/blame_helper.rb
@@ -0,0 +1,21 @@
+module BlameHelper
+ 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)
+ 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
+end