Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

624 basic livewire table new #199

Merged
merged 5 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"rebing/graphql-laravel": "^8.2",
"nyholm/psr7": "^1.4",
"laravel/passport": "^10.1|^10.2|^10.3",
"symfony/yaml": "^5.3|^6.0"
"symfony/yaml": "^5.3|^6.0",
"livewire/livewire": "^2.10"
},
"require-dev": {
"brianium/paratest": "^6.0",
Expand Down
21 changes: 21 additions & 0 deletions resources/views/catalog/category/_actions.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="flex">
<x-avored::link url="{{ route('admin.category.edit', $category) }}">
<i class="w-5 h-5" data-feather="edit"></i>
</x-avored::link>
<span class="mx-2">|</span>
<x-avored::link
x-on:click.prevent="toggleConfirmationDialog(
true,
{{ $category }},
'{{ __('avored::system.confirmation_delete_message', ['attribute_value' => $category->name, 'attribute' => strtolower(__('avored::system.category'))]) }}',
'{{ route('admin.category.destroy', $category) }}'
)"
url="{{ route('admin.category.destroy', $category) }}">
<i class="w-5 h-5" data-feather="trash"></i>
<x-avored::form.form
id="category-destory-{{ $category->id }}"
method="delete"
action="{{ route('admin.category.destroy', $category) }}">
</x-avored::form.form>
</x-avored::link>
</div>
71 changes: 2 additions & 69 deletions resources/views/catalog/category/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,75 +15,8 @@
<div class="w-full mt-5">
<!-- component -->
<div class="overflow-x-auto">
<x-avored::table>
<x-slot name="header">
<x-avored::table.row class="bg-gray-300">
<x-avored::table.header class="rounded-tl">
{{ __('avored::system.parent') }}
</x-avored::table.header>

<x-avored::table.header>
{{ __('avored::system.name') }}
</x-avored::table.header>
<x-avored::table.header>
{{ __('avored::system.slug') }}
</x-avored::table.header>
<x-avored::table.header>
{{ __('avored::system.meta_title') }}
</x-avored::table.header>
<x-avored::table.header>
{{ __('avored::system.meta_description') }}
</x-avored::table.header>
<x-avored::table.header class="rounded-tr">
{{ __('avored::system.actions') }}
</x-avored::table.header>
</x-avored::table.row>
</x-slot>
<x-slot name="body">
@foreach ($categories as $category)
<x-avored::table.row class="{{ ($loop->index % 2 == 0) ? '' : 'bg-gray-200' }}">
<x-avored::table.cell>
{{ $category->parent->name ?? '' }}
</x-avored::table.cell>
<x-avored::table.cell>
{{ $category->name ?? '' }}
</x-avored::table.cell>
<x-avored::table.cell>
{{ $category->slug ?? '' }}
</x-avored::table.cell>
<x-avored::table.cell>
{{ $category->meta_title ?? '' }}
</x-avored::table.cell>
<x-avored::table.cell>
{{ $category->meta_description ?? '' }}
</x-avored::table.cell>
<x-avored::table.cell>
<div class="flex">
<x-avored::link url="{{ route('admin.category.edit', $category) }}">
<i class="w-5 h-5" data-feather="edit"></i>
</x-avored::link>
<span class="mx-2">|</span>
<x-avored::link
x-on:click.prevent="toggleConfirmationDialog(
true,
{{ $category }},
'{{ __('avored::system.confirmation_delete_message', ['attribute_value' => $category->name, 'attribute' => strtolower(__('avored::system.category'))]) }}',
'{{ route('admin.category.destroy', $category) }}'
)"
url="{{ route('admin.category.destroy', $category) }}">
<i class="w-5 h-5" data-feather="trash"></i>
<x-avored::form.form
id="category-destory-{{ $category->id }}"
method="delete"
action="{{ route('admin.category.destroy', $category) }}">
</x-avored::form.form>
</x-avored::link>
</div>
</x-avored::table.cell>
</x-avored::table.row>
@endforeach
</x-slot>
</x-avored::table>
@livewire('avored-category-table')

<div class="w-full">
{{ $categories->render() }}
</div>
Expand Down
3 changes: 3 additions & 0 deletions resources/views/system/components/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

<link rel="stylesheet" href="{{ asset('vendor/avored/css/app.css') }}"></link>

<livewire:styles />
<livewire:scripts />
</head>
<body x-data="app">

Expand All @@ -24,6 +26,7 @@
{{ $slot }}
</div>
</div>

<script src="{{ asset('vendor/avored/js/app.js') }}"></script>
@stack('scripts')
<script>
Expand Down
3 changes: 1 addition & 2 deletions resources/views/system/components/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
</table>
</div>
</div>
</div
>
</div>
68 changes: 68 additions & 0 deletions resources/views/system/datatable.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

