Skip to content

Commit 059e0fc

Browse files
committed
Bug correction in pagination and some refactoring
1 parent 4c36e40 commit 059e0fc

File tree

5 files changed

+66
-30
lines changed

5 files changed

+66
-30
lines changed

app/Http/Controllers/BlogController.php

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
$this->nbrPages = 2;
4747

4848
$this->middleware('redac', ['except' => ['indexFront', 'show', 'tag', 'search']]);
49-
$this->middleware('ajax', ['only' => ['indexOrder', 'updateSeen', 'updateActive']]);
49+
$this->middleware('ajax', ['only' => ['updateSeen', 'updateActive']]);
5050
}
5151

5252
/**
@@ -57,25 +57,22 @@ public function __construct(
5757
public function indexFront()
5858
{
5959
$posts = $this->blog_gestion->indexFront($this->nbrPages);
60-
$links = str_replace('/?', '?', $posts->render());
60+
$links = $posts->setPath('')->render();
6161

6262
return view('front.blog.index', compact('posts', 'links'));
6363
}
6464

6565
/**
6666
* Display a listing of the resource.
6767
*
68-
* @param Illuminate\Contracts\Auth\Guard $auth
69-
* @return Response
68+
* @return Redirection
7069
*/
71-
public function index(Guard $auth)
70+
public function index()
7271
{
73-
$statut = $this->user_gestion->getStatut();
74-
$posts = $this->blog_gestion->index(10, $statut == 'admin' ? null : $auth->user()->id);
75-
76-
$links = str_replace('/?', '?', $posts->render());
77-
78-
return view('back.blog.index', compact('posts', 'links'));
72+
return redirect(route('blog.order', [
73+
'name' => 'created_at',
74+
'sens' => 'asc'
75+
]));
7976
}
8077

