feat: 🐛 admin/servers sortable
This commit is contained in:
parent
d905171fcb
commit
459069c5ee
2 changed files with 60 additions and 58 deletions
|
@ -6,6 +6,7 @@ use App\Classes\Pterodactyl;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Traits\DatatablesSortable;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
@ -14,9 +15,12 @@ use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class ServerController extends Controller
|
class ServerController extends Controller
|
||||||
{
|
{
|
||||||
|
use DatatablesSortable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
|
@ -27,38 +31,6 @@ class ServerController extends Controller
|
||||||
return view('admin.servers.index');
|
return view('admin.servers.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the form for creating a new resource.
|
|
||||||
*
|
|
||||||
* @return Response
|
|
||||||
*/
|
|
||||||
public function create()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
* @return Response
|
|
||||||
*/
|
|
||||||
public function store(Request $request)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param Server $server
|
|
||||||
* @return Response
|
|
||||||
*/
|
|
||||||
public function show(Server $server)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
|
@ -196,6 +168,7 @@ class ServerController extends Controller
|
||||||
public function dataTable(Request $request)
|
public function dataTable(Request $request)
|
||||||
{
|
{
|
||||||
$query = Server::with(['user', 'product']);
|
$query = Server::with(['user', 'product']);
|
||||||
|
|
||||||
if ($request->has('product')) {
|
if ($request->has('product')) {
|
||||||
$query->where('product_id', '=', $request->input('product'));
|
$query->where('product_id', '=', $request->input('product'));
|
||||||
}
|
}
|
||||||
|
@ -204,6 +177,11 @@ class ServerController extends Controller
|
||||||
}
|
}
|
||||||
$query->select('servers.*');
|
$query->select('servers.*');
|
||||||
|
|
||||||
|
|
||||||
|
if ($request->has('order')) {
|
||||||
|
$query = $this->sortByColumn($request->input('order'), $request->input('columns'), $query);
|
||||||
|
}
|
||||||
|
|
||||||
return datatables($query)
|
return datatables($query)
|
||||||
->addColumn('user', function (Server $server) {
|
->addColumn('user', function (Server $server) {
|
||||||
return '<a href="' . route('admin.users.show', $server->user->id) . '">' . $server->user->name . '</a>';
|
return '<a href="' . route('admin.users.show', $server->user->id) . '">' . $server->user->name . '</a>';
|
||||||
|
@ -232,7 +210,7 @@ class ServerController extends Controller
|
||||||
';
|
';
|
||||||
})
|
})
|
||||||
->addColumn('status', function (Server $server) {
|
->addColumn('status', function (Server $server) {
|
||||||
$labelColor = $server->isSuspended() ? 'text-danger' : 'text-success';
|
$labelColor = $server->suspended ? 'text-danger' : 'text-success';
|
||||||
|
|
||||||
return '<i class="fas ' . $labelColor . ' fa-circle mr-2"></i>';
|
return '<i class="fas ' . $labelColor . ' fa-circle mr-2"></i>';
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
<table id="datatable" class="table table-striped">
|
<table id="datatable" class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th width="20"></th>
|
<th width="20"></th>
|
||||||
<th>{{__('Name')}}</th>
|
<th>{{ __('Name') }}</th>
|
||||||
<th>{{__('User')}}</th>
|
<th>{{ __('User') }}</th>
|
||||||
<th>{{__('Server id')}}</th>
|
<th>{{ __('Server id') }}</th>
|
||||||
<th>{{__('Config')}}</th>
|
<th>{{ __('Config') }}</th>
|
||||||
<th>{{__('Suspended at')}}</th>
|
<th>{{ __('Suspended at') }}</th>
|
||||||
<th>{{__('Created at')}}</th>
|
<th>{{ __('Created at') }}</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -17,30 +17,54 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function submitResult() {
|
function submitResult() {
|
||||||
return confirm("{{__('Are you sure you wish to delete?')}}") !== false;
|
return confirm("{{ __('Are you sure you wish to delete?') }}") !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
$('#datatable').DataTable({
|
$('#datatable').DataTable({
|
||||||
language: {
|
language: {
|
||||||
url: '//cdn.datatables.net/plug-ins/1.11.3/i18n/{{config("SETTINGS::LOCALE:DATATABLES")}}.json'
|
url: '//cdn.datatables.net/plug-ins/1.11.3/i18n/{{ config('SETTINGS::LOCALE:DATATABLES') }}.json'
|
||||||
},
|
},
|
||||||
processing: true,
|
processing: true,
|
||||||
serverSide: true,
|
serverSide: true,
|
||||||
stateSave: true,
|
stateSave: true,
|
||||||
ajax: "{{route('admin.servers.datatable')}}{{$filter ?? ''}}",
|
ajax: "{{ route('admin.servers.datatable') }}{{ $filter ?? '' }}",
|
||||||
order: [[ 5, "desc" ]],
|
order: [
|
||||||
columns: [
|
[6, "desc"]
|
||||||
{data: 'status' , name : 'servers.suspended'},
|
|
||||||
{data: 'name'},
|
|
||||||
{data: 'user' , name : 'user.name'},
|
|
||||||
{data: 'identifier'},
|
|
||||||
{data: 'resources' , name : 'product.name'},
|
|
||||||
{data: 'suspended'},
|
|
||||||
{data: 'created_at'},
|
|
||||||
{data: 'actions' , sortable : false},
|
|
||||||
],
|
],
|
||||||
fnDrawCallback: function( oSettings ) {
|
columns: [{
|
||||||
|
data: 'status',
|
||||||
|
name: 'servers.suspended',
|
||||||
|
sortable: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'user',
|
||||||
|
name: 'user.name',
|
||||||
|
sortable: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'identifier'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'resources',
|
||||||
|
name: 'product.name',
|
||||||
|
sortable: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'suspended'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'created_at'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'actions',
|
||||||
|
sortable: false
|
||||||
|
},
|
||||||
|
],
|
||||||
|
fnDrawCallback: function(oSettings) {
|
||||||
$('[data-toggle="popover"]').popover();
|
$('[data-toggle="popover"]').popover();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue