Skip to content

Commit

Permalink
Added options
Browse files Browse the repository at this point in the history
  • Loading branch information
bald-cat committed Oct 23, 2024
1 parent 03ead6c commit 2499e63
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Actions/Action.php
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));
}

}
29 changes: 29 additions & 0 deletions src/Actions/Actions.php
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);
}
}
22 changes: 22 additions & 0 deletions src/Actions/Create.php
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');
}
}
24 changes: 24 additions & 0 deletions src/Actions/Delete.php
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);
}

}
22 changes: 22 additions & 0 deletions src/Actions/Edit.php
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);
}
}
13 changes: 13 additions & 0 deletions src/Actions/ModelFormButton.php
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);
}
}
17 changes: 17 additions & 0 deletions src/Actions/Save.php
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");
}
}
18 changes: 18 additions & 0 deletions src/Actions/Update.php
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);
}
}

0 comments on commit 2499e63

Please sign in to comment.