Skip to content

Commit

Permalink
Merge pull request #566 from rappasoft/develop
Browse files Browse the repository at this point in the history
1.21.0
  • Loading branch information
rappasoft authored Nov 21, 2021
2 parents 9d6bb5e + 274ab1d commit 5ec4a23
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 38 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to `laravel-livewire-tables` will be documented in this file

## [Unreleased]

## [1.21.0] - 2021-11-20

### Added

- Added Chinese translation - https://github.com/rappasoft/laravel-livewire-tables/pull/540
- Added 'select all' checkbox for multiselect filters - https://github.com/rappasoft/laravel-livewire-tables/pull/551
- Added attributes to filters - https://github.com/rappasoft/laravel-livewire-tables/pull/558
- Added 4th option for pills fallback value - https://github.com/rappasoft/laravel-livewire-tables/pull/538

### Changed

- Removed excess left padding on Bootstrap 5 form check on multiselect filters.
- Patch bulk actions random wire:key - https://github.com/rappasoft/laravel-livewire-tables/pull/557

## [1.20.1] - 2021-11-01

### Changed
Expand Down Expand Up @@ -561,7 +575,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
- Initial release

[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.20.1...development
[1.20.1]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.19.3...v1.20.1
[1.21.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.20.1...v1.21.0
[1.20.1]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.20.0...v1.20.1
[1.20.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.19.3...v1.20.0
[1.19.3]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.19.2...v1.19.3
[1.19.2]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.19.1...v1.19.2
Expand Down
26 changes: 26 additions & 0 deletions resources/lang/tw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"All": "全部",
"Applied Filters": "已套用的過濾規則",
"Applied Sorting": "已套用的搜尋規則",
"Bulk Actions": "批次操作",
"Clear": "清除",
"Columns": "欄位",
"Done Reordering": "排序完成",
"Filters": "過濾規則",
"Remove filter option": "移除過濾規則",
"Remove sort option": "移除排序規則",
"Search": "搜尋",
"Select All": "搜尋全部",
"Showing": "顯示",
"Unselect All": "取消選擇",
"You are currently selecting all": "您目前已選擇全部資料",
"You are not connected to the internet.": "目前為離線模式",
"You have selected": "您已選擇",
"of": "筆資料,共",
"Reorder": "重新排序",
"results": "筆資料",
"rows": "筆資料",
"rows, do you want to select all": "筆資料,您是否要全選",
"No items found. Try to broaden your search.": "無資料呈現。請嘗試擴大搜尋範圍。",
"to": ""
}
2 changes: 1 addition & 1 deletion resources/views/bootstrap-4/components/table/row.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@props(['url' => null, 'target' => '_self', 'reordering' => false, 'customAttributes' => []])

@if (!$reordering && $attributes->has('wire:sortable.item'))
@if (!$reordering && (method_exists($attributes, 'has') ? $attributes->has('wire:sortable.item') : array_key_exists('wire:sortable.item', $attributes->getAttributes())))
@php
$attributes = $attributes->filter(fn ($value, $key) => $key !== 'wire:sortable.item');
@endphp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
wire:key="filter-pill-{{ $key }}"
class="badge badge-pill badge-info d-inline-flex align-items-center"
>
{{ $filterNames[$key] ?? collect($this->columns())->pluck('text', 'column')->get($key, ucwords(strtr($key, ['_' => ' ', '-' => ' ']))) }}:
{{ $filterNames[$key] ?? collect($this->columns())->pluck('text', 'column')->get($key, isset($customFilters[$key]) && property_exists($customFilters[$key], 'name') ? $customFilters[$key]->name : ucwords(strtr($key, ['_' => ' ', '-' => ' ']))) }}:
@if(isset($customFilters[$key]) && method_exists($customFilters[$key], 'options'))
@if(is_array($value))
@foreach($value as $selectedValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<div class="form-check">
<input
class="form-check-input"
onclick="event.stopPropagation();"
type="checkbox"
id="filter-{{$key}}-select-all"
wire:input="selectAllFilters('{{ $key }}')"
{{ count($filters[$key]) === count($filter->options()) ? 'checked' : ''}}
>
<label class="form-check-label" for="filter-{{$key}}-select-all">@lang('All')</label>
</div>
@foreach($filter->options() as $optionKey => $value)
<div class="form-check" wire:key="filter-{{ $key }}-multiselect-{{ $optionKey }}">
<input
Expand Down
4 changes: 2 additions & 2 deletions resources/views/bootstrap-4/includes/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
@forelse ($rows as $index => $row)
<x-livewire-tables::bs4.table.row
wire:loading.class.delay="text-muted"
wire:key="table-row-{{ $row->{$primaryKey} }}"
wire:key="table-row-{{ md5(mt_rand()) }}-{{ $row->{$this->parseField($primaryKey)} }}"
wire:sortable.item="{{ $row->{$primaryKey} }}"
:reordering="$reordering"
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : ''"
Expand All @@ -115,7 +115,7 @@
<input
wire:model="selected"
wire:loading.attr.delay="disabled"
value="{{ $row->{\Rappasoft\LaravelLivewireTables\Utilities\ColumnUtilities::parseField($primaryKey)} }}"
value="{{ $row->{$this->parseField($primaryKey)} }}"
onclick="event.stopPropagation();return true;"
type="checkbox"
/>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/bootstrap-5/components/table/row.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@props(['url' => null, 'target' => '_self', 'reordering' => false, 'customAttributes' => []])

@if (!$reordering && $attributes->has('wire:sortable.item'))
@if (!$reordering && (method_exists($attributes, 'has') ? $attributes->has('wire:sortable.item') : array_key_exists('wire:sortable.item', $attributes->getAttributes())))
@php
$attributes = $attributes->filter(fn ($value, $key) => $key !== 'wire:sortable.item');
@endphp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
wire:key="filter-pill-{{ $key }}"
class="badge rounded-pill bg-info d-inline-flex align-items-center"
>
{{ $filterNames[$key] ?? collect($this->columns())->pluck('text', 'column')->get($key, ucwords(strtr($key, ['_' => ' ', '-' => ' ']))) }}:
{{ $filterNames[$key] ?? collect($this->columns())->pluck('text', 'column')->get($key, isset($customFilters[$key]) && property_exists($customFilters[$key], 'name') ? $customFilters[$key]->name : ucwords(strtr($key, ['_' => ' ', '-' => ' ']))) }}:
@if(isset($customFilters[$key]) && method_exists($customFilters[$key], 'options'))
@if(is_array($value))
@foreach($value as $selectedValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<div class="form-check p-0">
<input
onclick="event.stopPropagation();"
type="checkbox"
id="filter-{{$key}}-select-all"
wire:input="selectAllFilters('{{ $key }}')"
{{ count($filters[$key]) === count($filter->options()) ? 'checked' : ''}}
>
<label class="form-check-label" for="filter-{{$key}}-select-all">@lang('All')</label>
</div>
@foreach($filter->options() as $optionKey => $value)
<div class="form-check" wire:key="filter-{{ $key }}-multiselect-{{ $optionKey }}">
<div class="form-check p-0" wire:key="filter-{{ $key }}-multiselect-{{ $optionKey }}">
<input
onclick="event.stopPropagation();"
type="checkbox"
Expand Down
4 changes: 2 additions & 2 deletions resources/views/bootstrap-5/includes/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class="form-check-input"
@forelse ($rows as $index => $row)
<x-livewire-tables::bs5.table.row
wire:loading.class.delay="text-muted"
wire:key="table-row-{{ $row->{$primaryKey} }}"
wire:key="table-row-{{ md5(mt_rand()) }}-{{ $row->{$this->parseField($primaryKey)} }}"
wire:sortable.item="{{ $row->{$primaryKey} }}"
:reordering="$reordering"
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : ''"
Expand All @@ -116,7 +116,7 @@ class="form-check-input"
<input
wire:model="selected"
wire:loading.attr.delay="disabled"
value="{{ $row->{\Rappasoft\LaravelLivewireTables\Utilities\ColumnUtilities::parseField($primaryKey)} }}"
value="{{ $row->{$this->parseField($primaryKey)} }}"
onclick="event.stopPropagation();return true;"
class="form-check-input"
type="checkbox"
Expand Down
4 changes: 2 additions & 2 deletions resources/views/tailwind/components/table/row.blade.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@props(['url' => null, 'target' => '_self', 'reordering' => false, 'customAttributes' => []])

@if (!$reordering && $attributes->has('wire:sortable.item'))
@if (!$reordering && (method_exists($attributes, 'has') ? $attributes->has('wire:sortable.item') : array_key_exists('wire:sortable.item', $attributes->getAttributes())))
@php
$attributes = $attributes->filter(fn ($value, $key) => $key !== 'wire:sortable.item');
@endphp
@endif

<tr
{{ $attributes->merge($customAttributes)->class(['cursor-pointer' => $url]) }}
{{ $attributes->merge($customAttributes)->merge(['class' => $url ? 'cursor-pointer' : '']) }}

@if ($url)
onclick="window.open('{{ $url }}', '{{ $target }}')"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/tailwind/includes/filter-pills.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
wire:key="filter-pill-{{ $key }}"
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 bg-indigo-100 text-indigo-800 capitalize dark:bg-indigo-200 dark:text-indigo-900"
>
{{ $filterNames[$key] ?? collect($this->columns())->pluck('text', 'column')->get($key, ucwords(strtr($key, ['_' => ' ', '-' => ' ']))) }}:
{{ $filterNames[$key] ?? collect($this->columns())->pluck('text', 'column')->get($key, isset($customFilters[$key]) && property_exists($customFilters[$key], 'name') ? $customFilters[$key]->name : ucwords(strtr($key, ['_' => ' ', '-' => ' ']))) }}:
@if(isset($customFilters[$key]) && method_exists($customFilters[$key], 'options'))
@if(is_array($value))
@foreach($value as $selectedValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<div class="mt-1 relative rounded-md">
<div>
<input
type="checkbox"
id="filter-{{$key}}-select-all"
wire:input="selectAllFilters('{{ $key }}')"
{{ count($filters[$key]) === count($filter->options()) ? 'checked' : ''}}
>
<label for="filter-{{$key}}-select-all">@lang('All')</label>
</div>
@foreach($filter->options() as $optionKey => $value)
<div wire:key="filter-{{ $key }}-multiselect-{{ $optionKey }}">
<input
Expand Down
4 changes: 2 additions & 2 deletions resources/views/tailwind/includes/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class="rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150
@forelse ($rows as $index => $row)
<x-livewire-tables::table.row
wire:loading.class.delay="opacity-50 dark:bg-gray-900 dark:opacity-60"
wire:key="table-row-{{ $row->{$primaryKey} }}"
wire:key="table-row-{{ md5(mt_rand()) }}-{{ $row->{$this->parseField($primaryKey)} }}"
wire:sortable.item="{{ $row->{$primaryKey} }}"
:reordering="$reordering"
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : ''"
Expand Down Expand Up @@ -125,7 +125,7 @@ class="rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150
<input
wire:model="selected"
wire:loading.attr.delay="disabled"
value="{{ $row->{\Rappasoft\LaravelLivewireTables\Utilities\ColumnUtilities::parseField($primaryKey)} }}"
value="{{ $row->{$this->parseField($primaryKey)} }}"
onclick="event.stopPropagation();return true;"
type="checkbox"
class="rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600"
Expand Down
16 changes: 2 additions & 14 deletions src/DataTableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Livewire\Component;
use Rappasoft\LaravelLivewireTables\Traits\ComponentHelpers;
use Rappasoft\LaravelLivewireTables\Traits\WithBulkActions;
use Rappasoft\LaravelLivewireTables\Traits\WithColumnSelect;
use Rappasoft\LaravelLivewireTables\Traits\WithCustomPagination;
Expand All @@ -23,6 +24,7 @@
*/
abstract class DataTableComponent extends Component
{
use ComponentHelpers;
use WithBulkActions;
use WithColumnSelect;
use WithCustomPagination;
Expand Down Expand Up @@ -226,18 +228,4 @@ public function render()
'bulkActions' => $this->bulkActions,
]);
}

/**
* Get a column object by its field
*
* @param string $column
*
* @return mixed
*/
protected function getColumn(string $column)
{
return collect($this->columns())
->where('column', $column)
->first();
}
}
35 changes: 35 additions & 0 deletions src/Traits/ComponentHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits;

use Rappasoft\LaravelLivewireTables\Utilities\ColumnUtilities;

/**
* Trait ComponentHelpers.
*/
trait ComponentHelpers
{
/**
* Get a column object by its field
*
* @param string $column
*
* @return mixed
*/
protected function getColumn(string $column)
{
return collect($this->columns())
->where('column', $column)
->first();
}

/**
* @param string $field
*
* @return string
*/
protected function parseField(string $field): string
{
return ColumnUtilities::parseField($field);
}
}
17 changes: 17 additions & 0 deletions src/Traits/WithFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,23 @@ public function cleanFilters(): void
})->toArray();
}

public function selectAllFilters($filterKey): void
{
$filter = $this->filters()[$filterKey];

if (! $filter->isMultiSelect()) {
return;
}

if (count($this->filters[$filterKey]) === count($filter->options())) {
$this->removeFilter($filterKey);

return;
}

$this->filters[$filterKey] = array_keys($filter->options());
}

/**
* Define the string location to a view to be included as the filters view
*
Expand Down
20 changes: 13 additions & 7 deletions src/Views/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,29 @@ class Filter
public array $options = [];

/**
* Filter constructor.
*
* @param string $name
* @var array
*/
public array $attributes = [];

/**
* @param string $name
* @param array|null $attributes
*/
public function __construct(string $name)
public function __construct(string $name, ?array $attributes = [])
{
$this->name = $name;
$this->attributes = $attributes;
}

/**
* @param string $name
* @param string $name
* @param array|null $attributes
*
* @return Filter
*/
public static function make(string $name): Filter
public static function make(string $name, ?array $attributes = []): Filter
{
return new static($name);
return new static($name, $attributes);
}

/**
Expand Down
Loading

0 comments on commit 5ec4a23

Please sign in to comment.