From 70d58ea28eb3f72ca2e6aca727d9b66c7ff8dbfb Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 27 Sep 2016 15:10:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 2 +- app/helpers/application_helper.rb | 18 ++++++++++-------- app/views/repositories/show.html.erb | 4 ++-- config/locales/projects/zh.yml | 3 ++- .../lib/gitlab/client/repositories.rb | 10 ++++++++++ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 5d9528f87..d4042abf5 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -77,7 +77,7 @@ class RepositoriesController < ApplicationController respond_to do |format| format.html format.xls{ - filename = "#{@project.name.to_s}_#{l(:label_issue_list_xls)}_#{@rev}_#{l(:label_rep_xls)}.xls" + filename = "#{@project.name.to_s}_#{l(:label_rep_xls)}.xls" send_data(export_rep_xls(gpid, :rev => rev, :cycle => "1"), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename)) } end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8563f6f02..7ade73751 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -68,29 +68,31 @@ module ApplicationHelper g = Gitlab.client cycle = params[:cycle] rev = params[:rev] - # branch = g.branche(gpid, rev) - statics = g.rep_stats(gpid, :rev => rev) - + if cycle == "week" + statics = g.rep_stats_week(gpid, :rev => rev) + elsif cycle == "month" + statics = g.rep_stats_month(gpid, :rev => rev) + end xls_report = StringIO.new book = Spreadsheet::Workbook.new sheet1 = book.create_worksheet :name => "版本库" blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 sheet1.row(0).default_format = blue - sheet1.row(0).concat([l(:rep_branch),l(:rep_author),l(:rep_author_mail),l(:rep_code_add),l(:rep_code_delete),l(:rep_code_modified),l(:rep_sode_time),l(:rep_sode_cycle)]) + sheet1.row(0).concat([l(:rep_branch),l(:rep_author),l(:rep_changeset),l(:rep_code_add),l(:rep_code_delete),l(:rep_code_modified),l(:rep_sode_time),l(:rep_sode_cycle),l(:rep_author_mail)]) count_row = 1 statics.each do |static| user = User.where(:mail => static.email).first sheet1[count_row,0] = rev sheet1[count_row,1] = user.nil? ? static.uname : user.show_name - sheet1[count_row,2] = static.email + sheet1[count_row,2] = static.commits_num sheet1[count_row,3] = static.add sheet1[count_row,4] = static.del sheet1[count_row,5] = static.changes - sheet1[count_row,6] = Time.now - sheet1[count_row,7] = "1周" + sheet1[count_row,6] = Time.now.strftime('%Y-%m-%d %H:%M:%S') + sheet1[count_row,7] = cycle == "week" ? "最近1周" : "最近一月" + sheet1[count_row,8] = static.email count_row += 1 end - book.write xls_report xls_report.string end diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 21db53a31..b12302e6e 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -80,8 +80,8 @@ 如何提交代码
导出统计结果: - <%= link_to "当前一周", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "week" } %> | - <%= link_to "当前一月", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "month" } %> + <%= link_to "最近一周", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "week" } %> | + <%= link_to "最近一月", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "month" } %>
<%#= link_to "导出excel", {:controller => 'repositories', :action => 'export_rep_static', :rev => @rev}, :format => 'xls' %> diff --git a/config/locales/projects/zh.yml b/config/locales/projects/zh.yml index 1d44cffba..98e13a865 100644 --- a/config/locales/projects/zh.yml +++ b/config/locales/projects/zh.yml @@ -222,11 +222,12 @@ zh: rep_branch: 分支 rep_author: 作者 rep_author_mail: 邮箱 + rep_changeset: 提交次数 rep_code_add: 添加行数 rep_code_delete: 删除代码 rep_code_modified: 总行数 rep_sode_time: 导出时间 - rep_sode_cycle: 周期 + rep_sode_cycle: 时间区间 # 自定义查询 label_query_plural: 自定义查询 diff --git a/lib/gitlab-cli/lib/gitlab/client/repositories.rb b/lib/gitlab-cli/lib/gitlab/client/repositories.rb index 80d1058b5..daed2ee16 100644 --- a/lib/gitlab-cli/lib/gitlab/client/repositories.rb +++ b/lib/gitlab-cli/lib/gitlab/client/repositories.rb @@ -117,6 +117,16 @@ class Gitlab::Client end alias_method :repo_rep_stats, :rep_stats + def rep_stats_week(project, options={}) + get("/projects/#{project}/repository/rep_stats_week", :query => options) + end + alias_method :repo_rep_stats, :rep_stats + + def rep_stats_month(project, options={}) + get("/projects/#{project}/repository/rep_stats_month", :query => options) + end + alias_method :repo_rep_stats, :rep_stats + def rep_user_stats(project, options={}) get("/projects/#{project}/repository/rep_user_stats", :query => options) end