Skip to content

Commit

Permalink
Allow to filter conversation by Assignee - closes #3641
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Jan 2, 2024
1 parent 7c7fc41 commit d311b40
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 26 deletions.
65 changes: 65 additions & 0 deletions app/Http/Controllers/ConversationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,14 @@ public function ajax(Request $request)
// Conversations navigation
case 'conversations_pagination':
if (!empty($request->filter)) {
// Filter conversations by Assigned To column in Search.
if (!empty($request->params['user_id']) && !empty($request->filter['f'])) {
$filter = $request->filter ?? [];
$filter['f']['assigned'] = (int)$request->params['user_id'];

$request->merge(['filter' => $filter]);
}

$response = $this->ajaxConversationsFilter($request, $response, $user);
} else {
$response = $this->ajaxConversationsPagination($request, $response, $user);
Expand Down Expand Up @@ -2374,6 +2382,8 @@ public function ajaxHtml(Request $request)
return $this->ajaxHtmlMoveConv();
case 'merge_conv':
return $this->ajaxHtmlMergeConv();
case 'assignee_filter':
return $this->ajaxAssigneeFilter();
case 'default_redirect':
return $this->ajaxHtmlDefaultRedirect();
}
Expand Down Expand Up @@ -2558,6 +2568,50 @@ public function ajaxHtmlMergeConv()
]);
}

/**
* Filter conversations by assignee.
*/
public function ajaxAssigneeFilter()
{
$users = collect([]);

$mailbox_id = Input::get('mailbox_id');
$user_id = Input::get('user_id');

$user = auth()->user();

if ($mailbox_id) {

$mailbox = Mailbox::find($mailbox_id);
if (!$mailbox) {
abort(404);
}
if (!$user->can('view', $mailbox)) {
\Helper::denyAccess();
}
// Show users having access to the mailbox.
$users = $mailbox->usersAssignable();
} else {
// Show users from all accessible mailboxes.
$mailboxes = $user->mailboxesCanView();
foreach ($mailboxes as $mailbox) {
$users = $users->merge($mailbox->usersAssignable())->unique('id');
}
}

if (!$users->contains('id', $user->id)) {
$users[] = $user;
}

// Sort by full name.
$users = User::sortUsers($users);

return view('conversations/ajax_html/assignee_filter', [
'users' => $users,
'user_id' => $user_id,
]);
}

/**
* Change default redirect for the mailbox.
*/
Expand Down Expand Up @@ -2707,6 +2761,11 @@ public function ajaxConversationsPagination(Request $request, $response, $user)

if (!$response['msg']) {
$query_conversations = Conversation::getQueryByFolder($folder, $user->id);

if (!empty($request->params['user_id'])) {
$query_conversations->where('conversations.user_id', (int)$request->params['user_id']);
}

$conversations = $folder->queryAddOrderBy($query_conversations)->paginate(Conversation::DEFAULT_LIST_SIZE, ['*'], 'page', $request->page);
}

Expand All @@ -2715,6 +2774,7 @@ public function ajaxConversationsPagination(Request $request, $response, $user)
$response['html'] = view('conversations/conversations_table', [
'folder' => $folder,
'conversations' => $conversations,
'params' => $request->params ?? [],
])->render();

return $response;
Expand Down Expand Up @@ -2977,6 +3037,7 @@ public function ajaxConversationsFilter(Request $request, $response, $user)
$response['html'] = view('conversations/conversations_table', [
'conversations' => $conversations,
'params' => $request->params ?? [],
'conversations_filter' => $request->filter['f'] ?? $request->filter ?? [],
])->render();

return $response;
Expand All @@ -3001,6 +3062,10 @@ public function conversationsFilterQuery($request, $user)
}
}

if (!empty($request->params['user_id'])) {
$query_conversations->where('conversations.user_id', (int)$request->params['user_id']);
}

return $query_conversations->paginate(Conversation::DEFAULT_LIST_SIZE);
}

Expand Down
1 change: 1 addition & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ public function mailboxSettings($mailbox_id)

return $settings;
}

