Skip to content

Commit

Permalink
Merge branch 'master' into prepare-phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor authored Nov 4, 2023
2 parents 72dc07b + b65b2a6 commit 1d12b19
Show file tree
Hide file tree
Showing 51 changed files with 685 additions and 639 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/install-laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,19 @@ jobs:
sed -i -e 's#^DB_CONNECTION=.*$#DB_CONNECTION=sqlite#' .env
sed -i -e 's#^DB_DATABASE=.*$#DB_DATABASE=:memory:#' .env
php artisan key:generate
php artisan root:install --seed
# Wait for https://github.com/conedevelopment/root/issues/155
##php artisan root:install --seed
php artisan root:publish --packages
-
name: "Perform static analysis on stubs"
working-directory: "laravel"
run: |
composer require --no-interaction --dev --prefer-dist nunomaduro/larastan
php artisan root:action FooBar
php artisan root:extract FooBar
##php artisan root:extract FooBar
php artisan root:field FooBar
php artisan root:filter FooBar
php artisan root:resource FooBar
php artisan root:resource FooBar --model 'App\Models\User'
php artisan root:widget FooBar
vendor/bin/phpstan analyze -c vendor/nunomaduro/larastan/extension.neon -l 5 $(find app/Root/ -type f -name FooBar.php)
-
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
- [Filters](https://root.conedevelopment.com/docs/filters) - Filters are responsible for transforming the current request to a database query.
- [Actions](https://root.conedevelopment.com/docs/actions) - Actions are responsible for performing a specific action on a set of models.
- [Widgets](https://root.conedevelopment.com/docs/widgets) - Widgets are cards that display some information or any content you want to display.
- [Extracts](https://root.conedevelopment.com/docs/extracts) - Extracts are layers on the top of the resource index.

## Contributing

Expand Down
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.

2 changes: 1 addition & 1 deletion resources/views/components/layout/sidebar-group.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class="btn btn--light btn--sm btn--icon block-navigation__toggle"
<ul>
@foreach($items as $item)
<li>
<a href="{{ $item->url }}" @if($item->matched()) aria-current="page" @endif>
<a href="{{ $item->url }}" @if($item->partiallyMatched()) aria-current="page" @endif>
@if($item->icon)
<x-root::icon :name="$item->icon" class="icon" />
@endif
Expand Down
2 changes: 1 addition & 1 deletion resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@section('content')
<div class="l-row l-row--column:sm:2 l-row--column:lg:3">
@foreach($widgets as $widget)
{!! $widget !!}
@include($widget['template'], $widget)
@endforeach
</div>
@endsection
2 changes: 1 addition & 1 deletion resources/views/resources/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@if(! empty($widgets))
<div class="l-row l-row--column:sm:2 l-row--column:lg:3">
@foreach($widgets as $widget)
{!! $widget !!}
@include($widget['template'], $widget)
@endforeach
</div>
@endif
Expand Down
9 changes: 9 additions & 0 deletions resources/views/resources/show.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@extends('root::app')

{{-- Title --}}
@section('title', $title)

{{-- Content --}}
@section('content')

@endsection
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>
54 changes: 50 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,63 @@
<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('view', $row['model'])
<a href="{{ $row['url'] }}" class="btn btn--light btn--sm btn--icon" aria-label="{{ __('View') }}">
<x-root::icon name="eye" class="btn__icon" />
</a>
@endcan
@can('update', $row['model'])
<a href="{{ $row['url'] }}/edit" 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
3 changes: 2 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
Route::get('/{resource}', [ResourceController::class, 'index'])->name('resource.index');
Route::get('/{resource}/create', [ResourceController::class, 'create'])->name('resource.create');
Route::post('/{resource}', [ResourceController::class, 'store'])->name('resource.store');
Route::get('/{resource}/{resourceModel}', [ResourceController::class, 'edit'])->name('resource.edit');
Route::get('/{resource}/{resourceModel}', [ResourceController::class, 'show'])->name('resource.show');
Route::get('/{resource}/{resourceModel}/edit', [ResourceController::class, 'edit'])->name('resource.edit');
Route::patch('/{resource}/{resourceModel}', [ResourceController::class, 'update'])->name('resource.update');
Route::delete('/{resource}/{resourceModel}', [ResourceController::class, 'destroy'])->name('resource.delete');
Route::post('/{resource}/{resourceModel}/restore', [ResourceController::class, 'restore'])->name('resource.restore');
16 changes: 5 additions & 11 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 @@ -31,6 +32,7 @@ abstract class Action implements Arrayable, Form, JsonSerializable
use RegistersRoutes {
RegistersRoutes::registerRoutes as __registerRoutes;
}
use ResolvesVisibility;

/**
* The Blade template.
Expand Down Expand Up @@ -89,14 +91,6 @@ public function getModalKey(): string
return sprintf('action-%s', $this->getKey());
}

/**
* Get the Blade template.
*/
public function getTemplate(): string
{
return $this->template;
}

/**
* Set the Eloquent query.
*/
Expand Down Expand Up @@ -211,20 +205,20 @@ public function toArray(): array
'key' => $this->getKey(),
'modalKey' => $this->getModalKey(),
'name' => $this->getName(),
'template' => $this->getTemplate(),
'template' => $this->template,
'url' => $this->getUri(),
];
}

/**
* {@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();

Check failure on line 31 in src/Actions/Actions.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Method Cone\Root\Actions\Actions::authorized() should return static(Cone\Root\Actions\Actions) but returns Cone\Root\Actions\Actions.
}

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

Check failure on line 39 in src/Actions/Actions.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Method Cone\Root\Actions\Actions::visible() should return static(Cone\Root\Actions\Actions) but returns Cone\Root\Actions\Actions.
}

/**
* 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 1d12b19

Please sign in to comment.