added admin logs controller

added log to users
pull/44/head
A1Gard 6 months ago
parent 4ef0238dce
commit aa974c76c3

@ -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 "<ul> $ret </ul>";
}
}
/**
* 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]);
}

@ -0,0 +1,43 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Controllers\XController;
use App\Http\Requests\AdminLogSaveRequest;
use App\Models\Access;
use App\Models\AdminLog;
use App\Models\User;
use Illuminate\Http\Request;
use App\Helper;
use function App\Helpers\hasCreateRoute;
class AdminLogController extends XController
{
// protected $_MODEL_ = AdminLog::class;
// protected $SAVE_REQUEST = AdminLogSaveRequest::class;
protected $cols = ['action','user_id'];
protected $extra_cols = ['id','loggable_type','loggable_id'];
protected $searchable = ['action'];
protected $listView = 'admin.commons.adminlogs';
protected $buttons = [];
public function __construct()
{
parent::__construct(AdminLog::class);
}
public function log(User $item){
return redirect()->route('admin.adminlogs.index',['filter[user_id]'=> '['.$item->id.']']);
}
}

@ -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';

@ -0,0 +1,202 @@
@extends('admin.templates.panel-list-template-raw')
@section('table')
<table class="table-list">
<thead>
<tr>
<th>
<div
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
data-bs-title="{{__("Check all")}}"
class="form-check form-switch mt-1 mx-2">
<input class="form-check-input chkall"
type="checkbox" role="switch">
</div>
</th>
@foreach($cols as $col)
<th>
<a href="?sort={{$col}}{{sortSuffix($col)}}&{{queryBuilder('sort')}}">
{{__($col)}}
</a>
</th>
@endforeach
<th>
{{__("Subject")}}
</th>
<th>
</th>
</tr>
</thead>
<tbody>
@if(count($items) == 0)
<tr>
<td colspan="100%">
{{__("There is nothing to show!")}}
</td>
</tr>
@else
@foreach($items as $item)
<tr>
<td>
<input type="checkbox" id="chk-{{$item->id}}" class="chkbox"
name="id[{{$item->id}}]" value="{{$item->id}}">
<label for="chk-{{$item->id}}">
{{$item->id}}
</label>
</td>
@foreach($cols as $k => $col)
@if($k == 0 && hasRoute('edit'))
<td>
<a href="{{getRoute('edit',$item->{$item->getRouteKeyName()})}}">
<b>
{{$item?->{$cols[0]} }}
</b>
</a>
</td>
@else
<td>
@switch($col)
@case($col == 'user_id')
<a href="{{route('admin.user.edit',$item->user?->email)}}">
{{ $item->user?->name??'-' }}
</a>
@break
@case($col == 'action')
{{ getAction($item->$col) }}
@break
@default
{{$item->$col}}
@endswitch
</td>
@endif
@endforeach
<td>
<a href="{{getModelLink($item->loggable_type,$item->loggable_id)}}">
{{getModelName($item->loggable_type,$item->loggable_id)}}
</a>
</td>
<td>
@if(strpos(request()->url(),'trashed') != false && hasRoute('restore'))
<a href="{{getRoute('restore',$item->{$item->getRouteKeyName()})}}"
class="btn btn-success btn-sm mx-1 d-xl-none d-xxl-none"
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
data-bs-title="{{__("Restore")}}">
<i class="ri-recycle-line"></i>
</a>
@else
<div class="dropdown d-xl-none d-xxl-none">
<a class="btn btn-outline-secondary dropdown-toggle" href="#"
role="button"
data-bs-toggle="dropdown" aria-expanded="false">
</a>
<ul class="dropdown-menu">
@foreach($buttons as $btn => $btnData)
<li>
<a class="dropdown-item {{$btnData['class']}}"
href="{{getRoute($btn,$item->{$item->getRouteKeyName()})}}">
<i class="{{$btnData['icon']}}"></i>
&nbsp;
{{__($btnData['title'])}}
</a>
</li>
@endforeach
</ul>
</div>
@endif
<div class="d-none d-xl-block d-xxl-block">
@foreach($buttons as $btn => $btnData)
@if(strpos($btnData['class'],'delete') == false )
@if(strpos(request()->url(),'trashed') == false)
<a href="{{getRoute($btn,$item->{$item->getRouteKeyName()})}}"
class="btn {{$btnData['class']}} btn-sm mx-1"
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
data-bs-title="{{__($btnData['title'])}}">
<i class="{{$btnData['icon']}}"></i>
</a>
@endif
@else
@if( hasRoute('restore') && $item->trashed())
<a class="btn btn-success btn-sm mx-1"
href="{{getRoute('restore',$item->id)}}" {{--dont change this id to getRouteKeyName --}}
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
data-bs-title="{{__("Restore")}}">
<i class="ri-recycle-line"></i>
</a>
@else
<a href="{{getRoute($btn,$item->{$item->getRouteKeyName()})}}"
class="btn {{$btnData['class']}} btn-sm mx-1"
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
data-bs-title="{{__($btnData['title'])}}">
<i class="{{$btnData['icon']}}"></i>
</a>
@endif
@endif
@endforeach
</div>
</td>
</tr>
@endforeach
@endif
</tbody>
{{-- pagination and toggle button start --}}
<tfoot>
<tr>
<th colspan="100%">
<div class="row">
<div class="col-md-3 text-start">
<div
id="toggle-select"
class="btn btn-outline-light mx-2"
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
data-bs-title="{{__("Toggle selection")}}">
<i class="ri-toggle-line"></i>
</div>
</div>
<div class="col-md-6">
{{$items->withQueryString()->links()}}
</div>
<div class="col-md-3 text-center">
</div>
</div>
</th>
</tr>
</tfoot>
{{-- pagination and toggle button end --}}
</table>
@endsection
@section('filter')
<h2>
<i class="ri-shield-check-line"></i>
{{__("User filter")}}:
</h2>
<searchable-multi-select
:items='{{\App\Models\User::all('id','name')}}'
title-field="name"
value-field="id"
xname="filter[user_id]"
:xvalue='{{request()->input('filter.user_id','[]')}}'
:close-on-Select="true"></searchable-multi-select>
@endsection

@ -0,0 +1,125 @@
@extends('layouts.app')
@section('content')
<div class="mb-5 pb-5">
<div class="row">
{{-- list side bar start--}}
<div class="col-xl-3">
@include('components.err')
<div class="item-list mb-3">
<div class="row">
<div class="col-8">
<h1>
@yield('list-title')
</h1>
</div>
<div class="col-4 pt-3 text-end">
@if(hasRoute('trashed'))
<a class="btn btn-outline-danger me-3"
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
data-bs-title="{{__("Trashed items")}}"
href="{{getRoute('trashed')}}"
>
<i class="ri-delete-bin-6-line"></i>
</a>
@endif
</div>
</div>
<form action="" class="p-3">
<div class="input-group mb-3">
<span class="btn btn-outline-secondary" type="button" id="button-addon2">
<i class="ri-search-2-line"></i>
</span>
<input type="text" name="q" class="form-control" placeholder="{{__("Search")}}..."
aria-label="{{__("Search")}}..." aria-describedby="button-addon2"
value="{{request()->input('q','')}}">
</div>
@yield('filter')
<button class="btn btn-primary w-100">
{{__("Search & Filter")}}
</button>
</form>
</div>
<div class="item-list mb-3 py-3">
<div class="grid-equal text-center p-1">
<span>
{{__("Totol")}}
</span>
<span>
({{$items->total()}})
</span>
</div>
<hr>
<div class="grid-equal text-center p-1">
<span>
{{__("From - To")}}
</span>
<span>
@paginated($items)
</span>
</div>
</div>
@if(hasRoute('bulk'))
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-check-double-line"></i>
{{__("Bulk actions:")}}
</h3>
<form action="{{getRoute('bulk',[])}}" id="bulk-from" method="post">
<div class="p-3">
@csrf
<select class="form-control mb-3" name="action" required>
<option value=""></option>
@if(strpos(request()->url(),'trashed') != false)
<option value="restore"> {{__("Batch restore")}} </option>
@else
<option value="delete"> {{__("Batch delete")}} </option>
@endif
@yield('bulk')
</select>
<button class="btn btn-primary w-100">
{{__("Do it")}}
</button>
<div id="bulk-idz"></div>
</div>
</form>
</div>
@endif
</div>
{{-- list side bar end--}}
{{-- list content start--}}
<div class="col-xl-9 ps-xl-0">
<form class="item-list" id="main-form">
@yield('table')
</form>
</div>
</div>
{{-- list content end--}}
</div>
@if(hasRoute('create'))
<a class="action-btn circle-btn"
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
data-bs-title="{{__("Add another one")}}"
href="{{getRoute('create')}}"
>
<i class="ri-add-line"></i>
</a>
@endif
@endsection

@ -126,7 +126,7 @@
</a>
</th>
@endforeach
@yield('table-head')
{{-- @yield('table-head')--}}
<th>
</th>
@ -170,7 +170,7 @@
</td>
@endif
@endforeach
@yield('table-body')
{{-- @yield('table-body')--}}
<td>
@if(strpos(request()->url(),'trashed') != false && hasRoute('restore'))
@ -277,6 +277,7 @@
</tfoot>
{{-- pagination and toggle button end --}}
</table>
</form>
</div>
</div>
{{-- list content end--}}

@ -188,10 +188,16 @@
{{__("Users")}}
</a>
</li>
<li>
<a href="{{route('admin.adminlogs.index')}}">
<i class="ri-list-check-3"></i>
{{__('Logs of admins')}}
</a>
</li>
<li>
<a href="">
<i class="ri-list-check-3"></i>
{{__('Logs')}}
{{__('Logs of guests')}}
</a>
</li>
<li>

@ -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');

Loading…
Cancel
Save