thekordy / ticketit

A simple helpdesk tickets system for Laravel 5.1+ which integrates smoothly with Laravel default users and auth system, demo is available at: http://ticketit.kordy.info/tickets
MIT License
875 stars 387 forks source link

Sorting on agent in datatables fix #551

Open DJLemstra opened 4 years ago

DJLemstra commented 4 years ago

It is not possible to sort on agent in the current version.

To fix:

In /src/Views/bootstrap4/index.blade.php change:

 columns: [
                { data: 'id', name: 'ticketit.id' },
                { data: 'subject', name: 'subject' },
                { data: 'status', name: 'ticketit_statuses.name' },
                { data: 'updated_at', name: 'ticketit.updated_at' },
                { data: 'agent', name: 'users.name' },
                @if( $u->isAgent() || $u->isAdmin() )
                    { data: 'priority', name: 'ticketit_priorities.name' },
                    { data: 'owner', name: 'users.name' },
                    { data: 'category', name: 'ticketit_categories.name' }
                @endif
            ]

to

            columns: [
                { data: 'id', name: 'ticketit.id' },
                { data: 'subject', name: 'subject' },
                { data: 'status', name: 'ticketit_statuses.name' },
                { data: 'updated_at', name: 'ticketit.updated_at' },
                    { data: 'agent', name: 'ticketit.agent_id' },
                @if( $u->isAgent() || $u->isAdmin() )
                    { data: 'priority', name: 'ticketit_priorities.name' },
                    { data: 'owner', name: 'users.name' },
                    { data: 'category', name: 'ticketit_categories.name' }
                @endif
            ]

In src/Controllers/TicketsController.php change:

        $collection
            ->join('users', 'users.id', '=', 'ticketit.user_id')
            ->join('ticketit_statuses', 'ticketit_statuses.id', '=', 'ticketit.status_id')
            ->join('ticketit_priorities', 'ticketit_priorities.id', '=', 'ticketit.priority_id')
            ->join('ticketit_categories', 'ticketit_categories.id', '=', 'ticketit.category_id')
            ->select([
                'ticketit.id',
                'ticketit.subject AS subject',
                'ticketit_statuses.name AS status',
                'ticketit_statuses.color AS color_status',
                'ticketit_priorities.color AS color_priority',
                'ticketit_categories.color AS color_category',
                'ticketit.id AS agent',
                'ticketit.updated_at AS updated_at',
                'ticketit_priorities.name AS priority',
                'users.name AS owner',
                'ticketit.agent_id',
                'ticketit_categories.name AS category',
            ]);

to:

        $collection
            ->join('users', 'users.id', '=', 'ticketit.user_id')
            ->join('ticketit_statuses', 'ticketit_statuses.id', '=', 'ticketit.status_id')
            ->join('ticketit_priorities', 'ticketit_priorities.id', '=', 'ticketit.priority_id')
            ->join('ticketit_categories', 'ticketit_categories.id', '=', 'ticketit.category_id')
            ->select([
                'ticketit.id',
                'ticketit.subject AS subject',
                'ticketit_statuses.name AS status',
                'ticketit_statuses.color AS color_status',
                'ticketit_priorities.color AS color_priority',
                'ticketit_categories.color AS color_category',
                'ticketit.updated_at AS updated_at',
                'ticketit_priorities.name AS priority',
                'users.name AS owner',
                'ticketit.agent_id AS agent',
                'ticketit_categories.name AS category',
            ]);