Skip to content

Commit

Permalink
BREAKING CHANGE / refactor(controller): Controllers refactored / close
Browse files Browse the repository at this point in the history
  • Loading branch information
anibalealvarezs committed Feb 21, 2022
1 parent 02a4d0a commit d1c2d66
Show file tree
Hide file tree
Showing 23 changed files with 1,197 additions and 1,238 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,32 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.3.7.2] - 2022-02-21

- BREAKING CHANGES:
- [x] [1.3.7.1]

### Changed

- Controllers refactored

## [1.3.7.1] - 2022-02-19

### Added

- Implemented cache for controllers
- Added facades por ```PbDebugbar``` class
- Added ```PbCacheController```

### Changed

- 'Permissions' and 'Navigations' seeders updated

### Fixed

- Fixed errors in ```Loggers``` CRUD
- Fixed 'module' fields in forms
- Fixed 'settings' menu button

## [1.3.7] - 2022-02-14

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"homepage": "https://anibalalvarez.com",
"license": "MIT",
"version" : "1.3.7.1",
"version" : "1.3.7.2",
"type" : "package",
"authors": [
{
Expand Down
4 changes: 3 additions & 1 deletion src/Controllers/Config/PbCacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
use Anibalealvarezs\Projectbuilder\Models\PbCurrentUser;
use Anibalealvarezs\Projectbuilder\Traits\PbControllerTrait;
use Anibalealvarezs\Projectbuilder\Utilities\PbCache;
use Exception;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;

use Exception;

class PbCacheController
{
use PbControllerTrait;
Expand Down
11 changes: 4 additions & 7 deletions src/Controllers/Config/PbConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

use Auth;
use DB;
use Inertia\Response as InertiaResponse;
use Psr\SimpleCache\InvalidArgumentException;
use ReflectionException;
use Session;

use Inertia\Response as InertiaResponse;

class PbConfigController extends PbBuilderController
{
function __construct(Request $request, $crud_perms = false)
Expand All @@ -44,7 +43,7 @@ function __construct(Request $request, $crud_perms = false)
*
* @param string $route
* @return InertiaResponse|JsonResponse
* @throws ReflectionException|InvalidArgumentException
* @throws \ReflectionException
*/
public function create(string $route = 'level'): InertiaResponse|JsonResponse
{
Expand All @@ -58,7 +57,6 @@ public function create(string $route = 'level'): InertiaResponse|JsonResponse
*
* @param Request $request
* @return Application|Redirector|RedirectResponse|null
* @throws ReflectionException
*/
public function store(Request $request): Redirector|RedirectResponse|Application|null
{
Expand All @@ -75,7 +73,7 @@ public function store(Request $request): Redirector|RedirectResponse|Application
* @param bool $multiple
* @param string $route
* @return RedirectResponse|InertiaResponse|JsonResponse
* @throws ReflectionException|InvalidArgumentException
* @throws \ReflectionException
*/
public function edit(
int $id,
Expand All @@ -95,7 +93,6 @@ public function edit(
* @param Request $request
* @param int $id
* @return Application|Redirector|RedirectResponse|null
* @throws ReflectionException
*/
public function update(Request $request, int $id): Redirector|RedirectResponse|Application|null
{
Expand Down
2 changes: 2 additions & 0 deletions src/Controllers/Config/PbLocaleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Anibalealvarezs\Projectbuilder\Models\PbLanguage;
use Anibalealvarezs\Projectbuilder\Traits\PbControllerTrait;

use App\Http\Controllers\Controller;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

Expand Down
5 changes: 3 additions & 2 deletions src/Controllers/Dashboard/PbDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

use App\Http\Requests;

use Auth;
use DB;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

use Auth;
use DB;
use Session;

use Inertia\Response as InertiaResponse;
Expand Down
2 changes: 2 additions & 0 deletions src/Controllers/Logger/PbLoggerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Anibalealvarezs\Projectbuilder\Controllers\Logger;

use Anibalealvarezs\Projectbuilder\Controllers\PbBuilderController;

use App\Http\Requests;

use Illuminate\Http\Request;

class PbLoggerController extends PbBuilderController
Expand Down
47 changes: 18 additions & 29 deletions src/Controllers/Navigation/PbNavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Anibalealvarezs\Projectbuilder\Controllers\PbBuilderController;

use Anibalealvarezs\Projectbuilder\Facades\PbDebugbarFacade as Debug;
use Anibalealvarezs\Projectbuilder\Utilities\PbCache;
use App\Http\Requests;

use Illuminate\Http\JsonResponse;
Expand All @@ -15,11 +13,10 @@

use Auth;
use DB;
use Inertia\Response as InertiaResponse;
use Psr\SimpleCache\InvalidArgumentException;
use ReflectionException;
use Session;

use Inertia\Response as InertiaResponse;

class PbNavigationController extends PbBuilderController
{
function __construct(Request $request, $crud_perms = false)
Expand Down Expand Up @@ -62,7 +59,7 @@ function __construct(Request $request, $crud_perms = false)
* @param bool $multiple
* @param string $route
* @return InertiaResponse|JsonResponse|RedirectResponse
* @throws ReflectionException|InvalidArgumentException
* @throws \ReflectionException
*/
public function index(
int $page = 1,
Expand All @@ -74,33 +71,25 @@ public function index(
bool $multiple = false,
string $route = 'level'): InertiaResponse|JsonResponse|RedirectResponse
{
Debug::start('custom_controller', $this->vars->level->names.' crud controller');
$this->startController(getClassName(__CLASS__));

Debug::measure(
$this->vars->level->names.' crud controller - model list build',
function() use (&$model, $page, $perpage, $orderby, $field, $order) {
$cached = PbCache::run(
closure: fn() => $this->vars->level->modelPath::withPublicRelations()->orderedByDefault()->get(),
package: $this->vars->helper->package,
class: 'model_controller',
model: $this->vars->level->names,
modelFunction: 'getList',
byRoles: true,
);
$model = $cached['data'];
$this->vars->cacheObjects[$cached['tags']][] = $cached['keys'];
}
);
// Set cache/methods arguments
$this->initArgs([
'class' => 'model_controller',
'pagination' => ['page' => $page, 'perpage' => $perpage, 'orderby' => $orderby, 'field' => $field, 'order' => $order],
'byRoles' => true,
]);

// Get models list
$this->measuredRun(return: $model, name: getClassName(__CLASS__) . ' - models list build', args: [
'closure' => fn() => $this->vars->level->modelPath::withPublicRelations()->orderedByDefault()->get(),
'modelFunction' => 'getList',
]);

Debug::stop('custom_controller');
$this->stopController(getClassName(__CLASS__));

return parent::index(
$page,
$perpage,
$orderby,
$field,
$order,
$model
element: $model,
);
}
}
Loading

0 comments on commit d1c2d66

Please sign in to comment.