Skip to content

Commit 8d72016

Browse files
authored
Merge pull request #117 from Gustavinho/feature/add-bulk-actions
Feature/add bulk actions
2 parents 1e51adb + 63dda66 commit 8d72016

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+606
-364
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ branches:
2626
- dev
2727
- /^release-.*$/
2828
- /^release/.*$/
29+
- /^feature/.*$/
2930

3031
before_script:
3132
- composer config discard-changes true

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ Here's the plan for what's coming:
179179
## Upgrade guide
180180
### From 2.2 to 2.3
181181
- Clear your cached views `php artisan view:clear` since some of the internal components changed.
182-
- Update components
182+
- Update components.
183+
- Update config-file.
183184
- Update the renderIf() function in your action classes as follows:
184185
```php
185186
<?php

doc/grid-view.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,14 @@ Name|Description|Type|Value
9999
model|Model instance for this card|||
100100
actions|Actions defined in this view class|Array
101101
hasDefaultAction|Checks if the Grid View has defined a `onCardClick` method|Boolean|true,false
102+
selected|Defines if the item was selected when the grid view has bulk actions|Boolean|true,false
102103

103-
With all this data you can build your own card component as you need, remember to include the `actions` component.
104+
With all this data you can build your own card component as you need, remember to include an `actions` component.
104105

105106
```html
106107
<x-lv-actions :actions="$actions" :model="$model" />
108+
<!-- Or -->
109+
<x-lv-actions.drop-down :actions="$actions" :model="$model" />
107110
```
108111

109112

doc/table-view.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This view creates a dynamic data table with some features like filters, paginati
2121
- [Changing title](#changing-title)
2222
- [Actions](#actions)
2323
- [Registering actions](#registering-actions)
24+
- [Bulk actions](#bulk-actions)
2425
- [Redirect action](#redirect-action)
2526
- [Showing feedback messages](#showing-feedback-messages)
2627
- [Hiding actions](#hiding-actions)
@@ -317,6 +318,23 @@ protected function actionsByRow()
317318
}
318319
```
319320

321+
## Bulk actions
322+
You can execute bulk actions selecting items on the UI defining a `bulkActions` method with all the actions you want to use. If you define this method, a checkbox input will be displayed for each item to select or unselect it.
323+
324+
```php
325+
protected function bulkActions()
326+
{
327+
return [
328+
new ActivateUsersAction,
329+
];
330+
}
331+
```
332+
You can creat a bulk action by an artisan command just using the `--bulk` option.
333+
334+
```bash
335+
php artisan make:action Actions/ActivateUserAction --bulk
336+
```
337+
320338
## Redirect action
321339
This package has a defined action to redirect the user to a named route related to your model inside your project when the button is clicked, you can use it directly on the `actionsByRow` method
322340

@@ -395,7 +413,7 @@ public function getConfirmationMessage($item = null)
395413
```
396414

397415
# Showing UI components
398-
You can display some UI components instead of plain text like avateres, badges or icons, some of these components has different variants, you can customize these varians with the `laravel-views.php` config file.
416+
You can display some UI components instead of plain text like avatars, badges or icons, some of these components has different variants, you can customize these varians with the `laravel-views.php` config file.
399417

400418
## Avatar
401419
Shows an 32x32 rounded image
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@props(['actions' => [], 'model' => null])
2+
3+
<x-lv-drop-down>
4+
<x-slot name="trigger">
5+
<x-lv-icon-button icon="more-horizontal" size="sm"/>
6+
</x-slot>
7+
<x-lv-actions.icon-and-title :actions="$actions" :model="$model" />
8+
</x-lv-drop-down>
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
@props(['actions', 'model'])
1+
@props(['actions', 'model' => null])
22

33
@foreach ($actions as $action)
44
@if ($action->renderIf($model, $this))
5-
<a href="#!" wire:click.prevent="executeAction('{{ $action->id }}', '{{ $model->getKey() }}', true)" title="{{ $action->title}}" class="group flex items-center px-4 py-2 text-gray-700 hover:bg-gray-100 hover:text-gray-900">
5+
<button
6+
wire:click.prevent="{{ $model ? "executeAction('{$action->id}','{$model->getKey()}')" : "executeBulkAction('{$action->id}')" }}"
7+
title="{{ $action->title}}"
8+
class="group flex items-center px-4 py-2 text-gray-700 hover:bg-gray-100 hover:text-gray-900 w-full focus:outline-none"
9+
>
610
<i data-feather="{{ $action->icon }}" class="mr-3 h-4 w-4 text-gray-600 group-hover:text-gray-700"></i>
711
{{ $action->title }}
8-
</a>
12+
</button>
913
@endif
1014
@endforeach

resources/views/components/actions/icon.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
@foreach ($actions as $action)
44
@if ($action->renderIf($model, $this))
5-
<x-lv-icon-button :icon="$action->icon" size="sm" wire:click.prevent="executeAction('{{ $action->id }}', '{{ $model->getKey() }}', true)" />
5+
<x-lv-icon-button :icon="$action->icon" size="sm" wire:click.prevent="executeAction('{{ $action->id }}', '{{ $model->getKey() }}')" />
66
@endif
77
@endforeach

resources/views/components/actions/actions.blade.php renamed to resources/views/components/actions/responsive.blade.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
@props(['actions', 'model'])
1+
@props(['actions' => [], 'model' => null])
22

33
<div>
44
@if (count($actions))
55
{{-- Mobile actions dropdown --}}
66
<div class="lg:hidden text-right relative">
7-
<x-lv-drop-down>
8-
<x-slot name="trigger">
9-
<x-lv-icon-button icon="more-horizontal" size="sm" />
10-
</x-slot>
11-
12-
<x-lv-actions.icon-and-title :actions="$actions" :model="$model" />
13-
</x-lv-drop-down>
7+
<x-lv-actions.drop-down :actions="$actions" :model="$model" />
148
</div>
159

1610
{{-- Desktop action buttons --}}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@props(['variant' => 'primary', 'type' => 'button'])
2+
3+
<button {{ $attributes }} type="{{ $type }}" class="px-4 py-2 text-sm border border-transparent font-medium rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 {{ variants('buttons.' . $variant) }}">
4+
{{ $slot }}
5+
</button>

resources/views/components/buttons/select.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
class="border border-transparent hover:border-gray-300 focus:border-gray-300 focus:outline-none flex items-center gap-1 text-xs px-3 py-2 rounded hover:shadow-sm font-medium"
1515
>
1616
{{ $slot }}
17-
<i data-feather="{{ $icon }}" class="w-4 h-4"></i>
17+
@if ($icon)
18+
<i data-feather="{{ $icon }}" class="w-4 h-4"></i>
19+
@endif
1820
</button>

0 commit comments

Comments
 (0)