Skip to content

Commit

Permalink
Update: Upgraded laravel; Corrections for SSR; Various improvements
Browse files Browse the repository at this point in the history
- Added Enraiged TableBuilder::{column,columExists}() methods
- Added ability to define model for table action security assertions
- Added ability to configure tables to order by sortable count
- Added ability to define a horizontal rule before a form field
- Added ability to define field disabledIf,disabledUnless conditions
- Added ability to define field hiddenIf,hiddenUnless conditions
  - Add definition to the json template to process client-side
  - Or, add method call server-side to process in the form builder
- Added 'daterange' type table filter
- Added patch for correcting primevue import lines for ssr use
- Added patch for issue with primevue datatables rowgroup colspan
  - primefaces/primevue#3685
- Added 'enraiged:fix-ssr' command to enable ssr with primevue
- Corrected 419 error issue handling logout requests
- Corrected issue handling field disabled attribute when provided
- Corrected issue searching table columns with compound sources
- Corrected various issues with the user password validation
- Ensure table export options not displayed unless permitted
- Improved table global actions processing
- Removed neccessity of errors object in the js form system
- Updated to the Laravel 10 framework
  - https://laravel.com/docs/10.x/releases
  • Loading branch information
Todd Cytra committed Jul 11, 2023
1 parent df0756a commit 81bf4fa
Show file tree
Hide file tree
Showing 120 changed files with 8,488 additions and 2,592 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Release Notes

2023-07-11 : 0.3.0
Update: Upgraded laravel; Corrections for SSR; Various improvements

- Added Enraiged TableBuilder::{column,columExists}() methods
- Added ability to define model for table action security assertions
- Added ability to configure tables to order by sortable count
- Added ability to define a horizontal rule before a form field
- Added ability to define field disabledIf,disabledUnless conditions
- Added ability to define field hiddenIf,hiddenUnless conditions
- Add definition to the json template to process client-side
- Or, add method call server-side to process in the form builder
- Added 'daterange' type table filter
- Added patch for correcting primevue import lines for ssr use
- Added patch for issue with primevue datatables rowgroup colspan
- https://github.com/primefaces/primevue/issues/3685
- Added 'enraiged:fix-ssr' command to enable ssr with primevue
- Corrected 419 error issue handling logout requests
- Corrected issue handling field disabled attribute when provided
- Corrected issue searching table columns with compound sources
- Corrected various issues with the user password validation
- Ensure table export options not displayed unless permitted
- Improved table global actions processing
- Removed neccessity of errors object in the js form system
- Updated to the Laravel 10 framework
- https://laravel.com/docs/10.x/releases

---

2023-04-05 : 0.2.5
Update: Various updates,corrections for avatars,passwords,assertions

Expand Down
53 changes: 47 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Enraiged Laravel

**This package is experimental and not intended for production use.**
> **Status:** This package is currently being tested as the framework in a small number of production projects.
### Laravel +Vue +Inertiajs +PrimeVue +Vite

