Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Nov 24, 2023
1 parent b9f7f2c commit 4c37122
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions resources/views/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="csrf-token" content="{{ csrf_token() }}">

{{-- Styles --}}
<link rel="icon" href="{{ URL::asset('vendor/root/favicon.png') }}" sizes="32x32">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/table/filters.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form method="GET" action="{{ URL::full() }}" id="{{ $key }}" class="app-card__actions">
<form method="GET" action="{{ URL::full() }}" id="{{ $key }}" class="app-card__actions" onchange="this.requestSubmit()">
@if(! empty($filters))
<div class="data-table-filter" x-data="{ open: false }" x-on:click.outside="open = false">
<button
Expand Down
1 change: 1 addition & 0 deletions resources/views/table/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class="form-check__control"
class="form-control form-control--sm"
id="per_page"
name="per_page"
onchange="this.form.requestSubmit()"
>
@foreach($perPageOptions as $option)
<option value="{{ $option }}" @selected($option === $data->perPage())>
Expand Down
19 changes: 19 additions & 0 deletions src/Fields/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Closure;
use Cone\Root\Filters\RenderableFilter;
use Cone\Root\Filters\Search;
use Cone\Root\Filters\Sort;
use Cone\Root\Http\Controllers\RelationController;
use Cone\Root\Interfaces\Form;
use Cone\Root\Root;
Expand Down Expand Up @@ -328,6 +330,23 @@ public function resolveFormat(Request $request, Model $model): mixed
return parent::resolveFormat($request, $model);
}

/**
* Define the filters for the object.
*/
public function filters(Request $request): array
{
$fields = $this->resolveFields($request)->authorized($request);

$searchables = $fields->searchable();

$sortables = $fields->sortable();

return array_values(array_filter([
$searchables->isNotEmpty() ? new Search($searchables) : null,
$sortables->isNotEmpty() ? new Sort($sortables) : null,
]));
}

/**
* Handle the callback for the field resolution.
*/
Expand Down
1 change: 0 additions & 1 deletion src/Filters/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Relation as EloquentRelation;
use Illuminate\Database\Query\Expression;
use Illuminate\Http\Request;

class Sort extends Filter
Expand Down

0 comments on commit 4c37122

Please sign in to comment.