authors activity

This commit is contained in:
Tomasz Gieniusz 2012-10-21 20:05:12 +02:00
parent 81ad4e0e42
commit 56bfb8582e
10 changed files with 164 additions and 134 deletions

View file

@ -47,3 +47,6 @@ en:
first_commit: First_commit
last_commit: Last commit
author: Author
show_more: Show more
close: Close
more_data_not_available: More data not available

View file

@ -2,63 +2,64 @@ module GitStats
module StatsView
module Charts
class ActivityCharts
def initialize(activity)
@activity = activity
def initialize(repo)
@repo = repo
@activity = repo.activity
end
def activity_by_date
def activity_by_date(author)
Chart.new do |f|
f.date_column_chart(
data: @activity.by_date,
data: author.activity.by_date,
title: :commits_by_date.t,
y_text: :commits.t
)
end
end
def activity_by_hour
def activity_by_hour(author)
Chart.new do |f|
f.simple_column_chart(
title: :commits_by_hour.t,
y_text: :commits.t,
x_text: :hour.t,
data_x: (0..23),
data_y: @activity.by_hour_array
data_y: author.activity.by_hour_array
)
end
end
def activity_by_wday
def activity_by_wday(author)
Chart.new do |f|
f.simple_column_chart(
title: :commits_by_wday.t,
y_text: :commits.t,
x_text: :day.t,
data_x: Date::ABBR_DAYNAMES,
data_y: @activity.by_wday_array
data_y: author.activity.by_wday_array
)
end
end
def activity_by_month
def activity_by_month(author)
Chart.new do |f|
f.simple_column_chart(
title: :commits_by_month.t,
y_text: :commits.t,
x_text: :month.t,
data_x: Date::ABBR_MONTHNAMES[1..-1],
data_y: @activity.by_month_array
data_y: author.activity.by_month_array
)
end
end
def activity_by_year
def activity_by_year(author)
Chart.new do |f|
f.column_hash_chart(
title: :commits_by_year.t,
y_text: :commits.t,
x_text: :year.t,
data: @activity.by_year
data: author.activity.by_year
)
end
end

View file

@ -25,7 +25,7 @@ module GitStats
end
def activity_charts
@activity_charts ||= Charts::ActivityCharts.new(repo.activity)
@activity_charts ||= Charts::ActivityCharts.new(repo)
end
end

View file

@ -1,14 +1,18 @@
module GitStats
module StatsView
class Template
def initialize(name, layout)
def initialize(name, layout=nil)
@name = name
@layout = layout
@template = Tilt.new("templates/#@name.haml")
end
def render(data, all_templates)
@layout.render(data, :active_page => @name, :all_templates => all_templates) { @template.render(data) }
def render(data, params={})
if @layout
@layout.render(data, :active_page => @name, :all_templates => params[:all_templates]) { @template.render(data, params) }
else
@template.render(data, params)
end
end
end
end

View file

@ -12,7 +12,7 @@ module GitStats
layout = Tilt.new("templates/layout.haml")
all_templates.each do |template|
output = Template.new(template, layout).render(@view_data, all_templates)
output = Template.new(template, layout).render(@view_data, all_templates: all_templates)
File.open("#@out_path/#{template}.html", 'w') { |f| f.write output }
end
end

View file

@ -13,6 +13,10 @@ module GitStats
@charts ||= Charts::All.new(repo)
end
def render(template_name, params = {})
Template.new(template_name).render(self, params)
end
end
end
end

114
templates/_activity.haml Normal file
View file