8178
/**
@@ -87,14 +84,28 @@ public function index(Guard $auth)
8784
public function indexOrder(Request $request)
8885
{
8986
$statut = $this->user_gestion->getStatut();
90-
$posts = $this->blog_gestion->index(10, $statut == 'admin' ? null : $request->user()->id, $request->input('name'), $request->input('sens'));
87+
$posts = $this->blog_gestion->index(
88+
10,
89+
$statut == 'admin' ? null : $request->user()->id,
90+
$request->name,
91+
$request->sens
92+
);
9193

92-
$links = str_replace('/?', '?', $posts->render());
94+
$links = $posts->appends([
95+
'name' => $request->name,
96+
'sens' => $request->sens
97+
]);
98+
99+
if($request->ajax()) {
100+
return response()->json([
101+
'view' => view('back.blog.table', compact('statut', 'posts'))->render(),
102+
'links' => $links->setPath('order')->render()
103+
]);
104+
}
93105

94-
return response()->json([
95-
'view' => view('back.blog.table', compact('statut', 'posts'))->render(),
96-
'links' => $links
97-
]);
106+
$links->setPath('')->render();
107+
108+
return view('back.blog.index', compact('posts', 'links'));
98109
}
99110

100111
/**
@@ -225,7 +236,7 @@ public function tag(Request $request)
225236
{
226237
$tag = $request->input('tag');
227238
$posts = $this->blog_gestion->indexTag($this->nbrPages, $tag);
228-
$links = str_replace('/?', '?', $posts->appends(compact('tag'))->render());
239+
$links = $posts->setPath('')->appends(compact('tag'))->render();
229240
$info = trans('front/blog.info-tag') . '<strong>' . $this->blog_gestion->getTagById($tag) . '</strong>';
230241

231242
return view('front.blog.index', compact('posts', 'links', 'info'));
@@ -241,7 +252,7 @@ public function search(SearchRequest $request)
241252
{
242253
$search = $request->input('search');
243254
$posts = $this->blog_gestion->search($this->nbrPages, $search);
244-
$links = str_replace('/?', '?', $posts->appends(compact('search'))->render());
255+
$links = $posts->setPath('')->appends(compact('search'))->render();
245256
$info = trans('front/blog.info-search') . '<strong>' . $search . '</strong>';
246257

247258
return view('front.blog.index', compact('posts', 'links', 'info'));

app/Http/Controllers/CommentController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
public function index()
3939
{
4040
$comments = $this->comment_gestion->index(4);
41-
$links = str_replace('/?', '?', $comments->render());
41+
$links = $comments->setPath('')->render();
4242

4343
return view('back.comments.index', compact('comments', 'links'));
4444
}

app/Http/Controllers/UserController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private function indexGo($role, $ajax = false)
7474
{
7575
$counts = $this->user_gestion->counts();
7676
$users = $this->user_gestion->index(4, $role);
77-
$links = str_replace('/?', '?', $users->render());
77+
$links = $users->setPath('')->render();
7878
$roles = $this->role_gestion->all();
7979

8080
if($ajax)

app/Http/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
// Blog
26-
Route::get('blog/order', 'BlogController@indexOrder');
26+
Route::get('blog/order', ['uses' => 'BlogController@indexOrder', 'as' => 'blog.order']);
2727
Route::get('articles', 'BlogController@indexFront');
2828
Route::get('blog/tag', 'BlogController@tag');
2929
Route::get('blog/search', 'BlogController@search');

resources/views/back/blog/index.blade.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,37 @@
1717
<table class="table">
1818
<thead>
1919
<tr>
20-
<th>{{ trans('back/blog.title') }} <a href="#" name="title" class="order"><span class="fa fa-fw fa-unsorted"></lspan></a></th>
21-
<th>{{ trans('back/blog.date') }} <a href="#" name="created_at" class="order"><span class="fa fa-fw fa-sort-desc"></th>
22-
<th>{{ trans('back/blog.published') }} <a href="#" name="active" class="order"><span class="fa fa-fw fa-unsorted"></th>
20+
<th>
21+
{{ trans('back/blog.title') }}
22+
<a href="#" name="title" class="order">
23+
<span class="fa fa-fw fa-{{ Request::get('name') == 'title' ? Request::get('sens') : 'unsorted'}}"></span>
24+
</a>
25+
</th>
26+
<th>
27+
{{ trans('back/blog.date') }}
28+
<a href="#" name="created_at" class="order">
29+
<span class="fa fa-fw fa-{{ Request::get('name') == 'created_at' ? Request::get('sens') : 'unsorted'}}"></span>
30+
</a>
31+
</th>
32+
<th>
33+
{{ trans('back/blog.published') }}
34+
<a href="#" name="active" class="order">
35+
<span class="fa fa-fw fa-{{ Request::get('name') == 'active' ? Request::get('sens') : 'unsorted'}}"></span>
36+
</a>
37+
</th>
2338
@if(session('statut') == 'admin')
24-
<th>{{ trans('back/blog.author') }} <a href="#" name="username" class="order"><span class="fa fa-fw fa-unsorted"></th>
25-
<th>{{ trans('back/blog.seen') }} <a href="#" name="posts.seen" class="order"><span class="fa fa-fw fa-unsorted"></th>
39+
<th>
40+
{{ trans('back/blog.author') }}
41+
<a href="#" name="username" class="order">
42+
<span class="fa fa-fw fa-{{ Request::get('name') == 'username' ? Request::get('sens') : 'unsorted'}}"></span>
43+
</a>
44+
</th>
45+
<th>
46+
{{ trans('back/blog.seen') }}
47+
<a href="#" name="posts.seen" class="order">
48+
<span class="fa fa-fw fa-{{ Request::get('name') == 'posts.seen' ? Request::get('sens') : 'unsorted'}}"></span>
49+
</a>
50+
</th>
2651
@endif
2752
</tr>
2853
</thead>
@@ -51,7 +76,7 @@
5176
$(this).hide().parent().append('<i class="fa fa-refresh fa-spin"></i>');
5277
var token = $('input[name="_token"]').val();
5378
$.ajax({
54-
url: 'postseen/' + this.value,
79+
url: '{{ url('postseen') }}' + '/' + this.value,
5580
type: 'PUT',
5681
data: "seen=" + this.checked + "&_token=" + token
5782
})
@@ -72,7 +97,7 @@
7297
$(this).hide().parent().append('<i class="fa fa-refresh fa-spin"></i>');
7398
var token = $('input[name="_token"]').val();
7499
$.ajax({
75-
url: 'postactive/' + this.value,
100+
url: '{{ url('postactive') }}' + '/' + this.value,
76101
type: 'PUT',
77102
data: "active=" + this.checked + "&_token=" + token
78103
})
@@ -112,7 +137,7 @@
112137
$('.breadcrumb li').append('<span id="tempo" class="fa fa-refresh fa-spin"></span>');
113138
// Send ajax
114139
$.ajax({
115-
url: 'blog/order',
140+
url: '{{ url('blog/order') }}',
116141
type: 'GET',
117142
dataType: 'json',
118143
data: "name=" + $(this).attr('name') + "&sens=" + tri

0 commit comments

Comments
 (0)