Skip to content

Users admin table #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Controllers/Cpanel/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class DashboardController extends Controller
{
public function home()
public function __invoke()
{
$users = Cache::remember('new-members', now()->addHour(), fn () => User::verifiedUsers()->latest()->limit(15)->get());
$latestArticles = Cache::remember('last-posts', now()->addHour(), fn () => Article::latest()->limit(2)->get());
Expand Down
16 changes: 16 additions & 0 deletions app/Http/Controllers/Cpanel/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Controllers\Cpanel;

use App\Http\Controllers\Controller;
use App\Models\User;

class UserController extends Controller
{
public function __invoke()
{
return view('cpanel.users.index', [
'users' => User::verifiedUsers()->latest()->paginate(15),
]);
}
}
14 changes: 14 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class User extends Authenticatable implements MustVerifyEmail, HasMedia
*/
protected $appends = [
'profile_photo_url',
'roles_label',
];

public function hasProvider($provider): bool
Expand All @@ -96,6 +97,19 @@ public function hasProvider($provider): bool
return false;
}

public function getRolesLabelAttribute(): string
{
$roles = $this->getRoleNames()->toArray();

if (count($roles)) {
return implode(', ', array_map(function ($item) {
return ucwords($item);
}, $roles));
}

return 'N/A';
}

public function isAdmin(): bool
{
return $this->hasRole('admin');
Expand Down
2 changes: 1 addition & 1 deletion app/Widgets/RecentNumbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function run()
'count' => $totalViews,
'increase' => $difference > 0,
'decreased' => $difference < 0,
'current' => $differenceViews,
'current' => max($differenceViews, 0),
],
]);
}
Expand Down
2 changes: 1 addition & 1 deletion public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/app.js": "/js/app.js?id=3bd7a17ae8879cea08888521628605ff",
"/css/app.css": "/css/app.css?id=98fe644f6b48d5830bf4c4551fd7f65e"
"/css/app.css": "/css/app.css?id=d4494514b4272e25cc1fd3f9575bdb47"
}
2 changes: 1 addition & 1 deletion resources/views/components/layouts/admin-menu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<a href="{{ route('cpanel.home') }}" class="text-sm font-medium rounded-md py-2 px-3 inline-flex items-center {{ active(['cpanel.home'], 'bg-green-50 text-green-800', 'text-skin-base hover:bg-skin-card-muted hover:text-skin-inverted') }}" aria-current="page" x-state:on="Current" x-state:off="Default">
{{ __('Tableau de bord') }}
</a>
<a href="#" class="text-sm font-medium rounded-md py-2 px-3 inline-flex items-center {{ active(['users*'], 'bg-green-50 text-green-800', 'text-skin-base hover:bg-skin-card-muted hover:text-skin-inverted') }}">
<a href="{{ route('cpanel.users.browse') }}" class="text-sm font-medium rounded-md py-2 px-3 inline-flex items-center {{ active(['cpanel.users*'], 'bg-green-50 text-green-800', 'text-skin-base hover:bg-skin-card-muted hover:text-skin-inverted') }}">
{{ __('Utilisateurs') }}
</a>
<a href="#" class="text-sm font-medium rounded-md py-2 px-3 inline-flex items-center {{ active(['categories*'], 'bg-green-50 text-green-800', 'text-skin-base hover:bg-skin-card-muted hover:text-skin-inverted') }}">
Expand Down
73 changes: 73 additions & 0 deletions resources/views/cpanel/users/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<x-layouts.cp title="Tableau de bord">
<x-container class="max-w-7xl mx-auto px-4 sm:px-6">
<div>
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<h1 class="text-xl font-semibold text-skin-inverted">{{ __('Utilisateurs') }}</h1>
<p class="mt-2 text-sm text-skin-inverted-muted">{{ __('Une liste de tous les utilisateurs de votre compte, avec leur nom, leur titre, leur email et leur rôle.') }}</p>
</div>
<div class="mt-4 sm:mt-0 sm:ml-16 sm:flex-none">
<x-button type="button">{{ __('Inviter') }}</x-button>
</div>
</div>
<div class="mt-8 flex flex-col">
<div class="-my-2 -mx-4 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle md:px-6 lg:px-8">
<div class="overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg">
<table class="min-w-full divide-y divide-skin-base">
<thead class="bg-skin-card-muted">
<tr>
<th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-skin-inverted sm:pl-6">{{ __('Nom') }}</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-skin-inverted">{{ __('Email') }}</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-skin-inverted">{{ __('Role') }}</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-skin-inverted">{{ __('Inscription') }}</th>
<th scope="col" class="relative py-3.5 pl-3 pr-4 sm:pr-6">
<span class="sr-only">{{ __('Éditer') }}</span>
</th>
</tr>
</thead>
<tbody class="divide-y divide-skin-input bg-skin-menu">
@foreach($users as $user)
<tr>
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-skin-inverted sm:pl-6">
<div class="flex items-center">
<div class="h-10 w-10 flex-shrink-0">
<img class="h-10 w-10 rounded-full" src="{{ $user->profile_photo_url }}" alt="{{ $user->username }}">
</div>
<div class="ml-4">
<div class="flex items-center font-medium text-skin-inverted">
{{ $user->name }}
@if($user->isLoggedInUser())
<span class="ml-2 inline-flex items-center px-1.5 py-0.5 rounded-full text-xs font-medium leading-none bg-green-50 text-green-800">
{{ __('Moi') }}
</span>
@endif
</div>
<div class="text-skin-base">{{ $user->username }}</div>
</div>
</div>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-skin-base">{{ $user->email }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-skin-base">{{ $user->roles_label }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-skin-base">{{ $user->created_at->diffForHumans() }}</td>
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6">
@if(! $user->isLoggedInUser())
<a href="#" class="text-green-600 hover:text-green-900">{{ __('Afficher') }}<span class="sr-only">, {{ $user->name }}</span></a>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>

<div class="mt-6">
{{ $users->links() }}
</div>
</div>

</x-container>
</x-layouts.cp>
6 changes: 5 additions & 1 deletion routes/cpanel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

use App\Http\Controllers\Cpanel\DashboardController;
use App\Http\Controllers\Cpanel\UserController;
use Illuminate\Support\Facades\Route;

Route::redirect('/', 'cpanel/home');
Route::get('/home', [DashboardController::class, 'home'])->name('home');
Route::get('/home', DashboardController::class)->name('home');
Route::prefix('users')->as('users.')->group(function () {
Route::get('/', UserController::class)->name('browse');
});