From 926617e28360b16fe5bbb59fd9727325eea0562b Mon Sep 17 00:00:00 2001 From: Tomasz Gieniusz Date: Thu, 21 Feb 2013 11:15:58 +0100 Subject: [PATCH] #6 Show Lines For Any User --- config/locales/en.yml | 6 +++- .../stats_view/charts/authors_charts.rb | 8 ++--- lib/git_stats/stats_view/view.rb | 12 +++---- templates/author_details/_author_details.haml | 35 +++++++++++++++++++ .../author_details/changed_lines_by_date.haml | 1 + templates/author_details/commits_by_date.haml | 1 + .../author_details/deletions_by_date.haml | 1 + .../author_details/insertions_by_date.haml | 1 + templates/authors/_authors.haml | 4 ++- 9 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 templates/author_details/_author_details.haml create mode 100644 templates/author_details/changed_lines_by_date.haml create mode 100644 templates/author_details/commits_by_date.haml create mode 100644 templates/author_details/deletions_by_date.haml create mode 100644 templates/author_details/insertions_by_date.haml diff --git a/config/locales/en.yml b/config/locales/en.yml index 07b0841a9..41c44a929 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -53,4 +53,8 @@ en: close: Close binary: Binary text: Text - general: General \ No newline at end of file + general: General + details: Details + insertions_by_date: Lines added by date + deletions_by_date: Lines deleted by date + changed_lines_by_date: Changed lines by date \ No newline at end of file diff --git a/lib/git_stats/stats_view/charts/authors_charts.rb b/lib/git_stats/stats_view/charts/authors_charts.rb index 35dc22cb1..2be29799c 100644 --- a/lib/git_stats/stats_view/charts/authors_charts.rb +++ b/lib/git_stats/stats_view/charts/authors_charts.rb @@ -7,10 +7,10 @@ module GitStats @authors = authors end - def commits_sum_by_author_by_date(limit = 4) + def commits_sum_by_author_by_date(limit = 4, authors = nil) Chart.new do |f| f.multi_date_chart( - data: @authors.sort_by { |author| -author.commits.size }[0..limit].map { |author| {name: author.name, data: author.commits_sum_by_date} }, + data: (authors || @authors.sort_by { |author| -author.commits.size }[0..limit]).map { |author| {name: author.name, data: author.commits_sum_by_date} }, title: :lines_by_date.t, y_text: :lines.t ) @@ -18,10 +18,10 @@ module GitStats end [:insertions, :deletions, :changed_lines].each do |method| - define_method "#{method}_by_author_by_date" do |limit = 4| + define_method "#{method}_by_author_by_date" do |limit = 4, authors = nil| Chart.new do |f| f.multi_date_chart( - data: @authors.sort_by { |author| -author.send(method) }[0..limit].map { |author| {name: author.name, data: author.send("#{method}_by_date")} }, + data: (authors || @authors.sort_by { |author| -author.send(method) }[0..limit]).map { |author| {name: author.name, data: author.send("#{method}_by_date")} }, title: :lines_by_date.t, y_text: :lines.t ) diff --git a/lib/git_stats/stats_view/view.rb b/lib/git_stats/stats_view/view.rb index 91ec16fec..42e216ba2 100644 --- a/lib/git_stats/stats_view/view.rb +++ b/lib/git_stats/stats_view/view.rb @@ -11,20 +11,20 @@ module GitStats prepare_static_content prepare_assets - all_templates.each do |template| + all_templates.reject {|t| t =~ /author_details/}.each do |template| output = Template.new(template, @layout).render(@view_data, author: @view_data.repo, links: links) write(output, "#@out_path/#{template}.html") end - render_authors_activity + render_authors end - def render_authors_activity + def render_authors done = [] @view_data.repo.authors.sort_by { |a| -a.commits.size }.each do |author| next if done.include? author.dirname done << author.dirname - all_templates('activity/').each do |template| + (all_templates('activity/') + all_templates('author_details')).each do |template| output = Template.new(template, @layout).render(@view_data, author: author, links: links, @@ -35,11 +35,11 @@ module GitStats end def all_templates(root = '') - Dir["../../../../templates/#{root}**/[^_]*.haml".absolute_path].map { + (Dir["../../../../templates/#{root}**/[^_]*.haml".absolute_path].map { |f| Pathname.new(f) }.map { |f| f.relative_path_from(Pathname.new('../../../../templates'.absolute_path)).sub_ext('') - }.map(&:to_s) - %w(layout) + }.map(&:to_s) - %w(layout)) end private diff --git a/templates/author_details/_author_details.haml b/templates/author_details/_author_details.haml new file mode 100644 index 000000000..0b816f9e0 --- /dev/null +++ b/templates/author_details/_author_details.haml @@ -0,0 +1,35 @@ +.tabbable.tabs-left + %ul.nav.nav-tabs + %li{class: page == :commits_by_date ? "active" : ""} + %a{href: 'commits_by_date.html'}= :commits_by_date.t + %li{class: page == :changed_lines_by_date ? "active" : ""} + %a{href: 'changed_lines_by_date.html'}= :changed_lines_by_date.t + %li{class: page == :insertions_by_date ? "active" : ""} + %a{href: 'insertions_by_date.html'}= :insertions_by_date.t + %li{class: page == :deletions_by_date ? "active" : ""} + %a{href: 'deletions_by_date.html'}= :deletions_by_date.t + + .tab-content + .tab-pane.active + .page-header + %h1.pagination-centered= page.t + + -if page == :commits_by_date + = high_stock("charts.commits_sum_by_author_by_date", charts.commits_sum_by_author_by_date(4, [author])) + %small + %center= "5 #{:best_authors_shown.t}" + + -elsif page == :changed_lines_by_date + = high_stock("charts.changed_lines_by_author_by_date", charts.changed_lines_by_author_by_date(4, [author])) + %small + %center= "5 #{:best_authors_shown.t}" + + -elsif page == :insertions_by_date + = high_stock("charts.insertions_by_author_by_date", charts.insertions_by_author_by_date(4, [author])) + %small + %center= "5 #{:best_authors_shown.t}" + + -elsif page == :deletions_by_date + = high_stock("charts.deletions_by_author_by_date", charts.deletions_by_author_by_date(4, [author])) + %small + %center= "5 #{:best_authors_shown.t}" \ No newline at end of file diff --git a/templates/author_details/changed_lines_by_date.haml b/templates/author_details/changed_lines_by_date.haml new file mode 100644 index 000000000..84b83fc3f --- /dev/null +++ b/templates/author_details/changed_lines_by_date.haml @@ -0,0 +1 @@ += render_partial('author_details/_author_details', page: :changed_lines_by_date, author: author) \ No newline at end of file diff --git a/templates/author_details/commits_by_date.haml b/templates/author_details/commits_by_date.haml new file mode 100644 index 000000000..be1c924b9 --- /dev/null +++ b/templates/author_details/commits_by_date.haml @@ -0,0 +1 @@ += render_partial('author_details/_author_details', page: :commits_by_date, author: author) \ No newline at end of file diff --git a/templates/author_details/deletions_by_date.haml b/templates/author_details/deletions_by_date.haml new file mode 100644 index 000000000..4ef82aec1 --- /dev/null +++ b/templates/author_details/deletions_by_date.haml @@ -0,0 +1 @@ += render_partial('author_details/_author_details', page: :deletions_by_date, author: author) \ No newline at end of file diff --git a/templates/author_details/insertions_by_date.haml b/templates/author_details/insertions_by_date.haml new file mode 100644 index 000000000..0225c7902 --- /dev/null +++ b/templates/author_details/insertions_by_date.haml @@ -0,0 +1 @@ += render_partial('author_details/_author_details', page: :insertions_by_date, author: author) \ No newline at end of file diff --git a/templates/authors/_authors.haml b/templates/authors/_authors.haml index a899d5d71..bdeac9bcc 100644 --- a/templates/authors/_authors.haml +++ b/templates/authors/_authors.haml @@ -38,7 +38,9 @@ %td= I18n.localize(author.commits.first.try(:date), format: :long) rescue "" %td= I18n.localize(author.commits.last.try(:date), format: :long) rescue "" %td - %a.btn{:href => "#{author.dirname}/activity/by_date.html"}= :show_more.t + %a.btn{:href => "#{author.dirname}/activity/by_date.html"}= :activity.t + %td + %a.btn{:href => "#{author.dirname}/author_details/commits_by_date.html"}= :details.t -elsif page == :commits_count_by_author = high_chart("charts.commits_count_by_author", charts.commits_count_by_author(4))