Skip to content

Commit

Permalink
Tuning User table
Browse files Browse the repository at this point in the history
  • Loading branch information
hiamir committed Dec 12, 2022
1 parent 6763b02 commit 529ba0c
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 55 deletions.
6 changes: 3 additions & 3 deletions app/Actions/Permissions/PermissionSave.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class PermissionSave
*/
public function handle(Permission $permission):array
{
$permission= UserSanitizeData::run($permission);
$permission= PermissionSanitizeData::run($permission);
$data = $this->set('permission', $permission)->fill($permission->toArray());
Validator::make(
$data->attributes,
UserValidation::make()->rules($this->permission->id),
UserValidation::make()->messages(),
PermissionValidation::make()->rules($this->permission->id),
PermissionValidation::make()->messages(),
)->validate();
try {
$success = DB::transaction(function () use ($permission) {
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Permissions/PermissionSubmit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class PermissionSubmit
public function handle($thiss,$formType,$permission): void
{
$output = match ($formType) {
'create', 'update' => UserSave::run($permission),
'delete' => UserDelete::run($permission),
'create', 'update' => PermissionSave::run($permission),
'delete' => PermissionDelete::run($permission),
default => [],
};
$thiss->dispatchBrowserEvent('FirstModel', ['show' => false]);
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Users/UserModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function handle(User $user): array
$include=['Role','Permission'];
$exclude = ['Admin', 'Membership', 'Team', 'TeamInvitation'];
$array = [];
foreach (array_diff(array_merge($include,$models),$exclude) as $model) {
$array[$model] = $model;
foreach (array_diff(array_merge($include,$models),$exclude) as $modelData) {
$array[$modelData] = $modelData;
}
$models = $array;
if (auth()->guard('admin')->check()) {
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Users/UserSanitizeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace App\Actions\Users;

use App\Models\User;
use Lorisleiva\Actions\Concerns\AsAction;
use Lorisleiva\Actions\Concerns\WithAttributes;
use Spatie\Permission\Models\Permission;

class UserSanitizeData
{
use AsAction;
use withAttributes;

public function handle($data) :Permission{
public function handle($data) :User{
$data->name=strtolower($data->name);
return $data;
}
Expand Down
6 changes: 3 additions & 3 deletions app/Actions/Users/UserValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public function rules($id=null): array
];
}

public function validationAttributes($user): array
public function attributes($user): array
{
return [
'user.name' =>$user['name'],
'user.email' =>$user['email'],
];
}

Expand All @@ -30,7 +30,7 @@ public function messages(){
'user.name.min' => 'Permission must be at-least 4 letters long.',
'user.email.required' => 'Permission name is required.',
'user.email.email' => ':attribute must be valid email',
'user.email.unique' => ':attribute menu already exists!.',
'user.email.unique' => 'This email address ":attribute" already exists!.',
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use App\Traits\General;
use Livewire\Component;

class MenuParent extends Component
class Index extends Component
{
use General;
use Data;
Expand Down Expand Up @@ -55,6 +55,6 @@ public function submit()
public function render()
{
$menus = Menu::with('childMenus')->where('parent_id', '=', null)->orderBy('sort', 'ASC')->get();
return view('livewire.admin.menu.menu-parent', ['menus' => $menus]);
return view('livewire.admin.menu.index', ['menus' => $menus]);
}
}
13 changes: 10 additions & 3 deletions app/Http/Livewire/Admin/Users/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Index extends Component
/* UPDATING FIELD MAKE NAME FROM GUARD AND MODEL */
public function updated($variable, $value)
{
$this->disabled = UserValidation::make()->updated($this->user, $variable, $value);
$this->validateOnly('User.name');
// $this->disabled = UserValidation::make()->updated($this->user, $variable, $value);
$this->validateOnly('user.email');
}


Expand All @@ -41,9 +41,16 @@ public function mount()
/* INPUT RULES */
protected function rules(): array
{
return UserValidation::make()->rules();
return UserValidation::make()->rules($this->user->id);
}

protected function messages(){
return UserValidation::make()->messages();
}

protected function validationAttributes(){
return UserValidation::make()->attributes($this->user);
}

/* SHOW MODEL FOR CREATE, UPDATE, DELETE */
public function show($data)
Expand Down
110 changes: 79 additions & 31 deletions app/Http/Livewire/Admin/Users/UsersDatatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Livewire\Admin\Users;

use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;

Expand All @@ -21,15 +22,15 @@ class UsersDatatable extends DataTableComponent
public function configure(): void
{
$this->setPrimaryKey('id')
->setPerPageAccepted([10, 25, 50, 100])
->setPerPage(10)
->setSortingStatus(true)
->setSortingPillsStatus(false)
->setPageName('Roles')
->setPaginationVisibilityStatus(true)
->setPaginationStatus(true)
->setDefaultSort('id', 'desc')
->setQueryStringStatus(false)
// ->setPerPageAccepted([10, 25, 50, 100])
// ->setPerPage(10)
// ->setSortingStatus(true)
// ->setSortingPillsStatus(false)
//// ->setPageName('Users')
// ->setPaginationVisibilityStatus(true)
// ->setPaginationStatus(true)
// ->setDefaultSort('id', 'desc')
// ->setQueryStringStatus(false)
->setThAttributes(function (Column $column) {
if ($column->isField('id')) {
return [
Expand All @@ -39,13 +40,16 @@ public function configure(): void
return [
'class' => '!w-[20%] text-center',
];
}
elseif ($column->isField('email')) {
} elseif ($column->isField('email')) {
return [
'class' => '!w-[20%] !text-center',
];
} elseif ($column->isField('email_verified_at')) {
return [
'class' => '!w-[15%] text-center',
];
}
elseif ($column->isField('created_at')) {
elseif ($column->isField('created_at')) {
return [
'class' => '!w-[15%]',
];
Expand All @@ -62,43 +66,91 @@ public function configure(): void
return [];
})
->setThSortButtonAttributes(function (Column $column) {
if ($column->isField('created_at')) {
return [
'class' => 'mx-auto',
];
} elseif ($column->isField('updated_at')) {
if ($column->isField('email_verified_at') || $column->isField('created_at') || $column->isField('updated_at') ) {
return [
'class' => 'mx-auto',
];
}

return [];
})
->setTdAttributes(function (Column $column, $row, $columnIndex, $rowIndex) {
if ( $columnIndex === 4 || $columnIndex === 5) {
// if($columnIndex === 3 ){
// if($row->email_verified_at !== null){
// return [
// 'class' => '!bg-green-800',
// ];
// }
//
// }
if ($columnIndex === 3 || $columnIndex === 4 || $columnIndex === 5) {
return [
'class' => 'text-center',
];
}


return [];
})
->setUseHeaderAsFooterEnabled();
}


public function columns(): array
{
return [
Column::make("Id", "id")
Column::make('ID', 'id')
->sortable()
->setSortingPillTitle('Key')
->setSortingPillDirections('0-9', '9-0')
->html(),
Column::make('Name', 'name')
->searchable()
->sortable(),
Column::make("Name", "name")
->sortable()
->format( fn($value, $row, Column $column) => '<div class="flex flex-row justify-start items-center"> <img src="' . $row->profile_photo_url . '" alt="' . $row->name . '" class="flex rounded-full h-8 w-8 object-cover mr-2"><span class="flex">' . $row->name . '</span> </div>'
)->html(),
Column::make("Email", "email")
->searchable()
->sortable(),
Column::make("Model", "email")

// Column::make('Verified', 'email_verified_at')
// ->searchable()
// ->sortable()
// ->hideIf(request() === null)
// ->format( fn($value, $row, Column $column) => '
//
// <div class="inline-flex flex-row justify-start items-center text-xs py-1 px-3 pr-4 pl-3 bg-green-800 rounded-2xl gray-100 ">
// <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="flex mr-2 w-6 h-6">
// <path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
// </svg>
// <span class="flex">Verified</span>
// </div>
//
// '
// )->html(),

Column::make('Verified', 'email_verified_at')
->searchable()
->sortable(),
->sortable()
// ->hideIf($row->email_verified_at === null)
->format( fn($value, $row, Column $column) =>($row->email_verified_at ===null) ? '
<div class="inline-flex flex-row justify-start items-center text-xs py-1 px-2 pr-3 pl-2 bg-red-800 rounded-2xl gray-100 ">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="flex mr-2 w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<span class="flex">Not Verified</span>
</div>
' :
'
<div class="inline-flex flex-row justify-start items-center text-xs py-1 px-2 pr-3 pl-2 bg-green-800 rounded-2xl gray-100 ">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="flex mr-2 w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<span class="flex">Verified</span>
</div>
'
)->html(),

Column::make("Created at", "created_at")
->format(fn($value, $row, Column $column) => $row->created_at->diffForHumans())
->sortable(),
Expand All @@ -107,21 +159,17 @@ public function columns(): array
->sortable(),

Column::make('Action', 'ID')
->format(
fn($value, $row, Column $column) => '<div class="flex flex-row space-x-2"><span class="flex w-full"><svg wire:click.prevent="$emit(`show`,[`update`,' . $row . '])" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="cursor-pointer mx-auto w-5 h-5">
->format( fn($value, $row, Column $column) => '<div class="flex flex-row space-x-2"><span class="flex w-full"><svg wire:click.prevent="$emit(`show`,[`update`,' . $row . '])" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="cursor-pointer mx-auto w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L10.582 16.07a4.5 4.5 0 01-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 011.13-1.897l8.932-8.931zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0115.75 21H5.25A2.25 2.25 0 013 18.75V8.25A2.25 2.25 0 015.25 6H10" />
</svg></span>
<span class="flex w-full"><svg wire:click.prevent="$emit(`show`,[`delete`,' . $row . '])" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="cursor-pointer mx-auto text-red-500 w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" />
</svg></span>
</div>
'
)
->html(),
)->html(),

];
}



}
2 changes: 1 addition & 1 deletion resources/views/auth/verify-email.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class="underline text-sm text-gray-600 hover:text-gray-900"
>
{{ __('Edit Profile') }}</a>

<form method="POST" action="{{ route('logout') }}" class="inline">
<form method="POST" action="{{ route('user.logout') }}" class="inline">
@csrf

<button type="submit" class="underline text-sm text-gray-600 hover:text-gray-900 ml-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class="py-3 px-5 -m-2 bg-white border-slate-200 rounded-t-lg dark:bg-oblue-600 b
</div>
<div class="py-2 first:pt-0 last:pb-0">
<x-layout.dropdown-icon-link>
<x-svg.gear width="16" height="16"></x-svg.gear> {{ __('Account Settings') }}
<x-svg.cog width="16" height="16"></x-svg.cog> {{ __('Account Settings') }}
</x-layout.dropdown-icon-link>

{{-- ------- Logout -------- --}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class=" !w-3 !h-3 dark:text-olblue-300 dark:group-hover:text-white "></x-svg.clo
<div class="py-3 px-4 md:py-4 md:px-4">

<ul>
@foreach($menu->childMenus as $childMenu1)
@foreach($menu->childMenus->sortBy('sort') as $childMenu1)
<li class="dark:text-gray-300 my-2">
<div
class="inline-flex flex-row bg-gray-100 dark:bg-blue-900 px-2 py-1 rounded-md capitalize font-bold text-sm items-center items-center">
Expand Down
6 changes: 3 additions & 3 deletions resources/views/livewire/layout/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class="flex flex-col justify-center items-center px-6 xs:!h-[128px] lg:!h-[146px
<li class="hs-accordion @if(($menu->route !== null)){{ (strpos(Route::currentRouteName(), route($menu->route)) == 0) ? 'active' : '' }} @endif" id="{{$menu->id}}-accordion">
<a class="hs-accordion-toggle flex items-center gap-x-2.5 py-2 px-2.5 hs-accordion-active:text-blue-600 hs-accordion-active:hover:bg-transparent text-sm font-semibold text-slate-700 rounded-md hover:bg-slate-100 dark:hover:bg-oblue-500 dark:text-slate-400 dark:hover:bg-oblue-500 dark:hs-accordion-active:text-white dark:hs-accordion-active:bg-oblue-100"
href=@if(count($menu->childMenus) > 0) "javascript:;" @else @if($menu->route !== null)"{{route($menu->route)}}" @else "javascript:;" @endif @endif>
<x-svg.select :type="$menu->svg" class="h-5 w-5"></x-svg.select>{{$menu->name}}
<x-svg.select :type="$menu->svg" class="!h-5 !w-5"></x-svg.select>{{$menu->name}}
@if(count($menu->childMenus) > 0) <x-layout.sidebar.arrow-direction/> @endif
</a>

<div id="{{$menu->id}}-accordion"
class="hs-accordion-content w-full overflow-hidden transition-[height] duration-300 hidden">
<ul class="hs-accordion-group pt-2" data-hs-accordion-always-open>

@foreach($menu->childMenus as $childMenu1)
@foreach($menu->childMenus->sortBy('sort') as $childMenu1)
<li class="hs-accordion" id="{{$menu->id}}-accordion-sub-1">
<a class="hs-accordion-toggle flex items-center gap-x-3.5 py-2 px-2.5 pl-9 hs-accordion-active:text-blue-600 hs-accordion-active:hover:bg-transparent text-sm text-slate-700 rounded-md hover:bg-slate-100 dark:hover:bg-oblue-500 dark:text-slate-400 dark:hover:bg-oblue-500 dark:hs-accordion-active:text-white"
href=@if(count($childMenu1->childMenus) > 0 ) "javascript:;" @else @if($childMenu1->route !== null)"{{ route($childMenu1->route) }}" @else "javascript:;" @endif @endif">
Expand All @@ -45,7 +45,7 @@ class="hs-accordion-content w-full overflow-hidden transition-[height] duration-
class="hs-accordion-content w-full overflow-hidden transition-[height] duration-300 hidden">
<ul class="pl-0">
@foreach($childMenu1->childMenus as $childMenu2)
@foreach($childMenu1->childMenus->sortBy('sort') as $childMenu2)
<li>
<a class="flex items-center gap-x-3.5 py-2 px-2.5 pl-10 text-sm text-slate-700 rounded-md hover:bg-slate-100 dark:text-slate-400 dark:hover:bg-oblue-500"
href="{{ route($childMenu2->route) }}">
Expand Down
2 changes: 1 addition & 1 deletion routes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
Route::get('/profile', \App\Http\Livewire\Admin\Profile::class)->name('profile.show');

// Menu
Route::get('/menu', \App\Http\Livewire\Admin\Menu\MenuParent::class)->name('menu');
Route::get('/menu', \App\Http\Livewire\Admin\Menu\Index::class)->name('menu');
Route::get('/menu-levels', \App\Http\Livewire\Admin\Menu\Level::class)->name('menu-level');


Expand Down

0 comments on commit 529ba0c

Please sign in to comment.