Updated users table
Added new fields to the users table. Added ability to sort users table alphabetically.
This commit is contained in:
parent
b593b2ddfd
commit
5c26f1e8ab
|
@ -50,23 +50,33 @@ public function users(Request $request)
|
|||
|
||||
switch ($usersType) {
|
||||
case 'all':
|
||||
$users = User::select('id', 'name', 'email', 'littlelink_name', 'role', 'block', 'email_verified_at')->get();
|
||||
$users = User::select('id', 'name', 'email', 'littlelink_name', 'role', 'block', 'email_verified_at', 'created_at')->get();
|
||||
break;
|
||||
case 'user':
|
||||
$users = User::where('role', 'user')->select('id', 'email', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at')->get();
|
||||
$users = User::where('role', 'user')->select('id', 'email', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at', 'created_at')->get();
|
||||
break;
|
||||
case 'vip':
|
||||
$users = User::where('role', 'vip')->select('id', 'email', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at')->get();
|
||||
$users = User::where('role', 'vip')->select('id', 'email', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at', 'created_at')->get();
|
||||
break;
|
||||
case 'admin':
|
||||
$users = User::where('role', 'admin')->select('id', 'email', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at')->get();
|
||||
$users = User::where('role', 'admin')->select('id', 'email', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at', 'created_at')->get();
|
||||
break;
|
||||
}
|
||||
|
||||
$data['users'] = $users;
|
||||
|
||||
// Loop through each user to get their click count and link count
|
||||
foreach ($users as $user) {
|
||||
$clicks = Link::where('user_id', $user->id)->sum('click_number');
|
||||
$links = Link::where('user_id', $user->id)->select('link')->count();
|
||||
$user->clicks = $clicks;
|
||||
$user->links = $links;
|
||||
}
|
||||
|
||||
return view('panel/users', $data);
|
||||
}
|
||||
|
||||
|
||||
//Search user by name
|
||||
public function searchUser(Request $request)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
@section('content')
|
||||
|
||||
<style>.delete{color:transparent; background-color:tomato; border-radius:5px; padding:8px 12px; cursor: pointer;}.delete:hover{color:transparent;background-color:#f13d1d;}html,body{max-width:100%;overflow-x:hidden;}.shorten{cursor:help;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:200px;}</style>
|
||||
<style>#cs{cursor: pointer;}.delete{color:transparent; background-color:tomato; border-radius:5px; padding:8px 12px; cursor: pointer;}.delete:hover{color:transparent;background-color:#f13d1d;}html,body{max-width:100%;overflow-x:hidden;}.shorten{cursor:help;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:200px;}</style>
|
||||
|
||||
<section class="shadow text-gray-400">
|
||||
<h2 class="mb-4 card-header"><i class="bi bi-person"> Users</i></h2>
|
||||
|
@ -31,24 +31,36 @@
|
|||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Name</th>
|
||||
<th scope="col">E-Mail</th>
|
||||
<th scope="col">Page</th>
|
||||
<th scope="col">Role</th>
|
||||
<th scope="col">Edit</th>
|
||||
<th scope="col">Links</th>
|
||||
@if(env('REGISTER_AUTH') !== 'auth')<th style="width:15%" scope="col">E-Mail Verified</th>@endif
|
||||
<th scope="col">Block</th>
|
||||
<th scope="col" style="width:150px">Delete user</th>
|
||||
<th id="cs" scope="col" data-sort="id" data-order="asc">ID</th>
|
||||
<th id="cs" scope="col" data-sort="name" data-order="asc">Name</th>
|
||||
<th id="cs" scope="col" data-sort="email" data-order="asc">E-Mail</th>
|
||||
<th id="cs" scope="col" data-sort="page" data-order="asc">Page</th>
|
||||
<th id="cs" scope="col" data-sort="role" data-order="asc">Role</th>
|
||||
<th id="cs" scope="col" data-sort="links" data-order="asc">Total links</th>
|
||||
<th id="cs" scope="col" data-sort="clicks" data-order="asc">Total clicks</th>
|
||||
<th id="cs" scope="col" data-sort="created" data-order="asc">Created at</th>
|
||||
<th data-sortable="false">Edit</th>
|
||||
<th data-sortable="false">Links</th>
|
||||
@if(env('REGISTER_AUTH') !== 'auth')<th id="cs" style="width:15%" scope="col">E-Mail Verified</th>@endif
|
||||
<th id="cs" scope="col" data-sort="block" data-order="asc">Block</th>
|
||||
<th scope="col" style="width:150px" data-sortable="false">Delete user</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($users as $user)
|
||||
<?php
|
||||
$dateString = $user->created_at;
|
||||
$date = date('d.m.Y', strtotime($dateString));
|
||||
?>
|
||||
<tr>
|
||||
<td class="shorten" title="{{ $user->name }}"> {{ $user->name }} </td>
|
||||
<td class="shorten" title="{{ $user->email }}"> {{ $user->email }} </td>
|
||||
<td><a href="{{ url('') }}/@<?= $user->littlelink_name ?>" target="_blank" class="text-info"><i class="bi bi-box-arrow-up-right"></i> {{ $user->littlelink_name }} </a></td>
|
||||
<td>{{ $user->role }}</td>
|
||||
<td data-id>{{ $user->id }}</td>
|
||||
<td class="shorten" title="{{ $user->name }}" data-name> {{ $user->name }} </td>
|
||||
<td class="shorten" title="{{ $user->email }}" data-email> {{ $user->email }} </td>
|
||||
<td data-page>@if(isset($user->littlelink_name))<a href="{{ url('') }}/@<?= $user->littlelink_name ?>" target="_blank" class="text-info"><i class="bi bi-box-arrow-up-right"></i> {{ $user->littlelink_name }} </a>@else N/A @endif</td>
|
||||
<td data-role>{{ $user->role }}</td>
|
||||
<td data-links>{{$user->links}}</td>
|
||||
<td data-clicks>{{$user->clicks}}</td>
|
||||
<td data-created>{{$date}}</td>
|
||||
<td><a href="{{ route('editUser', $user->id ) }}">Edit</a></td>
|
||||
<td><a href="{{ route('showLinksUser', $user->id ) }}" class="text-primary">View</a></td>
|
||||
@if(env('REGISTER_AUTH') !== 'auth')
|
||||
|
@ -77,5 +89,50 @@
|
|||
|
||||
</div>
|
||||
</section>
|
||||
<script>
|
||||
const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;
|
||||
|
||||
@endsection
|
||||
const comparer = (idx, asc) => (a, b) =>
|
||||
((v1, v2) =>
|
||||
v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2)
|
||||
)(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx));
|
||||
|
||||
// Find the table and its headers
|
||||
const table = document.querySelector('table');
|
||||
const headers = table.querySelectorAll('th');
|
||||
|
||||
// Add caret icon to initial header element
|
||||
const initialHeader = table.querySelector('[data-order]');
|
||||
initialHeader.innerHTML = `${initialHeader.innerText} <i class="bi bi-caret-down-fill"></i>`;
|
||||
|
||||
// Attach click event listener to all headers
|
||||
headers.forEach(th => th.addEventListener('click', function() {
|
||||
// Get the clicked header's index, sort order, and sortable attribute
|
||||
const thIndex = Array.from(th.parentNode.children).indexOf(th);
|
||||
const isAscending = this.asc = !this.asc;
|
||||
const isSortable = th.getAttribute('data-sortable') !== 'false';
|
||||
|
||||
// If the column is not sortable, do nothing
|
||||
if (!isSortable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove caret icon and active class from all headers
|
||||
headers.forEach(h => {
|
||||
h.classList.remove('active');
|
||||
h.innerHTML = h.innerText;
|
||||
});
|
||||
|
||||
// Add caret icon and active class to clicked header
|
||||
th.classList.add('active');
|
||||
th.innerHTML = `${th.innerText} ${isAscending ? '<i class="bi bi-caret-down-fill"></i>' : '<i class="bi bi-caret-up-fill"></i>'}`;
|
||||
|
||||
// Sort the table rows based on the clicked header
|
||||
Array.from(table.querySelectorAll('tr:nth-child(n+2)'))
|
||||
.sort(comparer(thIndex, isAscending))
|
||||
.forEach(tr => table.appendChild(tr));
|
||||
}));
|
||||
</script>
|
||||
|
||||
|
||||
@endsection
|
Loading…
Reference in New Issue