Skip to content

Commit

Permalink
POC
Browse files Browse the repository at this point in the history
  • Loading branch information
dansysanalyst committed May 22, 2024
1 parent 5fe08cf commit 7df8c96
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions src/Concerns/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,33 @@ public function addEnabledFilters(string $field, ?string $label): void
}
}

//@TODO REFACTOR
public function ____COLUMNS_FOR_QUERY_STRING()
{
collect($this->columns())
->each(function ($column) use (&$columns) {
if (isset($column->dataField)) {
$columns[$column->dataField] = $column->title;
}

$columns[$column->field] = $column->title;
});

return collect($columns);

}

protected function powerGridQueryString(): array
{
$queryString = [];

$columns = $this->____COLUMNS_FOR_QUERY_STRING();

foreach (Arr::dot($this->filters()) as $filter) {
$as = str($filter->field)
->replace('_id', '');
$as = str($filter->field)->replace('.', '_');

if ($as->contains('.')) {
$as = $as->afterLast('.');
if(!is_null(request()->get($as))) {
$this->addEnabledFilters($filter->field, $columns->get($filter->field), $filter->field);
}

if ($filter->key === 'input_text') {
Expand All @@ -357,16 +374,26 @@ protected function powerGridQueryString(): array
}

if ($filter->key === 'number') {
$_start = $as->append('_start')->toString();
$_end = $as->append('_end')->toString();

$queryString['filters.number.' . $filter->field . '.start'] = [
'as' => $as->append('_start')->toString(),
'as' => $_start,
'except' => '',
];

if(!is_null(request()->get($_start))) {
$this->addEnabledFilters($filter->field . '_start', $columns->get($filter->field), $filter->field);
}

$queryString['filters.number.' . $filter->field . '.end'] = [
'as' => $as->append('_end')->toString(),
'as' => $_end,
'except' => '',
];

if(!is_null(request()->get($_end))) {
$this->addEnabledFilters($filter->field . '_end', $columns->get($filter->field), $filter->field);
}
continue;
}

Expand Down

0 comments on commit 7df8c96

Please sign in to comment.