Skip to content

Commit

Permalink
feat: add more actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Jun 14, 2022
1 parent 91f4df7 commit 123345d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
32 changes: 28 additions & 4 deletions config/tallkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,14 @@
'loading' => 'Saving',
],

'save-and-view' => [
'text' => 'Save and view',
'tooltip' => 'Save and view',
'color' => 'success',
'icon' => '<svg class="w-4 h-4" viewBox="0 0 512 512"><path fill="currentColor" d="M433.941 129.941l-83.882-83.882A48 48 0 0 0 316.118 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h352c26.51 0 48-21.49 48-48V163.882a48 48 0 0 0-14.059-33.941zM224 416c-35.346 0-64-28.654-64-64 0-35.346 28.654-64 64-64s64 28.654 64 64c0 35.346-28.654 64-64 64zm96-304.52V212c0 6.627-5.373 12-12 12H76c-6.627 0-12-5.373-12-12V108c0-6.627 5.373-12 12-12h228.52c3.183 0 6.235 1.264 8.485 3.515l3.48 3.48A11.996 11.996 0 0 1 320 111.48z"></path></svg>',
'loading' => 'Saving',
],

'send' => [
'text' => 'Send',
'tooltip' => 'Send',
Expand Down Expand Up @@ -1549,17 +1557,33 @@

'header' => [],

'header-save' => [],
'header-save' => [
'name' => 'crud-form',
'value' => 'save',
],

'header-save-and-view' => [
'name' => 'crud-form',
'value' => 'save-and-view',
],

'header-back' => [],

'content' => [],

'footer' => [
'class' => 'flex space-x-4 items-center justify-between pt-4',
'class' => 'flex space-x-4 items-center justify-end pt-4',
],

'footer-save' => [],
'footer-save' => [
'name' => 'crud-form',
'value' => 'save',
],

'footer-save-and-view' => [
'name' => 'crud-form',
'value' => 'save-and-view',
],

'footer-back' => [],
],
Expand All @@ -1578,7 +1602,7 @@
'content' => [],

'footer' => [
'class' => 'flex space-x-2 items-center pt-4',
'class' => 'flex space-x-2 items-center justify-end pt-4',
],

'footer-actions' => [],
Expand Down
11 changes: 11 additions & 0 deletions resources/views/components/crud/crud-actions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
/>
@endforeach

@if (! in_array($routeName, ['index', 'create', 'new', 'form']) && $route = route_detect([$prefix.'.create', $prefix.'.new', $prefix.'.form'], $parameters, null))
<x-button
{{ $attributes->mergeOnlyThemeProvider($themeProvider, 'create') }}
preset="create"
:text="$tooltip ? '' : null"
:tooltip="$tooltip"
:href="$route"
:theme="$theme"
/>
@endif

@if (! in_array($routeName, ['show', 'view']) && $route = route_detect([$prefix.'.show', $prefix.'.view'], $parameters, null))
<x-button
{{ $attributes->mergeOnlyThemeProvider($themeProvider, 'show') }}
Expand Down
22 changes: 21 additions & 1 deletion resources/views/components/crud/crud-form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
:theme="$theme"
/>

@if (Route::has($prefix.'.show') || Route::has($prefix.'.view'))
<x-submit
{{ $attributes->mergeOnlyThemeProvider($themeProvider, 'header-save-and-view') }}
preset="save-and-view"
:text="$tooltip ? '' : null"
:tooltip="$tooltip"
:theme="$theme"
/>
@endif

<x-back
{{ $attributes->mergeOnlyThemeProvider($themeProvider, 'header-back') }}
preset="back-right"
Expand Down Expand Up @@ -57,12 +67,22 @@
@else
<x-submit
{{ $attributes->mergeOnlyThemeProvider($themeProvider, 'footer-save') }}
preset="save"
:text="$tooltip ? '' : null"
:tooltip="$tooltip"
preset="save"
:theme="$theme"
/>

@if (Route::has($prefix.'.show') || Route::has($prefix.'.view'))
<x-submit
{{ $attributes->mergeOnlyThemeProvider($themeProvider, 'footer-save-and-view') }}
preset="save-and-view"
:text="$tooltip ? '' : null"
:tooltip="$tooltip"
:theme="$theme"
/>
@endif

<x-back
{{ $attributes->mergeOnlyThemeProvider($themeProvider, 'footer-back') }}
preset="back-right"
Expand Down
5 changes: 5 additions & 0 deletions src/Components/Crud/Crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public function __construct(
$this->prefix = implode('.', $parts);
}

if (! $this->routeName) {
$parts = explode('.', Route::currentRouteName());
$this->routeName = end($parts);
}

if (! $parts) {
$parts = explode('.', $this->prefix);
}
Expand Down

0 comments on commit 123345d

Please sign in to comment.