From aa974c76c3011381e05ac346cdb1bbb6b556a0b3 Mon Sep 17 00:00:00 2001 From: A1Gard Date: Thu, 13 Jun 2024 01:58:20 +0330 Subject: [PATCH] added admin logs controller added log to users --- app/Helpers/Helper.php | 43 ++++ .../Controllers/Admin/AdminLogController.php | 43 ++++ app/Http/Controllers/Admin/PostController.php | 2 +- .../views/admin/commons/adminlogs.blade.php | 202 ++++++++++++++++++ .../panel-list-template-raw.blade.php | 125 +++++++++++ .../templates/panel-list-template.blade.php | 5 +- .../components/panel-side-navbar.blade.php | 8 +- routes/web.php | 5 +- 8 files changed, 428 insertions(+), 5 deletions(-) create mode 100644 app/Http/Controllers/Admin/AdminLogController.php create mode 100644 resources/views/admin/commons/adminlogs.blade.php create mode 100644 resources/views/admin/templates/panel-list-template-raw.blade.php diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 70cb211..033872b 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -335,6 +335,12 @@ function lastCrump() } +/** + * @param $cats array categories or groups as nested ul li wih checkbox + * @param $checked array witch one checked default + * @param $parent null|integer parent id + * @return string + */ function showCatNestedControl($cats, $checked = [], $parent = null) { $ret = ""; @@ -354,3 +360,40 @@ function showCatNestedControl($cats, $checked = [], $parent = null) return ""; } } + +/** + * find model name form morph + * @param $modelable_type + * @param $modelable_id + * @return string + */ +function getModelName($modelable_type,$modelable_id){ + $r = explode('\\',$modelable_type); + return $r[count($r)-1].':'.$modelable_id; +} + +/** + * find model show link form morph + * @param $modelable_type + * @param $modelable_id + * @return string + */ +function getModelLink($modelable_type,$modelable_id){ + $r = explode('\\',$modelable_type); + $model = strtolower($r[count($r)-1]); + $name = 'admin.'.$model.'.show'; + if (Route::has($name)){ + return \route($name,$modelable_id); + }else{ + return ''; + } +} + +function getAction($act){ + $r = explode('::',$act); + return ucfirst($r[count($r)-1]); + +} + + + diff --git a/app/Http/Controllers/Admin/AdminLogController.php b/app/Http/Controllers/Admin/AdminLogController.php new file mode 100644 index 0000000..89c5f7a --- /dev/null +++ b/app/Http/Controllers/Admin/AdminLogController.php @@ -0,0 +1,43 @@ +route('admin.adminlogs.index',['filter[user_id]'=> '['.$item->id.']']); + } + + +} diff --git a/app/Http/Controllers/Admin/PostController.php b/app/Http/Controllers/Admin/PostController.php index d72e1d9..5d2733f 100644 --- a/app/Http/Controllers/Admin/PostController.php +++ b/app/Http/Controllers/Admin/PostController.php @@ -21,7 +21,7 @@ class PostController extends XController protected $cols = ['title','hash','view']; protected $extra_cols = ['id', 'slug']; - protected $searchable = []; + protected $searchable = ['title','subtitle','body']; protected $listView = 'admin.posts.post-list'; protected $formView = 'admin.posts.post-form'; diff --git a/resources/views/admin/commons/adminlogs.blade.php b/resources/views/admin/commons/adminlogs.blade.php new file mode 100644 index 0000000..7d4f7f1 --- /dev/null +++ b/resources/views/admin/commons/adminlogs.blade.php @@ -0,0 +1,202 @@ +@extends('admin.templates.panel-list-template-raw') + +@section('table') + + + + + + @foreach($cols as $col) + + @endforeach + + + + + + @if(count($items) == 0) + + + + @else + @foreach($items as $item) + + + @foreach($cols as $k => $col) + @if($k == 0 && hasRoute('edit')) + + @else + + @endif + @endforeach + + + + + @endforeach + @endif + + + + + {{-- pagination and toggle button start --}} + + + + + + {{-- pagination and toggle button end --}} +
+
+ +
+
+ + {{__($col)}} + + + {{__("Subject")}} + + +
+ {{__("There is nothing to show!")}} +
+ + + + + + {{$item?->{$cols[0]} }} + + + + @switch($col) + @case($col == 'user_id') + + {{ $item->user?->name??'-' }} + + @break + @case($col == 'action') + {{ getAction($item->$col) }} + @break + @default + {{$item->$col}} + @endswitch + + + {{getModelName($item->loggable_type,$item->loggable_id)}} + + + + @if(strpos(request()->url(),'trashed') != false && hasRoute('restore')) + + + + @else + + + @endif +
+ @foreach($buttons as $btn => $btnData) + + @if(strpos($btnData['class'],'delete') == false ) + @if(strpos(request()->url(),'trashed') == false) + + + + + @endif + @else + @if( hasRoute('restore') && $item->trashed()) + + + + @else + + + + @endif + @endif + @endforeach +
+
+
+
+
+ +
+
+
+ {{$items->withQueryString()->links()}} +
+
+
+
+
+@endsection + +@section('filter') +

