封装,优化本周代码

This commit is contained in:
daiao 2017-01-13 10:14:10 +08:00
parent 7b5c3435d4
commit 8a38e379ad
2 changed files with 20 additions and 18 deletions

View File

@ -193,12 +193,8 @@ class PullRequestsController < ApplicationController
begin
@status = @g.accept_merge_rquest(@project.gpid, params[:id], User.current.gid)
user = User.find_by_login(@status.author.try(:username))
# 更新所有管理员的这条pullrequest消息
ForgeMessage.where(:forge_message_id => params[:id].to_i, :project_id => @project.id, :forge_message_type => "PullRequest").update_all(:status => 2, :operate_user_id => User.current.id, :updated_at => Time.now)
# 更新自己的消息为已读
ForgeMessage.where(:forge_message_id => params[:id].to_i, :project_id => @project.id, :forge_message_type => "PullRequest", :user_id => User.current.id).update_all(:viewed => true)
# 更新pullrequest的status字段
PullRequest.where(:pull_request_id => params[:id].to_i).update_all(:status => 2)
# 更新管理员的pullrequest消息
update_pullrequest_message(params[:id].to_i, @project.id, "PullRequest", 2)
# 接受后,给用户发消息
if ForgeMessage.where(:forge_message_id => params[:id].to_i, :project_id => @project.id, :forge_message_type => "PullRequest", :user_id => user.id).count == 0
send_message_to_author(@project.id, @status.author.try(:username), params[:id], 2)
@ -237,12 +233,7 @@ class PullRequestsController < ApplicationController
user = User.find_by_login(request.author.try(:username))
status = params[:state] == "close" ? 4 : 3
#send_message_to_manager(@project.id, params[:id], status)
# 更新所有管理员的消息的
ForgeMessage.where(:forge_message_id => request.id, :project_id => @project.id, :forge_message_type => "PullRequest").update_all(:status => status, :operate_user_id => User.current.id, :updated_at => Time.now)
# 更新自己的消息为已读
ForgeMessage.where(:forge_message_id => request.id, :project_id => @project.id, :forge_message_type => "PullRequest", :user_id => User.current.id).update_all(:viewed => true)
# 更新pullrequest的status字段
PullRequest.where(:pull_request_id => params[:id].to_i).update_all(:status => status)
update_pullrequest_message(request.id, @project.id, "PullRequest", status)
# 给作者发送消息,如何已经发送了消息,则不发
if is_project_manager?(User.current.id, @project.id) && ForgeMessage.where(:forge_message_id => request.id, :project_id => @project.id, :forge_message_type => "PullRequest", :user_id => user.id).count == 0
send_message_to_author(@project.id, user.login, request.id, status)
@ -384,6 +375,15 @@ class PullRequestsController < ApplicationController
)
end
def update_pullrequest_message forge_message_id, project_id, forge_message_type, status
# 更新这条pullrequest消息所有相关的信息
ForgeMessage.where(:forge_message_id => forge_message_id, :project_id => project_id, :forge_message_type => forge_message_type).update_all(:status => status, :operate_user_id => User.current.id, :updated_at => Time.now)
# 更新自己的消息为已读
ForgeMessage.where(:forge_message_id => forge_message_id, :project_id => project_id, :forge_message_type => forge_message_type, :user_id => User.current.id).update_all(:viewed => true)
# 更新pullrequest的status字段
PullRequest.where(:pull_request_id => forge_message_id).update_all(:status => status)
end
def authorize_logged
if !User.current.logged?
redirect_to signin_path

View File

@ -172,9 +172,11 @@ class UsersController < ApplicationController
@issues = Issue.where("author_id =? and project_id=? and subject like ?",
@user.id, @project_id, "%#{@subject}%").order(order)
end
@issues_filter = Issue.where("author_id =?", @user.id).order('updated_on desc')
@issue_open_count = Issue.where(:author_id => @user.id, :status_id => [1, 2, 3, 4, 6]).count
@issue_close_count = Issue.where(:author_id => @user.id, :status_id => 5).count
@issues_filter = Issue.where("author_id =?", @user.id)
@issue_open_count = @issues_filter.where(:status_id => [1, 2, 3, 4, 6]).count
@issue_close_count = @issues_filter.where(:status_id => 5).count
# @issue_open_count = Issue.where(:author_id => @user.id, :status_id => [1, 2, 3, 4, 6]).count
# @issue_close_count = Issue.where(:author_id => @user.id, :status_id => 5).count
# 导出excel的issues
@excel_issues = @issues
@ -218,9 +220,9 @@ class UsersController < ApplicationController
@issues = Issue.where("assigned_to_id =? and project_id=? and subject like ?",
@user.id, @project_id, "%#{@subject}%").order(order)
end
@issues_filter = Issue.where("assigned_to_id =?", @user.id).order('updated_on desc')
@issue_open_count = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 3, 4, 6]).count
@issue_close_count = Issue.where(:assigned_to_id => @user.id, :status_id => 5).count
@issues_filter = Issue.where("assigned_to_id =?", @user.id)
@issue_open_count = @issues_filter.where(:status_id => [1, 2, 3, 4, 6]).count
@issue_close_count = @issues_filter.where(:status_id => 5).count
# 导出excel的issues
@excel_issues = @issues