Skip to content

Commit 5c51aec

Browse files
committed
Merge branch 'develop'
2 parents 9bada42 + a728559 commit 5c51aec

File tree

12 files changed

+164
-73
lines changed

12 files changed

+164
-73
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
44

55
## [Unreleased]
66

7+
## [0.2.1] - 2020-09-10
8+
9+
### Added
10+
11+
- Arabic translations
12+
- Ability to add a link to make table rows clickable
13+
- Added the ability to change the sort icons
14+
- Ability to hide a column based on a condition or permanently
15+
16+
### Updated
17+
18+
- Livewire to 2.x
19+
20+
### Removed
21+
22+
- Removed 1 hard coded font awesome icon
23+
24+
### Changed
25+
26+
- Publish tags to service provider
27+
728
## [0.2.0] - 2020-08-10
829

930
### Added

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class UsersTable extends TableComponent
4848
return [
4949
Column::make('ID')
5050
->searchable()
51-
->sortable(),
51+
->sortable()
52+
->hideIf(!auth()->user()->hasRole('admin')),
5253
Column::make('Name')
5354
->searchable()
5455
->sortable(),
@@ -138,6 +139,16 @@ public function customAttribute() : self;
138139
* This view will be used for the column, can still be used with sortable and searchable.
139140
*/
140141
public function view($view, $viewModelName = 'model') : self;
142+
143+
/**
144+
* Hide this column permanently
145+
*/
146+
public function hide() : self;
147+
148+
/**
149+
* Hide this column based on a condition. i.e.: user has or doesn't have a role or permission
150+
*/
151+
public function hideIf($condition) : self;
141152
```
142153

143154
### Properties
@@ -173,6 +184,9 @@ You can override any of these in your table component:
173184
| -------- | ------- | ----- |
174185
| $sortField | id | The initial field to be sorting by |
175186
| $sortDirection | asc | The initial direction to sort |
187+
| $sortDefaultClass | text-muted fas fa-sort | The default sort icon |
188+
| $ascSortClass | fas fa-sort-up | The sort icon when currently sorting ascending |
189+
| $descSortClass | fas fa-sort-down | The sort icon when currently sorting descending |
176190

177191
#### Pagination
178192

@@ -250,6 +264,11 @@ public function setTableRowId($model) : ?string;
250264
*/
251265
public function setTableRowAttributes($model) : array;
252266

267+
/**
268+
* Return a URL to go to when the table row is clicked
269+
*/
270+
public function getTableRowUrl($model): ?string;
271+
253272
/**
254273
* Used to set the class of a table cell based on the column and the value of the cell
255274
*/

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"require": {
2222
"php": "^7.2.5",
23-
"livewire/livewire": "^1.3"
23+
"livewire/livewire": "^1.3|^2.0"
2424
},
2525
"require-dev": {
2626
"friendsofphp/php-cs-fixer": "^2.16",

resources/lang/ar/strings.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
return [
4+
'clear' => 'مسح',
5+
'loading' => 'تحميل...',
6+
'no_results' => 'لا توجد نتائج لعرضها لهذا الاستعلام.',
7+
'offline' => 'أنت غير متصل حاليا بالإنترنت.',
8+
'per_page' => 'لكل صفحة',
9+
'results' => 'إظهار :first إلي :last من أصل :total مدخل',
10+
'search' => 'بحث...',
11+
];

resources/views/includes/_body.blade.php

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,57 +17,27 @@ class="{{ $this->setTableRowClass($model) }}"
1717
@foreach ($this->setTableRowAttributes($model) as $key => $value)
1818
{{ $key }}="{{ $value }}"
1919
@endforeach
20+
@if ($this->getTableRowUrl($model))
21+
onclick="window.location='{{ $this->getTableRowUrl($model) }}';"
22+
style="cursor:pointer"
23+
@endif
2024
>
2125
@if($checkbox && $checkboxLocation === 'left')
2226
@include('laravel-livewire-tables::includes._checkbox-row')
2327
@endif
2428

2529
@foreach($columns as $column)
26-
<td
27-
class="{{ $this->setTableDataClass($column->attribute, Arr::get($model->toArray(), $column->attribute)) }}"
28-
id="{{ $this->setTableDataId($column->attribute, Arr::get($model->toArray(), $column->attribute)) }}"
29-
@foreach ($this->setTableDataAttributes($column->attribute, Arr::get($model->toArray(), $column->attribute)) as $key => $value)
30-
{{ $key }}="{{ $value }}"
31-
@endforeach
32-
>
33-
@if ($column->hasComponents())
34-
@if ($column->componentsAreHiddenForModel($model))
35-
@if ($message = $column->componentsHiddenMessageForModel($model))
36-
{{ $message }}
37-
@else
38-
&nbsp;
39-
@endif
40-
@else
41-
@foreach($column->getComponents() as $component)
42-
@if (! $component->isHidden())
43-
@include($component->view(), ['model' => $model, 'attributes' => $component->getAttributes(), 'options' => $component->getOptions()])
44-
@endif
45-
@endforeach
46-
@endif
47-
@elseif ($column->isView())
48-
@include($column->view, [$column->getViewModelName() => $model])
49-
@else
50-
@if ($column->isHtml())
51-
@if ($column->isCustomAttribute())
52-
{{ new \Illuminate\Support\HtmlString(data_get($model, $column->attribute)) }}
53-
@else
54-
{{ new \Illuminate\Support\HtmlString(Arr::get($model->toArray(), $column->attribute)) }}
55-
@endif
56-
@elseif ($column->isUnescaped())
57-
@if ($column->isCustomAttribute())
58-
{!! data_get($model, $column->attribute) !!}
59-
@else
60-
{!! Arr::get($model->toArray(), $column->attribute) !!}
61-
@endif
62-
@else
63-
@if ($column->isCustomAttribute())
64-
{{ data_get($model, $column->attribute) }}
65-
@else
66-
{{ Arr::get($model->toArray(), $column->attribute) }}
67-
@endif
68-
@endif
69-
@endif
70-
</td>
30+
@if (!$column->isHidden())
31+
<td
32+
class="{{ $this->setTableDataClass($column->attribute, Arr::get($model->toArray(), $column->attribute)) }}"
33+
id="{{ $this->setTableDataId($column->attribute, Arr::get($model->toArray(), $column->attribute)) }}"
34+
@foreach ($this->setTableDataAttributes($column->attribute, Arr::get($model->toArray(), $column->attribute)) as $key => $value)
35+
{{ $key }}="{{ $value }}"
36+
@endforeach
37+
>
38+
@include('laravel-livewire-tables::includes._column-data')
39+
</td>
40+
@endif
7141
@endforeach
7242

7343
@if($checkbox && $checkboxLocation === 'right')
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@if ($column->hasComponents())
2+
@if ($column->componentsAreHiddenForModel($model))
3+
@if ($message = $column->componentsHiddenMessageForModel($model))
4+
{{ $message }}
5+
@endif
6+
@else
7+
@foreach($column->getComponents() as $component)
8+
@if (! $component->isHidden())
9+
@include($component->view(), ['model' => $model, 'attributes' => $component->getAttributes(), 'options' => $component->getOptions()])
10+
@endif
11+
@endforeach
12+
@endif
13+
@elseif ($column->isView())
14+
@include($column->view, [$column->getViewModelName() => $model])
15+
@else
16+
@if ($column->isHtml())
17+
@if ($column->isCustomAttribute())
18+
{{ new \Illuminate\Support\HtmlString(data_get($model, $column->attribute)) }}
19+
@else
20+
{{ new \Illuminate\Support\HtmlString(Arr::get($model->toArray(), $column->attribute)) }}
21+
@endif
22+
@elseif ($column->isUnescaped())
23+
@if ($column->isCustomAttribute())
24+
{!! data_get($model, $column->attribute) !!}
25+
@else
26+
{!! Arr::get($model->toArray(), $column->attribute) !!}
27+
@endif
28+
@else
29+
@if ($column->isCustomAttribute())
30+
{{ data_get($model, $column->attribute) }}
31+
@else
32+
{{ Arr::get($model->toArray(), $column->attribute) }}
33+
@endif
34+
@endif
35+
@endif

resources/views/includes/_columns.blade.php

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,31 @@
33
@endif
44

55
@foreach($columns as $column)
6-
<th
7-
class="{{ $this->setTableHeadClass($column->attribute) }}"
8-
id="{{ $this->setTableHeadId($column->attribute) }}"
9-
@foreach ($this->setTableHeadAttributes($column->attribute) as $key => $value)
10-
{{ $key }}="{{ $value }}"
11-
@endforeach
12-
>
13-
@if($column->sortable)
14-
<span style="cursor: pointer;" wire:click="sort('{{ $column->attribute }}')">
15-
{{ $column->text }}
6+
@if (!$column->isHidden())
7+
<th
8+
class="{{ $this->setTableHeadClass($column->attribute) }}"
9+
id="{{ $this->setTableHeadId($column->attribute) }}"
10+
@foreach ($this->setTableHeadAttributes($column->attribute) as $key => $value)
11+
{{ $key }}="{{ $value }}"
12+
@endforeach
13+
>
14+
@if($column->sortable)
15+
<span style="cursor: pointer;" wire:click="sort('{{ $column->attribute }}')">
16+
{{ $column->text }}
1617

17-
@if ($sortField !== $column->attribute)
18-
<i class="text-muted fas fa-sort"></i>
19-
@elseif ($sortDirection === 'asc')
20-
<i class="fas fa-sort-up"></i>
21-
@else
22-
<i class="fas fa-sort-down"></i>
23-
@endif
24-
</span>
25-
@else
26-
{{ $column->text }}
27-
@endif
28-
</th>
18+
@if ($sortField !== $column->attribute)
19+
<i class="{{ $sortDefaultClass }}"></i>
20+
@elseif ($sortDirection === 'asc')
21+
<i class="{{ $ascSortClass }}"></i>
22+
@else
23+
<i class="{{ $descSortClass }}"></i>
24+
@endif
25+
</span>
26+
@else
27+
{{ $column->text }}
28+
@endif
29+
</th>
30+
@endif
2931
@endforeach
3032

3133
@if($checkbox && $checkboxLocation === 'right')

resources/views/includes/_offline.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="row">
33
<div class="col-12">
44
<div wire:offline class="alert alert-danger">
5-
<i class="fa fa-info-circle"></i> @lang('laravel-livewire-tables::strings.offline')
5+
@lang('laravel-livewire-tables::strings.offline')
66
</div>
77
</div>
88
</div>

src/LivewireTablesServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ public function boot()
2020

2121
$this->publishes([
2222
__DIR__.'/../resources/views' => resource_path('views/vendor/laravel-livewire-tables'),
23-
]);
23+
], 'laravel-livewire-tables');
2424

2525
$this->publishes([
2626
__DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-livewire-tables'),
27-
]);
27+
], 'laravel-livewire-tables');
2828
}
2929
}

src/Traits/Sorting.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ trait Sorting
2525
*/
2626
public $sortDirection = 'asc';
2727

28+
/**
29+
* The default sort icon.
30+
*
31+
* @var string
32+
*/
33+
public $sortDefaultClass = 'text-muted fas fa-sort';
34+
35+
/**
36+
* The sort icon when currently sorting ascending.
37+
*
38+
* @var string
39+
*/
40+
public $ascSortClass = 'fas fa-sort-up';
41+
42+
/**
43+
* The sort icon when currently sorting descending.
44+
*
45+
* @var string
46+
*/
47+
public $descSortClass = 'fas fa-sort-down';
48+
2849
/**
2950
* @param $attribute
3051
*/

0 commit comments

Comments
 (0)