Skip to content

Commit

Permalink
Merge pull request #667 from Kovah/dev
Browse files Browse the repository at this point in the history
v1 Release
  • Loading branch information
Kovah authored Jul 20, 2023
2 parents 6e8b974 + d134903 commit b4670e3
Show file tree
Hide file tree
Showing 18 changed files with 1,126 additions and 7,816 deletions.
5 changes: 4 additions & 1 deletion app/Http/Controllers/Guest/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace App\Http\Controllers\Guest;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\HandlesQueryOrder;
use App\Models\Link;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;

class LinkController extends Controller
{
use HandlesQueryOrder;

/**
* Display an overview of all links.
*
Expand All @@ -21,7 +24,7 @@ public function index(Request $request): View
->with('tags');

$orderBy = $request->input('orderBy', 'created_at');
$orderDir = $request->input('orderDir', 'desc');
$orderDir = $this->getOrderDirection($request);
if ($orderBy === 'random') {
$links->inRandomOrder();
} else {
Expand Down
11 changes: 7 additions & 4 deletions app/Http/Controllers/Guest/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace App\Http\Controllers\Guest;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\HandlesQueryOrder;
use App\Models\LinkList;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;

class ListController extends Controller
{
use HandlesQueryOrder;

/**
* Display an overview of all lists.
*
Expand All @@ -21,14 +24,14 @@ public function index(Request $request): View
->withCount('links')
->orderBy(
$request->input('orderBy', 'name'),
$request->input('orderDir', 'asc')
$this->getOrderDirection($request, 'asc')
)
->paginate(getPaginationLimit());

return view('guest.lists.index', [
'lists' => $lists,
'orderBy' => $request->input('orderBy', 'name'),
'orderDir' => $request->input('orderDir', 'asc'),
'orderDir' => $this->getOrderDirection($request, 'asc'),
]);
}

Expand All @@ -47,15 +50,15 @@ public function show(Request $request, int $listID): View
->publicOnly()
->orderBy(
$request->input('orderBy', 'title'),
$request->input('orderDir', 'asc')
$this->getOrderDirection($request, 'asc')
)->paginate(getPaginationLimit());

return view('guest.lists.show', [
'list' => $list,
'listLinks' => $links,
'route' => $request->getBaseUrl(),
'orderBy' => $request->input('orderBy', 'title'),
'orderDir' => $request->input('orderDir', 'asc'),
'orderDir' => $this->getOrderDirection($request, 'asc'),
]);
}
}
7 changes: 5 additions & 2 deletions app/Http/Controllers/Guest/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace App\Http\Controllers\Guest;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\HandlesQueryOrder;
use App\Models\Tag;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;

class TagController extends Controller
{
use HandlesQueryOrder;

/**
* Display an overview of all lists.
*
Expand All @@ -21,15 +24,15 @@ public function index(Request $request): View
->withCount('links')
->orderBy(
$request->input('orderBy', 'name'),
$request->input('orderDir', 'asc')
$this->getOrderDirection($request, 'asc')
)
->paginate(getPaginationLimit());

return view('guest.tags.index', [
'tags' => $tags,
'route' => $request->getBaseUrl(),
'orderBy' => $request->input('orderBy', 'name'),
'orderDir' => $request->input('orderDir', 'asc'),
'orderDir' => $this->getOrderDirection($request, 'asc'),
]);
}

Expand Down
8 changes: 5 additions & 3 deletions app/Http/Controllers/Models/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Models;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\HandlesQueryOrder;
use App\Http\Requests\Models\LinkStoreRequest;
use App\Http\Requests\Models\LinkToggleCheckRequest;
use App\Http\Requests\Models\LinkUpdateRequest;
Expand All @@ -15,6 +16,8 @@

class LinkController extends Controller
{
use HandlesQueryOrder;

/**
* Display a listing of the resource.
*
Expand All @@ -24,13 +27,12 @@ class LinkController extends Controller
public function index(Request $request): View
{
$orderBy = $request->input('orderBy', session()->get('links.index.orderBy', 'created_at'));
$orderDir = $request->input('orderDir', session()->get('links.index.orderDir', 'desc'));
$orderDir = $this->getOrderDirection($request, session()->get('links.index.orderDir', 'desc'));

session()->put('links.index.orderBy', $orderBy);
session()->put('links.index.orderDir', $orderDir);

$links = Link::byUser()
->with('tags');
$links = Link::byUser()->with('tags');

if ($orderBy === 'random') {
$links->inRandomOrder();
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/Models/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Models;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\HandlesQueryOrder;
use App\Http\Requests\Models\ListStoreRequest;
use App\Http\Requests\Models\ListUpdateRequest;
use App\Models\LinkList;
Expand All @@ -14,6 +15,8 @@

class ListController extends Controller
{
use HandlesQueryOrder;

/**
* Display a listing of the resource.
*
Expand All @@ -23,7 +26,7 @@ class ListController extends Controller
public function index(Request $request): View
{
$orderBy = $request->input('orderBy', session()->get('lists.index.orderBy', 'name'));
$orderDir = $request->input('orderDir', session()->get('lists.index.orderDir', 'asc'));
$orderDir = $this->getOrderDirection($request, session()->get('lists.index.orderDir', 'asc'));

session()->put('lists.index.orderBy', $orderBy);
session()->put('lists.index.orderDir', $orderDir);
Expand Down
9 changes: 6 additions & 3 deletions app/Http/Controllers/Models/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Models;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\HandlesQueryOrder;
use App\Http\Requests\Models\TagStoreRequest;
use App\Http\Requests\Models\TagUpdateRequest;
use App\Models\Tag;
Expand All @@ -14,6 +15,8 @@

class TagController extends Controller
{
use HandlesQueryOrder;

/**
* Display a listing of the resource.
*
Expand All @@ -23,7 +26,7 @@ class TagController extends Controller
public function index(Request $request): View
{
$orderBy = $request->input('orderBy', session()->get('tags.index.orderBy', 'name'));
$orderDir = $request->input('orderDir', session()->get('tags.index.orderDir', 'asc'));
$orderDir = $this->getOrderDirection($request, session()->get('tags.index.orderDir', 'asc'));

session()->put('tags.index.orderBy', $orderBy);
session()->put('tags.index.orderDir', $orderDir);
Expand Down Expand Up @@ -91,7 +94,7 @@ public function show(Request $request, Tag $tag): View
$links = $tag->links()->byUser()
->orderBy(
$request->input('orderBy', 'created_at'),
$request->input('orderDir', 'desc')
$this->getOrderDirection($request),
)
->paginate(getPaginationLimit());

Expand All @@ -100,7 +103,7 @@ public function show(Request $request, Tag $tag): View
'tagLinks' => $links,
'route' => $request->getBaseUrl(),
'orderBy' => $request->input('orderBy', 'created_at'),
'orderDir' => $request->input('orderDir', 'desc'),
'orderDir' => $this->getOrderDirection($request),
]);
}

Expand Down
14 changes: 14 additions & 0 deletions app/Http/Controllers/Traits/HandlesQueryOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Controllers\Traits;

use Illuminate\Http\Request;

trait HandlesQueryOrder
{
protected function getOrderDirection(Request $request, $default = 'desc'): string
{
$dir = $request->input('orderDir');
return in_array($dir, ['asc', 'desc']) ? $dir : $default;
}
}
Loading

0 comments on commit b4670e3

Please sign in to comment.