Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Nov 28, 2023
1 parent e1f88cb commit b355b90
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
8 changes: 4 additions & 4 deletions resources/views/table/column.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
@if($sortable)
<div class="data-table-sort">
{{ $label }}
@if(Request::input('sort.by') !== $attribute || Request::input('sort.order', 'asc') === 'asc')
@if(Request::input($sortKey.'.by') !== $attribute || Request::input($sortKey.'.order', 'asc') === 'asc')
<a
href="{{ Request::fullUrlWithQuery(['sort' => ['order' => 'desc', 'by' => $attribute]]) }}"
href="{{ Request::fullUrlWithQuery([$sortKey => ['order' => 'desc', 'by' => $attribute]]) }}"
class="data-table-sort__control"
aria-label="{{ __('Sort descending') }}"
>
@if(Request::input('sort.by') !== $attribute)
@if(Request::input($sortKey.'.by') !== $attribute)
<x-root::icon name="chevron-up-down" class="data-table-sort__icon" />
@else
<x-root::icon name="chevron-up" class="data-table-sort__icon" />
@endif
</a>
@else
<a
href="{{ Request::fullUrlWithQuery(['sort' => ['order' => 'asc', 'by' => $attribute]]) }}"
href="{{ Request::fullUrlWithQuery([$sortKey => ['order' => 'asc', 'by' => $attribute]]) }}"
class="data-table-sort__control"
aria-label="{{ __('Sort ascending') }}"
>
Expand Down
11 changes: 11 additions & 0 deletions src/Fields/Fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cone\Root\Fields;

use Closure;
use Cone\Root\Traits\RegistersRoutes;
use Cone\Root\Traits\ResolvesFields;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -18,6 +19,16 @@ class Fieldset extends Field
*/
protected string $template = 'root::fields.fieldset';

/**
* Create a new field instance.
*/
public function __construct(string $label, Closure|string $modelAttribute = null)
{
parent::__construct($label, $modelAttribute);

$this->hiddenOn(['index', 'show']);
}

/**
* Get the URI key.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Fields/ID.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public function __construct(string $label = 'ID', string $modelAttribute = 'id')
parent::__construct($label, $modelAttribute);

$this->hiddenOn(['create', 'update']);

$this->sortable();
}
}
11 changes: 10 additions & 1 deletion src/Fields/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,15 @@ public function getPerPageOptions(): array
*/
public function getPerPageKey(): string
{
return sprintf('%s:per_page', $this->getRequestKey());
return sprintf('%s_per_page', $this->getRequestKey());
}

/**
* Get the sort key.
*/
public function getSortKey(): string
{
return sprintf('%s_sort', $this->getRequestKey());
}

/**
Expand Down Expand Up @@ -654,6 +662,7 @@ public function toIndex(Request $request, Model $model): array
}),
'perPageOptions' => $this->getPerPageOptions(),
'perPageKey' => $this->getPerPageKey(),
'sortKey' => $this->getSortKey(),
'filters' => $this->resolveFilters($request)
->authorized($request)
->renderable()
Expand Down
4 changes: 2 additions & 2 deletions src/Fields/Slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class Slug extends Text
/**
* Create a new field instance.
*/
public function __construct(string $label, Closure|string $modelAttribute = null)
public function __construct(string $label = null, Closure|string $modelAttribute = null)
{
parent::__construct($label, $modelAttribute);
parent::__construct($label ?: __('Slug'), $modelAttribute ?: 'slug');

$this->readonly();

Expand Down
11 changes: 10 additions & 1 deletion src/Resources/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,15 @@ public function getPerPageOptions(): array
*/
public function getPerPageKey(): string
{
return sprintf('%s:per_page', $this->getKey());
return sprintf('%s_per_page', $this->getKey());
}

/**
* Get the sort key.
*/
public function getSortKey(): string
{
return sprintf('%s_sort', $this->getKey());
}

/**
Expand Down Expand Up @@ -417,6 +425,7 @@ public function toIndex(Request $request): array
->toArray(),
'perPageOptions' => $this->getPerPageOptions(),
'perPageKey' => $this->getPerPageKey(),
'sortKey' => $this->getSortKey(),
'filters' => $this->resolveFilters($request)
->authorized($request)
->renderable()
Expand Down

0 comments on commit b355b90

Please sign in to comment.