+ [Laravel 9](https://laravel.com/docs/9.x/releases)
+ [Laravel 10](https://laravel.com/docs/10.x/releases)
+ [Vue 3](https://vuejs.org/guide/introduction.html)
+ [Inertia.js v1](https://inertiajs.com/)
+ [PrimeVUE 3](https://www.primefaces.org/primevue/#/setup)
Expand Down Expand Up @@ -32,6 +32,8 @@ install -d storage/{app,logs,framework/{cache,sessions,views}}

Install the vendor packages:

> Add the --no-dev flag when installing on a production host.
```sh
composer install
```
Expand Down Expand Up @@ -66,6 +68,8 @@ php artisan migrate --seed

Finally, we will install the node packages and build the front-end resources. Start with:

> Add the --no-dev flag when installing on a production host.
```sh
npm install
```
Expand All @@ -82,10 +86,17 @@ When complete, build the app for service:
npm run build
```

Apply the patch:
### Known Issue

I encountered an issue with Primevue Datatables handling of rowgroup colspan. In the vendor files, they are actively
subtracting the calculated column count and I don't understand why. I've included a patch to prevent this subtraction.

Apply the patch (optional):

> Revert these changes by using `-Rp0` instead of `-p0`
```sh
patch -Nr - --version-control none -p0 < patches/primevue-datatable-correct-rowgroup-colspan.patch
patch -Nr - --version-control none -p0 < patches/primevue-3.29.2-datatable-correct-rowgroup-colspan.patch
```

---
Expand Down Expand Up @@ -115,8 +126,38 @@ Stop the SSR server:
php artisan inertia:stop-ssr
```

Please see [https://inertiajs.com/server-side-rendering](https://inertiajs.com/server-side-rendering) for more
information.
### Known Issue

Primevue does not seem to be ssr-ready and I spent some time providing a quick means of correcting the vendor files.
There are two options for applying these corrections. While option 2 is quicker, option 1 is more likely to work for
future versions of the vendor packages.

**Option 1: Artisan Command**

The primevue packages can be fixed with an artisan command:

> Add the --revert flag to reverse these changes.
```sh
php artisan enraiged:fix-ssr
```

**Option 2: Apply Patch**

Or, the quicker option is to apply a patch I've provided:

> Reverse these changes by using `-Rp0` instead of `-p0`
```sh
patch -Nr - --version-control none -p0 < patches/primevue-3.29.2-ssr-ready-corrections.patch
```

Even with these corrections, I still see the following error output when running inertia:start-ssr (i'm not sure what
this means or how to correct this):

`[Vue warn]: Invalid vnode type when creating vnode: undefined.`

---

## License

Expand Down
2 changes: 1 addition & 1 deletion app/Auth/Enums/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Auth\Enums;

use LaravelEnso\Enums\Services\Enum;
use Enraiged\Enums\Services\Enum;

final class Roles extends Enum
{
Expand Down
124 changes: 124 additions & 0 deletions app/Console/Enraiged/FixSSR.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace App\Console\Enraiged;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage;

class FixSSR extends Command
{
/** @var string The name and signature of the console command. */
protected $signature = 'enraiged:fix-ssr {--revert}';

/** @var string The console command description. */
protected $description = 'Fix the Primevue packages for SSR usage.';

/** @var bool An argument to execute a reversal. */
protected $revert = false;

/**
* Cycle through the package names and executes a find/sed replace to ensure ssr compatibility.
*
* @return void
*/
public function handle(): void
{
$this->basepath = base_path('node_modules/primevue');
$this->revert = $this->option('revert');

(object) $this
->addPackageJsonType()
->applyIconsImportsFix()
->applyPackageImportsFix();

$this->info('Done.');

if (!$this->revert) {
$this->info('Execute php artisan enraiged:fix-ssr --revert to reverse these changes.');
}
}

/**
* This executes a sed to add the type: module line to the package.json files.
*
* @return self
*/
private function addPackageJsonType(): self
{
$this->line('Applying package.json fix...');

$progress = $this->output->createProgressBar(1);
$progress->start(1);

$command = $this->revert
? "sed -i '/\"type\": \"module\",/d' {$this->basepath}/{icons/*,*}/package.json"
: "find {$this->basepath}/*/ -type f -name 'package.json' -exec sed -i '1 a\ \"type\": \"module\",' {} \;";

Process::run($command);

$progress->advance();
$progress->finish();
$this->newLine();

return $this;
}

/**
* This executes a sed to expand the include call to the full *.esm.js package filename.
*
* @return self
*/
private function applyIconsImportsFix(): self
{
$this->line('Applying icons imports fix...');

$directories = collect(Storage::disk('node')->directories('primevue/icons'));

$progress = $this->output->createProgressBar($directories->count());

$directories->each(function ($package) use ($progress) {
$command = $this->revert
? "find {$this->basepath}/ -type f -name '*.esm.js' -exec sed -i \"s|'{$package}/index.esm.js'|'{$package}'|\" {} \;"
: "find {$this->basepath}/ -type f -name '*.esm.js' -exec sed -i \"s|'{$package}'|'{$package}/index.esm.js'|\" {} \;";
Process::run($command);

$progress->advance();
});

$progress->finish();
$this->newLine();

return $this;
}

/**
* This executes a sed to expand the include call to the full *.esm.js package filename.
*
* @return $this
*/
private function applyPackageImportsFix(): self
{
$this->line('Applying package imports fix...');

$directories = collect(Storage::disk('node')->directories('primevue'))
->filter(fn ($directory) => Storage::disk('node')->exists("{$directory}/package.json"));

$progress = $this->output->createProgressBar($directories->count());

$directories->each(function ($package) use ($progress) {
$filename = substr($package, strrpos($package, '/') +1);
$command = $this->revert
? "find {$this->basepath}/ -type f -name '*.esm.js' -exec sed -i \"s|'{$package}/{$filename}.esm.js'|'{$package}'|\" {} \;"
: "find {$this->basepath}/ -type f -name '*.esm.js' -exec sed -i \"s|'{$package}'|'{$package}/{$filename}.esm.js'|\" {} \;";
Process::run($command);

$progress->advance();
});

$progress->finish();
$this->newLine();

return $this;
}
}
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function schedule(Schedule $schedule)
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
$this->load(__DIR__.'/Enraiged');

require base_path('routes/console.php');
}
Expand Down
18 changes: 0 additions & 18 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,6 @@

class Handler extends ExceptionHandler
{
/**
* A list of exception types with their corresponding custom log levels.
*
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
*/
protected $levels = [
//
];

/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<\Throwable>>
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed to the session on validation exceptions.
*
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Kernel extends HttpKernel

'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
Expand All @@ -56,11 +56,12 @@ class Kernel extends HttpKernel
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
// 'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \App\Http\Middleware\RequirePassword::class,
'precognitive' => \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
Expand Down
7 changes: 3 additions & 4 deletions app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;

class Authenticate extends Middleware
{
Expand All @@ -12,10 +13,8 @@ class Authenticate extends Middleware
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
protected function redirectTo(Request $request): ?string
{
if (! $request->expectsJson()) {
return route('login');
}
return $request->expectsJson() ? null : route('login');
}
}
7 changes: 4 additions & 3 deletions app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param \Closure $next
* @param string|null ...$guards
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle(Request $request, Closure $next, ...$guards)
public function handle(Request $request, Closure $next, string ...$guards): Response
{
$guards = empty($guards) ? [null] : $guards;

Expand Down
Loading

0 comments on commit 81bf4fa

Please sign in to comment.