Skip to content

Commit

Permalink
merge columns into fields
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Nov 2, 2023
1 parent 5c74887 commit 3d6aec3
Show file tree
Hide file tree
Showing 39 changed files with 476 additions and 656 deletions.
3 changes: 0 additions & 3 deletions resources/views/columns/actions.blade.php

This file was deleted.

18 changes: 0 additions & 18 deletions resources/views/columns/cells/row-actions.blade.php

This file was deleted.

5 changes: 0 additions & 5 deletions resources/views/columns/cells/row-select.blade.php

This file was deleted.

12 changes: 0 additions & 12 deletions resources/views/columns/column.blade.php

This file was deleted.

6 changes: 0 additions & 6 deletions resources/views/columns/select-all.blade.php

This file was deleted.

30 changes: 30 additions & 0 deletions resources/views/resources/table/column.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<th scope="col">
@if($sortable)
<div class="data-table-sort">
{{ $label }}
@if(Request::input('sort.by') !== $attribute || Request::input('sort.order', 'asc') === 'asc')
<a
href="{{ Request::fullUrlWithQuery(['sort' => ['order' => 'desc', 'by' => $attribute]]) }}"
class="data-table-sort__control"
aria-label="{{ __('Sort descending') }}"
>
@if(Request::input('sort.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]]) }}"
class="data-table-sort__control"
aria-label="{{ __('Sort ascending') }}"
>
<x-root::icon name="chevron-down" class="data-table-sort__icon" />
</a>
@endif
</div>
@else
{{ $label }}
@endif
</th>
49 changes: 45 additions & 4 deletions resources/views/resources/table/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,58 @@
<table class="table table--hover">
<thead>
<tr>
@foreach($columns as $column)
@include($column['template'], $column)
@if(! empty($actions))
<th style="inline-size: 3.25rem;" scope="col">
<span class="sr-only">{{ __('Select') }}</span>
<label class="form-check" aria-label="{{ __('Select all items') }}">
<input class="form-check__control" type="checkbox">
</label>
</th>
@endif
@foreach($data[0]['fields'] as $column)
@include('root::resources.table.column', $column)
@endforeach
<th scope="col">
<span class="sr-only">{{ __('Actions') }}</span>
</th>
</tr>
</thead>
<tbody>
@foreach($data as $row)
<tr>
@foreach($row['cells'] as $cell)
@include($cell['template'], $cell)
@if(! empty($actions))
<td>
<label class="form-check" aria-label="">
<input
class="form-check__control"
type="checkbox"
value="{{ $row['id'] }}"
x-model="selection"
>
</label>
</td>
@endif
@foreach($row['fields'] as $cell)
@include('root::resources.table.cell', $cell)
@endforeach
<td>
<div class="data-table__actions">
@can('update', $row['model'])
<a href="{{ $row['url'] }}" class="btn btn--light btn--sm btn--icon" aria-label="{{ __('Edit') }}">
<x-root::icon name="edit" class="btn__icon" />
</a>
@endcan
@can('delete', $row['model'])
<form action="{{ $row['url'] }}" method="POST" onsubmit="return window.confirm('{{ __('Are you sure?') }}');">
@csrf
@method('DELETE')
<button type="submit" class="btn btn--delete btn--sm btn--icon" aria-label="{{ __('Delete') }}">
<x-root::icon name="trash" class="btn__icon" />
</button>
</form>
@endcan
</div>
</td>
</tr>
@endforeach
</tbody>
Expand Down
6 changes: 4 additions & 2 deletions src/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Cone\Root\Traits\Authorizable;
use Cone\Root\Traits\Makeable;
use Cone\Root\Traits\RegistersRoutes;
use Cone\Root\Traits\ResolvesVisibility;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
Expand All @@ -28,6 +29,7 @@ abstract class Action implements Arrayable, Form, JsonSerializable
use Authorizable;
use HasAttributes;
use Makeable;
use ResolvesVisibility;
use RegistersRoutes {
RegistersRoutes::registerRoutes as __registerRoutes;
}
Expand Down Expand Up @@ -219,12 +221,12 @@ public function toArray(): array
/**
* {@inheritdoc}
*/
public function toTableComponent(Request $request): array
public function toForm(Request $request): array
{
return array_merge($this->toArray(), [
'open' => $this->errors($request)->isNotEmpty(),
'fields' => $this->resolveFields($request)
->mapToFormComponents($request, $this->query->getModel()),
->mapToInputs($request, $this->query->getModel()),
]);
}
}
21 changes: 19 additions & 2 deletions src/Actions/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Cone\Root\Actions;

use Cone\Root\Traits\RegistersRoutes;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
use Illuminate\Support\Arr;
Expand All @@ -22,12 +23,28 @@ public function register(array|Action $actions): static
return $this;
}

/**
* Filter the actions that are available for the current request and model.
*/
public function authorized(Request $request, Model $model = null): static
{
return $this->filter->authorized($request, $model)->values();
}

/**
* Filter the actions that are visible in the given context.
*/
public function visible(string|array $context): static
{
return $this->filter->visible($context)->values();
}

/**
* Map the action to table components.
*/
public function mapToTableComponents(Request $request): array
public function mapToForms(Request $request): array
{
return $this->map->toTableComponent($request)->all();
return $this->map->toForm($request)->all();
}

/**
Expand Down
Loading

0 comments on commit 3d6aec3

Please sign in to comment.