Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8dfe983
Merge pull request #62 from revosystems/added-time-range-field
BadChoice May 4, 2023
4e5d367
Merge pull request #63 from revosystems/added-time-range-field
BadChoice May 10, 2023
6c8b3fc
fixed javascript calls
draude May 15, 2023
29bf10c
Merge pull request #64 from revosystems/added-time-range-field
dadraude May 15, 2023
57049c3
REV-11528
MartiSalaMorral May 24, 2023
ec12c25
Merge pull request #65 from revosystems/feature/REV-11528
BadChoice May 24, 2023
ad76f8b
REV-11882
MartiSalaMorral Jun 22, 2023
c75b9fe
PR fixes
MartiSalaMorral Jun 28, 2023
c0b7def
Merge pull request #66 from revosystems/feature/REV-11882
BadChoice Jun 28, 2023
d4d1609
Changed edit blade to support creations
JordiFL-Revo Jul 5, 2023
5ef1a80
Merge pull request #67 from JordiFL-Revo/feature/rev-11956
BadChoice Jul 5, 2023
4327b4c
REV-12050 fetch correct actions while searching
MartiSalaMorral Jul 7, 2023
3dac118
Added an optional redirect
alexrevo Aug 2, 2023
141415e
Refactored last commit
alexrevo Aug 2, 2023
d3731e7
Merge pull request #69 from revosystems/feature/redirect
BadChoice Aug 2, 2023
3ac5dc5
Database actions should be created within current model connection.
PauRevo Aug 7, 2023
4260bc0
Merge pull request #70 from revosystems/feature/rev-11808
PauBenetPrat Aug 7, 2023
5353733
REV-12144: hide Thrust Resource delete action when forbidden
alexdenizg Aug 7, 2023
0969be0
Merge pull request #71 from revosystems/feature/rev-12144
alexdenizg Aug 8, 2023
f2236b3
Revert "REV-12144: hide Thrust Resource delete action when forbidden"
PauBenetPrat Aug 18, 2023
bbd1b68
Merge pull request #72 from revosystems/revert-71-feature/rev-12144
PauBenetPrat Aug 18, 2023
55496c5
Disable query log on import
Aug 22, 2023
9842bce
Added compatibility wiht Laravel 10
MartiSalaMorral Aug 22, 2023
b7d4001
Merge pull request #73 from revosystems/laravel-10
BadChoice Aug 22, 2023
b4ac8e2
Add resource request validation.
PauRevo Aug 28, 2023
579c2ae
REV-12275: make decimal field nullable
alexdenizg Aug 29, 2023
1f44756
Instead of validating the request directly, we create a validator and…
PauRevo Aug 30, 2023
7b0e0f0
Merge pull request #74 from revosystems/feature/rev-12341
BadChoice Aug 31, 2023
7ba4f40
REV-12637
MartiSalaMorral Sep 13, 2023
af49121
Merge pull request #76 from revosystems/bugfix/REV-12637
BadChoice Sep 13, 2023
0fe4e15
Merge pull request #75 from revosystems/feature/rev-12275
BadChoice Sep 14, 2023
3cc5bf5
Thrust can force a image filename
Sep 15, 2023
1f197d9
REV-12665: hide default delete action when forbidden
alexdenizg Sep 15, 2023
ada0abf
Merge pull request #77 from revosystems/feature/rev-12665
BadChoice Sep 15, 2023
c2c3525
REV-12665: fix belongs to many index blade
alexdenizg Sep 18, 2023
de16690
Merge pull request #78 from revosystems/feature/rev-12665
BadChoice Sep 18, 2023
087e2f8
REV-12685: fix thrust messages translations
alexdenizg Sep 19, 2023
38cc73c
Merge pull request #79 from revosystems/feature/rev-12685
BadChoice Sep 19, 2023
cb63be6
Removed the optimize command
alexrevo Sep 27, 2023
b68f0d9
Merge pull request #80 from revosystems/feature/remove-optimize-command
BadChoice Sep 27, 2023
2286a4b
Merge pull request #68 from revosystems/bugfix/REV-12050-display-corr…
BadChoice Oct 9, 2023
5bec8cb
PR fixes
MartiSalaMorral Oct 19, 2023
a060831
Merge pull request #82 from revosystems/bugfix/REV-12050-display-corr…
BadChoice Oct 19, 2023
ae70980
REV-13066: fix belongsToMany blade
alexdenizg Oct 26, 2023
9bf397f
REV-13003: add permission check to *ManyController index
alexdenizg Oct 26, 2023
95c513e
Merge pull request #84 from revosystems/bugfix/rev-13066
alexdenizg Oct 26, 2023
f005284
Merge pull request #83 from revosystems/bugfix/rev-13003
alexdenizg Oct 26, 2023
d02d590
REV-13367 fixed text get value on null
MartiSalaMorral Nov 13, 2023
8d4292a
Merge pull request #85 from revosystems/bugfix/REV-13367
BadChoice Nov 13, 2023
6b32f4d
REV-13381
MartiSalaMorral Nov 13, 2023
ee78924
Merge pull request #86 from revosystems/bugfix/REV-13381
BadChoice Nov 13, 2023
afe7749
feature: add German, Euskera, Italian and Chinese languages.
Nov 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions src/ChildResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BadChoice\Thrust;

use BadChoice\Thrust\ResourceManager;
use BadChoice\Thrust\Facades\Thrust;

