diff --git a/composer.json b/composer.json index b97e5e8..6d97b65 100644 --- a/composer.json +++ b/composer.json @@ -19,11 +19,11 @@ ], "require": { "php": "^8.2", - "gammamatrix/playground": "dev-develop|dev-master|dev-feature/*|^73.0@dev|^73.0" + "gammamatrix/playground": "*" }, "require-dev": { - "gammamatrix/playground-auth": "dev-develop|dev-master|dev-feature/*|^73.0@dev|^73.0", - "gammamatrix/playground-test": "dev-develop|dev-master|dev-feature/*|^73.0@dev|^73.0" + "gammamatrix/playground-auth": "*", + "gammamatrix/playground-test": "*" }, "minimum-stability": "dev", "prefer-stable": true, @@ -47,8 +47,7 @@ }, "extra": { "branch-alias": { - "dev-develop": "73.x-dev", - "dev-master": "73.x-dev" + "dev-develop": "73.x-dev" }, "laravel": { "providers": [ diff --git a/config/playground-blade.php b/config/playground-blade.php index 98534b3..c539525 100644 --- a/config/playground-blade.php +++ b/config/playground-blade.php @@ -3,6 +3,7 @@ declare(strict_types=1); return [ + 'about' => (bool) env('PLAYGROUND_BLADE_ABOUT', true), 'app' => [ 'name' => env('PLAYGROUND_BLADE_APP_NAME', 'Demo'), 'url' => env('PLAYGROUND_BLADE_APP_URL', '/'), @@ -11,6 +12,7 @@ 'view' => env('PLAYGROUND_BLADE_VIEW', 'playground::'), 'load' => [ 'views' => (bool) env('PLAYGROUND_BLADE_LOAD_VIEWS', true), + 'translations' => (bool) env('PLAYGROUND_BLADE_LOAD_TRANSLATIONS', true), ], 'session' => [ 'enable' => (bool) env('PLAYGROUND_BLADE_SESSION_ENABLE', true), diff --git a/lang/en/pagination.php b/lang/en/pagination.php new file mode 100644 index 0000000..8bdf4b6 --- /dev/null +++ b/lang/en/pagination.php @@ -0,0 +1,26 @@ + '« Previous', + 'next' => 'Next »', + + 'go' => 'Go', + + 'form.label' => 'Pagination Options', + + 'show' => 'Showing page :currentPage of :lastPage with :perPage per page.', + + 'row.actions.label' => 'Record Controls and Actions', + +]; diff --git a/resources/views/components/forms/column-select.blade.php b/resources/views/components/forms/column-select.blade.php index 6c60f54..0185f74 100644 --- a/resources/views/components/forms/column-select.blade.php +++ b/resources/views/components/forms/column-select.blade.php @@ -56,6 +56,7 @@ // '__METHOD__' => __METHOD__, // '__FILE__' => __FILE__, // '__LINE__' => __LINE__, +// '$flags' => $flags, // '$key' => $key, // '$column' => $column, // '$records' => $records, @@ -66,10 +67,14 @@
@if (empty($column)) -
Expecting a column for the form select.
+
+ Expecting a column for the form select. +
@endif @if ($label) - + @endif
@@ -88,11 +109,15 @@
@else @error($column) -
{{ $message }}
+
+ {{ $message }} +
@enderror @endif @if ($described) - {!! $described !!} + + {!! $described !!} + @endif {{ $slot }} diff --git a/resources/views/components/model/image.blade.php b/resources/views/components/model/image.blade.php new file mode 100644 index 0000000..fa3c560 --- /dev/null +++ b/resources/views/components/model/image.blade.php @@ -0,0 +1,44 @@ +@if(empty($fkModelData)) +{{$value}} +@else +@php + +$withInitials = !empty($columnMeta['with-initials']) && is_bool($columnMeta['with-initials']); +$withName = !empty($columnMeta['with-name']) && is_bool($columnMeta['with-name']); + +$hasAvatar = !empty($fkModelData['avatar']) && is_string($fkModelData['avatar']); +$hasImage = !empty($fkModelData['image']) && is_string($fkModelData['image']); + +$property = !empty($columnMeta['property']) && is_string($columnMeta['property']) ? $columnMeta['property'] : ''; + +$width = 36; +$image = ''; +$initials = ''; +$name = !empty($fkModelData[$property]) && is_string($fkModelData[$property]) ? $fkModelData[$property] : ''; +if ($name) { + $initials = preg_filter('/[^A-Z]/', '', $name); + if (mb_strlen($initials) > 2) { + $initials = mb_substr($initials, 0, 1).mb_substr($initials, -1); + } +} + +if ($hasAvatar) { + $image = $fkModelData['avatar']; +} elseif ($hasImage) { + $image = $fkModelData['image']; +} + +@endphp +@if($image) +Avatar +@elseif($initials) + + {{$initials}} + +@endif + +@if($withName && $name) +{{$name}} +@endif + +@endif diff --git a/resources/views/components/table/data-form-filter-columns.blade.php b/resources/views/components/table/data-form-filter-columns.blade.php new file mode 100644 index 0000000..4f0edb6 --- /dev/null +++ b/resources/views/components/table/data-form-filter-columns.blade.php @@ -0,0 +1,53 @@ + [ + 'label' => 'All', + ], + 'standard' => [ + 'label' => 'Standard', + ], + 'mobile' => [ + 'label' => 'Mobile', + ], +]; + +$viewableColumns = 'standard'; +if (!empty($validated) + && !empty($validated['columns']) + && is_string($validated['columns']) + && in_array($validated['columns'], array_keys($columns)) +) { + $viewableColumns = $validated['columns']; +} +// dd([ +// '$viewableColumns' => $viewableColumns, +// '$validated' => $validated, +// '$columns' => $columns, +// '$meta' => $meta, +// ]) +?> +
+ + Filter Columns + + +
+
+ +
+
+ + @foreach($columns as $column => $columnMeta) +
+ + +
+ @endforeach +
+
+
+
+
diff --git a/resources/views/components/table/data-form-filter-trash.blade.php b/resources/views/components/table/data-form-filter-trash.blade.php index 83a2e0a..0b437b1 100644 --- a/resources/views/components/table/data-form-filter-trash.blade.php +++ b/resources/views/components/table/data-form-filter-trash.blade.php @@ -10,7 +10,7 @@ } } ?> -
+
Filter Trash diff --git a/resources/views/components/table/data-form-filter.blade.php b/resources/views/components/table/data-form-filter.blade.php index bd65669..67ba578 100644 --- a/resources/views/components/table/data-form-filter.blade.php +++ b/resources/views/components/table/data-form-filter.blade.php @@ -12,6 +12,8 @@ +@include('playground::components/table/data-form-filter-columns') + @includeWhen($trashable, 'playground::components/table/data-form-filter-trash') @includeWhen(!empty($meta['ids']), 'playground::components/table/data-form-filter-ids') diff --git a/resources/views/components/table/data-form-pagination.blade.php b/resources/views/components/table/data-form-pagination.blade.php index 0f94ac6..aa5727f 100644 --- a/resources/views/components/table/data-form-pagination.blade.php +++ b/resources/views/components/table/data-form-pagination.blade.php @@ -1,11 +1,11 @@
- {{ __('playground::pagination.form.label') }} + {{ __('playground-blade::pagination.form.label') }}
diff --git a/resources/views/components/table/data-row-actions.blade.php b/resources/views/components/table/data-row-actions.blade.php index ee3c4ff..81e3c6f 100644 --- a/resources/views/components/table/data-row-actions.blade.php +++ b/resources/views/components/table/data-row-actions.blade.php @@ -1,5 +1,5 @@ -
+
@if ($withUnlock && !empty($record['locked']) && $routeUnlock) @include('playground::components/table/data-row-actions-unlock') @else diff --git a/resources/views/components/table/data-row.blade.php b/resources/views/components/table/data-row.blade.php index ca6199f..b2dfd3d 100644 --- a/resources/views/components/table/data-row.blade.php +++ b/resources/views/components/table/data-row.blade.php @@ -6,6 +6,8 @@ $routeParameter = !empty($routeParameter) && is_string($routeParameter) ? $routeParameter : ''; $record = !empty($record) && is_array($record) ? $record : []; + $fkModelData = []; + $hasColumnError = false; /** @@ -63,7 +65,7 @@ /** * @var string $isFk Is the column a foreign key? */ - $isFk = 'fk' === $columnMeta['linkType']; + $isFk = in_array($columnMeta['linkType'], ['fk', 'filter-id']); // The foreign key needs a property to access. $isFk = $isFk && isset($columnMeta['property']) && !empty($columnMeta['property']); if ($preferLinkSlug) { @@ -85,7 +87,10 @@ // '$isUrlLink' => $isUrlLink, // '$link' => $link, // '$record' => $record, - // '$datum' => $datum, + // // '$datum' => $datum, + // '$routeParameter' => $routeParameter, + // '$routeParameterKey' => $routeParameterKey, + // '$record[$routeParameterKey]' => $record[$routeParameterKey] ?? 'nope', // ]); // Check for slug link first. @@ -98,7 +103,11 @@ } elseif ($preferLinkGo) { $link = empty($record[$routeParameterKey]) ? '' : route($columnMeta['linkRoute'], ['go' => $record[$routeParameterKey]]); } elseif ($isFk) { - $link = empty($record[$column]) ? '' : route($columnMeta['linkRoute'], [$routeParameter => $record[$column]]); + if (!empty($record[$column]) && !empty($columnMeta['routeParameter']) && !empty($columnMeta['routeParameterKey'])) { + $link = route($columnMeta['linkRoute'], [ + $columnMeta['routeParameter'] => $record[$columnMeta['routeParameterKey']], + ]); + } } if ($isUrlLink) { @@ -117,8 +126,8 @@ // '$isFk' => $isFk, // '$isUrlLink' => $isUrlLink, // '$link' => $link, - // '$record' => $record, - // '$datum' => $datum, + // // '$record' => $record, + // // '$datum' => $datum, // ]); if ($isFk && !empty($accessor)) { @@ -126,8 +135,12 @@ $fkModel = $datum && is_callable([$datum, $accessor]) ? $datum->{$accessor}()->first() : null; if ($fkModel) { $fkModelData = $fkModel->toArray(); - if (!empty($property) && isset($fkModelData[$property])) { - $value = $fkModelData[$property]; + if (!empty($property)) { + if ($property === 'label_or_title') { + $value = $fkModel->label_or_title; + } elseif (isset($fkModelData[$property])) { + $value = $fkModelData[$property]; + } } } } catch (\Throwable $th) { @@ -170,6 +183,7 @@ } $isFlag = isset($columnMeta['flag']) && is_bool($columnMeta['flag']) && $columnMeta['flag']; + $withImage = isset($columnMeta['with-image']) && is_bool($columnMeta['with-image']) && $columnMeta['with-image']; // dump([ // '__METHOD__' => __METHOD__, @@ -195,6 +209,8 @@ class="{{ !empty($hasColumnError) ? 'text-danger ' : '' }}{{ !empty($columnMeta[ @if ($isFlag) + @elseif ($withImage) + @elseif ($columnMeta['html']) {!! $value !!} @elseif ($isDate) diff --git a/resources/views/layouts/resource/detail-accordion.blade.php b/resources/views/layouts/resource/detail-accordion.blade.php new file mode 100644 index 0000000..82a8481 --- /dev/null +++ b/resources/views/layouts/resource/detail-accordion.blade.php @@ -0,0 +1,45 @@ +
+
+

+ +

+
+
+
+ @include('playground::layouts.resource.detail-actions', ['css' => 'mb-3']) +
+ @yield('detail-accordion-body-header') + @yield('detail-accordion-body') + @includeWhen($withInfo, 'playground::layouts.resource.detail-info') + + @if ($withAccordionFlags) +
+
+ @yield('detail-information-flags') +
+
+ @endif + + @if ($withAccordionTimestamps) +
+
+ @include('playground::layouts.resource.detail-timestamps') +
+
+ @endif + + @yield('detail-accordion-body-footer') +
+
+
+
diff --git a/resources/views/layouts/resource/detail-actions.blade.php b/resources/views/layouts/resource/detail-actions.blade.php new file mode 100644 index 0000000..91f6580 --- /dev/null +++ b/resources/views/layouts/resource/detail-actions.blade.php @@ -0,0 +1,52 @@ +@if ($withDelete || $withEdit) +
+ + +
+@endif diff --git a/resources/views/layouts/resource/detail-card.blade.php b/resources/views/layouts/resource/detail-card.blade.php new file mode 100644 index 0000000..3a5585f --- /dev/null +++ b/resources/views/layouts/resource/detail-card.blade.php @@ -0,0 +1,34 @@ +
+ @if($withCardHeader) +
+ @include('playground::layouts.resource.detail-actions') +

{{ __($data->getAttributeValue($meta['info']['model_attribute'])) }}

+
+ @endif + @if ($withImage && $data && $data->image) +
+ {{ __(':model_label Image', ['model_label' => $meta['info']['model_label']]) }} +
+ @endif + @if($withCardBody) +
+ @yield('detail-card-body-header') + @yield('detail-card-body') + @includeWhen($withInfo, 'playground::layouts.resource.detail-info') + @yield('detail-card-body-footer') +
+ @endif + + @if($withCardFlags) + + @endif + + @if($withCardTimestamps) + + @endif + +
diff --git a/resources/views/layouts/resource/detail-flags.blade.php b/resources/views/layouts/resource/detail-flags.blade.php new file mode 100644 index 0000000..f534764 --- /dev/null +++ b/resources/views/layouts/resource/detail-flags.blade.php @@ -0,0 +1,17 @@ +@if(!empty($data) && $data->deleted_at) + + + {{ __('Trashed') }} + +@endif + +@if(!empty($flags) && is_array($flags)) +@foreach ($flags as $flagKey => $flagMeta) +@if ($data->getAttribute($flagKey)) + + + {{ __($flagMeta['label']) }} + +@endif +@endforeach +@endif diff --git a/resources/views/layouts/resource/detail-info.blade.php b/resources/views/layouts/resource/detail-info.blade.php new file mode 100644 index 0000000..a5fa033 --- /dev/null +++ b/resources/views/layouts/resource/detail-info.blade.php @@ -0,0 +1,48 @@ + + + @yield('detail-info-table-header') + + + + + + @yield('detail-info-table-body') + @if ($parent) + + + + + @endif + + @yield('detail-info-table-header') + +
{{ __('Slug') }}{{ $data->slug }}
{{ __('Parent ' . $meta['info']['model_label']) }} + + {{ __($parent->label) }} + +
+ +@if ($data->description) +

{{ __('Description') }}

+ +
{{ $data->description }}
+@endif + +@if ($data->introduction) +

{{ __('Introduction') }}

+ +
{{ $data->introduction }}
+@endif + +@if ($data->content) +

{{ __('Content') }}

+ +
{!! $data->content !!}
+@endif + +@if ($data->summary) +

{{ __('Summary') }}

+ +
{!! $data->summary !!}
+@endif diff --git a/resources/views/layouts/resource/detail-information.blade.php b/resources/views/layouts/resource/detail-information.blade.php deleted file mode 100644 index bf55649..0000000 --- a/resources/views/layouts/resource/detail-information.blade.php +++ /dev/null @@ -1,130 +0,0 @@ -
-
- @if ($withDelete || $withEdit) -
- -
- @endif -

{{ $data->getAttributeValue($meta['info']['model_attribute']) }}

-
- @if ($withImage && $data && $data->image) -
- {{ $meta['info']['model_label'] }} Image -
- @endif -
- -

{{ __('Information') }}

- - - - - - - - @if ($parent) - - - - - @endif - - - - - - - - - @yield('detail-information-table') - -
{{ __('Slug') }}{{ $data->slug }}
{{ __('Parent ' . $meta['info']['model_label']) }} - - {{ $parent->label }} - -
{{ __('Created') }} - @if ($data->created_at) - - @endif -
{{ __('Updated') }} - @if ($data->updated_at) - - @endif -
- - @if ($data->description) -

{{ __('Description') }}

- -
{{ $data->description }}
- @endif - - @if ($data->introduction) -

{{ __('Introduction') }}

- -
{{ $data->introduction }}
- @endif - - @if ($data->content) -

{{ __('Content') }}

- -
{!! $data->content !!}
- @endif - - @if ($data->summary) -

{{ __('Summary') }}

- -
{!! $data->summary !!}
- @endif - -
- - - - - -
diff --git a/resources/views/layouts/resource/detail-tables.blade.php b/resources/views/layouts/resource/detail-tables.blade.php new file mode 100644 index 0000000..addb894 --- /dev/null +++ b/resources/views/layouts/resource/detail-tables.blade.php @@ -0,0 +1,45 @@ +@if ($hasTables) +@foreach ($dataDetail['tables'] as $table) +
+ @php + $hasTable = is_string($table) && !empty($dataDetail[$table]) && !empty($dataDetail[$table]['label']) && !empty($$table) && is_object($$table); + @endphp + @continue(!$hasTable) + @php + if (!empty($dataDetail[$table]['table']) && is_array($dataDetail[$table]['table'])) { + $components_table = $dataDetail[$table]['table']; + $components_table['paginator'] = $$table; + } else { + $components_table = [ + 'columns' => [ + $meta['info']['model_attribute'] => [ + 'label' => ucfirst($meta['info']['model_attribute']), + ], + 'slug' => [ + // 'linkType' => 'slug', + // 'linkRoute' => 'slug', + 'label' => 'Slug', + ], + ], + 'modelActions' => true, + 'routeEdit' => sprintf('%1$s.edit', $meta['info']['model_route']), + 'paginator' => $$table, + 'styling' => [ + 'header' => [ + 'class' => 'mt-3', + ], + ], + ]; + } + @endphp +
+
+ @component(sprintf('%1$scomponents/table', $package_config['view']), $components_table) + {{ $dataDetail[$table]['label'] }} + @endcomponent +
+
+ +
+@endforeach +@endif diff --git a/resources/views/layouts/resource/detail-timestamps.blade.php b/resources/views/layouts/resource/detail-timestamps.blade.php new file mode 100644 index 0000000..326c279 --- /dev/null +++ b/resources/views/layouts/resource/detail-timestamps.blade.php @@ -0,0 +1,26 @@ +
    + @if ($data->created_at) +
  • + {{ __('Created') }}: + +
  • + @endif + @if ($data->updated_at) +
  • + {{ __('Updated') }}: + +
  • + @endif + @if ($data->deleted_at) +
  • + {{ __('Deleted') }}: + +
  • + @endif + @if ($data->closed_at) +
  • + {{ __('Closed At') }}: + +
  • + @endif +
diff --git a/resources/views/layouts/resource/detail.blade.php b/resources/views/layouts/resource/detail.blade.php index 0d9bb5d..3f84d18 100644 --- a/resources/views/layouts/resource/detail.blade.php +++ b/resources/views/layouts/resource/detail.blade.php @@ -28,9 +28,16 @@ $withPrivilege = !empty($meta['info']) && !empty($meta['info']['privilege']) && is_string($meta['info']['privilege']) ? $meta['info']['privilege'] : 'playground'; +$_return_url = old('_return_url'); + +$routeModule = route($meta['info']['module_route']); +$routeModel = route($meta['info']['model_route']); +$routeShow = !$data ? '' : route(sprintf('%1$s.show', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]); +$routeLock = !$data ? '' : route(sprintf('%1$s.lock', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]); $routeUnlock = !$data ? '' : route(sprintf('%1$s.unlock', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]); -$routeDelete = !$data ? '' : route(sprintf('%1$s.destroy', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]); -$routeEdit = !$data ? '' : route(sprintf('%1$s.edit', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]); +$routeDelete = !$data ? '' : route(sprintf('%1$s.destroy', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id'), '_return_url' => $_return_url ?: $routeShow]); +$routeRestore = !$data ? '' : route(sprintf('%1$s.restore', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]); +$routeEdit = !$data ? '' : route(sprintf('%1$s.edit', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id'), '_return_url' => $_return_url ?: $routeShow]); $user = \Illuminate\Support\Facades\Auth::user(); @@ -62,16 +69,68 @@ 'roles' => ['admin', 'manager'], ])->allowed(); +$withLock = \Playground\Auth\Facades\Can::access($user, [ + 'allow' => false, + 'any' => true, + 'privilege' => $withPrivilege . ':lock', + 'roles' => ['admin', 'manager'], +])->allowed(); + +/** + * @var boolean|string $withAccordion + */ +$withAccordion = isset($withAccordion) && (is_bool($withAccordion) || is_string($withAccordion)) ? $withAccordion : false; + +/** + * @var boolean|string $withAccordionFlags + */ +$withAccordionFlags = isset($withAccordionFlags) && (is_bool($withAccordionFlags) || is_string($withAccordionFlags)) ? $withAccordionFlags : true; + +/** + * @var boolean|string $withAccordionTimestamps + */ +$withAccordionTimestamps = isset($withAccordionTimestamps) && (is_bool($withAccordionTimestamps) || is_string($withAccordionTimestamps)) ? $withAccordionTimestamps : true; + +/** + * @var boolean|string $withCard + */ +$withCard = isset($withCard) && (is_bool($withCard) || is_string($withCard)) ? $withCard : true; + +/** + * @var boolean|string $withCardHeader + */ +$withCardHeader = isset($withCardHeader) && (is_bool($withCardHeader) || is_string($withCardHeader)) ? $withCardHeader : true; + +/** + * @var boolean|string $withCardBody + */ +$withCardBody = isset($withCardBody) && (is_bool($withCardBody) || is_string($withCardBody)) ? $withCardBody : true; + +/** + * @var boolean|string $withCardFlags + */ +$withCardFlags = isset($withCardFlags) && (is_bool($withCardFlags) || is_string($withCardFlags)) ? $withCardFlags : true; + +/** + * @var boolean|string $withCardTimestamps + */ +$withCardTimestamps = isset($withCardTimestamps) && (is_bool($withCardTimestamps) || is_string($withCardTimestamps)) ? $withCardTimestamps : true; + /** * @var boolean|string $withInfo */ $withInfo = isset($withInfo) && (is_bool($withInfo) || is_string($withInfo)) ? $withInfo : true; /** - * @var boolean $withInfo + * @var boolean $withImage */ $withImage = isset($withImage) && is_bool($withImage) ? $withImage : true; +/** + * @var boolean $withTables + */ +$withTables = isset($withTables) && is_bool($withTables) ? $withTables : true; + /** * @var boolean $hasTables */ @@ -84,97 +143,60 @@ @section('breadcrumbs') @endsection @section('content')
-
- - @if ($withCreate) -
-
- Create -
-
- @endif - - @yield('section-primary') - - @if ($withInfo) - @if (is_string($withInfo)) -
- @include($withInfo) -
- @else - @include('playground::layouts.resource.detail-information') - @endif - @endif - - @yield('section-secondary') - - @yield('section-children') - - @if ($hasTables) - @foreach ($dataDetail['tables'] as $table) -
- @php - $hasTable = is_string($table) && !empty($dataDetail[$table]) && !empty($dataDetail[$table]['label']) && !empty($$table) && is_object($$table); - @endphp - @continue(!$hasTable) - @php - if (!empty($dataDetail[$table]['table']) && is_array($dataDetail[$table]['table'])) { - $components_table = $dataDetail[$table]['table']; - $components_table['paginator'] = $$table; - } else { - $components_table = [ - 'columns' => [ - $meta['info']['model_attribute'] => [ - 'label' => ucfirst($meta['info']['model_attribute']), - ], - 'slug' => [ - // 'linkType' => 'slug', - // 'linkRoute' => 'slug', - 'label' => 'Slug', - ], - ], - 'modelActions' => true, - 'routeEdit' => sprintf('%1$s.edit', $meta['info']['model_route']), - 'paginator' => $$table, - 'styling' => [ - 'header' => [ - 'class' => 'mt-3', - ], - ], - ]; - } - @endphp -
-
- @component(sprintf('%1$scomponents/table', $package_config['view']), $components_table) - {{ $dataDetail[$table]['label'] }} - @endcomponent -
-
- -
- @endforeach - @endif - - @yield('section-tables') - - @yield('section-tertiary') - -
+ + @yield('section-header') + + @includeWhen($withCard, 'playground::layouts.resource.detail-card') + + @includeWhen($withAccordion, 'playground::layouts.resource.detail-accordion') + + @yield('section-primary') + + @yield('section-secondary') + + @yield('section-children') + + @includeWhen($withTables, 'playground::layouts.resource.detail-tables') + + @yield('section-tables') + + @yield('section-tertiary') + + @yield('section-footer') +
@endsection + +@push('body') + +@endpush diff --git a/resources/views/layouts/resource/form.blade.php b/resources/views/layouts/resource/form.blade.php index 0e5fcae..e18e676 100644 --- a/resources/views/layouts/resource/form.blade.php +++ b/resources/views/layouts/resource/form.blade.php @@ -98,12 +98,23 @@ */ $model_attribute = $hasMetaInfo && $data && is_string($data->getAttributeValue($meta['info']['model_attribute'])) ? $data->getAttributeValue($meta['info']['model_attribute']) : ''; +$_return_url = old('_return_url'); + +$routeModule = route($meta['info']['module_route']); +$routeModel = route($meta['info']['model_route']); + +$routeShow = ''; +$routeCreate = route(sprintf('%1$s.create', $meta['info']['model_route']), ['_return_url' => $_return_url]); +$routeEdit = ''; + $formTitle = ''; $_methodUrl = ''; $_method = empty($_method) ? '' : $_method; if ('patch' === $_method) { $formTitle = sprintf('Editing: %1$s', $model_attribute); $_methodUrl = route(sprintf('%1$s.patch', $meta['info']['model_route']), $data?->getAttributeValue('id')); + $routeShow = route(sprintf('%1$s.show', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]); + $routeEdit = route(sprintf('%1$s.edit', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id'), '_return_url' => $_return_url ?: $routeShow]); } elseif ('post' === $_method) { $formTitle = sprintf('Create a %1$s', $meta['info']['model_label']); $_methodUrl = route(sprintf('%1$s.post', $meta['info']['model_route'])); @@ -117,18 +128,42 @@ @section('breadcrumbs') @@ -145,7 +180,7 @@ @csrf - + @if ('patch' === $_method) @@ -185,10 +220,15 @@ @else
- - - {{ __('Cancel') }} + + + + {{ __('Cancel') }} +
@endif diff --git a/resources/views/layouts/resource/index.blade.php b/resources/views/layouts/resource/index.blade.php index 2d65b54..a408af2 100644 --- a/resources/views/layouts/resource/index.blade.php +++ b/resources/views/layouts/resource/index.blade.php @@ -101,6 +101,7 @@ 'routeEdit' => sprintf('%1$s.edit', $meta['info']['model_route']), 'routeDelete' => sprintf('%1$s.destroy', $meta['info']['model_route']), 'routeRestore' => sprintf('%1$s.restore', $meta['info']['model_route']), + 'routeShow' => sprintf('%1$s.show', $meta['info']['model_route']), 'routeUnlock' => sprintf('%1$s.unlock', $meta['info']['model_route']), 'paginator' => $paginator ?? null, 'privilege' => $withPrivilege, @@ -117,11 +118,21 @@ @section('breadcrumbs') @endsection diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index dda1c41..4501ef7 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -21,25 +21,40 @@ class ServiceProvider extends AuthServiceProvider public function boot(): void { + /** + * @var array $config + */ $config = config($this->package); - if (! empty($config)) { - $this->loadViewsFrom( - dirname(__DIR__).'/resources/views', - 'playground' - ); + if (! empty($config['load']) && is_array($config['load'])) { - Blade::componentNamespace('Playground\\Blade\\View\\Components', 'playground'); + if (! empty($config['load']['translations'])) { + $this->loadTranslationsFrom( + dirname(__DIR__).'/lang', + $this->package + ); + } + + if (! empty($config['load']['views'])) { + + Blade::componentNamespace('Playground\\Blade\\View\\Components', 'playground'); + $this->loadViewsFrom( + dirname(__DIR__).'/resources/views', + 'playground' + ); + } if ($this->app->runningInConsole()) { // Publish configuration $this->publishes([ - sprintf('%1$s/config/playground-blade.php', dirname(__DIR__)) => config_path('playground-blade.php'), + sprintf('%1$s/config/%2$s.php', dirname(__DIR__), $this->package) => config_path(sprintf('%1$s.php', $this->package)), ], 'playground-config'); $this->publishesAssets(); } + } + if (! empty($config['about'])) { $this->about(); } } diff --git a/src/View/Components/Forms/ColumnSelect.php b/src/View/Components/Forms/ColumnSelect.php index 50d9763..993159e 100644 --- a/src/View/Components/Forms/ColumnSelect.php +++ b/src/View/Components/Forms/ColumnSelect.php @@ -28,6 +28,10 @@ public function __construct( public string $key = 'label', public string $label = '', public string $pattern = '', + /** + * @var array> + */ + public array $flags = [], public bool|string $placeholder = false, /** * @var array> $records diff --git a/src/View/Components/ModelImage.php b/src/View/Components/ModelImage.php new file mode 100644 index 0000000..cac000d --- /dev/null +++ b/src/View/Components/ModelImage.php @@ -0,0 +1,41 @@ + $columnMeta + */ + public array $columnMeta = [], + /** + * @var array $fkModelData + */ + public array $fkModelData = [], + public mixed $value = null + ) { + } + + public function render(): Factory|View + { + $prefix = config('playground-blade.view'); + + return view(sprintf( + '%1$scomponents.model.image', + is_string($prefix) ? $prefix : '' + )); + } +}