Skip to content

Commit

Permalink
Merge pull request #2113 from LuckyCyborg/4.0
Browse files Browse the repository at this point in the history
Overall improvements
  • Loading branch information
LuckyCyborg authored Aug 27, 2018
2 parents 2dff29b + b5b1875 commit a41ec6f
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 114 deletions.
2 changes: 1 addition & 1 deletion app/Config/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
| Supported: "file", "database", "apc", "memcached", "redis", "array"
*/

'driver' => 'tagged_file',
'driver' => 'taggedFile',

/*
|--------------------------------------------------------------------------
Expand Down
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.90');
define('VERSION', '4.0.91');

//--------------------------------------------------------------------------
// Set PHP Error Reporting Options
Expand Down
38 changes: 23 additions & 15 deletions modules/Roles/Controllers/Admin/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,23 @@ protected function validator(array $data, $id = null)
return $validator;
}

public function data(Request $request)
protected function dataTable()
{
// Authorize the current User.
if (Gate::denies('lists', Role::class)) {
throw new AuthorizationException();
}
$format = __d('users', '%d %b %Y, %H:%M');

$query = Role::withCount('users');
// Create a DataTable instance.
$dataTable = DataTable::make();

$dataTable = DataTable::make($query)
->column('id')
->column('name')
->column('slug')
->column('description');
// Setup the columns.
$dataTable->column('id');
$dataTable->column('name');
$dataTable->column('slug');
$dataTable->column('description');

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

$dataTable->column('created_at', function ($role)
$dataTable->column('created_at', function ($role) use ($format)
{
$format = __d('roles', '%d %b %Y, %H:%M');

return $role->created_at->formatLocalized($format);
});

Expand All @@ -93,7 +89,19 @@ public function data(Request $request)
return View::fetch('Modules/Roles::Partials/RolesTableActions', compact('role'));
});

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

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

$query = Role::withCount('users');

return $this->dataTable()->handle($query, $request);
}

public function index()
Expand Down
65 changes: 41 additions & 24 deletions modules/Users/Controllers/Admin/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,41 +147,57 @@ protected function validator(array $data, Collection $items, $id = null)
return $validator;
}

public function data(Request $request)
protected function dataTable()
{
// Authorize the current User.
if (Gate::denies('lists', User::class)) {
throw new AuthorizationException();
}
$dataTable = DataTable::make();

$query = User::with('roles')->where('activated', 1);
// Setup the DataTable columns.
$dataTable->group(array('className' => 'text-center'), function ($dataTable)
{
$dataTable->column('id')->orderable(true);

$dataTable = DataTable::make($query)
->column('id')
->column('username')
->column('realname')
->column('email');
$dataTable->column('username', array('orderable' => true, 'searchable' => true));

$dataTable->column('roles.name', 'roles', function ($user)
{
$roles = $user->roles->lists('name');
$dataTable->group(array('orderable' => true, 'searchable' => true), function ($dataTable)
{
$dataTable->column('roles.name', array('data' => 'roles', 'uses' => function ($user)
{
$roles = $user->roles->lists('name');

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

$dataTable->column('created_at', function ($user)
{
$format = __d('users', '%d %b %Y, %H:%M');
$dataTable->column('realname');
$dataTable->column('email');
});

$dataTable->column('created_at', function ($user)
{
$format = __d('users', '%d %b %Y, %H:%M');

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

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

$dataTable->column('actions', function ($user)
$dataTable->column('actions', array('className' => 'text-right compact', function ($user)
{
return View::fetch('Modules/Users::Partials/UsersTableActions', compact('user'));
});
}));

return $dataTable;
}

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

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

return $dataTable->handle($request);
return $this->dataTable()->handle($query, $request);
}

public function index()
Expand All @@ -192,7 +208,8 @@ public function index()
}

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

public function create(Request $request)
Expand Down
9 changes: 2 additions & 7 deletions modules/Users/Views/Admin/Users/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,8 @@
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" },
<?= $dataTable->script(); ?>

],

drawCallback: function(settings)
Expand Down
2 changes: 1 addition & 1 deletion shared/Cache/CacheServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function boot()
{
$config = $this->app['config'];

$this->app['cache']->extend('tagged_file', function ($app) use ($config)
$this->app['cache']->extend('taggedFile', function ($app) use ($config)
{
$path = $config->get('cache.path');

Expand Down
146 changes: 146 additions & 0 deletions shared/DataTable/Column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php

namespace Shared\DataTable;


class Column implements \ArrayAccess
{
/**
* @var array
*/
protected $attributes = array();


/**
* Create a new Column instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes)
{
$this->attributes = $attributes;
}

/**
* Determine if the given attribute exists.
*
* @param mixed $key
* @return bool
*/
public function has($key)
{
return isset($this->attributes[$key]);
}

/**
* Get an attribute from the column.
*
* @param mixed $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
{
return isset($this->attributes[$key]) ? $this->attributes[$key] : $default;
}

/**
* Set an attribute from the column.
*
* @param mixed $key
* @param mixed $value
* @return mixed
*/
public function set($key, $value)
{
$this->attributes[$key] = $value;
}

/**
* Forget the value of a given attribute.
*
* @param mixed $offset
* @return void
*/
public function forget($key)
{
unset($this->attributes[$key]);
}

/**
* Get all of the current attributes on the column.
*
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}

/**
* Determine if the given attribute exists.
*
* @param mixed $offset
* @return bool
*/
public function offsetExists($offset)
{
return $this->has($offset);
}

/**
* Get the value for a given offset.
*
* @param mixed $offset
* @return mixed
*/
public function offsetGet($offset)
{
return $this->get($offset);
}

/**
* Set the value for a given offset.
*
* @param mixed $offset
* @param mixed $value
* @return void
*/
public function offsetSet($offset, $value)
{
$this->set($offset, $value);
}

/**
* Unset the value for a given offset.
*
* @param mixed $offset
* @return void
*/
public function offsetUnset($offset)
{
$this->forget($offset);
}

/**
* Handle dynamic method calls into the method.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, array $parameters)
{
if (empty($parameters)) {
return $this->get($method);
}

// The method call is for a setter.
else if (in_array($method, array('orderable', 'searchable', 'className'))) {
$this->set($method, head($parameters));
}

return $this;
}
}
Loading

0 comments on commit a41ec6f

Please sign in to comment.