abstract class ChildResource extends Resource
{
Expand Down Expand Up @@ -57,6 +57,16 @@ public function parent($object)
public function getParentHasManyUrlParams($object)
{
$parent = $this->parent($object);
return $this::$parentChildsRelation && $parent ? [app(ResourceManager::class)->resourceNameFromModel($parent), $parent->id, static::$parentChildsRelation] : null;
return $this::$parentChildsRelation && $parent ? [Thrust::resourceNameFromModel($parent), $parent->id, static::$parentChildsRelation] : null;
}

public function breadcrumbs(mixed $object): ?string
{
$parent = $this->parent($object);
if(! $parent) {
return null;
}
$parentResource = Thrust::make(Thrust::resourceNameFromModel($parent));
return implode(' / ', array_filter([$parentResource->breadcrumbs($parent), $parent->{$parentResource->nameField}]));
}
}
21 changes: 0 additions & 21 deletions src/Console/Commands/Optimize.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/Console/Commands/OptimizeClear.php

This file was deleted.

23 changes: 20 additions & 3 deletions src/Controllers/ThrustActionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ 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);
}

$action->setSelectedTargets(collect(explode(',', request('ids'))));

if(request('search')) {
$resourceName = Thrust::make($resourceName)::$searchResource ?? $resourceName;
}
return view('thrust::actions.create', [
'action' => $action,
'resourceName' => $resourceName,
Expand Down Expand Up @@ -60,13 +63,27 @@ public function perform($resourceName)
return back()->withMessage($response);
}

public function index($resourceName)
{
$resource = Thrust::make($resourceName);

return view('thrust::components.actionsIndex', [
'actions' => collect($resource->searchActions(request('search'))),
'resourceName' => $resource->name(),
]);
}

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;
}
}
4 changes: 4 additions & 0 deletions src/Controllers/ThrustBelongsToManyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,7 +18,10 @@ 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,
'pivotResourceName' => end($explodedPivotClass),
'object' => $object,
Expand Down
26 changes: 20 additions & 6 deletions src/Controllers/ThrustController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function index($resourceName)
return view('thrust::index', [
'resourceName' => $resourceName,
'resource' => $resource,
'actions' => collect($resource->actions()),
'searchable' => count($resource::$search) > 0,
'description' => $resource->getDescription(),
]);
Expand Down Expand Up @@ -64,15 +65,17 @@ 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) {
if (request()->ajax()) { return response()->json(["error" => $e->getMessage()], Response::HTTP_UNPROCESSABLE_ENTITY);}
return back()->withErrors(['message' => $e->getMessage()]);
}
if (request()->ajax()) { return response()->json($result);}
return back()->withMessage(__('thrust::messages.created'));

return $this->backWithMessage('created');
}

public function storeMultiple($resourceName)
Expand All @@ -95,22 +98,24 @@ public function storeMultiple($resourceName)
}

DB::commit();
return back()->withMessage(__('thrust::messages.created'));

return $this->backWithMessage('created');
}

public function update($resourceName, $id)
{
$resource = Thrust::make($resourceName);
if (! request()->has('inline')) {
request()->validate($resource->getValidationRules($id));
$resource->validate(request(), $id);
}

try {
$resource->update($id, request()->except('inline'));
} catch (\Exception $e) {
return back()->withErrors(['message' => $e->getMessage()]);
}
return back()->withMessage(__('thrust::messages.updated'));

return $this->backWithMessage('updated');
}

public function delete($resourceName, $id)
Expand All @@ -120,7 +125,8 @@ public function delete($resourceName, $id)
} catch (\Exception $e) {
return back()->withErrors(['delete' => $e->getMessage()]);
}
return back()->withMessage(__('thrust::messages.deleted'));

return $this->backWithMessage('deleted');
}

private function singleResourceIndex($resourceName, $resource)
Expand All @@ -131,4 +137,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}"));
}
}
3 changes: 3 additions & 0 deletions src/Controllers/ThrustHasManyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,13 +15,15 @@ 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;

return view('thrust::index', [
'resourceName' => $hasManyField->resourceName,
'searchable' => count($resource::$search) > 0,
'resource' => $childResource,
'actions' => collect($childResource->actions()),
'parent_id' => $id,
'isChild' => $resource instanceof ChildResource && $backHasManyURLParams,
'hasManyBackUrlParams' => $backHasManyURLParams,
Expand Down
2 changes: 2 additions & 0 deletions src/Controllers/ThrustImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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());
Expand Down
10 changes: 10 additions & 0 deletions src/Fields/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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';
Expand Down
7 changes: 7 additions & 0 deletions src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ abstract class Field

public $showInIndex = true;
public $showInEdit = true;
public $showInSearch = false;
public $policyAction = null;

public $withDesc = false;
Expand Down Expand Up @@ -161,6 +162,12 @@ public function hideInEdit($hideInEdit = true)
return $this;
}

public function showInSearch(bool $show = true): self
{
$this->showInSearch = $show;
return $this;
}

public function onlyInEdit()
{
$this->showInIndex = false;
Expand Down
9 changes: 8 additions & 1 deletion src/Fields/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion src/Fields/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions src/Html/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -56,6 +56,7 @@ public function show($id, $fullPage = false, $multiple = false)
return view('thrust::edit', [
'title' => $this->resource->getTitle(),
'nameField' => $this->resource->nameField,
'breadcrumbs' => $this->resource->breadcrumbs($object),
'resourceName' => $this->resourceName ? : $this->resource->name(),
'fields' => $this->getEditFields($multiple),
'object' => $object,
Expand All @@ -74,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();
}
Expand All @@ -87,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},
Expand Down
Loading