admin添加导出用户所有代码提交量
This commit is contained in:
parent
1afc3fe4d0
commit
ef43488861
|
@ -1,3 +1,4 @@
|
|||
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
|
@ -31,6 +32,74 @@ class AdminController < ApplicationController
|
|||
@no_configuration_data = Redmine::DefaultData::Loader::no_data?
|
||||
end
|
||||
|
||||
def export_rep_static_users
|
||||
rev = params[:rev]
|
||||
cycle = params[:cycle]
|
||||
cycle_name = (params[:cycle] == "admin_week" ? l(:label_per_week) : (params[:cycle] == "admin_month" ? l(:label_per_month) : l(:label_per_all)))
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xls{
|
||||
filename = "#{l(:label_user_rep_xls)}_#{cycle_name}.xls"
|
||||
send_data(admin_export_rep_xls(:rev => rev, :cycle => "1"), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# 管理员界面导出所有项目代码、提交次数统计
|
||||
def admin_export_rep_xls (options = {})
|
||||
cycle = params[:cycle]
|
||||
g = Gitlab.client
|
||||
users_results = []
|
||||
User.first(13).each do |user|
|
||||
unless user.mail.nil?
|
||||
user_mail = user.mail
|
||||
user.projects.where("gpid is not null").each do |project|
|
||||
begin
|
||||
g.branches(project.gpid).each do |branch|
|
||||
if cycle == "admin_week"
|
||||
statics = g.admin_rep_stats_week(project.gpid, :rev => branch.name, :user_mail => user_mail)
|
||||
elsif cycle == "admin_month"
|
||||
statics = g.admin_rep_stats_month(project.gpid, :rev => branch.name, :user_mail => user_mail)
|
||||
elsif cycle == "admin_all"
|
||||
statics = g.admin_rep_stats_all(project.gpid, :rev => branch.name, :user_mail => user_mail)
|
||||
end
|
||||
unless statics.first.commits_num == "0"
|
||||
user_details = {:user_id => user.id, :user_name => user.show_name, :project_id => project.id, :project_name => project.name,
|
||||
:commits_num => statics.first.commits_num, :add => statics.first.add, :del => statics.first.del, :changes => statics.first.changes, :branch => branch.name}
|
||||
users_results << user_details
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
puts e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
xls_report = StringIO.new
|
||||
book = Spreadsheet::Workbook.new
|
||||
sheet1 = book.create_worksheet :name => l(:project_module_repository)
|
||||
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
||||
sheet1.row(0).default_format = blue
|
||||
sheet1.row(0).concat([l(:label_rep_user_id),l(:label_rep_user_name),l(:label_rep_project_id),l(:label_rep_project_name),l(:rep_branch),l(:rep_changeset),l(:rep_code_add),l(:rep_code_delete),l(:rep_code_modified),l(:rep_sode_time)])
|
||||
count_row = 1
|
||||
users_results.each do |static|
|
||||
sheet1[count_row,0] = static[:user_id]
|
||||
sheet1[count_row,1] = static[:user_name]
|
||||
sheet1[count_row,2] = static[:project_id]
|
||||
sheet1[count_row,3] = static[:project_name]
|
||||
sheet1[count_row,4] = static[:branch]
|
||||
sheet1[count_row,5] = static[:commits_num]
|
||||
sheet1[count_row,6] = static[:add]
|
||||
sheet1[count_row,7] = static[:del]
|
||||
sheet1[count_row,8] = static[:changes]
|
||||
sheet1[count_row,9] = Time.now.strftime('%Y-%m-%d %H:%M:%S')
|
||||
count_row += 1
|
||||
end
|
||||
book.write xls_report
|
||||
xls_report.string
|
||||
end
|
||||
|
||||
# 管理员界面 项目列表
|
||||
def projects
|
||||
=begin
|
||||
|
|
|
@ -74,9 +74,19 @@ class RepositoriesController < ApplicationController
|
|||
def export_rep_static
|
||||
# 管理员界面导出所有项目
|
||||
if params[:cycle] == "admin_week" || params[:cycle] == "admin_month" || params[:cycle] == "admin_all"
|
||||
if User.current.admin
|
||||
projects = Project.where(:gpid => !nil)
|
||||
|
||||
if User.current.admin?
|
||||
@project = Project.find(params[:id])
|
||||
gpid = @project.gpid
|
||||
rev = params[:rev]
|
||||
cycle = params[:cycle]
|
||||
cycle_name = (params[:cycle] == "admin_week" ? "每周" : (params[:cycle] == "admin_month" ? "每月" : "所有"))
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xls{
|
||||
filename = "#{l(:label_user_rep_xls)}_#{l(:cycle_name)}_.xls"
|
||||
send_data(admin_export_rep_xls(gpid, :rev => rev, :cycle => "1"), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
end
|
||||
else
|
||||
render_403
|
||||
end
|
||||
|
@ -89,7 +99,7 @@ class RepositoriesController < ApplicationController
|
|||
format.html
|
||||
format.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))
|
||||
send_data(export_rep_xls(gpid, :rev => rev, :cycle => cycle), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -115,35 +115,6 @@ module ApplicationHelper
|
|||
xls_report.string
|
||||
end
|
||||
|
||||
# 管理员界面导出所有项目代码、提交次数统计
|
||||
def admin_export_rep_xls
|
||||
users = User.all
|
||||
user_details = {}
|
||||
results = []
|
||||
users.each do |user|
|
||||
user.projects.each do |project|
|
||||
g = Gitlab.client
|
||||
cycle = params[:cycle]
|
||||
rev = params[:rev]
|
||||
if cycle == "week"
|
||||
statics = g.rep_stats_week(project.gpid, :rev => rev)
|
||||
elsif cycle == "month"
|
||||
statics = g.rep_stats_month(project.gpid, :rev => rev)
|
||||
end.
|
||||
user_details = {:user_id => user.id, :user_name => user.show_name, :project_id => project.id, :project_name => project.name,
|
||||
:commits_num => static.commits_num, :add => static.add, :del => static.del, :changes => static.changes}
|
||||
results << user_details
|
||||
end
|
||||
|
||||
static.commits_num
|
||||
sheet1[count_row,3] = static.add
|
||||
sheet1[count_row,4] = static.del
|
||||
sheet1[count_row,5] = static.changes
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 项目issue列表导出Excel功能
|
||||
def issue_list_xls issues
|
||||
xls_report = StringIO.new
|
||||
|
|
|
@ -78,9 +78,9 @@
|
|||
|
||||
<% html_title(l(:label_project_plural)) -%>
|
||||
<div class="fr">项目代码/提交数统计:
|
||||
<%= link_to "最近一周", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "admin_week" }, :class => "linkBlue2" %> <a style="color: #7f7f7f;">|</a>
|
||||
<%= link_to "最近一月", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "admin_month" }, :class => "linkBlue2" %>
|
||||
<%= link_to "所有", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "admin_all" }, :class => "linkBlue2" %>
|
||||
<%= link_to "最近一周", {:controller => 'admin', :action => 'export_rep_static_users', :format => 'xls', :cycle => "admin_week" }, :class => "linkBlue2" %> <a style="color: #7f7f7f;">|</a>
|
||||
<%= link_to "最近一月", {:controller => 'admin', :action => 'export_rep_static_users', :format => 'xls', :cycle => "admin_month" }, :class => "linkBlue2" %><a style="color: #7f7f7f;">|</a>
|
||||
<%= link_to "所有", {:controller => 'admin', :action => 'export_rep_static_users', :format => 'xls', :cycle => "admin_all" }, :class => "linkBlue2" %>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
|
|
@ -202,8 +202,16 @@ zh:
|
|||
label_issue_new: 新建问题
|
||||
label_query: 自定义查询
|
||||
label_issue_list_xls: Issue列表
|
||||
label_per_week: 每周
|
||||
label_per_month: 每月
|
||||
label_per_all: 所有
|
||||
label_rep_xls: 版本库代码统计
|
||||
label_user_rep_xls: 用户开发量统计
|
||||
label_rep_branch: 分支
|
||||
label_rep_user_id: 用户ID
|
||||
label_rep_user_name: 用户名
|
||||
label_rep_project_id: 项目ID
|
||||
label_rep_project_name: 项目名
|
||||
|
||||
# Issue列表 excel导出参数
|
||||
issue_xls_id: ID
|
||||
|
|
|
@ -1107,6 +1107,7 @@ RedmineApp::Application.routes.draw do
|
|||
|
||||
match 'admin', :to => 'admin#index', :via => :get
|
||||
match 'admin/projects', :via => :get
|
||||
match 'admin/export_rep_static_users', :via => :get
|
||||
get 'admin/courses', as: :all_courses
|
||||
get 'admin/syllabuses', as: :all_syllabuses
|
||||
get 'admin/non_syllabus_courses', as: :non_syllabus_courses
|
||||
|
|
|
@ -132,6 +132,22 @@ class Gitlab::Client
|
|||
end
|
||||
alias_method :repo_rep_stats, :rep_stats
|
||||
|
||||
# static all users
|
||||
def admin_rep_stats_week(project, options={})
|
||||
get("/projects/#{project}/repository/admin_rep_stats_week", :query => options)
|
||||
end
|
||||
alias_method :repo_rep_stats, :rep_stats
|
||||
|
||||
def admin_rep_stats_month(project, options={})
|
||||
get("/projects/#{project}/repository/admin_rep_stats_month", :query => options)
|
||||
end
|
||||
alias_method :repo_rep_stats, :rep_stats
|
||||
|
||||
def admin_rep_stats_all(project, options={})
|
||||
get("/projects/#{project}/repository/admin_rep_stats_all", :query => options)
|
||||
end
|
||||
alias_method :repo_rep_stats, :rep_stats
|
||||
|
||||
# Gets a tree activities of project repository.
|
||||
#
|
||||
# @example
|
||||
|
|
Loading…
Reference in New Issue