-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Orchid\Actions; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Str; | ||
|
||
class Action | ||
{ | ||
|
||
protected static function modelName(Model $model): string | ||
{ | ||
return class_basename($model); | ||
} | ||
|
||
protected static function modelAttribute(Model $model): string | ||
{ | ||
return Str::camel(self::modelName($model)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Orchid\Actions; | ||
|
||
use Illuminate\Support\Arr; | ||
use Orchid\Screen\Actions\Button; | ||
use Orchid\Screen\Fields\Group; | ||
use Orchid\Screen\TD; | ||
|
||
class Actions | ||
{ | ||
/** | ||
* Return Actions button group for table | ||
* @param array $actions | ||
* @return TD | ||
*/ | ||
public static function make(array $actions = []): TD | ||
{ | ||
return TD::make('Actions')->render(function ($row) use ($actions) { | ||
|
||
$group = []; | ||
foreach ($actions as $action) { | ||
$group[] = $action::make($row); | ||
} | ||
|
||
return Group::make($group)->toEnd(); | ||
})->width(count($actions) * 75); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Orchid\Actions; | ||
|
||
use Orchid\Screen\Actions\Link; | ||
use Orchid\Support\Color; | ||
|
||
class Create extends Action | ||
{ | ||
|
||
/** | ||
* @param string $attribute | ||
* @return Link | ||
*/ | ||
public static function make(string $attribute): Link | ||
{ | ||
return Link::make() | ||
->name(__('Create')) | ||
->type(Color::INFO) | ||
->route('platform.' . $attribute . '.form'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Orchid\Actions; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Str; | ||
use Orchid\Screen\Actions\Button; | ||
use Orchid\Support\Color; | ||
|
||
class Delete extends Action | ||
{ | ||
|
||
const ROUTE_PREFIX = '.destroy'; | ||
|
||
public static function make(Model $model) | ||
{ | ||
return Button::make() | ||
->type(Color::DANGER) | ||
->name(__('Delete')) | ||
->confirm(__('Are you sure you want to delete this ' . self::modelName($model) . '?')) | ||
->route(self::modelAttribute($model) . self::ROUTE_PREFIX, $model->id); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Orchid\Actions; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Orchid\Screen\Actions\Link; | ||
use Orchid\Support\Color; | ||
|
||
class Edit extends Action | ||
{ | ||
|
||
const ROUTE_PREFIX = '.form.edit'; | ||
|
||
public static function make(Model $model) | ||
{ | ||
return Link::make() | ||
->name(__('Edit')) | ||
->type(Color::WARNING) | ||
->rawClick(true) | ||
->route('platform.' . self::modelAttribute($model) . self::ROUTE_PREFIX, $model->id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\Orchid\Actions; | ||
|
||
class ModelFormButton | ||
{ | ||
public static function make(string $attribute, ?int $id) | ||
{ | ||
return $id | ||
? Update::make($attribute, $id) | ||
: Save::make($attribute); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Orchid\Actions; | ||
|
||
use Orchid\Screen\Actions\Button; | ||
use Orchid\Support\Color; | ||
|
||
class Save | ||
{ | ||
public static function make(string $attribute) | ||
{ | ||
return Button::make() | ||
->name(__('Save')) | ||
->type(Color::DARK) | ||
->route("$attribute.store"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Orchid\Actions; | ||
|
||
use Orchid\Screen\Actions\Button; | ||
use Orchid\Screen\Actions\Link; | ||
use Orchid\Support\Color; | ||
|
||
class Update | ||
{ | ||
public static function make(string $attribute, int $id) | ||
{ | ||
return Button::make() | ||
->name(__('Update')) | ||
->type(Color::DARK) | ||
->route($attribute . '.update', $id); | ||
} | ||
} |