From 6c8b3fcb7755d51dee5ae09e8db178f5e20b5d48 Mon Sep 17 00:00:00 2001 From: Eduard Altimiras Date: Mon, 15 May 2023 18:54:27 +0200 Subject: [PATCH 01/28] fixed javascript calls --- src/resources/views/fields/timeRangeValue.blade.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/resources/views/fields/timeRangeValue.blade.php b/src/resources/views/fields/timeRangeValue.blade.php index ac0d4094..4635a80b 100644 --- a/src/resources/views/fields/timeRangeValue.blade.php +++ b/src/resources/views/fields/timeRangeValue.blade.php @@ -17,7 +17,7 @@ - @icon(times) + @icon(times) {{-- --}} @@ -43,7 +43,7 @@ @if(!$fixed) - @icon(times) + @icon(times) @endif @@ -52,18 +52,18 @@ @if(! $fixed)
- @icon(plus) {{ __('admin.add') }} + @icon(plus) {{ __('admin.add') }}
@endif @push('edit-scripts') \ No newline at end of file + + registerActionPopupListeners() + + window.addEventListener('thrust.searchStarted', () => { + fetch("{{ route('thrust.actions.index', ['resourceName' => $resourceName, 'search' => true]) }}").then(response => { + response.text().then(html => { + document.getElementById('thrust-resource-actions').innerHTML = html + registerActionPopupListeners() + }) + }) + }) + + window.addEventListener('thrust.searchEnded', () => { + fetch("{{ route('thrust.actions.index', ['resourceName' => $resourceName]) }}").then(response => { + response.text().then(html => { + document.getElementById('thrust-resource-actions').innerHTML = html + registerActionPopupListeners() + }) + }) + }) + diff --git a/src/routes.php b/src/routes.php index bb51ac0a..65d9d5c2 100644 --- a/src/routes.php +++ b/src/routes.php @@ -18,6 +18,7 @@ Route::group(['prefix' => config('thrust.routePrefix', 'thrust'), 'namespace' => 'BadChoice\Thrust\Controllers', 'middleware' => config('thrust.routeMiddleware', ['web','auth'])], function () { Route::post('{resourceName}/actions', 'ThrustActionsController@perform')->name('thrust.actions.perform'); Route::get('{resourceName}/actions', 'ThrustActionsController@create')->name('thrust.actions.create'); + Route::get('{resourceName}/index/actions', 'ThrustActionsController@index')->name('thrust.actions.index'); Route::post('{resourceName}/updateOrder', 'ThrustSortController@updateOrder')->name('thrust.updateOrder'); Route::get('{resourceName}/{id}/toggle/{field}', 'ThrustActionsController@toggle')->name('thrust.toggle'); From 3dac1184c971118c2b36907818ac3dc4ca5c242a Mon Sep 17 00:00:00 2001 From: Alex Toro Date: Wed, 2 Aug 2023 11:08:59 +0200 Subject: [PATCH 07/28] Added an optional redirect --- src/Controllers/ThrustController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Controllers/ThrustController.php b/src/Controllers/ThrustController.php index 709b9d5c..6521989b 100644 --- a/src/Controllers/ThrustController.php +++ b/src/Controllers/ThrustController.php @@ -72,6 +72,7 @@ public function store($resourceName) return back()->withErrors(['message' => $e->getMessage()]); } if (request()->ajax()) { return response()->json($result);} + if (session()->has('thrust-redirect')) { return redirect(session('thrust-redirect'));} return back()->withMessage(__('thrust::messages.created')); } @@ -95,6 +96,7 @@ public function storeMultiple($resourceName) } DB::commit(); + if (session()->has('thrust-redirect')) { return redirect(session('thrust-redirect'));} return back()->withMessage(__('thrust::messages.created')); } @@ -110,6 +112,7 @@ public function update($resourceName, $id) } catch (\Exception $e) { return back()->withErrors(['message' => $e->getMessage()]); } + if (session()->has('thrust-redirect')) { return redirect(session('thrust-redirect'));} return back()->withMessage(__('thrust::messages.updated')); } @@ -120,6 +123,7 @@ public function delete($resourceName, $id) } catch (\Exception $e) { return back()->withErrors(['delete' => $e->getMessage()]); } + if (session()->has('thrust-redirect')) { return redirect(session('thrust-redirect'));} return back()->withMessage(__('thrust::messages.deleted')); } From 141415ea30bccf127ff05f38ad46c3f47fcf5dcc Mon Sep 17 00:00:00 2001 From: Alex Toro Date: Wed, 2 Aug 2023 13:11:48 +0200 Subject: [PATCH 08/28] Refactored last commit --- src/Controllers/ThrustController.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Controllers/ThrustController.php b/src/Controllers/ThrustController.php index 6521989b..27f9145a 100644 --- a/src/Controllers/ThrustController.php +++ b/src/Controllers/ThrustController.php @@ -72,8 +72,8 @@ public function store($resourceName) return back()->withErrors(['message' => $e->getMessage()]); } if (request()->ajax()) { return response()->json($result);} - if (session()->has('thrust-redirect')) { return redirect(session('thrust-redirect'));} - return back()->withMessage(__('thrust::messages.created')); + + return $this->backWithMessage('created'); } public function storeMultiple($resourceName) @@ -96,8 +96,8 @@ public function storeMultiple($resourceName) } DB::commit(); - if (session()->has('thrust-redirect')) { return redirect(session('thrust-redirect'));} - return back()->withMessage(__('thrust::messages.created')); + + return $this->backWithMessage('created'); } public function update($resourceName, $id) @@ -112,8 +112,8 @@ public function update($resourceName, $id) } catch (\Exception $e) { return back()->withErrors(['message' => $e->getMessage()]); } - if (session()->has('thrust-redirect')) { return redirect(session('thrust-redirect'));} - return back()->withMessage(__('thrust::messages.updated')); + + return $this->backWithMessage('updated'); } public function delete($resourceName, $id) @@ -123,8 +123,8 @@ public function delete($resourceName, $id) } catch (\Exception $e) { return back()->withErrors(['delete' => $e->getMessage()]); } - if (session()->has('thrust-redirect')) { return redirect(session('thrust-redirect'));} - return back()->withMessage(__('thrust::messages.deleted')); + + return $this->backWithMessage('deleted'); } private function singleResourceIndex($resourceName, $resource) @@ -135,4 +135,12 @@ private function singleResourceIndex($resourceName, $resource) 'object' => $resource->first() ]); } + + private function backWithMessage(string $message) + { + if (session()->has('thrust-redirect')) { + return redirect(session('thrust-redirect')); + } + return back()->withMessage(__("'thrust::messages.{$message}")); + } } From 3ac5dc5d73538a6e04361d3bebe3b7a73d6db75e Mon Sep 17 00:00:00 2001 From: Pau Benet Prat Date: Mon, 7 Aug 2023 11:02:58 +0200 Subject: [PATCH 09/28] Database actions should be created within current model connection. When performing actions from a master account they get logged in the master database actions table. --- src/ThrustObserver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ThrustObserver.php b/src/ThrustObserver.php index 4f9ca49a..fa623498 100644 --- a/src/ThrustObserver.php +++ b/src/ThrustObserver.php @@ -137,7 +137,7 @@ protected function trackDatabaseAction( ]; try { - return DatabaseAction::create($attributes); + return DatabaseAction::on($model->getConnectionName())->create($attributes); } catch (QueryException $e) { // The table is probably not found because the user have not yet // logged in, so we don't bother to log anything. From 5353733bfca77702575b21da3cc97b5198919217 Mon Sep 17 00:00:00 2001 From: Alex Deniz Garcia Date: Mon, 7 Aug 2023 16:59:44 +0200 Subject: [PATCH 10/28] REV-12144: hide Thrust Resource delete action when forbidden --- src/Resource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resource.php b/src/Resource.php index e63f2e0e..f699fdce 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -270,7 +270,7 @@ public function mainActions() public function actions() { return [ - new Delete(), + ...($this->canDelete(self::$model) ? [new Delete()] : []), ]; } From f2236b3c36d99524f0d55f72cfa2f5c2fafe56f7 Mon Sep 17 00:00:00 2001 From: PauBenetPrat Date: Fri, 18 Aug 2023 09:53:53 +0200 Subject: [PATCH 11/28] Revert "REV-12144: hide Thrust Resource delete action when forbidden" --- src/Resource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resource.php b/src/Resource.php index f699fdce..e63f2e0e 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -270,7 +270,7 @@ public function mainActions() public function actions() { return [ - ...($this->canDelete(self::$model) ? [new Delete()] : []), + new Delete(), ]; } From 55496c5ebe2d4fe2d90bb185a9fe9bdf74f2e06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puigdell=C3=ADvol?= Date: Tue, 22 Aug 2023 10:14:20 +0200 Subject: [PATCH 12/28] Disable query log on import --- src/Controllers/ThrustImportController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Controllers/ThrustImportController.php b/src/Controllers/ThrustImportController.php index a6a234a9..85196596 100644 --- a/src/Controllers/ThrustImportController.php +++ b/src/Controllers/ThrustImportController.php @@ -7,6 +7,7 @@ use BadChoice\Thrust\Importer\Importer; use BadChoice\Thrust\ResourceGate; use Illuminate\Routing\Controller; +use Illuminate\Support\Facades\DB; class ThrustImportController extends Controller { @@ -47,6 +48,7 @@ public function store($resourceName) app(ResourceGate::class)->check($resource, 'create'); $importer = new Importer(request('csv'), $resource); try { + DB::connection()->disableQueryLog(); $imported = $importer->import(request('mapping')); }catch(\Exception $e){ // dd($e->validator->errors()->getMessages()); From 9842bcef7b08c65cc9b69f2d780853dc6b467781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Sala=20Morral?= Date: Tue, 22 Aug 2023 14:38:50 +0200 Subject: [PATCH 13/28] Added compatibility wiht Laravel 10 --- composer.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 2e2a7c1b..c8a4f63d 100644 --- a/composer.json +++ b/composer.json @@ -4,10 +4,9 @@ "type": "library", "require": { "php": "^8.0", - "laravel/framework": "8.x|9.x", + "laravel/framework": "^8.0|^9.0|^10.0", "intervention/image": "^2.5", - "psr/container": "^1.0|^2.0", - "illuminate/contracts": "8.x|^9.43" + "psr/container": "^1.0|^2.0" }, "require-dev": { "orchestra/testbench": "^7.17", From b4ac8e29b2218c3a837f8c3350916ad8be40c205 Mon Sep 17 00:00:00 2001 From: Pau Benet Prat Date: Mon, 28 Aug 2023 17:46:54 +0200 Subject: [PATCH 14/28] Add resource request validation. --- src/Controllers/ThrustController.php | 5 +++-- src/Resource.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Controllers/ThrustController.php b/src/Controllers/ThrustController.php index 27f9145a..eb7f33dc 100644 --- a/src/Controllers/ThrustController.php +++ b/src/Controllers/ThrustController.php @@ -64,7 +64,8 @@ public function editInline($resourceName, $id) public function store($resourceName) { $resource = Thrust::make($resourceName); - request()->validate($resource->getValidationRules(null)); + $resource->validate(request(), null); + try { $result = $resource->create(request()->all()); } catch (\Exception $e) { @@ -104,7 +105,7 @@ public function update($resourceName, $id) { $resource = Thrust::make($resourceName); if (! request()->has('inline')) { - request()->validate($resource->getValidationRules($id)); + $resource->validate(request(), $id); } try { diff --git a/src/Resource.php b/src/Resource.php index e63f2e0e..baba51fd 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -16,7 +16,9 @@ use BadChoice\Thrust\ResourceFilters\Search; use BadChoice\Thrust\ResourceFilters\Sort; use Illuminate\Database\Eloquent\Model; +use Illuminate\Http\Request; use Illuminate\Support\Str; +use Illuminate\Validation\ValidationException; abstract class Resource { @@ -424,4 +426,12 @@ public function breadcrumbs(mixed $object): ?string { return null; } + + /** + * @throws ValidationException + */ + public function validate(Request $request, ?int $id = null): void + { + $request->validate($this->getValidationRules($id)); + } } From 579c2ae68be36eb0a6cea472b680333ba914b68e Mon Sep 17 00:00:00 2001 From: Alex Deniz Garcia Date: Tue, 29 Aug 2023 13:19:04 +0200 Subject: [PATCH 15/28] REV-12275: make decimal field nullable --- src/Fields/Decimal.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Fields/Decimal.php b/src/Fields/Decimal.php index a439f12b..92c69a93 100644 --- a/src/Fields/Decimal.php +++ b/src/Fields/Decimal.php @@ -5,11 +5,15 @@ class Decimal extends Text { protected $asInteger = false; + protected $nullable = false; public $rowClass = 'text-right'; public function getValue($object) { $value = parent::getValue($object); + if ($value === null & $this->nullable) { + return null; + } if ($value && $this->asInteger) { return number_format(floatval($value) / 100.0, 2); } @@ -30,6 +34,12 @@ public function asInteger($asInteger = true) return $this; } + public function nullable($nullable = true) + { + $this->nullable = $nullable; + return $this; + } + protected function getFieldType() { return 'number'; From 1f44756ff1da18b873de09ac7fb51b9c3e677f11 Mon Sep 17 00:00:00 2001 From: Pau Benet Prat Date: Wed, 30 Aug 2023 13:08:22 +0200 Subject: [PATCH 16/28] Instead of validating the request directly, we create a validator and after that we validate it. --- src/Resource.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Resource.php b/src/Resource.php index baba51fd..7b0693f4 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -15,6 +15,7 @@ use BadChoice\Thrust\ResourceFilters\Filters; use BadChoice\Thrust\ResourceFilters\Search; use BadChoice\Thrust\ResourceFilters\Sort; +use Illuminate\Contracts\Validation\Validator; use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Illuminate\Support\Str; @@ -430,8 +431,14 @@ public function breadcrumbs(mixed $object): ?string /** * @throws ValidationException */ - public function validate(Request $request, ?int $id = null): void + final public function validate(Request $request, ?int $id = null): void + { + $validator = \Illuminate\Support\Facades\Validator::make($request->all(), $this->getValidationRules($id)); + $this->withValidator($request, $validator); + $validator->validate(); + } + + protected function withValidator(Request $request, Validator $validator) { - $request->validate($this->getValidationRules($id)); } } From 7ba4f40df22fa9868da9af229425a58ceec334bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Sala=20Morral?= Date: Wed, 13 Sep 2023 16:21:14 +0200 Subject: [PATCH 17/28] REV-12637 Resources are sortable only if can be edited --- src/Html/Edit.php | 6 +++--- src/Resource.php | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Html/Edit.php b/src/Html/Edit.php index 4e71324e..8e09492e 100644 --- a/src/Html/Edit.php +++ b/src/Html/Edit.php @@ -30,7 +30,7 @@ public function getEditFields($multiple = false) return $field->excludeOnMultiple; }); } - if ($this->resource::$sortable) { + if ($this->resource->canSort()) { $fields->prepend(Hidden::make($this->resource::$sortField)); } if ($this->resource instanceof ChildResource) { @@ -75,7 +75,7 @@ public function showInline($id) 'nameField' => $this->resource->nameField, 'resourceName' => $this->resource->name(), 'fields' => $this->getEditInlineFields(), - 'sortable' => $this->resource::$sortable, + 'sortable' => $this->resource->canSort(), 'object' => $object, ])->render(); } @@ -88,7 +88,7 @@ public function showBelongsToManyInline($id, $belongsToManyField) 'nameField' => $this->resource->nameField, 'resourceName' => $this->resource->name(), 'fields' => $this->getEditInlineFields(), - 'sortable' => $this->resource::$sortable, + 'sortable' => $this->resource->canSort(), 'object' => $object, 'belongsToManyField' => $belongsToManyField, 'relatedName' => $object->{$relation}?->{$belongsToManyField->relationDisplayField}, diff --git a/src/Resource.php b/src/Resource.php index 7b0693f4..3f325208 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -216,6 +216,11 @@ public function canDelete($object) return $this->can('delete', $object); } + public function canSort(): bool + { + return static::$sortable && $this->can('update'); + } + public function can($ability, $object = null) { if (! $ability) { @@ -405,7 +410,7 @@ protected function getPagination() public function sortableIsActive() { - return static::$sortable && ! request('sort'); + return $this->canSort() && ! request('sort'); } public function getUpdateConfirmationMessage() From 3cc5bf5eed34bebe76cd5070804d778920ba1d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puigdell=C3=ADvol?= Date: Fri, 15 Sep 2023 15:59:45 +0200 Subject: [PATCH 18/28] Thrust can force a image filename --- src/Fields/Image.php | 9 ++++++++- src/resources/views/editImage.blade.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Fields/Image.php b/src/Fields/Image.php index ccff57a9..4363e3b3 100644 --- a/src/Fields/Image.php +++ b/src/Fields/Image.php @@ -18,6 +18,7 @@ class Image extends File implements Prunable protected $maxHeight = 400; protected $maxWidth = 400; protected $square = false; + protected $forceFilename = null; protected $maxFileSize = 1024; // 1 MB @@ -28,6 +29,12 @@ public function gravatar($field = 'email', $default = null) return $this; } + public function withForcedFilename($filename) : self + { + $this->forceFilename = $filename; + return $this; + } + public function maxSize($width, $height) { $this->maxWidth = $width; @@ -92,7 +99,7 @@ public function store($object, $file) $image->crop($size, $size); } - $filename = Str::random(10) . '.png'; + $filename = $this->forceFilename ?? Str::random(10) . '.png'; $this->getStorage()->put($this->getPath() . $filename, (string)$image->encode('png'), $this->storageVisibility); $this->getStorage()->put($this->getPath() . "{$this->resizedPrefix}{$filename}", (string)$image->resize(100, 100, function ($constraint) { $constraint->aspectRatio(); diff --git a/src/resources/views/editImage.blade.php b/src/resources/views/editImage.blade.php index 55010ed1..7c9c42b5 100644 --- a/src/resources/views/editImage.blade.php +++ b/src/resources/views/editImage.blade.php @@ -7,7 +7,7 @@
{{ csrf_field() }} - +
From 1f197d9779cef71bdf68d5ff0ab68adabeff448e Mon Sep 17 00:00:00 2001 From: Alex Deniz Garcia Date: Fri, 15 Sep 2023 16:33:17 +0200 Subject: [PATCH 19/28] REV-12665: hide default delete action when forbidden --- src/Resource.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Resource.php b/src/Resource.php index 3f325208..a5c03809 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -277,9 +277,9 @@ public function mainActions() public function actions() { - return [ - new Delete(), - ]; + return $this->canDelete(static::$model) + ? [new Delete()] + : []; } public function filters() From c2c3525d9101b4c32a658246f48266f859d25ecb Mon Sep 17 00:00:00 2001 From: Alex Deniz Garcia Date: Mon, 18 Sep 2023 15:50:48 +0200 Subject: [PATCH 20/28] REV-12665: fix belongs to many index blade - Show fields in creation if they should show in edit --- src/Controllers/ThrustBelongsToManyController.php | 1 + src/resources/views/belongsToManyIndex.blade.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Controllers/ThrustBelongsToManyController.php b/src/Controllers/ThrustBelongsToManyController.php index 5a23e774..e03d3a28 100644 --- a/src/Controllers/ThrustBelongsToManyController.php +++ b/src/Controllers/ThrustBelongsToManyController.php @@ -18,6 +18,7 @@ public function index($resourceName, $id, $relationship) $belongsToManyField = $resource->fieldFor($relationship); $explodedPivotClass = explode('\\', $object->$relationship()->getPivotClass()); return view('thrust::belongsToManyIndex', [ + 'resource' => $resource, 'resourceName' => $resourceName, 'pivotResourceName' => end($explodedPivotClass), 'object' => $object, diff --git a/src/resources/views/belongsToManyIndex.blade.php b/src/resources/views/belongsToManyIndex.blade.php index 0524b196..4e591ec1 100644 --- a/src/resources/views/belongsToManyIndex.blade.php +++ b/src/resources/views/belongsToManyIndex.blade.php @@ -24,7 +24,7 @@ @endif @foreach($belongsToManyField->pivotFields as $field) - @if(!$field->shouldHide($object, 'index')) + @if($field->showInEdit && $resource->can($field->policyAction))) {!! $field->displayInEdit(null, true) !!} @endif @endforeach From 087e2f831f44012a23aa563983c949391150572a Mon Sep 17 00:00:00 2001 From: Alex Deniz Garcia Date: Tue, 19 Sep 2023 13:16:04 +0200 Subject: [PATCH 21/28] REV-12685: fix thrust messages translations --- src/Controllers/ThrustController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controllers/ThrustController.php b/src/Controllers/ThrustController.php index eb7f33dc..4b8aa330 100644 --- a/src/Controllers/ThrustController.php +++ b/src/Controllers/ThrustController.php @@ -142,6 +142,6 @@ private function backWithMessage(string $message) if (session()->has('thrust-redirect')) { return redirect(session('thrust-redirect')); } - return back()->withMessage(__("'thrust::messages.{$message}")); + return back()->withMessage(__("thrust::messages.{$message}")); } } From cb63be6cb7e459a3cd793ca55dfbd81a60810c81 Mon Sep 17 00:00:00 2001 From: Alex Toro Date: Wed, 27 Sep 2023 14:39:04 +0200 Subject: [PATCH 22/28] Removed the optimize command --- src/Console/Commands/Optimize.php | 21 --------------------- src/Console/Commands/OptimizeClear.php | 21 --------------------- src/ThrustServiceProvider.php | 4 ---- 3 files changed, 46 deletions(-) delete mode 100644 src/Console/Commands/Optimize.php delete mode 100644 src/Console/Commands/OptimizeClear.php diff --git a/src/Console/Commands/Optimize.php b/src/Console/Commands/Optimize.php deleted file mode 100644 index b67cf7e9..00000000 --- a/src/Console/Commands/Optimize.php +++ /dev/null @@ -1,21 +0,0 @@ -call(OptimizeCommand::class); - $this->call(Cache::class); - - return static::SUCCESS; - } -} diff --git a/src/Console/Commands/OptimizeClear.php b/src/Console/Commands/OptimizeClear.php deleted file mode 100644 index 98c8afa6..00000000 --- a/src/Console/Commands/OptimizeClear.php +++ /dev/null @@ -1,21 +0,0 @@ -call(OptimizeClearCommand::class); - $this->call(Clear::class); - - return static::SUCCESS; - } -} diff --git a/src/ThrustServiceProvider.php b/src/ThrustServiceProvider.php index e4b1b6df..c7c4e729 100644 --- a/src/ThrustServiceProvider.php +++ b/src/ThrustServiceProvider.php @@ -4,8 +4,6 @@ use BadChoice\Thrust\Console\Commands\Cache; use BadChoice\Thrust\Console\Commands\Clear; -use BadChoice\Thrust\Console\Commands\Optimize; -use BadChoice\Thrust\Console\Commands\OptimizeClear; use BadChoice\Thrust\Console\Commands\Prune; use Illuminate\Support\ServiceProvider; @@ -29,8 +27,6 @@ public function boot() $this->commands([ Cache::class, Clear::class, - Optimize::class, - OptimizeClear::class, Prune::class, ]); } From 5bec8cb55e10c000be1711b21fc2ef7290ce77a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Sala=20Morral?= Date: Thu, 19 Oct 2023 16:10:06 +0200 Subject: [PATCH 23/28] PR fixes Fixed resource actions swap --- src/Controllers/ThrustActionsController.php | 19 ++++++---- src/Resource.php | 8 +++++ .../views/components/js/actions.blade.php | 35 +++++++++++-------- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/Controllers/ThrustActionsController.php b/src/Controllers/ThrustActionsController.php index d272c498..3b042238 100644 --- a/src/Controllers/ThrustActionsController.php +++ b/src/Controllers/ThrustActionsController.php @@ -25,7 +25,7 @@ public function toggle($resourceName, $id, $field) public function create($resourceName) { - $action = $this->findActionForResource($resourceName, request('action')); + $action = $this->findActionForResource($resourceName, request('action')); if (! $action) { abort(404); @@ -33,6 +33,9 @@ public function create($resourceName) $action->setSelectedTargets(collect(explode(',', request('ids')))); + if(request('search')) { + $resourceName = Thrust::make($resourceName)::$searchResource ?? $resourceName; + } return view('thrust::actions.create', [ 'action' => $action, 'resourceName' => $resourceName, @@ -63,11 +66,9 @@ public function perform($resourceName) public function index($resourceName) { $resource = Thrust::make($resourceName); - if(request('search') && $resource::$searchResource) { - $resource = Thrust::make($resource::$searchResource); - } + return view('thrust::components.actionsIndex', [ - 'actions' => collect($resource->actions()), + 'actions' => collect($resource->searchActions(request('search'))), 'resourceName' => $resource->name(), ]); } @@ -75,10 +76,14 @@ public function index($resourceName) private function findActionForResource($resourceName, $actionClass) { $resource = Thrust::make($resourceName); - $action = collect($resource->actions())->first(function ($action) use ($actionClass) { + $action = collect($resource->searchActions(request('search')))->first(function ($action) use ($actionClass) { return $action instanceof $actionClass; }); - $action->resource = $resource; + + $action->resource = request('search') && $resource::$searchResource + ? Thrust::make($resource::$searchResource) + : $resource; + return $action; } } diff --git a/src/Resource.php b/src/Resource.php index a5c03809..62c1d6a1 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -8,6 +8,7 @@ use BadChoice\Thrust\Contracts\FormatsNewObject; use BadChoice\Thrust\Contracts\Prunable; use BadChoice\Thrust\Exceptions\CanNotDeleteException; +use BadChoice\Thrust\Facades\Thrust; use BadChoice\Thrust\Fields\Edit; use BadChoice\Thrust\Fields\FieldContainer; use BadChoice\Thrust\Fields\Relationship; @@ -282,6 +283,13 @@ public function actions() : []; } + public function searchActions(?bool $whileSearch = false) + { + return $whileSearch && static::$searchResource + ? Thrust::make(static::$searchResource)->actions() + : $this->actions(); + } + public function filters() { return null; diff --git a/src/resources/views/components/js/actions.blade.php b/src/resources/views/components/js/actions.blade.php index f7389a82..f6be26d8 100644 --- a/src/resources/views/components/js/actions.blade.php +++ b/src/resources/views/components/js/actions.blade.php @@ -6,7 +6,7 @@ return alert("{!! __("thrust::messages.noRowsSelected") !!}") } - this.setAttribute('href', this.getAttribute('href') + "&ids=" + selected) + this.setAttribute('href', this.getAttribute('href') + "&ids=" + selected + "&search=" + searching) showPopup(this.getAttribute('href')) } @@ -35,7 +35,8 @@ function doAction(actionClass, selected){ $.post("{{ route('thrust.actions.perform', [$resourceName]) }}", { "_token": "{{ csrf_token() }}", "action" : actionClass, - "ids" : selected + "ids" : selected, + "search": searching, }).done(function(data){ document.getElementById('actions-loading').style.display = 'none' if (data["responseAsPopup"]){ @@ -58,7 +59,6 @@ function getSelectedRowsIds(){ } function toggleSelectAll(checkbox){ - console.log([...document.querySelectorAll('input[name^=selected]')]); [...document.querySelectorAll('input[name^=selected]')] .forEach(elem => checkbox.checked ? elem.checked = true @@ -68,21 +68,26 @@ function toggleSelectAll(checkbox){ registerActionPopupListeners() - window.addEventListener('thrust.searchStarted', () => { - fetch("{{ route('thrust.actions.index', ['resourceName' => $resourceName, 'search' => true]) }}").then(response => { - response.text().then(html => { - document.getElementById('thrust-resource-actions').innerHTML = html - registerActionPopupListeners() + let searching = false + @if($resource::$searchResource) + window.addEventListener('thrust.searchStarted', () => { + searching = true + fetch("{{ route('thrust.actions.index', ['resourceName' => $resourceName, 'search' => true]) }}").then(response => { + response.text().then(html => { + document.getElementById('thrust-resource-actions').innerHTML = html + registerActionPopupListeners() + }) }) }) - }) - window.addEventListener('thrust.searchEnded', () => { - fetch("{{ route('thrust.actions.index', ['resourceName' => $resourceName]) }}").then(response => { - response.text().then(html => { - document.getElementById('thrust-resource-actions').innerHTML = html - registerActionPopupListeners() + window.addEventListener('thrust.searchEnded', () => { + searching = false + fetch("{{ route('thrust.actions.index', ['resourceName' => $resourceName]) }}").then(response => { + response.text().then(html => { + document.getElementById('thrust-resource-actions').innerHTML = html + registerActionPopupListeners() + }) }) }) - }) + @endif From ae709809d13cc1d79d5e262197a1c79c8675d2df Mon Sep 17 00:00:00 2001 From: Alex Deniz Garcia Date: Thu, 26 Oct 2023 15:00:21 +0200 Subject: [PATCH 24/28] REV-13066: fix belongsToMany blade --- src/resources/views/belongsToManyIndex.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/views/belongsToManyIndex.blade.php b/src/resources/views/belongsToManyIndex.blade.php index 4e591ec1..3e809a4d 100644 --- a/src/resources/views/belongsToManyIndex.blade.php +++ b/src/resources/views/belongsToManyIndex.blade.php @@ -24,7 +24,7 @@ @endif @foreach($belongsToManyField->pivotFields as $field) - @if($field->showInEdit && $resource->can($field->policyAction))) + @if($field->showInEdit && $resource->can($field->policyAction)) {!! $field->displayInEdit(null, true) !!} @endif @endforeach From 9bf397f5d1378e70948b6b1f3353bbb0b7198174 Mon Sep 17 00:00:00 2001 From: Alex Deniz Garcia Date: Thu, 26 Oct 2023 15:13:29 +0200 Subject: [PATCH 25/28] REV-13003: add permission check to *ManyController index --- src/Controllers/ThrustBelongsToManyController.php | 3 +++ src/Controllers/ThrustHasManyController.php | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/Controllers/ThrustBelongsToManyController.php b/src/Controllers/ThrustBelongsToManyController.php index e03d3a28..f3785f7f 100644 --- a/src/Controllers/ThrustBelongsToManyController.php +++ b/src/Controllers/ThrustBelongsToManyController.php @@ -4,6 +4,7 @@ use BadChoice\Thrust\Facades\Thrust; use BadChoice\Thrust\Fields\BelongsToMany; +use BadChoice\Thrust\ResourceGate; use Illuminate\Database\Eloquent\Relations\BelongsToMany as BelongsToManyBuilder; use Illuminate\Database\Eloquent\Model; use Illuminate\Routing\Controller; @@ -17,6 +18,8 @@ public function index($resourceName, $id, $relationship) $object = $resource->find($id); $belongsToManyField = $resource->fieldFor($relationship); $explodedPivotClass = explode('\\', $object->$relationship()->getPivotClass()); + app(ResourceGate::class)->check($resource, 'index'); + return view('thrust::belongsToManyIndex', [ 'resource' => $resource, 'resourceName' => $resourceName, diff --git a/src/Controllers/ThrustHasManyController.php b/src/Controllers/ThrustHasManyController.php index a18bfd40..5f276bec 100644 --- a/src/Controllers/ThrustHasManyController.php +++ b/src/Controllers/ThrustHasManyController.php @@ -2,6 +2,7 @@ namespace BadChoice\Thrust\Controllers; +use BadChoice\Thrust\ResourceGate; use Illuminate\Routing\Controller; use BadChoice\Thrust\Facades\Thrust; use BadChoice\Thrust\ChildResource; @@ -14,6 +15,7 @@ public function index($resourceName, $id, $relationship) $object = $resource->find($id); $hasManyField = $resource->fieldFor($relationship); $childResource = Thrust::make($hasManyField->resourceName)->parentId($id); + app(ResourceGate::class)->check($resource, 'index'); $backHasManyURLParams = $resource instanceof ChildResource ? $resource->getParentHasManyUrlParams($object) : null; From d02d59034c5bbfcf5973b1d907f2824427ef265c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Sala=20Morral?= Date: Mon, 13 Nov 2023 11:04:47 +0100 Subject: [PATCH 26/28] REV-13367 fixed text get value on null --- src/Fields/Text.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Fields/Text.php b/src/Fields/Text.php index bfda114b..9cd78da4 100644 --- a/src/Fields/Text.php +++ b/src/Fields/Text.php @@ -69,7 +69,12 @@ public function getValue($object) if (! $object) { return null; } - return htmlspecialchars(parent::getValue($object)); + + $value = parent::getValue($object); + + return $value === null + ? null + : htmlspecialchars($value); } public function allowScripts() From 6b32f4d95320c818ee225a7d17d1f45af1e69ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Sala=20Morral?= Date: Mon, 13 Nov 2023 15:54:35 +0100 Subject: [PATCH 27/28] REV-13381 Fixed searching="false" evaluating to true --- src/resources/views/components/js/actions.blade.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/resources/views/components/js/actions.blade.php b/src/resources/views/components/js/actions.blade.php index f6be26d8..e5858f74 100644 --- a/src/resources/views/components/js/actions.blade.php +++ b/src/resources/views/components/js/actions.blade.php @@ -68,10 +68,10 @@ function toggleSelectAll(checkbox){ registerActionPopupListeners() - let searching = false + let searching = 0 @if($resource::$searchResource) window.addEventListener('thrust.searchStarted', () => { - searching = true + searching = 1 fetch("{{ route('thrust.actions.index', ['resourceName' => $resourceName, 'search' => true]) }}").then(response => { response.text().then(html => { document.getElementById('thrust-resource-actions').innerHTML = html @@ -81,7 +81,7 @@ function toggleSelectAll(checkbox){ }) window.addEventListener('thrust.searchEnded', () => { - searching = false + searching = 0 fetch("{{ route('thrust.actions.index', ['resourceName' => $resourceName]) }}").then(response => { response.text().then(html => { document.getElementById('thrust-resource-actions').innerHTML = html From afe7749960b47810c187e160011bf722ddf3b0fc Mon Sep 17 00:00:00 2001 From: adriamartin Date: Thu, 16 Nov 2023 10:13:46 +0100 Subject: [PATCH 28/28] feature: add German, Euskera, Italian and Chinese languages. --- src/resources/lang/de/messages.php | 32 ++++++++++++++++++++++++++++++ src/resources/lang/eu/messages.php | 32 ++++++++++++++++++++++++++++++ src/resources/lang/it/messages.php | 32 ++++++++++++++++++++++++++++++ src/resources/lang/zh/messages.php | 32 ++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 src/resources/lang/de/messages.php create mode 100644 src/resources/lang/eu/messages.php create mode 100644 src/resources/lang/it/messages.php create mode 100644 src/resources/lang/zh/messages.php diff --git a/src/resources/lang/de/messages.php b/src/resources/lang/de/messages.php new file mode 100644 index 00000000..997c6730 --- /dev/null +++ b/src/resources/lang/de/messages.php @@ -0,0 +1,32 @@ + 'Suchen', + 'save' => 'Speichern', + 'saveAndContinueEditing' => 'Speichern und weiter bearbeiten', + 'new' => 'Neu', + 'saveOrder' => 'Sortierung speichern', + 'add' => 'Hinzufügen', + 'delete' => 'Löschen', + 'noData' => 'Keine Daten', + 'actions' => 'Aktionen', + 'perform' => 'Ausführen', + 'noRowsSelected' => 'Keine Zeile ausgewählt', + 'created' => 'Erstellt', + 'updated' => 'Aktualisiert', + 'deleted' => 'Gelöscht', + 'apply' => 'Anwenden', + 'activate' => 'Aktivieren', + 'deactivate' => 'Deaktivieren', + 'clearSorting' => 'Sortierung löschen', + 'clearSelection' => 'Auswahl löschen', + 'amount' => 'Menge', + 'amountDesc' => 'Anzahl der zu erstellenden Kopien.', + 'createMultiple' => 'Mehrfaches Erstellen', + 'import' => 'Importieren', + 'selectCsvFile' => 'CSV-Datei auswählen', + 'rowsToImport' => 'Zeilen zum Importieren', + 'next' => 'Weiter', + 'importFailed' => 'Import fehlgeschlagen', + 'retryImport' => 'Import erneut versuchen' +]; \ No newline at end of file diff --git a/src/resources/lang/eu/messages.php b/src/resources/lang/eu/messages.php new file mode 100644 index 00000000..0a707748 --- /dev/null +++ b/src/resources/lang/eu/messages.php @@ -0,0 +1,32 @@ + 'Bilatu', + 'save' => 'Gorde', + 'saveAndContinueEditing' => 'Gorde eta editatzen jarraitu', + 'new' => 'Berria', + 'saveOrder' => 'Orden gorde', + 'add' => 'Gehitu', + 'delete' => 'Ezabatu', + 'noData' => 'Ez dago daturik', + 'actions' => 'Ekintzak', + 'perform' => 'Egin', + 'noRowsSelected' => 'Ez dago errenkadarik hautatuta', + 'created' => 'Sortua', + 'updated' => 'Eguneratua', + 'deleted' => 'Ezabatua', + 'apply' => 'Aplikatu', + 'activate' => 'Aktibatu', + 'deactivate' => 'Desaktibatu', + 'clearSorting' => 'Ordenaketa garbitu', + 'clearSelection' => 'Hautaketa garbitu', + 'amount' => 'Kopurua', + 'amountDesc' => 'Sortu beharreko kopien kopurua.', + 'createMultiple' => 'Kopia anitz sortu', + 'import' => 'Inportatu', + 'selectCsvFile' => 'Hautatu CSV fitxategia', + 'rowsToImport' => 'Inportatu beharreko errenkadak', + 'next' => 'Hurrengoa', + 'importFailed' => 'Inportazioa huts egin du', + 'retryImport' => 'Inportazioa saiatu berriro' +]; \ No newline at end of file diff --git a/src/resources/lang/it/messages.php b/src/resources/lang/it/messages.php new file mode 100644 index 00000000..47ea393f --- /dev/null +++ b/src/resources/lang/it/messages.php @@ -0,0 +1,32 @@ + 'Cerca', + 'save' => 'Salva', + 'saveAndContinueEditing' => 'Salva e continua a modificare', + 'new' => 'Nuovo', + 'saveOrder' => 'Salva ordine', + 'add' => 'Aggiungi', + 'delete' => 'Elimina', + 'noData' => 'Nessun dato', + 'actions' => 'Azioni', + 'perform' => 'Esegui', + 'noRowsSelected' => 'Nessuna riga selezionata', + 'created' => 'Creato', + 'updated' => 'Aggiornato', + 'deleted' => 'Eliminato', + 'apply' => 'Applica', + 'activate' => 'Attiva', + 'deactivate' => 'Disattiva', + 'clearSorting' => 'Cancella ordine', + 'clearSelection' => 'Cancella selezione', + 'amount' => 'Quantità', + 'amountDesc' => 'Numero di copie da creare.', + 'createMultiple' => 'Creazione multipla', + 'import' => 'Importa', + 'selectCsvFile' => 'Seleziona il file CSV', + 'rowsToImport' => 'Righe da importare', + 'next' => 'Avanti', + 'importFailed' => 'Importazione fallita', + 'retryImport' => 'Riprova l\'importazione' +]; \ No newline at end of file diff --git a/src/resources/lang/zh/messages.php b/src/resources/lang/zh/messages.php new file mode 100644 index 00000000..8e688dd5 --- /dev/null +++ b/src/resources/lang/zh/messages.php @@ -0,0 +1,32 @@ + '搜索', + 'save' => '保存', + 'saveAndContinueEditing' => '保存并继续编辑', + 'new' => '新建', + 'saveOrder' => '保存排序', + 'add' => '添加', + 'delete' => '删除', + 'noData' => '没有数据', + 'actions' => '操作', + 'perform' => '执行', + 'noRowsSelected' => '没有选中的行', + 'created' => '已创建', + 'updated' => '已更新', + 'deleted' => '已删除', + 'apply' => '应用', + 'activate' => '激活', + 'deactivate' => '停用', + 'clearSorting' => '清除排序', + 'clearSelection' => '清除选择', + 'amount' => '数量', + 'amountDesc' => '要创建的副本数量。', + 'createMultiple' => '多重创建', + 'import' => '导入', + 'selectCsvFile' => '选择 CSV 文件', + 'rowsToImport' => '要导入的行', + 'next' => '下一步', + 'importFailed' => '导入失败', + 'retryImport' => '重试导入' +]; \ No newline at end of file