Skip to content

Commit

Permalink
Merge pull request #20 from lara-zeus/customize-columns-models
Browse files Browse the repository at this point in the history
Customize columns models
  • Loading branch information
atmonshi committed Jul 7, 2023
2 parents fc58f1d + 4a1306e commit 7e56a8b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions config/zeus-rain.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
'models' => [
'layout' => \LaraZeus\Rain\Models\Layout::class,
'columns' => \LaraZeus\Rain\Models\Columns::class,
],

/**
Expand Down
2 changes: 1 addition & 1 deletion resources/views/filament/pages/layouts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ $this->{'widgetsFromMain'} }}

<div class="grid grid-cols-12 gap-2 w-full">
@foreach (\LaraZeus\Rain\Models\Columns::all() as $layout)
@foreach (config('zeus-rain.models.columns')::all() as $layout)
<x-filament::card class="w-full {{ $layout->class }} p-2">
<p>{{ $layout->name }}</p>
{{ $this->{'widgetsFrom'.$layout->key} }}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/themes/zeus/layouts.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="container mx-auto">
@if($layout->widgets !== null)
<div class="grid grid-cols-1 md:grid-cols-12 gap-2 w-full px-2">
@foreach (\LaraZeus\Rain\Models\Columns::all() as $column)
@foreach (config('zeus-rain.models.columns')::all() as $column)
<div class="w-full {{ $column->class }}">
@if(isset($layout->widgets[$column->key]))
@php
Expand Down
9 changes: 4 additions & 5 deletions src/Filament/Resources/LayoutResource/Pages/CreateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Illuminate\Support\Str;
use LaraZeus\Rain\Facades\Rain;
use LaraZeus\Rain\Filament\Resources\LayoutResource;
use LaraZeus\Rain\Models\Columns;
use LaraZeus\Rain\Models\Layout;

/**
Expand Down Expand Up @@ -48,7 +47,7 @@ public function mount(?int $record = null): void
if ($record === null) {
$layoutModel = config('zeus-rain.models.layout');
$this->rainLayout = new $layoutModel;
foreach (Columns::all() as $column) {
foreach (config('zeus-rain.models.columns')::all() as $column) {
$this->{'widgetsFrom' . $column->key}->fill([
$column->key => '',
]);
Expand All @@ -61,7 +60,7 @@ public function mount(?int $record = null): void
$this->rainLayout = config('zeus-rain.models.layout')::findOrFail($record);

$allWidgets = $this->rainLayout->widgets;
foreach (Columns::all() as $column) {
foreach (config('zeus-rain.models.columns')::all() as $column) {
if (isset($allWidgets[$column->key])) {
$widgetsItems = (new Collection($allWidgets[$column->key]))->sortBy('data.sort')->toArray();
$this->{'widgetsFrom' . $column->key}->fill([
Expand Down Expand Up @@ -125,7 +124,7 @@ protected function getForms(): array

$forms['widgetsFromMain'] = $this->makeForm()->schema($this->mainComponents());

foreach (Columns::all() as $layout) {
foreach (config('zeus-rain.models.columns')::all() as $layout) {
$forms['widgetsFrom' . $layout->key] = $this->makeForm()
->schema($this->getBlocksForms($layout->key));
}
Expand All @@ -137,7 +136,7 @@ public function submit(): void
{
$widgetsData = [];

foreach (Columns::all() as $layout) {
foreach (config('zeus-rain.models.columns')::all() as $layout) {
$widgetsData[$layout->key] = $this->{'widgetsFrom' . $layout->key}->getState()[$layout->key];
}

Expand Down
10 changes: 5 additions & 5 deletions src/Models/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class Columns extends Model
public function getRows(): array
{
return [
['key' => 'headerColumn', 'name' => __('top'), 'class' => 'w-full col-span-1 md:col-span-12'],
['key' => 'rightColumn', 'name' => __('right'), 'class' => 'w-1/4 col-span-1 md:col-span-3'],
['key' => 'middleColumn', 'name' => __('middle'), 'class' => 'w-2/4 col-span-1 md:col-span-6'],
['key' => 'leftColumn', 'name' => __('left'), 'class' => 'w-1/4 col-span-1 md:col-span-3'],
['key' => 'footerColumn', 'name' => __('bottom'), 'class' => 'w-full col-span-1 md:col-span-12'],
['key' => 'headerColumn', 'name' => __('top'), 'class' => 'w-full col-span-12 md:col-span-12'],
['key' => 'rightColumn', 'name' => __('right'), 'class' => 'w-1/4 col-span-12 md:col-span-3'],
['key' => 'middleColumn', 'name' => __('middle'), 'class' => 'w-2/4 col-span-12 md:col-span-6'],
['key' => 'leftColumn', 'name' => __('left'), 'class' => 'w-1/4 col-span-12 md:col-span-3'],
['key' => 'footerColumn', 'name' => __('bottom'), 'class' => 'w-full col-span-12 md:col-span-12'],
];
}
}

0 comments on commit 7e56a8b

Please sign in to comment.