Skip to content

Commit

Permalink
Merge pull request #2101 from LuckyCyborg/4.0
Browse files Browse the repository at this point in the history
Overall improvements
  • Loading branch information
LuckyCyborg authored Aug 13, 2018
2 parents 2deb761 + f6c7cd8 commit 5f357f7
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 156 deletions.
2 changes: 2 additions & 0 deletions app/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class VerifyCsrfToken extends BaseVerifier
*/
protected $except = array(
'admin/files/connector',
'admin/roles/data',
'admin/users/data',
'livechat/*',
);
}
2 changes: 1 addition & 1 deletion app/Platform/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Define The Application Version
//--------------------------------------------------------------------------

define('VERSION', '4.0.81');
define('VERSION', '4.0.82');

//--------------------------------------------------------------------------
// Set PHP Error Reporting Options
Expand Down
37 changes: 32 additions & 5 deletions modules/Roles/Controllers/Admin/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@

use Nova\Auth\Access\AuthorizationException;
use Nova\Database\ORM\ModelNotFoundException;
use Nova\Http\Request;
use Nova\Support\Facades\Gate;
use Nova\Support\Facades\Input;
use Nova\Support\Facades\Redirect;
use Nova\Support\Facades\Validator;
use Nova\Support\Facades\View;
use Nova\Support\Str;

use Shared\Support\Facades\DataTable;

use Modules\Platform\Controllers\Admin\BaseController;
use Modules\Roles\Models\Role;
Expand Down Expand Up @@ -56,19 +61,41 @@ protected function validator(array $data, $id = null)
return Validator::make($data, $rules, $messages, $attributes);
}

public function data(Request $request)
{
$query = Role::withCount('users');

$dataTable = DataTable::make($query)
->column('id')
->column('name')
->column('slug');

$dataTable->column('description', function ($role)
{
$shortDesc = Str::limit($role->description, 80);

return sprintf('<div title="%s">%s</div>', e($role->description), e($shortDesc));
});

$dataTable->column('users', 'users_count');

$dataTable->column('actions', function ($role)
{
return View::fetch('Modules/Roles::Partials/RolesTableActions', compact('role'));
});

return $dataTable->handle($request);
}

public function index()
{
// Authorize the current User.
if (Gate::denies('lists', Role::class)) {
throw new AuthorizationException();
}

// Get all Role records for current page.
$roles = Role::with('users')->paginate(25);

return $this->createView()
->shares('title', __d('roles', 'Roles'))
->with('roles', $roles);
->shares('title', __d('roles', 'Roles'));
}

public function create()
Expand Down
5 changes: 4 additions & 1 deletion modules/Roles/Routes/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
// The Adminstration Routes.
Route::group(array('prefix' => 'admin', 'middleware' => 'auth', 'namespace' => 'Admin'), function ()
{
Route::paginate('roles', 'Roles@index');
// Server Side Processor for Roles DataTable.
Route::post('roles/data', 'Roles@data');

// The Users CRUD.
Route::get( 'roles', 'Roles@index');
Route::get( 'roles/create', 'Roles@create');
Route::post('roles', 'Roles@store');
Route::get( 'roles/{id}', 'Roles@show');
Expand Down
136 changes: 86 additions & 50 deletions modules/Roles/Views/Admin/Roles/Index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
<style>
#rolesTable td {
vertical-align: middle;
}

#rolesTable td.compact {
padding: 5px;
}

#rolesTable {
border-bottom: 1px solid #f4f4f4;
}

#rolesTable_length {
padding: 10px 0 0 10px;
}

#rolesTable_filter {
padding: 10px 10px 0 0;
}

#rolesTable_info {
padding: 9px 0 15px 20px;
}

#rolesTable_paginate {
padding: 2px 10px 4px 0;
}
</style>

<section class="content-header">
<h1><?= __d('roles', 'Roles'); ?></h1>
<ol class="breadcrumb">
Expand All @@ -22,63 +52,72 @@
</div>
</div>

<?php $boxType = 'widget'; ?>
<?php } else { ?>
<?php $boxType = 'default'; ?>
<?php } ?>