+ + {{__("User filter")}}: +

+ +@endsection diff --git a/resources/views/admin/templates/panel-list-template-raw.blade.php b/resources/views/admin/templates/panel-list-template-raw.blade.php new file mode 100644 index 0000000..1f14c8e --- /dev/null +++ b/resources/views/admin/templates/panel-list-template-raw.blade.php @@ -0,0 +1,125 @@ +@extends('layouts.app') + +@section('content') +
+
+ + {{-- list side bar start--}} +
+ @include('components.err') +
+
+
+

+ @yield('list-title') +

+
+
+ @if(hasRoute('trashed')) + + + + @endif +
+
+
+
+ + + + +
+ @yield('filter') + +
+
+ + +
+
+ + {{__("Totol")}} + + + ({{$items->total()}}) + +
+
+
+ + {{__("From - To")}} + + + @paginated($items) + +
+
+ + @if(hasRoute('bulk')) + +
+

+ + {{__("Bulk actions:")}} +

+
+ +
+ + @csrf + + + +
+
+
+
+ @endif + + +
+ {{-- list side bar end--}} + + + {{-- list content start--}} +
+
+ @yield('table') +
+
+
+ {{-- list content end--}} +
+ + @if(hasRoute('create')) + + + + @endif +@endsection diff --git a/resources/views/admin/templates/panel-list-template.blade.php b/resources/views/admin/templates/panel-list-template.blade.php index bc6f6eb..97fb753 100644 --- a/resources/views/admin/templates/panel-list-template.blade.php +++ b/resources/views/admin/templates/panel-list-template.blade.php @@ -126,7 +126,7 @@ @endforeach - @yield('table-head') +{{-- @yield('table-head')--}} @@ -170,7 +170,7 @@ @endif @endforeach - @yield('table-body') +{{-- @yield('table-body')--}} @if(strpos(request()->url(),'trashed') != false && hasRoute('restore')) @@ -277,6 +277,7 @@ {{-- pagination and toggle button end --}} + {{-- list content end--}} diff --git a/resources/views/components/panel-side-navbar.blade.php b/resources/views/components/panel-side-navbar.blade.php index 77c51d9..1f8aac5 100644 --- a/resources/views/components/panel-side-navbar.blade.php +++ b/resources/views/components/panel-side-navbar.blade.php @@ -188,10 +188,16 @@ {{__("Users")}} +
  • + + + {{__('Logs of admins')}} + +
  • - {{__('Logs')}} + {{__('Logs of guests')}}
  • diff --git a/routes/web.php b/routes/web.php index 080bec1..b7980d8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -20,6 +20,8 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group( Route::get('/',[\App\Http\Controllers\HomeController::class,'index'])->name('dash'); Route::post('ckeditor/upload', [\App\Http\Controllers\Admin\CkeditorController::class,'upload'])->name('ckeditor.upload'); + Route::get('adminlogs', [\App\Http\Controllers\Admin\AdminLogController::class,'index'])->name('adminlogs.index'); + Route::get('adminlogs/{user}', [\App\Http\Controllers\Admin\AdminLogController::class,'log'])->name('adminlogs.show'); Route::prefix('users')->name('user.')->group( function () { @@ -27,7 +29,7 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group( Route::get('create', [\App\Http\Controllers\Admin\UserController::class, 'create'])->name('create'); Route::post('store', [\App\Http\Controllers\Admin\UserController::class, 'store'])->name('store'); Route::get('edit/{item}', [\App\Http\Controllers\Admin\UserController::class, 'edit'])->name('edit'); - Route::get('log/{item}', [\App\Http\Controllers\Admin\UserController::class, 'log'])->name('log'); + Route::get('log/{item}', [\App\Http\Controllers\Admin\AdminLogController::class, 'log'])->name('log'); Route::get('show/{item}', [\App\Http\Controllers\Admin\UserController::class, 'show'])->name('show'); Route::post('update/{item}', [\App\Http\Controllers\Admin\UserController::class, 'update'])->name('update'); Route::get('delete/{item}', [\App\Http\Controllers\Admin\UserController::class, 'destroy'])->name('destroy'); @@ -52,6 +54,7 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group( Route::get('', [\App\Http\Controllers\Admin\PostController::class, 'index'])->name('index'); Route::get('create', [\App\Http\Controllers\Admin\PostController::class, 'create'])->name('create'); Route::post('store', [\App\Http\Controllers\Admin\PostController::class, 'store'])->name('store'); + Route::post('show/{item}', [\App\Http\Controllers\Admin\PostController::class, 'show'])->name('show'); Route::get('edit/{item}', [\App\Http\Controllers\Admin\PostController::class, 'edit'])->name('edit'); Route::post('update/{item}', [\App\Http\Controllers\Admin\PostController::class, 'update'])->name('update'); Route::get('delete/{item}', [\App\Http\Controllers\Admin\PostController::class, 'destroy'])->name('destroy');