This commit is contained in:
yystopf 2023-02-24 15:26:40 +08:00
parent b616c971db
commit dab636d122
3 changed files with 24 additions and 17 deletions

View File

@ -32,10 +32,12 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController
# 里程碑详情
def show
@object_results = Api::V1::Issues::Milestones::DetailIssuesService.call(@project, @milestone, query_params, current_user)
@closed_issues_count = @object_results.closed.size
@opened_issues_count = @object_results.opened.size
@issues = kaminari_paginate(@object_results)
@object_result = Api::V1::Issues::Milestones::DetailIssuesService.call(@project, @milestone, query_params, current_user)
@total_issues_count = @object_result[:total_issues_count]
@opened_issues_count = @object_result[:opened_issues_count]
@closed_issues_count = @object_result[:closed_issues_count]
@issues = kaminari_paginate(@object_result[:data])
end
def update

View File

@ -2,7 +2,7 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService
include ActiveModel::Model
attr_reader :project, :category, :author_id, :assigner_id, :issue_tag_ids, :sort_by, :sort_direction, :current_user
attr_accessor :queried_issues
attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count
validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"}
validates :sort_by, inclusion: {in: ['issues.created_on', 'issues.updated_on', 'issue_priorities.position'], message: '请输入正确的SortBy'}, allow_blank: true
@ -26,7 +26,7 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService
begin
issue_query_data
queried_issues
return {data: queried_issues, total_issues_count: @total_issues_count, closed_issues_count: @closed_issues_count, opened_issues_count: @opened_issues_count}
rescue
raise Error, "服务器错误,请联系系统管理员!"
end
@ -36,6 +36,18 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService
def issue_query_data
issues = @milestone.issues.issue_issue
# author_id
issues = issues.where(author_id: author_id) if author_id.present?
# assigner_id
issues = issues.joins(:assigners).where(users: {id: assigner_id}).or(issues.joins(:assigners).where(assigned_to_id: assigner_id)) if assigner_id.present?
issues = issues.ransack(issue_tags_value_cont: issue_tag_ids.sort!.join(",")).result unless issue_tag_ids.blank?
@total_issues_count = issues.distinct.size
@closed_issues_count = issues.closed.distinct.size
@opened_issues_count = issues.opened.distinct.size
case category
when 'closed'
issues = issues.closed
@ -43,15 +55,7 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService
issues = issues.opened
end
# author_id
issues = issues.where(author_id: author_id) if author_id.present?
# assigner_id
issues = issues.joins(:assigners).where(users: {id: assigner_id}).or(issues.joins(:assigners).where(assigned_to_id: assigner_id)) if assigner_id.present?
issues = issues.joins(:issue_tags).where(issue_tags: {id: issue_tag_ids}) if issue_tag_ids.present?
scope = issues.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals).references(:assigners)
scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :version, :show_issue_tags, :comment_journals).references(:assigners)
scope = scope.reorder("#{sort_by} #{sort_direction}").distinct

View File

@ -1,11 +1,12 @@
json.milestone do
json.partial! "detail", locals: {milestone: @milestone}
end
json.total_issues_count @issues.total_count
json.total_issues_count @total_issues_count
json.closed_issues_count @closed_issues_count
json.opened_issues_count @opened_issues_count
json.total_count @issues.total_count
json.issues @issues.each do |issue|
if issue.issue_classify == "Issue"
if issue.issue_classify == "issue"
json.partial! "api/v1/issues/simple_detail", locals: {issue: issue}
end
end