<div class="box box-widget">
<div class="box-header">
<div class="box box-<?= $boxType; ?>">
<div class="box-header with-border">
<h3 class="box-title"><?= __d('roles', 'Registered Roles'); ?></h3>
<div class="box-tools">
<?= $roles->links(); ?>
</div>
</div>
<div class="box-body no-padding">
<?php $deletables = 0; ?>
<?php if (! $roles->isEmpty()) { ?>
<table id="left" class="table table-striped table-hover responsive">
<tr class="bg-navy disabled">
<th style="text-align: center; vertical-align: middle;"><?= __d('roles', 'ID'); ?></th>
<th style="text-align: center; vertical-align: middle;"><?= __d('roles', 'Name'); ?></th>
<th style="text-align: center; vertical-align: middle;"><?= __d('roles', 'Slug'); ?></th>
<th style="text-align: center; vertical-align: middle;"><?= __d('roles', 'Description'); ?></th>
<th style="text-align: center; vertical-align: middle;"><?= __d('roles', 'Users'); ?></th>
<th style="text-align: right; vertical-align: middle;"><?= __d('roles', 'Operations'); ?></th>
</tr>
<?php foreach ($roles->items() as $role) { ?>
<tr>
<td style="text-align: center; vertical-align: middle;" width="5%"><?= $role->id; ?></td>
<td style="text-align: center; vertical-align: middle;" width="17%"><?= $role->name; ?></td>
<td style="text-align: center; vertical-align: middle;" width="17%"><?= $role->slug; ?></td>
<td style="text-align: left; vertical-align: middle;" width="40%"><?= $role->description; ?></td>
<td style="text-align: center; vertical-align: middle;" width="6%"><?= $role->users->count(); ?></td>
<td style="text-align: right; vertical-align: middle;" width="15%">
<div class="btn-group" role="group" aria-label="...">
<?php if (Gate::allows('delete', $role)) { ?>
<?php $deletables++; ?>
<a class="btn btn-sm btn-danger" href="#" data-toggle="modal" data-target="#modal-delete-dialog" data-id="<?= $role->id; ?>" title="<?= __d('roles', 'Delete this Role'); ?>" role="button"><i class="fa fa-remove"></i></a>
<?php } ?>
<?php if (Gate::allows('update', $role)) { ?>
<a class="btn btn-sm btn-success" href="<?= site_url('admin/roles/' .$role->id .'/edit'); ?>" title="<?= __d('roles', 'Edit this Role'); ?>" role="button"><i class="fa fa-pencil"></i></a>
<?php } ?>
<?php if (Gate::allows('view', $role)) { ?>
<a class="btn btn-sm btn-warning" href="<?= site_url('admin/roles/' .$role->id); ?>" title="<?= __d('roles', 'Show the Details'); ?>" role="button"><i class="fa fa-search"></i></a>
<?php } ?>
</div>
</td>
</tr>
<?php } ?>
<table id='rolesTable' class='table table-striped table-hover responsive' style="width: 100%;">
<thead>
<tr class="bg-navy disabled">
<th width='5%'><?= __d('roles', 'ID'); ?></th>
<th width='15%'><?= __d('roles', 'Name'); ?></th>
<th width='15%'><?= __d('roles', 'Slug'); ?></th>
<th width='40%'><?= __d('roles', 'Description'); ?></th>
<th width='10%'><?= __d('roles', 'Users'); ?></th>
<th width='15%'><?= __d('roles', 'Actions'); ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<?php } else { ?>
<div class="alert alert-warning" style="margin: 0 5px 5px;">
<h4><i class="icon fa fa-warning"></i> <?= strftime("%d %b %Y, %R", time()) ." - "; ?> <?= __d('roles', 'No registered Roles'); ?></h4>
<?= __d('roles', 'There are no registered Roles.'); ?>
</div>
<?php } ?>
</div>
</div>

</section>
<script>

$(function () {
$('#rolesTable').DataTable({
language: {
url: '//cdn.datatables.net/plug-ins/1.10.15/i18n/<?= Language::info(); ?>.json'
},
responsive: true,
stateSave: true,
processing: true,
serverSide: true,
ajax: {
type: 'POST',
url: '<?= site_url('admin/roles/data'); ?>'
},
pageLength: 15,
lengthMenu: [ 5, 10, 15, 20, 25, 50, 100 ],

columns: [
{ data: 'id', name: 'id', orderable: true, searchable: false, className: "text-center" },
{ data: 'name', name: 'name', orderable: true, searchable: true, className: "text-center" },
{ data: 'slug', name: 'slug', orderable: true, searchable: true, className: "text-center" },
{ data: 'description', name: 'description', orderable: false, searchable: true, className: "text-left" },
{ data: 'users', name: 'users_count', orderable: true, searchable: false, className: "text-center" },
{ data: 'actions', name: 'actions', orderable: false, searchable: false, className: "text-right compact" },
],

drawCallback: function(settings)
{
var pagination = $(this).closest('.dataTables_wrapper').find('.dataTables_paginate');

pagination.toggle(this.api().page.info().pages > 1);
},
});
});

<?php if ($deletables > 0) { ?>
</script>

</section>

<div class="modal modal-default" id="modal-delete-dialog">
<div class="modal-dialog">
Expand Down Expand Up @@ -121,6 +160,3 @@
});

</script>

<?php } ?>

11 changes: 11 additions & 0 deletions modules/Roles/Views/Partials/RolesTableActions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="btn-group" role="group" aria-label="...">
<?php if (Gate::allows('delete', $role)) { ?>
<a class="btn btn-sm btn-danger" href="#" data-toggle="modal" data-target="#modal-delete-dialog" data-id="<?= $role->id; ?>" title="<?= __d('roles', 'Delete this Role'); ?>" role="button"><i class="fa fa-remove"></i></a>
<?php } ?>
<?php if (Gate::allows('update', $role)) { ?>
<a class="btn btn-sm btn-success" href="<?= site_url('admin/roles/' .$role->id .'/edit'); ?>" title="<?= __d('roles', 'Edit this Role'); ?>" role="button"><i class="fa fa-pencil"></i></a>
<?php } ?>
<?php if (Gate::allows('view', $role)) { ?>
<a class="btn btn-sm btn-warning" href="<?= site_url('admin/roles/' .$role->id); ?>" title="<?= __d('roles', 'Show the Details'); ?>" role="button"><i class="fa fa-search"></i></a>
<?php } ?>
</div>
7 changes: 2 additions & 5 deletions modules/Users/Controllers/Admin/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