/**
* Get IDs of mailboxes to which user has access.
*/
Expand Down
11 changes: 10 additions & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,8 @@ thead .conv-cb label {
display: block;
font-weight: bold;
}
.table-conversations th .conv-col-sort {
.table-conversations th .conv-col-sort,
.table-conversations th.conv-owner span {
cursor: pointer;
}
.table.table-conversations tbody td {
Expand Down Expand Up @@ -1577,6 +1578,14 @@ table.table-conversations td.conv-attachment {
/*.conv-subject-number {
display: none;
}*/
.conv-owner .glyphicon {
margin-left: 3px;
display: none;
}
.conv-owner:hover .glyphicon,
.conv-owner.filtered .glyphicon {
display: inline-block;
}
.conv-owner-mobile {
display: none;
font-weight: normal;
Expand Down
28 changes: 27 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,7 @@ function loadConversations(page, table, no_loader)
}
}

if (typeof(URL) != "undefined") {
if (typeof(URL) != "undefined" && getGlobalAttr('folder_id')) {
const url = new URL(window.location);
url.searchParams.set('page', page);
window.history.replaceState({}, '', url);
Expand Down Expand Up @@ -3106,6 +3106,32 @@ function initMergeConv()
});
}

// Filter conversations by Assignee
function initConvAssigneeFilter()
{
$(document).ready(function() {

$(".conv-assignee-filter:visible:first").change(function(e){
var user_id = $(this).val();
var table = $('.table-conversations:first');
table.attr('data-param_user_id', user_id);

if (user_id) {
table.children().find('.conv-owner:first').addClass('filtered');
} else {
table.children().find('.conv-owner:first').removeClass('filtered');
}

loadConversations();
closeAllModals();
});

$(".conv-assignee-filter-reset:visible:first").click(function(e){
$(".conv-assignee-filter:visible:first").val('').change();
});
});
}

function initMergeConvSelect()
{
$('.conv-merge-id').click(function() {
Expand Down
13 changes: 13 additions & 0 deletions resources/views/conversations/ajax_html/assignee_filter.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="form-group">
<div class="input-group input-group-lg">
<select class="form-control input-lg conv-assignee-filter">
<option value=""></option>
@foreach($users as $user)
<option value="{{ $user->id }}" @if ($user->id == $user_id) selected="selected" @endif>{{ $user->getFullName() }}</option>
@endforeach
</select>
<span class="input-group-btn">
<button class="btn btn-default btn-lg conv-assignee-filter-reset" type="button"><i class="glyphicon glyphicon-remove"></i></button>
</span>
</div>
</div>
68 changes: 45 additions & 23 deletions resources/views/conversations/conversations_table.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
@if (count($conversations))
@if (count($conversations) || (isset($params) && !empty($params['user_id'])))
@php
if (is_array($conversations)) {
$conversations = collect($conversations);
}
if (empty($folder)) {
// Create dummy folder
$folder = new App\Folder();
$folder->type = App\Folder::TYPE_ASSIGNED;
}
// Clean filter.
if (!empty($conversations_filter)) {
foreach ($conversations_filter as $i => $filter_value) {
if (is_array($filter_value)) {
unset($conversations_filter[$i]);
}
}
}
// Preload users and customers
App\Conversation::loadUsers($conversations);
Expand All @@ -22,6 +33,14 @@
$params = [];
}
// For customer profile.
if (!empty($params['no_customer'])) {
$no_customer = true;
}
if (!empty($params['no_checkboxes'])) {
$no_checkboxes = true;
}
// Sorting.
$sorting = App\Conversation::getConvTableSorting();
Expand Down Expand Up @@ -83,8 +102,9 @@
</span>
</th>
@if ($show_assigned)
<th class="conv-owner">
<span>{{ __("Assigned To") }}</span>
<th class="conv-owner fs-trigger-modal @if (!empty($params['user_id'])) filtered @endif" data-remote="{{ route('conversations.ajax_html', ['action' =>
'assignee_filter', 'mailbox_id' => (\Helper::isRoute('mailboxes.view.folder') ? $folder->mailbox_id : ''), 'user_id' => ($params['user_id'] ?? '')]) }}" data-trigger="modal" data-modal-title="{{ __("Assigned To") }}" data-modal-no-footer="true" data-modal-on-show="initConvAssigneeFilter">
<span>{{ __("Assigned To") }}<small class="glyphicon glyphicon-filter"></small></span>
</th>
{{--<th class="conv-owner dropdown">
<span {{--data-target="#"- -}} class="dropdown-toggle" data-toggle="dropdown">{{ __("Assigned To") }}</span>
Expand Down Expand Up @@ -190,28 +210,30 @@
@action('conversations_table.after_row', $conversation, $columns, $col_counter)
@endforeach
</tbody>
<tfoot>
<tr>
<td class="conv-totals" colspan="{{ $col_counter-3 }}">
@if ($conversations->total())
{!! __(':count conversations', ['count' => '<strong>'.$conversations->total().'</strong>']) !!}&nbsp;|&nbsp;
@endif
@if (isset($folder->active_count) && !$folder->isIndirect())
<strong>{{ $folder->getActiveCount() }}</strong> {{ __('active') }}&nbsp;|&nbsp;
@endif
@if ($conversations)
<strong>{{ $conversations->firstItem() }}</strong>-<strong>{{ $conversations->lastItem() }}</strong>
@endif
</td>
<td colspan="3" class="conv-nav">
<div class="table-pager">
@if (count($conversations))
<tfoot>
<tr>
<td class="conv-totals" colspan="{{ $col_counter-3 }}">
@if ($conversations->total())
{!! __(':count conversations', ['count' => '<strong>'.$conversations->total().'</strong>']) !!}&nbsp;|&nbsp;
@endif
@if (isset($folder->active_count) && !$folder->isIndirect())
<strong>{{ $folder->getActiveCount() }}</strong> {{ __('active') }}&nbsp;|&nbsp;
@endif
@if ($conversations)
{{ $conversations->links('conversations/conversations_pagination') }}
<strong>{{ $conversations->firstItem() }}</strong>-<strong>{{ $conversations->lastItem() }}</strong>
@endif
</div>
</td>
</tr>
</tfoot>
</td>
<td colspan="3" class="conv-nav">
<div class="table-pager">
@if ($conversations)
{{ $conversations->links('conversations/conversations_pagination') }}
@endif
</div>
</td>
</tr>
</tfoot>
@endif
</table>
@else
@include('partials/empty', ['empty_text' => __('There are no conversations here')])
Expand Down
2 changes: 1 addition & 1 deletion resources/views/customers/conversations.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@section('content')
@include('customers/profile_tabs')
@include('conversations/conversations_table', ['no_checkboxes' => true, 'no_customer' => true, 'conversations_filter' => ['customer_id' => $customer->id] ])
@include('conversations/conversations_table', ['params' => ['no_checkboxes' => 1, 'no_customer' => 1], 'conversations_filter' => ['customer_id' => $customer->id] ])
@endsection

@section('javascript')
Expand Down

0 comments on commit d311b40

Please sign in to comment.