@ -0,0 +1,114 @@
.tabbable.tabs-left
%ul.nav.nav-tabs
%li.active
%a{:href => "#activity_by_date-#{author.hash}", 'data-toogle' => 'tab'}= :activity_by_date.t
%li
%a{:href => "#hour_of_day-#{author.hash}", 'data-toogle' => 'tab'}= :hour_of_day.t
%li
%a{:href => "#day_of_week-#{author.hash}", 'data-toogle' => 'tab'}= :day_of_week.t
%li
%a{:href => "#hour_of_week-#{author.hash}", 'data-toogle' => 'tab'}= :hour_of_week.t
%li
%a{:href => "#month_of_year-#{author.hash}", 'data-toogle' => 'tab'}= :month_of_year.t
%li
%a{:href => "#year-#{author.hash}", 'data-toogle' => 'tab'}= :year.t
%li
%a{:href => "#year_month-#{author.hash}", 'data-toogle' => 'tab'}= :year_month.t
.tab-content
.tab-pane.active{id: "activity_by_date-#{author.hash}"}
.page-header
%h1.pagination-centered= :activity_by_date.t
= high_stock("charts.activity_by_date-#{author.hash}", charts.activity_by_date(author))
.tab-pane{id: "hour_of_day-#{author.hash}"}
.page-header
%h1.pagination-centered= :hour_of_day.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th= :hour.t
- (0..23).each do |h|
%th= h
%tr
%th= :commits.t
- author.activity.by_hour_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- author.activity.by_hour_array.each do |commits|
%td= (commits * 100.0 / author.activity.by_hour_array.sum).round(1)
= high_chart("charts.activity_by_hour-#{author.hash}", charts.activity_by_hour(author))
.tab-pane{id: "day_of_week-#{author.hash}"}
.page-header
%h1.pagination-centered= :day_of_week.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th= :day.t
- Date::ABBR_DAYNAMES.each do |d|
%th= d
%tr
%th= :commits.t
- author.activity.by_wday_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- author.activity.by_wday_array.each do |commits|
%td= (commits * 100.0 / author.activity.by_wday_array.sum).round(1)
= high_chart("charts.activity_by_wday-#{author.hash}", charts.activity_by_wday(author))
.tab-pane{id: "hour_of_week-#{author.hash}"}
.page-header
%h1.pagination-centered= :hour_of_week.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th
- (0..23).each do |h|
%th= h
- (0..6).each do |day|
%tr
%th= Date::ABBR_DAYNAMES[day]
- (0..23).each do |hour|
%td= author.activity.by_wday_hour[day][hour]
.tab-pane{id: "month_of_year-#{author.hash}"}
.page-header
%h1.pagination-centered= :month_of_year.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th= :day.t
- Date::ABBR_MONTHNAMES[1..-1].each do |m|
%th= m
%tr
%th= :commits.t
- author.activity.by_month_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- author.activity.by_month_array.each do |commits|
%td= (commits * 100.0 / author.activity.by_month_array.sum).round(1)
= high_chart("charts.activity_by_month-#{author.hash}", charts.activity_by_month(author))
.tab-pane{id: "year-#{author.hash}"}
.page-header
%h1.pagination-centered= :year.t
= high_chart("charts.activity_by_year-#{author.hash}", charts.activity_by_year(author))
.tab-pane{id: "year_month-#{author.hash}"}
.page-header
%h1.pagination-centered= :year_month.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th
- Date::ABBR_MONTHNAMES[1..-1].each do |h|
%th= h
- author.activity.by_year_month.each do |year, months|
%tr
%th= year
- (1..12).each do |month|
%td= months[month]

View file