namespace Modules\Users\Controllers\Admin;

use Nova\Http\Request;
use Nova\Auth\Access\AuthorizationException;
use Nova\Database\ORM\Collection;
use Nova\Database\ORM\ModelNotFoundException;
use Nova\Http\Request;
use Nova\Support\Facades\Cache;
use Nova\Support\Facades\Event;
use Nova\Support\Facades\Gate;
Expand Down Expand Up @@ -186,11 +186,8 @@ public function index()
throw new AuthorizationException();
}

$langInfo = Language::info();

return $this->createView()
->shares('title', __d('users', 'Users'))
->with('langInfo', $langInfo);
->shares('title', __d('users', 'Users'));
}

public function create(Request $request)
Expand Down
2 changes: 1 addition & 1 deletion modules/Users/Routes/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// The Users Search.
Route::get('users/search', 'Users@search');

// Server Side Processor for Roles DataTable.
// Server Side Processor for Users DataTable.
Route::post('users/data', 'Users@data');

// The Users CRUD.
Expand Down
41 changes: 34 additions & 7 deletions modules/Users/Views/Admin/Users/Index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
<style>
#usersTable td {
vertical-align: middle;
}

#usersTable td.compact {
padding: 5px;
}

#usersTable {
border-bottom: 1px solid #f4f4f4;
}

#usersTable_length {
padding: 10px 0 0 10px;
}

#usersTable_filter {
padding: 10px 10px 0 0;
}

#usersTable_info {
padding: 9px 0 15px 20px;
}

#usersTable_paginate {
padding: 2px 10px 4px 0;
}
</style>

<section class="content-header">
<h1><?= $title; ?></h1>
<ol class="breadcrumb">
Expand Down Expand Up @@ -53,24 +83,21 @@
$(function () {
$('#usersTable').DataTable({
language: {
url: '//cdn.datatables.net/plug-ins/1.10.15/i18n/<?= $langInfo; ?>.json'
url: '//cdn.datatables.net/plug-ins/1.10.15/i18n/<?= Language::info(); ?>.json'
},
responsive: true,
stateSave: true,
stateSave: true,
processing: true,
serverSide: true,
ajax: {
type: 'POST',
url: '<?= site_url('admin/users/data'); ?>',
data: function (data) {
data._token = '<?= csrf_token(); ?>';
}
url: '<?= site_url('admin/users/data'); ?>'
},
pageLength: 15,
lengthMenu: [ 5, 10, 15, 20, 25, 50, 100 ],

columns: [
{ data: 'id', name: 'id', orderable: true, searchable: false, className: "text-center" },
{ data: 'id', name: 'id', orderable: true, searchable: false, className: "text-center" },
{ data: 'username', name: 'username', orderable: true, searchable: true, className: "text-center" },
{ data: 'roles', name: 'roles.name', orderable: true, searchable: true, className: "text-center" },
{ data: 'realname', name: 'realname', orderable: true, searchable: true, className: "text-center" },
Expand Down
10 changes: 8 additions & 2 deletions modules/Users/Views/Partials/UsersTableActions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<div class='btn-group pull-right' role='group' aria-label='...'>
<a class='btn btn-sm btn-warning' href='<?= site_url('admin/users/{0}', $user->id); ?>' title='<?= __d('users', 'Show the Details'); ?>' role='button'><i class='fa fa-search'></i></a>
<a class='btn btn-sm btn-success' href='<?= site_url('admin/users/{0}/edit', $user->id); ?>' title='<?= __d('users', 'Edit this User'); ?>' role='button'><i class='fa fa-pencil'></i></a>
<?php if (Gate::allows('delete', $user)) { ?>
<a class='btn btn-sm btn-danger' href='#' data-toggle='modal' data-target='#modal-delete-dialog' data-id='<?= $user->id ?>' title='<?= __d('users', 'Delete this User'); ?>' role='button'><i class='fa fa-remove'></i></a>
<?php } ?>
<?php if (Gate::allows('update', $user)) { ?>
<a class='btn btn-sm btn-success' href='<?= site_url('admin/users/{0}/edit', $user->id); ?>' title='<?= __d('users', 'Edit this User'); ?>' role='button'><i class='fa fa-pencil'></i></a>
<?php } ?>
<?php if (Gate::allows('view', $user)) { ?>
<a class='btn btn-sm btn-warning' href='<?= site_url('admin/users/{0}', $user->id); ?>' title='<?= __d('users', 'Show the Details'); ?>' role='button'><i class='fa fa-search'></i></a>
<?php } ?>
</div>
Loading

0 comments on commit 5f357f7

Please sign in to comment.