<x-avored::table>
<x-slot name="header">
<x-avored::table.row class="bg-gray-300">
@foreach ($columns as $column)
<x-avored::table.header class="rounded-tl">
{{ __('avored::system.' . $column['identifier']) }}
</x-avored::table.header>
@endforeach
</x-avored::table.row>
</x-slot>
<x-slot name="body">
@foreach ($rows as $row)

<x-avored::table.row class="{{ ($loop->index % 2 == 0) ? '' : 'bg-gray-200' }}">
@foreach ($columns as $column)
<x-avored::table.cell>
@if (isset ($column['render']) && is_callable($column['render']))
@php $renderFunc = $column['render']; @endphp
{!! $renderFunc($row) !!}
@else
@php $identifier = $column['identifier']; @endphp
{{ $row->$identifier ?? '' }}
@endif
</x-avored::table.cell>
@endforeach
{{-- <x-avored::table.cell>
{{ $category->parent->name ?? '' }}
</x-avored::table.cell>
<x-avored::table.cell>
{{ $category->name ?? '' }}
</x-avored::table.cell>
<x-avored::table.cell>
{{ $category->slug ?? '' }}
</x-avored::table.cell>
<x-avored::table.cell>
{{ $category->meta_title ?? '' }}
</x-avored::table.cell>
<x-avored::table.cell>
{{ $category->meta_description ?? '' }}
</x-avored::table.cell>
<x-avored::table.cell>
<div class="flex">
<x-avored::link url="{{ route('admin.category.edit', $category) }}">
<i class="w-5 h-5" data-feather="edit"></i>
</x-avored::link>
<span class="mx-2">|</span>
<x-avored::link
x-on:click.prevent="toggleConfirmationDialog(
true,
{{ $category }},
'{{ __('avored::system.confirmation_delete_message', ['attribute_value' => $category->name, 'attribute' => strtolower(__('avored::system.category'))]) }}',
'{{ route('admin.category.destroy', $category) }}'
)"
url="{{ route('admin.category.destroy', $category) }}">
<i class="w-5 h-5" data-feather="trash"></i>
<x-avored::form.form
id="category-destory-{{ $category->id }}"
method="delete"
action="{{ route('admin.category.destroy', $category) }}">
</x-avored::form.form>
</x-avored::link>
</div>
</x-avored::table.cell> --}}
</x-avored::table.row>
@endforeach
</x-slot>
</x-avored::table>
52 changes: 52 additions & 0 deletions src/Catalog/Tables/CategoryTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
namespace AvoRed\Framework\Catalog\Tables;

use AvoRed\Framework\Database\Models\Category;
use Illuminate\Support\Collection;
use Livewire\Component;

class CategoryTable extends Component
{

public function columns()
{
$columns = Collection::make([]);
$columns->push([
'identifier' => 'parent',
'render' => function ($row) {
return ($row->parent) ? $row->parent->name : '';
}
]);
$columns->push([
'identifier' => 'name'
]);
$columns->push([
'identifier' => 'slug'
]);
$columns->push([
'identifier' => 'meta_title'
]);
$columns->push([
'identifier' => 'meta_description'
]);
$columns->push([
'identifier' => 'actions',
'render' => function ($row) {
return view('avored::catalog.category._actions')
->with('category', $row);
}
]);
return $columns;
}
/**
* @return mixed
*/
public function render()
{
return view('avored::system.datatable')
->with('rows', Category::all())
->with('columns', $this->columns())
;
}

}
13 changes: 12 additions & 1 deletion src/Support/Providers/ComponentsProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace AvoRed\Framework\Support\Providers;

use AvoRed\Framework\Catalog\Tables\CategoryTable;
use AvoRed\Framework\System\Components\Alert;
use AvoRed\Framework\System\Components\Form\Checkbox;
use AvoRed\Framework\System\Components\Form\Form;
Expand All @@ -9,14 +10,15 @@
use AvoRed\Framework\System\Components\Form\Link;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;

class ComponentsProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
* @var bool
*/
protected $defer = true;
protected $defer = false;

public function boot()
{
Expand All @@ -26,6 +28,15 @@ public function boot()
public function registerBlades()
{
Blade::componentNamespace('AvoRed\\Framework\\System\\Components', 'avored');


// Blade::component('avored::system.components.livewire.table.table', 'avored-table::tailwind.table');


Livewire::component('avored-category-table', CategoryTable::class);



// Blade::component('avored-input', Input::class);
// Blade::component('avored-checkbox', Checkbox::class);
// Blade::component('avored-form', Form::class);
Expand Down