Skip to content

Commit 3724177

Browse files
authored
3.4.6 - Develop to Master (rappasoft#1847)
## [v3.4.6] - 2024-08-16 ### New Features - Column Features - deselectedIf/selectedIf by @lrljoe in rappasoft#1846 - Add setTrimSearchStringEnabled/setTrimSearchStringDisabled by @lrljoe in rappasoft#1843 ### Bug Fixes - Restore the original JS methods for users with published views by @lrljoe in rappasoft#1848 ### Tweaks - Remove Component from Column, move getRows into ComputedProperty by @lrljoe in rappasoft#1838 - Clean up filter generic data by @lrljoe in rappasoft#1837 - Clean up of Views, Properties by @lrljoe in rappasoft#1850
1 parent da06686 commit 3724177

File tree

80 files changed

+1062
-417
lines changed

Some content is hidden

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

80 files changed

+1062
-417
lines changed

.github/workflows/run-phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
run: composer update --${{ matrix.stability }} --no-interaction
8585

8686
- name: Install PHPStan
87-
run: composer require nunomaduro/larastan:^2.0 --dev --no-interaction
87+
run: composer require larastan/larastan:^2.0 --dev --no-interaction
8888

8989
- name: Run PHPStan Tests
9090
run: ./vendor/bin/phpstan analyse

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
All notable changes to `laravel-livewire-tables` will be documented in this file
44

5+
## [v3.4.6] - 2024-08-15
6+
### New Features
7+
- Column Features - deselectedIf/selectedIf by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1846
8+
- Add setTrimSearchStringEnabled/setTrimSearchStringDisabled by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1843
9+
10+
### Bug Fixes
11+
- Restore the original JS methods for users with published views by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1848
12+
13+
### Tweaks
14+
- Remove Component from Column, move getRows into ComputedProperty by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1838
15+
- Clean up filter generic data by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1837
16+
517
## [v3.4.5] - 2024-08-10
618
### Bug Fixes
719
- Fix sort queryString bug by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1835

docs/columns/column-selection.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,41 @@ Column::make('Address', 'address.address')
2323
->deselected(),
2424
```
2525

26+
## DeselectedIf
27+
28+
If you would like a column to be included in the column select but deselected based on an external parameter/callback, you may use this approach.
29+
30+
Returning "true" will deselect the Column by default, returning "false" will select the Column by default
31+
32+
```php
33+
Column::make('Address', 'address.address')
34+
->deselectedIf(fn() => 2 > 1),
35+
```
36+
37+
or
38+
39+
```php
40+
Column::make('Address', 'address.address')
41+
->deselectedIf(!Auth::user()),
42+
```
43+
44+
## SelectedIf
45+
46+
If you would like a column to be included in the column select and selected based on an external parameter/callback, you may use this approach.
47+
48+
Returning "true" will select the Column by default, returning "false" will deselect the Column by default
49+
50+
```php
51+
Column::make('Address', 'address.address')
52+
->selectedIf(fn() => 2 > 1),
53+
```
54+
or
55+
56+
```php
57+
Column::make('Address', 'address.address')
58+
->selectedIf(Auth::user()),
59+
```
60+
2661
## Available Methods
2762

2863
### setColumnSelectStatus

docs/search/available-methods.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,27 @@ public function configure(): void
168168
$this->setSearchThrottle(1000);
169169
}
170170
```
171+
172+
## setTrimSearchStringEnabled
173+
174+
A new behaviour, which will trim search strings of whitespace at either end
175+
176+
```php
177+
public function configure(): void
178+
{
179+
// Will trim whitespace from either end of search strings
180+
$this->setTrimSearchStringEnabled();
181+
}
182+
```
183+
184+
## setTrimSearchStringDisabled
185+
186+
The default behaviour, does not trim search strings of whitespace.
187+
188+
```php
189+
public function configure(): void
190+
{
191+
// Will not trim whitespace from either end of search strings
192+
$this->setTrimSearchStringDisabled();
193+
}
194+
```

resources/js/laravel-livewire-tables.js

Lines changed: 214 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*jshint esversion: 6 */
22

33
document.addEventListener('alpine:init', () => {
4-
4+
55
Alpine.data('laravellivewiretable', (wire, showBulkActionsAlpine, tableID, primaryKeyName) => ({
66
listeners: [],
77
childElementOpen: false,
@@ -103,13 +103,11 @@ document.addEventListener('alpine:init', () => {
103103
},
104104
reorderToggle() {
105105
if (this.currentlyReorderingStatus) {
106-
console.log("Disable Reordering");
107106
wire.disableReordering();
108107
}
109108
else {
110109
if (this.hideReorderColumnUnlessReorderingStatus) {
111110
this.reorderDisplayColumn = true;
112-
console.log("enableReordering");
113111
}
114112
this.setupEvenOddClasses();
115113
wire.enableReordering();
@@ -120,7 +118,6 @@ document.addEventListener('alpine:init', () => {
120118
if (this.hideReorderColumnUnlessReorderingStatus) {
121119
this.reorderDisplayColumn = false;
122120
}
123-
console.log("cancelReorder");
124121

125122
wire.disableReordering();
126123

@@ -367,4 +364,217 @@ document.addEventListener('alpine:init', () => {
367364

368365

369366
}));
367+
368+
369+
Alpine.data('tableWrapper', (wire, showBulkActionsAlpine) => ({
370+
listeners: [],
371+
childElementOpen: false,
372+
filtersOpen: wire.entangle('filterSlideDownDefaultVisible'),
373+
paginationCurrentCount: wire.entangle('paginationCurrentCount'),
374+
paginationTotalItemCount: wire.entangle('paginationTotalItemCount'),
375+
paginationCurrentItems: wire.entangle('paginationCurrentItems'),
376+
selectedItems: wire.entangle('selected'),
377+
selectAllStatus: wire.entangle('selectAll'),
378+
delaySelectAll: wire.entangle('delaySelectAll'),
379+
hideBulkActionsWhenEmpty: wire.entangle('hideBulkActionsWhenEmpty'),
380+
toggleSelectAll() {
381+
if (!showBulkActionsAlpine) {
382+
return;
383+
}
384+
385+
if (this.paginationTotalItemCount === this.selectedItems.length) {
386+
this.clearSelected();
387+
this.selectAllStatus = false;
388+
} else {
389+
if (this.delaySelectAll)
390+
{
391+
this.setAllItemsSelected();
392+
}
393+
else
394+
{
395+
this.setAllSelected();
396+
}
397+
}
398+
},
399+
setAllItemsSelected() {
400+
if (!showBulkActionsAlpine) {
401+
return;
402+
}
403+
this.selectAllStatus = true;
404+
this.selectAllOnPage();
405+
},
406+
setAllSelected() {
407+
if (!showBulkActionsAlpine) {
408+
return;
409+
}
410+
if (this.delaySelectAll)
411+
{
412+
this.selectAllStatus = true;
413+
this.selectAllOnPage();
414+
}
415+
else
416+
{
417+
wire.setAllSelected();
418+
}
419+
},
420+
clearSelected() {
421+
if (!showBulkActionsAlpine) {
422+
return;
423+
}
424+
this.selectAllStatus = false;
425+
wire.clearSelected();
426+
},
427+
selectAllOnPage() {
428+
if (!showBulkActionsAlpine) {
429+
return;
430+
}
431+
432+
let tempSelectedItems = this.selectedItems;
433+
const iterator = this.paginationCurrentItems.values();
434+
for (const value of iterator) {
435+
tempSelectedItems.push(value.toString());
436+
}
437+
this.selectedItems = [...new Set(tempSelectedItems)];
438+
},
439+
destroy() {
440+
this.listeners.forEach((listener) => {
441+
listener();
442+
});
443+
}
444+
}));
445+
446+
Alpine.data('reorderFunction', (wire, tableID, primaryKeyName) => ({
447+
dragging: false,
448+
reorderEnabled: false,
449+
sourceID: '',
450+
targetID: '',
451+
evenRowClasses: '',
452+
oddRowClasses: '',
453+
currentlyHighlightedElement: '',
454+
evenRowClassArray: {},
455+
oddRowClassArray: {},
456+
evenNotInOdd: {},
457+
oddNotInEven: {},
458+
orderedRows: [],
459+
defaultReorderColumn: wire.get('defaultReorderColumn'),
460+
reorderStatus: wire.get('reorderStatus'),
461+
currentlyReorderingStatus: wire.entangle('currentlyReorderingStatus'),
462+
hideReorderColumnUnlessReorderingStatus: wire.entangle('hideReorderColumnUnlessReorderingStatus'),
463+
reorderDisplayColumn: wire.entangle('reorderDisplayColumn'),
464+
dragStart(event) {
465+
this.$nextTick(() => { this.setupEvenOddClasses() });
466+
this.sourceID = event.target.id;
467+
event.dataTransfer.effectAllowed = 'move';
468+
event.dataTransfer.setData('text/plain', event.target.id);
469+
event.target.classList.add("laravel-livewire-tables-dragging");
470+
},
471+
dragOverEvent(event) {
472+
if (typeof this.currentlyHighlightedElement == 'object') {
473+
this.currentlyHighlightedElement.classList.remove('laravel-livewire-tables-highlight-bottom', 'laravel-livewire-tables-highlight-top');
474+
}
475+
let target = event.target.closest('tr');
476+
this.currentlyHighlightedElement = target;
477+
478+
if (event.offsetY < (target.getBoundingClientRect().height / 2)) {
479+
target.classList.add('laravel-livewire-tables-highlight-top');
480+
target.classList.remove('laravel-livewire-tables-highlight-bottom');
481+
}
482+
else {
483+
target.classList.remove('laravel-livewire-tables-highlight-top');
484+
target.classList.add('laravel-livewire-tables-highlight-bottom');
485+
}
486+
},
487+
dragLeaveEvent(event) {
488+
event.target.closest('tr').classList.remove('laravel-livewire-tables-highlight-bottom', 'laravel-livewire-tables-highlight-top');
489+
},
490+
dropEvent(event) {
491+
if (typeof this.currentlyHighlightedElement == 'object') {
492+
this.currentlyHighlightedElement.classList.remove('laravel-livewire-tables-highlight-bottom', 'laravel-livewire-tables-highlight-top');
493+
}
494+
495+
let target = event.target.closest('tr');
496+
let parent = event.target.closest('tr').parentNode;
497+
let element = document.getElementById(this.sourceID).closest('tr');
498+
element.classList.remove("laravel-livewire-table-dragging");
499+
let originalPosition = element.rowIndex;
500+
let newPosition = target.rowIndex;
501+
let table = document.getElementById(tableID);
502+
let loopStart = originalPosition;
503+
if (event.offsetY > (target.getBoundingClientRect().height / 2)) {
504+
parent.insertBefore(element, target.nextSibling);
505+
}
506+
else {
507+
parent.insertBefore(element, target);
508+
}
509+
if (newPosition < originalPosition) {
510+
loopStart = newPosition;
511+
}
512+
let nextLoop = 'even';
513+
for (let i = 1, row; row = table.rows[i]; i++) {
514+
if (!row.classList.contains('hidden') && !row.classList.contains('md:hidden') ) {
515+
if (nextLoop === 'even') {
516+
row.classList.remove(...this.oddNotInEven);
517+
row.classList.add(...this.evenNotInOdd);
518+
nextLoop = 'odd';
519+
}
520+
else {
521+
row.classList.remove(...this.evenNotInOdd);
522+
row.classList.add(...this.oddNotInEven);
523+
nextLoop = 'even';
524+
}
525+
}
526+
}
527+
},
528+
reorderToggle() {
529+
this.$nextTick(() => { this.setupEvenOddClasses() });
530+
if (this.currentlyReorderingStatus) {
531+
wire.disableReordering();
532+
533+
}
534+
else {
535+
this.setupEvenOddClasses();
536+
if (this.hideReorderColumnUnlessReorderingStatus) {
537+
this.reorderDisplayColumn = true;
538+
}
539+
wire.enableReordering();
540+
541+
}
542+
},
543+
cancelReorder() {
544+
if (this.hideReorderColumnUnlessReorderingStatus) {
545+
this.reorderDisplayColumn = false;
546+
}
547+
wire.disableReordering();
548+
549+
},
550+
updateOrderedItems() {
551+
let table = document.getElementById(tableID);
552+
let orderedRows = [];
553+
for (let i = 1, row; row = table.rows[i]; i++) {
554+
orderedRows.push({ [primaryKeyName]: row.getAttribute('rowpk'), [this.defaultReorderColumn]: i });
555+
}
556+
wire.storeReorder(orderedRows);
557+
},
558+
setupEvenOddClasses() {
559+
if (this.evenNotInOdd.length === undefined || this.evenNotInOdd.length == 0 || this.oddNotInEven.length === undefined || this.oddNotInEven.length == 0)
560+
{
561+
let tbody = document.getElementById(tableID).getElementsByTagName('tbody')[0];
562+
let evenRowClassArray = [];
563+
let oddRowClassArray = [];
564+
565+
if (tbody.rows[0] !== undefined && tbody.rows[1] !== undefined) {
566+
evenRowClassArray = Array.from(tbody.rows[0].classList);
567+
oddRowClassArray = Array.from(tbody.rows[1].classList);
568+
this.evenNotInOdd = evenRowClassArray.filter(element => !oddRowClassArray.includes(element));
569+
this.oddNotInEven = oddRowClassArray.filter(element => !evenRowClassArray.includes(element));
570+
571+
evenRowClassArray = []
572+
oddRowClassArray = []
573+
}
574+
}
575+
},
576+
init() {
577+
}
578+
}));
579+
370580
});

0 commit comments

Comments
 (0)