* [#247] Filters conversation by status * Fixes conversation finder specs * [#248] Paginates conversation * Use method name in description * Move page to default param, add filters on frontend * Fix code climate issues
This commit is contained in:
@@ -6,6 +6,8 @@ class ConversationFinder
|
||||
ASSIGNEE_TYPES_BY_ID = ASSIGNEE_TYPES.invert
|
||||
ASSIGNEE_TYPES_BY_ID.default = :me
|
||||
|
||||
DEFAULT_STATUS = 'open'.freeze
|
||||
|
||||
# assumptions
|
||||
# inbox_id if not given, take from all conversations, else specific to inbox
|
||||
# assignee_type if not given, take 'me'
|
||||
@@ -15,7 +17,7 @@ class ConversationFinder
|
||||
# {conversations: [array of conversations], count: {open: count, resolved: count}}
|
||||
|
||||
# params
|
||||
# assignee_type_id, inbox_id, :conversation_status_id,
|
||||
# assignee_type_id, inbox_id, :status
|
||||
|
||||
def initialize(current_user, params)
|
||||
@current_user = current_user
|
||||
@@ -27,12 +29,21 @@ class ConversationFinder
|
||||
set_inboxes
|
||||
set_assignee_type
|
||||
|
||||
find_all_conversations # find all with the inbox
|
||||
filter_by_assignee_type # filter by assignee
|
||||
open_count, resolved_count = set_count_for_all_conversations # fetch count for both before filtering by status
|
||||
find_all_conversations
|
||||
filter_by_status
|
||||
|
||||
{ conversations: @conversations.latest,
|
||||
count: { open: open_count, resolved: resolved_count } }
|
||||
mine_count, unassigned_count, all_count = set_count_for_all_conversations
|
||||
|
||||
filter_by_assignee_type
|
||||
|
||||
{
|
||||
conversations: conversations,
|
||||
count: {
|
||||
mine_count: mine_count,
|
||||
unassigned_count: unassigned_count,
|
||||
all_count: all_count
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
@@ -69,7 +80,23 @@ class ConversationFinder
|
||||
@conversations
|
||||
end
|
||||
|
||||
def filter_by_status
|
||||
@conversations = @conversations.where(status: params[:status] || DEFAULT_STATUS)
|
||||
end
|
||||
|
||||
def set_count_for_all_conversations
|
||||
[@conversations.open.count, @conversations.resolved.count]
|
||||
[
|
||||
@conversations.assigned_to(current_user).count,
|
||||
@conversations.unassigned.count,
|
||||
@conversations.count
|
||||
]
|
||||
end
|
||||
|
||||
def current_page
|
||||
params[:page]
|
||||
end
|
||||
|
||||
def conversations
|
||||
current_page ? @conversations.latest.page(current_page) : @conversations.latest
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user