新增: 组织工作台部分接口以及关联工作项变动
This commit is contained in:
		
							parent
							
								
									f9cf1e3a13
								
							
						
					
					
						commit
						9cdc593763
					
				| 
						 | 
					@ -0,0 +1,123 @@
 | 
				
			||||||
 | 
					class Api::Pm::DashboardsController <  Api::Pm::BaseController
 | 
				
			||||||
 | 
					  before_action :require_login
 | 
				
			||||||
 | 
					  def index 
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def todo 
 | 
				
			||||||
 | 
					    return render_error('请输入正确的pm_project_ids.') if params[:pm_project_ids].blank? 
 | 
				
			||||||
 | 
					    pm_project_ids = params[:pm_project_ids].split(",") rescue []
 | 
				
			||||||
 | 
					    date = params[:date].present? ? params[:date].to_date : Date.today rescue Date.today
 | 
				
			||||||
 | 
					    @issues = Issue.where("start_date < ? and due_date > ?", date, date)
 | 
				
			||||||
 | 
					    @issues = @issues.where(pm_project_id: pm_project_ids).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'})
 | 
				
			||||||
 | 
					    @issues = kaminari_paginate(@issues.distinct.pm_includes)
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def my_issues
 | 
				
			||||||
 | 
					    return render_error('请输入正确的pm_project_ids.') if params[:pm_project_ids].blank? 
 | 
				
			||||||
 | 
					    pm_project_ids = params[:pm_project_ids].split(",") rescue []
 | 
				
			||||||
 | 
					    @all_issues = Issue.where(pm_project_id: pm_project_ids)
 | 
				
			||||||
 | 
					    @issues = @all_issues.joins(:issue_participants).where(issue_participants: {participant_id: current_user.id})
 | 
				
			||||||
 | 
					    @issues = @issues.where(pm_issue_type: params[:pm_issue_type].to_i) if params[:pm_issue_type].present?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @issues = kaminari_paginate(@issues.distinct.pm_includes)
 | 
				
			||||||
 | 
					    @my_assign_requirements_count = @all_issues.where(pm_issue_type: 1).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size
 | 
				
			||||||
 | 
					    @my_assign_tasks_count = @all_issues.where(pm_issue_type: 2).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size
 | 
				
			||||||
 | 
					    @my_assign_bugs_count = @all_issues.where(pm_issue_type: 3).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def my_pm_projects
 | 
				
			||||||
 | 
					    return render_error('请输入正确的pm_project_id.') if params[:pm_project_id].blank? 
 | 
				
			||||||
 | 
					    @all_issues = Issue.where(pm_project_id: params[:pm_project_id])
 | 
				
			||||||
 | 
					    time_now = Time.now
 | 
				
			||||||
 | 
					    @last_week_create_issues_count = @all_issues.where("created_on > ? and created_on < ?", time_now - 7.days, time_now).size 
 | 
				
			||||||
 | 
					    @before_last_week_create_issue_count = @all_issues.where("created_on > ? and created_on < ?", time_now - 14.days, time_now - 7.days).size
 | 
				
			||||||
 | 
					    @compare_last_week_create_issues = @before_last_week_create_issue_count.zero? ? 0 :(@last_week_create_issues_count - @before_last_week_create_issue_count).to_f / @before_last_week_create_issue_count rescue 0
 | 
				
			||||||
 | 
					    @last_week_close_issues_count = @all_issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
 | 
				
			||||||
 | 
					    @before_last_week_close_issue_count = @all_issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 14.days, time_now - 7.days).size
 | 
				
			||||||
 | 
					    @compare_last_week_close_issues = @before_last_week_close_issue_count.zero? ? 0 :(@last_week_close_issues_count - @before_last_week_close_issue_count).to_f / @before_last_week_close_issue_count rescue 0
 | 
				
			||||||
 | 
					    @all_requirement_issues_count = @all_issues.where(pm_issue_type: 1).size
 | 
				
			||||||
 | 
					    @last_week_close_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
 | 
				
			||||||
 | 
					    @last_month_close_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size
 | 
				
			||||||
 | 
					    @all_task_issues_count = @all_issues.where(pm_issue_type: 2).size 
 | 
				
			||||||
 | 
					    @last_week_close_tast_issues_count = @all_issues.where(pm_issue_type: 2).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
 | 
				
			||||||
 | 
					    @last_month_close_task_issues_count = @all_issues.where(pm_issue_type: 2).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size
 | 
				
			||||||
 | 
					    @all_bug_issues_count = @all_issues.where(pm_issue_type: 3).size
 | 
				
			||||||
 | 
					    @last_week_close_bug_issues_count = @all_issues.where(pm_issue_type: 3).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
 | 
				
			||||||
 | 
					    @last_month_close_bug_issues_count = @all_issues.where(pm_issue_type: 3).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @requirement_close_trend = [[],[]]
 | 
				
			||||||
 | 
					    @task_close_trend = [[],[]]
 | 
				
			||||||
 | 
					    @bug_close_trend = [[],[]]
 | 
				
			||||||
 | 
					    ((time_now-29.days).to_date..time_now.to_date).to_a.each do |i|
 | 
				
			||||||
 | 
					      @requirement_close_trend[0] << i.strftime("%Y.%m.%d")
 | 
				
			||||||
 | 
					      @task_close_trend[0] << i.strftime("%Y.%m.%d")
 | 
				
			||||||
 | 
					      @bug_close_trend[0] << i.strftime("%Y.%m.%d") 
 | 
				
			||||||
 | 
					      @requirement_close_trend[1] << @all_issues.where(pm_issue_type: 1, status_id: 5).where("DATE(updated_on) = ?", i).size
 | 
				
			||||||
 | 
					      @task_close_trend[1] << @all_issues.where(pm_issue_type: 2, status_id: 5).where("DATE(updated_on) = ?", i).size
 | 
				
			||||||
 | 
					      @bug_close_trend[1] << @all_issues.where(pm_issue_type: 3, status_id: 5).where("DATE(updated_on) = ?", i).size
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    @close_trend = {requirement: @requirement_close_trend, task: @task_close_trend, bug: @bug_close_trend}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    render :json => {
 | 
				
			||||||
 | 
					      last_week_close_issues_count: @last_week_close_issues_count,
 | 
				
			||||||
 | 
					      before_last_week_close_issue_count: @before_last_week_close_issue_count,
 | 
				
			||||||
 | 
					      compare_last_week_close_issues: @compare_last_week_close_issues,
 | 
				
			||||||
 | 
					      last_week_create_issues_count: @last_week_create_issues_count,
 | 
				
			||||||
 | 
					      before_last_week_create_issue_count: @before_last_week_create_issue_count,
 | 
				
			||||||
 | 
					      compare_last_week_create_issues: @compare_last_week_create_issues,
 | 
				
			||||||
 | 
					      all_requirement_issues_count: @all_requirement_issues_count,
 | 
				
			||||||
 | 
					      last_week_close_requirement_issues_count: @last_week_close_requirement_issues_count,
 | 
				
			||||||
 | 
					      last_month_close_requirement_issues_count: @last_month_close_requirement_issues_count,
 | 
				
			||||||
 | 
					      all_task_issues_count: @all_task_issues_count,
 | 
				
			||||||
 | 
					      last_week_close_tast_issues_count: @last_week_close_tast_issues_count,
 | 
				
			||||||
 | 
					      last_month_close_task_issues_count: @last_month_close_task_issues_count,
 | 
				
			||||||
 | 
					      all_bug_issues_count: @all_bug_issues_count,
 | 
				
			||||||
 | 
					      last_week_close_bug_issues_count: @last_week_close_bug_issues_count,
 | 
				
			||||||
 | 
					      last_month_close_bug_issues_count: @last_month_close_bug_issues_count,
 | 
				
			||||||
 | 
					      close_trend: @close_trend
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def my_projects
 | 
				
			||||||
 | 
					    return render_error('请输入正确的project_id.') if params[:project_id].blank?
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    @project = Project.find_by_id params[:project_id]
 | 
				
			||||||
 | 
					    return render_error('请输入正确的project_id.') unless @project.present?
 | 
				
			||||||
 | 
					    time_now = Time.now
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    branch_tag_result = $gitea_hat_client.get_repos_branch_tag_count_by_owner_repo(@project&.owner&.login, @project&.identifier) rescue {}
 | 
				
			||||||
 | 
					    languages_result = $gitea_client.get_repos_languages_by_owner_repo(@project&.owner&.login, @project&.identifier) rescue {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @open_pull_requests_count = @project.pull_requests.opening.size 
 | 
				
			||||||
 | 
					    @last_week_close_pull_requests_count = @project.pull_requests.where(status: 1).where("updated_at > ? and updated_at < ?", time_now - 7.days, time_now).size
 | 
				
			||||||
 | 
					    @last_month_close_pull_requets_count = @project.pull_requests.where(status: 1).where("updated_at > ? and updated_at < ?", time_now - 30.days, time_now).size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @commits_count = @project.commit_logs.size
 | 
				
			||||||
 | 
					    @last_week_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 7.days, time_now).size
 | 
				
			||||||
 | 
					    @last_month_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 30.days, time_now).size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    render :json => {
 | 
				
			||||||
 | 
					      branch_count: branch_tag_result["branch_count"].to_i,
 | 
				
			||||||
 | 
					      tag_count: branch_tag_result["tag_count"].to_i,
 | 
				
			||||||
 | 
					      license_name: @project.license&.name,
 | 
				
			||||||
 | 
					      open_pull_requests_count: @open_pull_requests_count,
 | 
				
			||||||
 | 
					      last_week_close_pull_requests_count: @last_week_close_pull_requests_count,
 | 
				
			||||||
 | 
					      last_month_close_pull_requets_count: @last_month_close_pull_requets_count,
 | 
				
			||||||
 | 
					      commits_count: @commits_count,
 | 
				
			||||||
 | 
					      last_week_commits_count: @last_week_commits_count,
 | 
				
			||||||
 | 
					      last_month_commits_count: @last_month_commits_count,
 | 
				
			||||||
 | 
					      language: hash_transform_precentagable(languages_result),
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private 
 | 
				
			||||||
 | 
					  def hash_transform_precentagable(hash)
 | 
				
			||||||
 | 
					    total_byte_size = hash.values.sum
 | 
				
			||||||
 | 
					    hash.transform_values { |v|
 | 
				
			||||||
 | 
					      ActionController::Base.helpers
 | 
				
			||||||
 | 
					        .number_to_percentage((v * 100.0 / total_byte_size), precision: 1)
 | 
				
			||||||
 | 
					    }.select{|k,v| v != "0.0%"}
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
| 
						 | 
					@ -238,7 +238,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def link_issues
 | 
					  def link_issues
 | 
				
			||||||
    children_issues = Issue.where(root_id: @issue.id)
 | 
					    children_issues = @issue.pm_issue_type == 1 ? @issue.child_count > 0 ? Issue.where(id: @issue.id) : Issue.none : Issue.where(root_id: @issue.id)
 | 
				
			||||||
    linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: @issue.id).pluck(:be_linkable_id))
 | 
					    linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: @issue.id).pluck(:be_linkable_id))
 | 
				
			||||||
    belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: @issue.id).pluck(:linkable_id))
 | 
					    belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: @issue.id).pluck(:linkable_id))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -246,7 +246,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController
 | 
				
			||||||
    compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id)
 | 
					    compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id)
 | 
				
			||||||
    i = compare_link_issues_ids.count
 | 
					    i = compare_link_issues_ids.count
 | 
				
			||||||
    while i > 0 do 
 | 
					    while i > 0 do 
 | 
				
			||||||
      children_issues = Issue.where(root_id: compare_link_issues_ids)
 | 
					      children_issues = Issue.where(root_id: compare_link_issues_ids).where.not(pm_issue_type: 1)
 | 
				
			||||||
      linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: compare_link_issues_ids).pluck(:be_linkable_id))
 | 
					      linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: compare_link_issues_ids).pluck(:be_linkable_id))
 | 
				
			||||||
      belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: compare_link_issues_ids).pluck(:linkable_id))
 | 
					      belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: compare_link_issues_ids).pluck(:linkable_id))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -255,9 +255,9 @@ class Api::Pm::IssuesController < Api::Pm::BaseController
 | 
				
			||||||
      i = compare_link_issues_ids.count
 | 
					      i = compare_link_issues_ids.count
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1)
 | 
					    @requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1).pm_includes
 | 
				
			||||||
    @task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2)
 | 
					    @task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2).pm_includes
 | 
				
			||||||
    @bug_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:3)
 | 
					    @bug_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:3).pm_includes
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private
 | 
					  private
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -102,6 +102,7 @@ class Issue < ApplicationRecord
 | 
				
			||||||
  scope :issue_issue, ->{where(issue_classify: [nil, 'issue'])}
 | 
					  scope :issue_issue, ->{where(issue_classify: [nil, 'issue'])}
 | 
				
			||||||
  scope :issue_pull_request, ->{where(issue_classify: 'pull_request')}
 | 
					  scope :issue_pull_request, ->{where(issue_classify: 'pull_request')}
 | 
				
			||||||
  scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)}
 | 
					  scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)}
 | 
				
			||||||
 | 
					  scope :pm_includes, -> {includes(:project, :show_issue_tags, :issue_status, :priority, :version, :user, :show_assigners, :comment_journals, :operate_journals)}
 | 
				
			||||||
  scope :closed, ->{where(status_id: 5)}
 | 
					  scope :closed, ->{where(status_id: 5)}
 | 
				
			||||||
  scope :opened, ->{where.not(status_id: 5)}
 | 
					  scope :opened, ->{where.not(status_id: 5)}
 | 
				
			||||||
  after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic
 | 
					  after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					json.total_count @issues.total_count
 | 
				
			||||||
 | 
					json.my_assign_requirements_count @my_assign_requirements_count
 | 
				
			||||||
 | 
					json.my_assign_tasks_count @my_assign_tasks_count
 | 
				
			||||||
 | 
					json.my_assign_bugs_count @my_assign_bugs_count
 | 
				
			||||||
 | 
					json.issues @issues.each do |issue| 
 | 
				
			||||||
 | 
					  json.partial! "api/v1/issues/simple_detail", locals: {issue: issue}
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					json.total_count @issues.total_count
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					json.issues @issues.each do |issue| 
 | 
				
			||||||
 | 
					  json.partial! "api/v1/issues/simple_detail", locals: {issue: issue}
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,18 @@
 | 
				
			||||||
defaults format: :json do 
 | 
					defaults format: :json do 
 | 
				
			||||||
  namespace :api do
 | 
					  namespace :api do
 | 
				
			||||||
    namespace :pm do
 | 
					    namespace :pm do
 | 
				
			||||||
 | 
					      resources :dashboards,only: [:index] do 
 | 
				
			||||||
 | 
					        collection do 
 | 
				
			||||||
 | 
					          get :todo 
 | 
				
			||||||
 | 
					          get :my_issues 
 | 
				
			||||||
 | 
					          get :my_pm_projects 
 | 
				
			||||||
 | 
					          get :my_projects
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      namespace :projects do 
 | 
				
			||||||
 | 
					        resources :dashboards, only: [:index] do 
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
      resources :issues do
 | 
					      resources :issues do
 | 
				
			||||||
        collection do
 | 
					        collection do
 | 
				
			||||||
          patch :batch_update
 | 
					          patch :batch_update
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue