Skip to content

Commit cb613f6

Browse files
author
Milan C
committed
Init Sortable links.
1 parent 435e09a commit cb613f6

File tree

14 files changed

+149
-11
lines changed

14 files changed

+149
-11
lines changed

app/Http/Controllers/UserController.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,50 @@ public function addLink(request $request)
134134
$links->title = $title;
135135
$links->button_id = $buttonId;
136136
$links->save();
137+
$links->order = (intval($links->id) - 1);
138+
$links->save();
137139

138140
return back();
139141
}
140142

143+
public function sortLinks(Request $request)
144+
{
145+
$linkOrders = $request->input("linkOrders", []);
146+
$currentPage = $request->input("currentPage", 1);
147+
$perPage = $request->input("perPage", 0);
148+
149+
if ($perPage == 0) {
150+
$currentPage = 1;
151+
}
152+
153+
$linkOrders = array_unique(array_filter($linkOrders));
154+
if (!$linkOrders || $currentPage < 1) {
155+
return response()->json([
156+
'status' => 'ERROR',
157+
]);
158+
}
159+
160+
$newOrder = $startLinkOrder = $perPage * ($currentPage - 1);
161+
$linkNewOrders = [];
162+
foreach ($linkOrders as $linkId) {
163+
if ($linkId < 0) {
164+
continue;
165+
}
166+
167+
$linkNewOrders[$linkId] = $newOrder;
168+
Link::where("id", $linkId)
169+
->update([
170+
'order' => $newOrder
171+
]);
172+
$newOrder++;
173+
}
174+
175+
return response()->json([
176+
'status' => 'OK',
177+
'linkOrders' => $linkNewOrders,
178+
]);
179+
}
180+
141181
//Count the number of clicks and redirect to link
142182
public function clickNumber(request $request)
143183
{
@@ -165,6 +205,7 @@ public function clickNumber(request $request)
165205
public function showLinks()
166206
{
167207
$userId = Auth::user()->id;
208+
$data['pagePage'] = 10;
168209

169210
$data['links'] = Link::select('id', 'link', 'title', 'order', 'click_number', 'up_link', 'links.button_id')->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(10);
170211
return view('studio/links', $data);
@@ -174,6 +215,7 @@ public function showLinks()
174215
public function showLinks20()
175216
{
176217
$userId = Auth::user()->id;
218+
$data['pagePage'] = 20;
177219

178220
$data['links'] = Link::select('id', 'link', 'title', 'order', 'click_number', 'up_link', 'links.button_id')->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(20);
179221
return view('studio/links', $data);
@@ -183,6 +225,7 @@ public function showLinks20()
183225
public function showLinks30()
184226
{
185227
$userId = Auth::user()->id;
228+
$data['pagePage'] = 30;
186229

187230
$data['links'] = Link::select('id', 'link', 'title', 'order', 'click_number', 'up_link', 'links.button_id')->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(30);
188231
return view('studio/links', $data);
@@ -192,6 +235,7 @@ public function showLinks30()
192235
public function showLinksAll()
193236
{
194237
$userId = Auth::user()->id;
238+
$data['pagePage'] = 0;
195239

196240
$data['links'] = Link::select('id', 'link', 'title', 'order', 'click_number', 'up_link', 'links.button_id')->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(10000000000);
197241
return view('studio/links', $data);

img/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
*
22
!.gitignore
3-
!user.png
3+
!user.png
4+
!drag-dark.png
5+
!drag.png
6+
!loading.gif

img/drag-dark.png

776 Bytes
Loading

img/drag.png

518 Bytes
Loading

img/loading.gif

5.41 KB
Loading

resources/views/layouts/sidebar.blade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@include('layouts.analytics')
88

99
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
10+
<meta name="csrf-token" content="{{ csrf_token() }}">
1011
<link rel="stylesheet" href="{{ asset('littlelink/css/hover-min.css') }}">
1112
<link rel="stylesheet" href="{{ asset('littlelink/css/animate.css') }}">
1213

@@ -376,6 +377,8 @@ function URL_event_exists(string $urlsb): bool
376377
<script src="{{ asset('/studio/js/jquery.min.js') }}"></script>
377378
<script src="{{ asset('/studio/js/popper.js') }}"></script>
378379
<script src="{{ asset('/studio/js/bootstrap.min.js') }}"></script>
380+
<script src="{{ asset('/studio/js/Sortable.min.js') }}"></script>
381+
<script src="{{ asset('/studio/js/jquery-block-ui.js') }}"></script>
379382
<script src="{{ asset('/studio/js/main-dashboard.js') }}"></script>
380383
381384
@stack('sidebar-scripts')

resources/views/studio/links.blade.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
<th scope="col">Delete</th>
3030
</tr>
3131
</thead>
32-
<tbody>
32+
<tbody id="links-table-body" data-page="{{request('page', 1)}}" data-per-page="{{$pagePage ? $pagePage : 0}}">
3333
@foreach($links as $link)
34-
<tr>
35-
<td title="{{ $link->link }}">{{ Str::limit($link->link, 30) }}</td>
34+
<tr data-id="{{$link->id}}">
35+
<td title="{{ $link->link }}"><span class="sortable-handle"></span> {{ Str::limit($link->link, 30) }}</td>
3636
<td title="{{ $link->title }}">{{ Str::limit($link->title, 30) }}</td>
3737
<td class="text-right">{{ $link->click_number }}</td>
3838
<td class="text-right">{{ $link->order }}</td>
@@ -50,6 +50,9 @@
5050
@endforeach
5151
</tbody>
5252
</table>
53+
<script type="text/javascript">
54+
const linksTableOrders = "{{ implode("|", $links->pluck('id')->toArray()) }}"
55+
</script>
5356
</div>
5457

5558
<ul class="pagination justify-content-center">

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
if(isset($_COOKIE['LinkCount'])){if($_COOKIE['LinkCount'] == '20'){$LinkPage = 'showLinks20';}elseif($_COOKIE['LinkCount'] == '30'){$LinkPage = 'showLinks30';}elseif($_COOKIE['LinkCount'] == 'all'){$LinkPage = 'showLinksAll';} else {$LinkPage = 'showLinks';}} else {$LinkPage = 'showLinks';} //Shows correct link number
7575
Route::get('/studio/index', [UserController::class, 'index'])->name('studioIndex');
7676
Route::get('/studio/add-link', [UserController::class, 'showButtons'])->name('showButtons');
77+
Route::post('/studio/sort-link', [UserController::class, 'sortLinks'])->name('sortLinks');
7778
Route::post('/studio/add-link', [UserController::class, 'addLink'])->name('addLink');
7879
Route::get('/studio/links', [UserController::class, $LinkPage])->name($LinkPage);
7980
Route::get('/studio/links/10', [UserController::class, 'showLinks'])->name('showLinks');

studio/css/style-dashboard-dark.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8317,4 +8317,13 @@ a[data-toggle="collapse"] {
83178317
background-color: #171a1d;
83188318
border-radius: 30px;
83198319
border: 3px none #ffffff;
8320-
}
8320+
}
8321+
8322+
.sortable-handle {
8323+
padding: 0px 12px;
8324+
margin-right: 5px;
8325+
cursor: grab;
8326+
cursor: -webkit-grabbing;
8327+
background-image: url("/img/drag-dark.png");
8328+
background-size: 22px;
8329+
}

studio/css/style-dashboard.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8317,4 +8317,13 @@ a[data-toggle="collapse"] {
83178317
background-color: #323232;
83188318
border-radius: 30px;
83198319
border: 3px none #ffffff;
8320-
}
8320+
}
8321+
8322+
.sortable-handle {
8323+
padding: 0px 12px;
8324+
margin-right: 5px;
8325+
cursor: grab;
8326+
cursor: -webkit-grabbing;
8327+
background-image: url("/img/drag.png");
8328+
background-size: 22px;
8329+
}

0 commit comments

Comments
 (0)