add issue count to pm projects
This commit is contained in:
parent
005f1d4aa5
commit
8329cc113b
|
@ -75,9 +75,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController
|
|||
render "api/v1/issues/statues/index"
|
||||
end
|
||||
|
||||
def count
|
||||
|
||||
end
|
||||
|
||||
def destroy
|
||||
@object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class Api::Pm::ProjectsController < Api::Pm::BaseController
|
||||
before_action :require_login, except: [:convert]
|
||||
before_action :load_project
|
||||
before_action :load_project, only: [:convert]
|
||||
def convert
|
||||
data = {
|
||||
owner: @project.owner.try(:login),
|
||||
|
@ -9,6 +9,24 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController
|
|||
render_ok(data: data)
|
||||
end
|
||||
|
||||
def issues_count
|
||||
return tip_exception '参数错误' unless params[:pm_project_id].present?
|
||||
@issues = Issue.where(pm_project_id_params)
|
||||
data = {}
|
||||
@issues_count = @issues.group(:pm_project_id).count
|
||||
# requirement 1 task 2 bug 3
|
||||
@issues_type_count = @issues.group(:pm_project_id, :pm_issue_type).count
|
||||
pm_project_id_params[:pm_project_id].map(&:to_i).map do |project_id|
|
||||
data[project_id] = {
|
||||
total: @issues_count[project_id] || 0,
|
||||
requirement: @issues_type_count[[project_id, 1]] || 0,
|
||||
task: @issues_type_count[[project_id, 2]] || 0,
|
||||
bug: @issues_type_count[[project_id, 3]] || 0
|
||||
}
|
||||
end
|
||||
render_ok(data: data)
|
||||
end
|
||||
|
||||
def bind_project
|
||||
return render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin?
|
||||
Issue.where(pm_project_id: params[:pm_project_id], user_id: current_user).update_all(project_id: params[:project_id])
|
||||
|
@ -18,4 +36,10 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController
|
|||
def load_project
|
||||
@project = Project.joins(:owner).find params[:project_id]
|
||||
end
|
||||
|
||||
def pm_project_id_params
|
||||
params.permit(
|
||||
pm_project_id: []
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,6 @@ defaults format: :json do
|
|||
get :priorities
|
||||
get :tags
|
||||
get :statues
|
||||
get :count
|
||||
end
|
||||
|
||||
resources :journals do
|
||||
|
@ -20,6 +19,7 @@ defaults format: :json do
|
|||
resources :projects do
|
||||
collection do
|
||||
get :convert
|
||||
get :issues_count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue