Skip to content

Commit

Permalink
Merge pull request #2099 from LuckyCyborg/4.0
Browse files Browse the repository at this point in the history
Overall improvements
  • Loading branch information
LuckyCyborg authored Aug 8, 2018
2 parents 28e61f4 + ff35e01 commit bc24ffa
Show file tree
Hide file tree
Showing 19 changed files with 397 additions and 183 deletions.
12 changes: 12 additions & 0 deletions app/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ public function autoLayout($enable = null)
return $this->autoLayout;
}

/**
* Return the current called action
*
* NOTE: this information is available after Controller initialization.
*
* @return string
*/
public function getAction()
{
return $this->action;
}

/**
* Return the current Theme.
*
Expand Down
1 change: 1 addition & 0 deletions app/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ class VerifyCsrfToken extends BaseVerifier
*/
protected $except = array(
'admin/files/connector',
'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.79');
define('VERSION', '4.0.80');

//--------------------------------------------------------------------------
// Set PHP Error Reporting Options
Expand Down
2 changes: 1 addition & 1 deletion modules/Platform/Notifications/AccountActivation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Nova\Notifications\Notification;
use Nova\Notifications\Messages\MailMessage;
use Nova\Queue\ShouldQueueInterface;
use Nova\Support\Facades\Config
use Nova\Support\Facades\Config;


class AccountActivation extends Notification implements ShouldQueueInterface
Expand Down
2 changes: 1 addition & 1 deletion modules/Roles/Views/Admin/Roles/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<?php } ?>

<div class="box box-widget">
<div class="box-header with-border">
<div class="box-header">
<h3 class="box-title"><?= __d('roles', 'Registered Roles'); ?></h3>
<div class="box-tools">
<?= $roles->links(); ?>
Expand Down
45 changes: 42 additions & 3 deletions modules/Users/Controllers/Admin/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
use Nova\Support\Facades\Gate;
use Nova\Support\Facades\Hash;
use Nova\Support\Facades\Input;
use Nova\Support\Facades\Language;
use Nova\Support\Facades\File;
use Nova\Support\Facades\Redirect;
use Nova\Support\Facades\Response;
use Nova\Support\Facades\Validator;
use Nova\Support\Facades\View;
use Nova\Support\Arr;
use Nova\Support\Str;

use Shared\Support\DataTable;

use Modules\Platform\Controllers\Admin\BaseController;
use Modules\Roles\Models\Role;
use Modules\Users\Models\Field;
Expand Down Expand Up @@ -142,19 +147,53 @@ protected function validator(array $data, Collection $items, $id = null)
return $validator;
}

public function data(Request $request)
{
$columns = array(
array('data' => 'id', 'name' => 'id'),
array('data' => 'username', 'name' => 'username'),
array('data' => 'realname', 'name' => 'realname'),
array('data' => 'email', 'name' => 'email'),

array('data' => 'roles', 'name' => 'roles.name', 'uses' => function ($user)
{
$roles = $user->roles->lists('name');

return implode(', ', $roles);
}),

array('data' => 'created_at', 'name' => 'created_at', 'uses' => function ($user)
{
$format = __d('users', '%d %b %Y, %H:%M');

return $user->created_at->formatLocalized($format);
}),

array('data' => 'actions', 'name' => 'actions', 'uses' => function ($user)
{
return View::fetch('Modules/Users::Partials/UsersTableActions', compact('user'));
}),
);

$query = User::with('roles')->where('activated', 1);

$data = DataTable::handle($query, $request, $columns);

return Response::json($data);
}

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

// Get all User records for current page.
$users = User::where('activated', 1)->paginate(25);
$langInfo = Language::info();

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

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

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

// The Users CRUD.
Route::get( 'users', 'Users@index');
Route::get( 'users/create', 'Users@create');
Route::post('users', 'Users@store');
Route::get( 'users/{id}', 'Users@show');
Expand Down
107 changes: 57 additions & 50 deletions modules/Users/Views/Admin/Users/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,71 @@
</div>

<div class="box box-widget">
<div class="box-header">
<div class="box-header with-border">
<h3 class="box-title"><?= __d('users', 'Registered Users'); ?></h3>
<div class="box-tools">
<?= $users->links(); ?>
</div>
</div>
<div class="box-body no-padding">
<?php $deletables = 0; ?>
<?php if (! $users->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('users', 'ID'); ?></th>
<th style="text-align: center; vertical-align: middle;"><?= __d('users', 'Username'); ?></th>
<th style="text-align: center; vertical-align: middle;"><?= __d('users', 'Roles'); ?></th>
<th style="text-align: center; vertical-align: middle;"><?= __d('users', 'Name and Surname'); ?></th>
<th style="text-align: center; vertical-align: middle;"><?= __d('users', 'E-mail'); ?></th>
<th style="text-align: center; vertical-align: middle;"><?= __d('users', 'Created At'); ?></th>
<th style="text-align: right; vertical-align: middle;"><?= __d('users', 'Operations'); ?></th>
</tr>
<?php foreach ($users->items() as $user) { ?>
<tr>
<td style="text-align: center; vertical-align: middle;" width="5%"><?= $user->id; ?></td>
<td style="text-align: center; vertical-align: middle;" width="18%"><?= $user->username; ?></td>
<td style="text-align: center; vertical-align: middle;" width="11%"><?= implode(', ', $user->roles->lists('name')); ?></td>
<td style="text-align: center; vertical-align: middle;" width="18%"><?= $user->realname; ?></td>
<td style="text-align: center; vertical-align: middle;" width="18%"><?= $user->email; ?></td>
<td style="text-align: center; vertical-align: middle;" width="15%"><?= $user->created_at->formatLocalized(__d('users', '%d %b %Y, %R')); ?></td>
<td style="text-align: right; vertical-align: middle;" width="15%">
<div class="btn-group" role="group" aria-label="...">
<?php if (Gate::allows('delete', $user)) { ?>
<?php $deletables++; ?>
<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/' .$user->id .'/edit'); ?>" 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/' .$user->id); ?>" title="<?= __d('users', 'Show the Details'); ?>" role="button"><i class="fa fa-search"></i></a>
<?php } ?>
</div>
</td>
</tr>
<?php } ?>
<table id='usersTable' class='table table-striped table-hover responsive' style="width: 100%;">
<thead>
<tr class="bg-navy disabled">
<th width='5%'><?= __d('users', 'ID'); ?></th>
<th width='18%'><?= __d('users', 'Username'); ?></th>
<th width='11%'><?= __d('users', 'Roles'); ?></th>
<th width='18%'><?= __d('users', 'Name and Surname'); ?></th>
<th width='18%'><?= __d('users', 'E-mail'); ?></th>
<th width='15%'><?= __d('users', 'Created At'); ?></th>
<th width='15%'><?= __d('users', '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('users', 'No registered Users'); ?></h4>
<?= __d('users', 'There are no registered Users.'); ?>
</div>
<?php } ?>
</div>
</div>

</section>
<script>

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

columns: [
{ 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" },
{ data: 'email', name: 'email', orderable: true, searchable: true, className: "text-center" },
{ data: 'created_at', name: 'created_at', orderable: true, searchable: false, className: "text-center" },
{ data: 'actions', name: 'actions', orderable: false, searchable: false, className: "text-right compact" },
],

<?php if ($deletables > 0) { ?>
drawCallback: function(settings)
{
var pagination = $(this).closest('.dataTables_wrapper').find('.dataTables_paginate');

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

</script>

</section>

<div class="modal modal-default" id="modal-delete-dialog">
<div class="modal-dialog">
Expand Down Expand Up @@ -124,5 +133,3 @@
});

</script>

<?php } ?>
5 changes: 5 additions & 0 deletions modules/Users/Views/Partials/UsersTableActions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<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>
<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>
</div>
10 changes: 3 additions & 7 deletions shared/Pagination/Middleware/SetupRoutePagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,11 @@ public function handle(Request $request, Closure $next)

Paginator::currentPageResolver(function ($pageName = 'page') use ($route)
{
$page = str_replace(
$pageName .'/', '', $route->parameter('pageQuery', $pageName .'/1')
$page = (int) str_replace(
$pageName .'/', '', $route->parameter('pageQuery', 1)
);

if ((filter_var($page, FILTER_VALIDATE_INT) !== false) && ((int) $page >= 1)) {
return $page;
}

return 1;
return $page;
});

Paginator::urlGeneratorResolver(function (AbstractPaginator $paginator)
Expand Down
Loading

0 comments on commit bc24ffa

Please sign in to comment.