Ticket sort and paginator

This commit is contained in:
Jérémy Munsch 2021-04-15 16:47:57 +02:00
parent 269f860917
commit 6ecb6216e0
5 changed files with 112 additions and 8 deletions

View file

@ -18,9 +18,39 @@ class TicketController extends Controller
{
private $status = [1 => "Nouveau", 2 => "En cours", 3 => "Traité", 4 => "Archivé"];
public function index() {
public function index(Request $request)
{
if (Auth::check()) {
$tickets = Ticket::where('status', '<>', 4)->get();
$tickets = Ticket::where('status', '<>', 4);
$sortway = $request->sort_way == 'asc' ? 'asc' : null;
$sortway = $request->sort_way == 'desc' ? 'desc' : null;
if ($request->sort_col and $sortway) {
switch ($request->sort_col) {
case 'id':
$tickets = $tickets->orderBy('id', $sortway);
break;
case 'project':
$tickets = $tickets->orderBy('project_id', $sortway);
break;
case 'created_at':
$tickets = $tickets->orderBy('created_at', $sortway);
break;
case 'created_by':
$tickets = $tickets->orderBy('created_by', $sortway);
break;
case 'type':
$tickets = $tickets->orderBy('type', $sortway);
break;
case 'status':
$tickets = $tickets->orderBy('status', $sortway);
break;
}
}
$tickets = $tickets->paginate();
$status = $this->status;
return view('home', compact('tickets', 'status'));
} else {

View file

@ -2,6 +2,7 @@
namespace App\Providers;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@ -23,6 +24,7 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
Paginator::useBootstrap();
if(config('app.env') !== 'local') {
\URL::forceScheme('https');
}

50
config/trustedproxy.php Normal file
View file

@ -0,0 +1,50 @@
<?php
return [
/*
* Set trusted proxy IP addresses.
*
* Both IPv4 and IPv6 addresses are
* supported, along with CIDR notation.
*
* The "*" character is syntactic sugar
* within TrustedProxy to trust any proxy
* that connects directly to your server,
* a requirement when you cannot know the address
* of your proxy (e.g. if using ELB or similar).
*
*/
'proxies' => '*', // [<ip addresses>,], '*', '<ip addresses>,'
/*
* To trust one or more specific proxies that connect
* directly to your server, use an array or a string separated by comma of IP addresses:
*/
// 'proxies' => ['192.168.1.1'],
// 'proxies' => '192.168.1.1, 192.168.1.2',
/*
* Or, to trust all proxies that connect
* directly to your server, use a "*"
*/
// 'proxies' => '*',
/*
* Which headers to use to detect proxy related data (For, Host, Proto, Port)
*
* Options include:
*
* - Illuminate\Http\Request::HEADER_X_FORWARDED_ALL (use all x-forwarded-* headers to establish trust)
* - Illuminate\Http\Request::HEADER_FORWARDED (use the FORWARDED header to establish trust)
* - Illuminate\Http\Request::HEADER_X_FORWARDED_AWS_ELB (If you are using AWS Elastic Load Balancer)
*
* - 'HEADER_X_FORWARDED_ALL' (use all x-forwarded-* headers to establish trust)
* - 'HEADER_FORWARDED' (use the FORWARDED header to establish trust)
* - 'HEADER_X_FORWARDED_AWS_ELB' (If you are using AWS Elastic Load Balancer)
*
* @link https://symfony.com/doc/current/deployment/proxies.html
*/
'headers' => Illuminate\Http\Request::HEADER_X_FORWARDED_ALL,
];

View file

@ -8,14 +8,29 @@
<h2>Gestion des tickets<a href="{{ route('create-ticket') }}" class="float-right btn btn-sm btn-primary">Créer un ticket</a></h2>
<table class="table table-hover">
<thead>
<th scope="col">#</th>
<th scope="col">Projet</th>
<th scope="col">Type</th>
<th scope="col">
#&nbsp;
@include('modules.sorter', ['colname' => 'id'])
</th>
<th scope="col">
Projet&nbsp;
@include('modules.sorter', ['colname' => 'project'])
</th>
<th scope="col">
Type&nbsp;
@include('modules.sorter', ['colname' => 'type'])</th>
<th scope="col">Fichier</th>
<th scope="col">Fichier 2</th>
<th scope="col">Date de création</th>
<th scope="col">Créer par</th>
<th scope="col">Status</th>
<th scope="col">
Date de création&nbsp;
@include('modules.sorter', ['colname' => 'created_at'])</th>
<th scope="col">
Créé par&nbsp;
@include('modules.sorter', ['colname' => 'created_by'])</th>
<th scope="col">
Status&nbsp;
@include('modules.sorter', ['colname' => 'status'])
</th>
<th scope="col">Contenu</th>
@if (Auth::user()->role === 1)
<th></th>
@ -90,6 +105,7 @@
@endforeach
</tbody>
</table>
{{ $tickets->withQueryString()->links() }}
@else
<h2>Bienvenue sur le support LDC WEB.</h2>
<p>Pour consulter vos tickets, merci de vous connecter : <a href="{{ route('login') }}">Connexion</a></p>

View file

@ -0,0 +1,6 @@
@if(!request('sort_way') or request('sort_col') !== $colname or (request('sort_way') === 'desc' and request('sort_col') === $colname))
<a class="col_sort asc" href="{{ route('home', ['sort_col' => $colname, 'sort_way' => 'asc']) }}">&darr;</a>
@endif
@if(!request('sort_way') or request('sort_col') !== $colname or (request('sort_way') === 'asc' and request('sort_col') === $colname))
<a class="col_sort desc" href="{{ route('home', ['sort_col' => $colname, 'sort_way' => 'desc']) }}">&uarr;</a>
@endif