@ -1,113 +1 @@
.tabbable.tabs-left
%ul.nav.nav-tabs
%li.active
%a{:href => '#activity_by_date', 'data-toogle' => 'tab'}= :activity_by_date.t
%li
%a{:href => '#hour_of_day', 'data-toogle' => 'tab'}= :hour_of_day.t
%li
%a{:href => '#day_of_week', 'data-toogle' => 'tab'}= :day_of_week.t
%li
%a{:href => '#hour_of_week', 'data-toogle' => 'tab'}= :hour_of_week.t
%li
%a{:href => '#month_of_year', 'data-toogle' => 'tab'}= :month_of_year.t
%li
%a{:href => '#year', 'data-toogle' => 'tab'}= :year.t
%li
%a{:href => '#year_month', 'data-toogle' => 'tab'}= :year_month.t
.tab-content
.tab-pane.active{id: 'activity_by_date'}
.page-header
%h1.pagination-centered= :activity_by_date.t
= high_stock("charts.activity_by_date", charts.activity_by_date)
.tab-pane{id: 'hour_of_day'}
.page-header
%h1.pagination-centered= :hour_of_day.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th= :hour.t
- (0..23).each do |h|
%th= h
%tr
%th= :commits.t
- repo.activity.by_hour_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- repo.activity.by_hour_array.each do |commits|
%td= (commits * 100.0 / repo.activity.by_hour_array.sum).round(1)
= high_chart("charts.activity_by_hour", charts.activity_by_hour)
.tab-pane{id: 'day_of_week'}
.page-header
%h1.pagination-centered= :day_of_week.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th= :day.t
- Date::ABBR_DAYNAMES.each do |d|
%th= d
%tr
%th= :commits.t
- repo.activity.by_wday_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- repo.activity.by_wday_array.each do |commits|
%td= (commits * 100.0 / repo.activity.by_wday_array.sum).round(1)
= high_chart("charts.activity_by_wday", charts.activity_by_wday)
.tab-pane{id: 'hour_of_week'}
.page-header
%h1.pagination-centered= :hour_of_week.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th
- (0..23).each do |h|
%th= h
- (0..6).each do |day|
%tr
%th= Date::ABBR_DAYNAMES[day]
- (0..23).each do |hour|
%td= repo.activity.by_wday_hour[day][hour]
.tab-pane{id: 'month_of_year'}
.page-header
%h1.pagination-centered= :month_of_year.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th= :day.t
- Date::ABBR_MONTHNAMES[1..-1].each do |m|
%th= m
%tr
%th= :commits.t
- repo.activity.by_month_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- repo.activity.by_month_array.each do |commits|
%td= (commits * 100.0 / repo.activity.by_month_array.sum).round(1)
= high_chart("charts.activity_by_month", charts.activity_by_month)
.tab-pane{id: 'year'}
.page-header
%h1.pagination-centered= :year.t
= high_chart("charts.activity_by_year", charts.activity_by_year)
.tab-pane{id: 'year_month'}
.page-header
%h1.pagination-centered= :year_month.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th
- Date::ABBR_MONTHNAMES[1..-1].each do |h|
%th= h
- repo.activity.by_year_month.each do |year, months|
%tr
%th= year
- (1..12).each do |month|
%td= months[month]
= render '_activity', author: repo

View file

@ -27,7 +27,9 @@
%th= :lines_deleted.t
%th= :first_commit.t
%th= :last_commit.t
- repo.authors.sort_by { |a| -a.commits.size}.each do |author|
%th
- sorted_authors = repo.authors.sort_by { |a| -a.commits.size}
- sorted_authors.each_with_index do |author, i|
%tr
%th= author.name
%td= author.commits.size
@ -35,6 +37,19 @@
%td= author.lines_deleted
%td= author.commits.first.try(:date).try(:to_formatted_s, :long)
%td= author.commits.last.try(:date).try(:to_formatted_s, :long)
%td
- if i <= 4
%a.btn{:href => "##{author.hash}-modal", :role => "button", 'data-toggle'=>"modal"}= :show_more.t
- else
= :more_data_not_available.t
- sorted_authors[0..4].each do |author|
.modal.hide{:id => "#{author.hash}-modal", :role => "dialog", :style => "width: 1140px; margin-left:-570px; top: 30%;"}
.modal-header
%h1.pagination-centered= "#{author.name} <#{author.email}>"
.modal-body{:style => "height: 650px; max-height: 800px;"}
= render '_activity', author: author
.modal-footer
%a.btn{'data-dismiss' => "modal"}= :close.t
.tab-pane{id: 'commits_count_by_author'}
.page-header

View file

@ -17,8 +17,9 @@
$('.tabbable ul a').click(function (e) {
e.preventDefault();
$(this).tab('show');
$(document.body).trigger('load');
})
});
$('.modal').on('shown', function (e) {
});
});
%body
%div.navbar.navbar-fixed-top