Skip to content

Instantly share code, notes, and snippets.

@marcuscaum
Created September 18, 2015 03:10
Show Gist options
  • Select an option

  • Save marcuscaum/945aa6759947869f2e2f to your computer and use it in GitHub Desktop.

Select an option

Save marcuscaum/945aa6759947869f2e2f to your computer and use it in GitHub Desktop.
module DashboardHelper
TIME_WINDOW = 5.years.ago
def number_box(type)
if type == 'prs'
box(pr_values[:closed], prs_percentage, type)
elsif type == 'issues'
box(issues_values[:open], issues_percentage, type)
end
end
private
def box(principal_value, percentage, type)
html = ""
html << content_tag(:h1, principal_value)
if type == 'prs'
html << pr_box_title(principal_value)
elsif type == 'issues'
html << issues_box_title(principal_value)
end
html << progress_bar(percentage)
html.html_safe
end
def pr_box_title(principal_value)
if principal_value == 1
content_tag(:p, 'PR MERGED', style: 'letter-spacing: 1px')
else
content_tag(:p, 'PRs MERGED', style: 'letter-spacing: 1px')
end
end
def issues_box_title(principal_value)
if principal_value == 1
content_tag(:p, 'ISSUE OPEN', style: 'letter-spacing: 1px')
else
content_tag(:p, 'ISSUES OPEN', style: 'letter-spacing: 1px')
end
end
def progress_bar(percentage)
content_tag :div, class: 'progress-bar' do
concat(content_tag(:div, '', class: 'merged', style: "width: #{100 - percentage}%"))
concat(content_tag(:div, '', class: 'danger', style: "width: #{percentage}%"))
end
end
def pr_values
{
all: @repo.pr_through_issues(state: 'all', since: TIME_WINDOW),
open: (@repo.pr_through_issues(state: 'open', since: TIME_WINDOW)).size,
closed: (@repo.pr_through_issues(state: 'closed', since: TIME_WINDOW)).size
}
end
def issues_values
{
all: @repo.issues(state: 'all', since: TIME_WINDOW),
open: @repo.issues(state: 'open', since: TIME_WINDOW).size,
closed: @repo.issues(state: 'closed', since: TIME_WINDOW).size
}
end
def prs_percentage
((pr_values[:open].to_f / pr_values[:all].size.to_f) * 100).to_i
end
def issues_percentage
((issues_values[:open].to_f / issues_values[:all].size.to_f) * 100).to_i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment