Skip to content

Commit 56cae0d

Browse files
✨ implement report generator
1 parent 2fd6c8d commit 56cae0d

8 files changed

Lines changed: 147 additions & 32 deletions

File tree

resources/views/editor.blade.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:
5555
</div>
5656
@endif
5757

58+
@if($criterion['inputType'] === 'number')
59+
<div class="p-1 col-span-1">
60+
<label for="value-{{ $loop->index }}"
61+
class="sr-only block mb-2 text-sm font-medium text-gray-900 dark:text-white">Number</label>
62+
<input wire:model.live.debounce.1000ms="criteria.{{ $loop->index }}.value"
63+
type="number"
64+
id="value-{{ $loop->index }}"
65+
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
66+
</div>
67+
@endif
68+
5869
@if($criterion['inputType'] === 'date')
5970
@include('query-builder::components.date-input')
6071
@endif

resources/views/query-table.blade.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@
5656
<thead class="text-xs text-gray-700 uppercase bg-gray-50">
5757
<tr class="border-y border-gray-200">
5858

59-
<th class="p-0">
60-
<div class="pl-6 flex items-center">
61-
<input wire:model.live="selectPage" id="checkbox-select-page" type="checkbox"
62-
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
63-
<label for="checkbox-select-page"
64-
class="sr-only ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"></label>
65-
</div>
66-
</th>
59+
@if($selectable)
60+
<th class="p-0">
61+
<div class="pl-6 flex items-center">
62+
<input wire:model.live="selectPage" id="checkbox-select-page" type="checkbox"
63+
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
64+
<label for="checkbox-select-page"
65+
class="sr-only ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"></label>
66+
</div>
67+
</th>
68+
@endif
6769

6870
@foreach ($this->columns() as $column)
6971
@if(in_array($column->key, $displayColumns))
@@ -107,7 +109,7 @@ class="sr-only ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"></labe
107109
</tr>
108110
</thead>
109111
<tbody @if($this->useLoadingIndicator()) wire:loading.class="{{ $this->loadingClass }}" @endif>
110-
@if($selectPage && $this->rows->count() < $this->rows->total())
112+
@if($selectable && $selectPage && $this->rows->count() < $this->rows->total())
111113
<tr class="bg-gray-100" wire:key="row-message">
112114
<td colspan="{{ count($displayColumns) + 1 }}" class="px-6 py-4">
113115
@unless($selectAll)
@@ -140,16 +142,18 @@ class="ml-2 text-blue-500 hover:text-blue-600">
140142
'hover:bg-gray-50 cursor-pointer' => $this->isClickable(),
141143
])>
142144

143-
<td class="p-0">
144-
<div class="pl-6 flex items-center">
145-
<input wire:model.live="selectedRows" id="checkbox-{{ $row->id }}"
146-
type="checkbox"
147-
value="{{ $row->id }}"
148-
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
149-
<label for="checkbox-{{ $row->id }}"
150-
class="sr-only ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"></label>
151-
</div>
152-
</td>
145+
@if($selectable)
146+
<td class="p-0">
147+
<div class="pl-6 flex items-center">
148+
<input wire:model.live="selectedRows" id="checkbox-{{ $row->id }}"
149+
type="checkbox"
150+
value="{{ $row->id }}"
151+
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
152+
<label for="checkbox-{{ $row->id }}"
153+
class="sr-only ml-2 text-sm font-medium text-gray-900 dark:text-gray-300"></label>
154+
</div>
155+
</td>
156+
@endif
153157

154158
@foreach ($this->columns() as $column)
155159
@if(in_array($column->key, $displayColumns))
Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,52 @@
1-
<div class="m-6 block p-6 bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700">
2-
@foreach($this->availableColumns() as $section => $columns)
3-
<h6 class="mb-2 text-lg font-bold text-gray-800 dark:text-white">{{ $section }}</h6>
4-
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6">
5-
{{ json_encode($selectedColumns) }}
6-
@foreach($columns as $columnKey => $column)
7-
<div class="flex items-center mb-4">
8-
<input wire:model="selectedColumns" id="{{$column['key']}}" type="checkbox" value="{{ $columnKey }}" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
9-
<label for="{{$column['key']}}" class="ms-2 text-sm font-medium text-gray-900 dark:text-gray-300">{{$column['label']}}</label>
1+
<div x-data="{open: true }" x-cloak
2+
class="m-4 block p-6 bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700">
3+
4+
@if(!$selectedColumns)
5+
<div class="p-4 mb-4 text-sm text-blue-800 rounded-lg bg-blue-50 dark:bg-gray-800 dark:text-blue-400" role="alert">
6+
Please select one or more columns.
7+
</div>
8+
@endif
9+
10+
<div x-show="open">
11+
@foreach($this->availableColumns() as $section => $columns)
12+
<h6 class="mb-4 pb-1 text-base font-bold text-gray-600 dark:text-white border-b border-dashed">{{ $section }}</h6>
13+
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6">
14+
@foreach($columns as $columnKey => $column)
15+
<div class="flex items-center mb-4">
16+
<input wire:model.live.debounce="selectedColumns" id="{{$column['key']}}" type="checkbox"
17+
value="{{ $column['key'] }}"
18+
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
19+
<label for="{{$column['key']}}"
20+
class="ms-2 text-sm font-medium text-gray-900 dark:text-gray-300">{{$column['label']}}</label>
21+
</div>
22+
@endforeach
1023
</div>
1124
@endforeach
1225
</div>
13-
@endforeach
26+
27+
<div class="flex items-center gap-2 p-1 px-2 bg-gray-50 -mx-6 -mb-6 rounded-b-lg">
28+
<span class="text-sm text-gray-600">Columns</span>
29+
<button @click="open = !open">
30+
<span x-show="!open">
31+
<svg xmlns="http://www.w3.org/2000/svg"
32+
class="w-6 h-6"
33+
viewBox="0 0 24 24" stroke-width="1.5" stroke="#2c3e50" fill="none"
34+
stroke-linecap="round" stroke-linejoin="round">
35+
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
36+
<path d="M6 9l6 6l6 -6"/>
37+
</svg>
38+
</span>
39+
<span x-show="open">
40+
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24" stroke-width="1.5"
41+
stroke="#2c3e50" fill="none"
42+
stroke-linecap="round" stroke-linejoin="round">
43+
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
44+
<path d="M6 15l6 -6l6 6"/>
45+
</svg>
46+
</span>
47+
</button>
48+
</div>
1449
</div>
1550

1651

52+

src/ReportBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ abstract class ReportBuilder extends QueryBuilder
1010
{
1111
use WithReportBuilder;
1212

13+
public bool $selectable = false;
14+
1315
}

src/Support/Concerns/WithQueryBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ private function getCriteriaClass($criteria
161161
}
162162

163163
return match ($criteria['operation']) {
164+
'equals' => new CompareCriteria($column, $value, '='),
164165
'not_equals' => new CompareCriteria($column, $value, '!='),
166+
'greater_than' => new CompareCriteria($column, $value, '>'),
167+
'less_than' => new CompareCriteria($column, $value, '<'),
168+
'greater_than_or_equal' => new CompareCriteria($column, $value, '>='),
169+
'less_than_or_equal' => new CompareCriteria($column, $value, '<='),
165170
'contains' => new LikeCriteria($column, '%'.$value.'%'),
166171
'not_contains' => new LikeCriteria($column, '%'.$value.'%', 'not like'),
167172
'starts_with' => new LikeCriteria($column, $value.'%'),

src/Support/Concerns/WithReportBuilder.php

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,38 @@
77
use ACTTraining\QueryBuilder\Support\Columns\DateColumn;
88
use ACTTraining\QueryBuilder\Support\Conditions\BooleanCondition;
99
use ACTTraining\QueryBuilder\Support\Conditions\DateCondition;
10+
use ACTTraining\QueryBuilder\Support\Conditions\NumberCondition;
1011
use ACTTraining\QueryBuilder\Support\Conditions\TextCondition;
1112

1213
trait WithReportBuilder
1314
{
1415
public array $selectedColumns = [];
1516

16-
public function updatedSelectedColumns($value): void
17+
private function findElementByKey(array $array, $targetValue): ?array
18+
{
19+
foreach ($array as $value) {
20+
// Check if the current item is an array
21+
if (is_array($value)) {
22+
// Check if it contains the 'key' element with the target value
23+
if (isset($value['key']) && $value['key'] === $targetValue) {
24+
return $value; // Return the found item
25+
}
26+
27+
// Recursively search the sub-array
28+
$result = $this->findElementByKey($value, $targetValue);
29+
if ($result !== null) {
30+
return $result;
31+
}
32+
}
33+
}
34+
35+
return null; // Return null if no match is found
36+
}
37+
38+
public function updatedSelectedColumns(): void
1739
{
1840
$this->resetPage();
19-
ray($value);
41+
$this->dispatch('refreshTable')->self();
2042
}
2143

2244
public function availableColumns(): array
@@ -26,7 +48,12 @@ public function availableColumns(): array
2648

2749
public function configuredColumns(): array
2850
{
29-
return [];
51+
$columns = [];
52+
53+
foreach ($this->selectedColumns as $column) {
54+
$columns[] = $this->findElementByKey($this->availableColumns(), $column);
55+
}
56+
return $columns;
3057
}
3158

3259
public function buildColumns(): array
@@ -37,6 +64,7 @@ public function buildColumns(): array
3764

3865
foreach ($this->configuredColumns() as $column) {
3966
$columnToAdd = match ($column['type'] ?? null) {
67+
'number' => Column::make($column['label'], $column['key'])->justify('right'),
4068
'boolean' => BooleanColumn::make($column['label'], $column['key'])->justify('center')->hideIf(false),
4169
'date' => DateColumn::make($column['label'], $column['key'])->format(config('settings.date.short-format'))->justify('right'),
4270
default => Column::make($column['label'], $column['key'])
@@ -48,6 +76,10 @@ public function buildColumns(): array
4876
$columnToAdd->component('columns.common.title');
4977
}
5078

79+
if ($column['sortable'] ?? false) {
80+
$columnToAdd->sortable();
81+
}
82+
5183
$columns[] = $columnToAdd;
5284

5385
$counter++;
@@ -64,6 +96,7 @@ public function buildConditions(): array
6496
continue;
6597
}
6698
$conditions[] = match ($column['type'] ?? null) {
99+
'number' => NumberCondition::make($column['label'], $column['key']),
67100
'boolean' => BooleanCondition::make($column['label'], $column['key']),
68101
'date' => DateCondition::make($column['label'], $column['key']),
69102
default => TextCondition::make($column['label'], $column['key'])

src/Support/Concerns/WithSelecting.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
trait WithSelecting
66
{
7+
public bool $selectable = true;
8+
79
public array $selectedRows = [];
810

911
public bool $selectPage = false;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace ACTTraining\QueryBuilder\Support\Conditions;
4+
5+
class NumberCondition extends BaseCondition
6+
{
7+
public string $inputType = 'number';
8+
9+
public function operations(): array
10+
{
11+
return [
12+
'equals' => 'equals',
13+
'not_equals' => 'is not equal to',
14+
'greater_than' => 'is greater than',
15+
'less_than' => 'is less than',
16+
'greater_than_or_equal' => 'is greater than or equal to',
17+
'less_than_or_equal' => 'is less than or equal to',
18+
'is_set' => 'is set',
19+
'is_not_set' => 'is not set',
20+
];
21+
}
22+
}

0 commit comments

Comments
 (0)