新增:评论/操作记录总数返回
This commit is contained in:
parent
b5383bfa5a
commit
2827e28b07
|
@ -6,8 +6,11 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController
|
|||
before_action :check_journal_operate_permission, only: [:update, :destroy]
|
||||
|
||||
def index
|
||||
@object_results = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user)
|
||||
@journals = kaminari_paginate(@object_results)
|
||||
@object_result = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user)
|
||||
@total_journals_count = @object_result[:total_journals_count]
|
||||
@total_operate_journals_count = @object_result[:total_operate_journals_count]
|
||||
@total_comment_journals_count = @object_result[:total_comment_journals_count]
|
||||
@journals = kaminari_paginate(@object_result[:data])
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
@ -3,7 +3,7 @@ class Api::V1::Issues::Journals::ListService < ApplicationService
|
|||
include ActiveModel::Model
|
||||
|
||||
attr_reader :issue, :category, :keyword, :sort_by, :sort_direction
|
||||
attr_accessor :queried_journals
|
||||
attr_accessor :queried_journals, :total_journals_count, :total_operate_journals_count, :total_comment_journals_count
|
||||
|
||||
validates :category, inclusion: {in: %w(all comment operate), message: "请输入正确的Category"}
|
||||
validates :sort_by, inclusion: {in: Journal.column_names, message: '请输入正确的SortBy'}, allow_blank: true
|
||||
|
@ -22,7 +22,7 @@ class Api::V1::Issues::Journals::ListService < ApplicationService
|
|||
begin
|
||||
journal_query_data
|
||||
|
||||
@queried_journals
|
||||
{data: @queried_journals, total_journals_count: @total_journals_count, total_operate_journals_count: total_operate_journals_count, total_comment_journals_count: total_comment_journals_count}
|
||||
rescue
|
||||
raise Error, "服务器错误,请联系系统管理员!"
|
||||
end
|
||||
|
@ -33,17 +33,21 @@ class Api::V1::Issues::Journals::ListService < ApplicationService
|
|||
|
||||
@queried_journals = issue.journals
|
||||
|
||||
case category
|
||||
when 'comment'
|
||||
@queried_journals = issue.comment_journals
|
||||
when 'operate'
|
||||
@queried_journals = issue.operate_journals
|
||||
end
|
||||
|
||||
@queried_journals = @queried_journals.parent_journals
|
||||
|
||||
@queried_journals = @queried_journals.ransack(notes_cont: keyword).result if keyword.present?
|
||||
|
||||
@total_journals_count = queried_journals.distinct.size
|
||||
@total_operate_journals_count = @queried_journals.where(notes: nil).distinct.size
|
||||
@total_comment_journals_count = @queried_journals.where.not(notes: nil).distinct.size
|
||||
|
||||
case category
|
||||
when 'comment'
|
||||
@queried_journals = @queried_journals.where.not(notes: nil)
|
||||
when 'operate'
|
||||
@queried_journals = @queried_journals.where(notes: nil)
|
||||
end
|
||||
|
||||
@queried_journals = @queried_journals.includes(:journal_details, :user, :attachments, first_ten_children_journals: [:parent_journal, :reply_journal])
|
||||
@queried_journals = @queried_journals.reorder("journals.#{sort_by} #{sort_direction}").distinct
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
json.total_journals_count @total_journals_count
|
||||
json.total_operate_journals_count @total_operate_journals_count
|
||||
json.total_comment_journals_count @total_comment_journals_count
|
||||
json.total_count @journals.total_count
|
||||
json.journals @journals do |journal|
|
||||
json.partial! "detail", journal: journal
|
||||
|
|
Loading…
Reference in New Issue