Skip to content

Commit

Permalink
wip testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim-the-Diamond committed Oct 15, 2024
1 parent a2e4f87 commit f8e4f92
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 132 deletions.
50 changes: 0 additions & 50 deletions packages/builder/.github/pest.yml

This file was deleted.

9 changes: 7 additions & 2 deletions packages/builder/database/factories/ItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ public function definition()
{
return [
'title' => $this->faker->sentence,
'slug' => $this->faker->slug,
'slug' => $this->faker->unique()->slug,
'featured_image_url' => $this->faker->image(null, 30, 30),
'content' => $this->faker->paragraph,
'status' => 'published',
'gallery_image_urls' => null,
'status' => 'draft',
'type' => 'post',
'author_id' => null,
'publish_at' => null,
'deleted_at' => null,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ return new class extends Migration
$table->string('slug')->unique();
$table->string('featured_image_url')->nullable();
$table->text('content')->nullable();
$table->json('gallery_imageurls')->nullable();
$table->json('gallery_image_urls')->nullable();
$table->string('status')->default('draft');
$table->string('type')->default('post');
$table->string('author_id')->nullable();
Expand Down
12 changes: 7 additions & 5 deletions packages/builder/src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Moox\Builder\Commands;

use Illuminate\Console\Command;
Expand Down Expand Up @@ -44,7 +46,7 @@ public function handle()
if ($panelsToregister != null) {
if (is_array($panelsToregister)) {
foreach ($panelsToregister as $panelprovider) {
$this->registerPlugins($providerPath.'/'.$panelprovider);
$this->registerPlugins($providerPath . '/' . $panelprovider);
}
} else {
$this->registerPlugins($panelsToregister);
Expand Down Expand Up @@ -136,11 +138,11 @@ public function registerPlugins(string $providerPath): void
$newPlugins = '';

foreach ($pluginsToAdd as $plugin) {
$searchPlugin = '/'.$plugin.'/';
$searchPlugin = '/' . $plugin . '/';
if (preg_match($searchPlugin, $content)) {
warning("$plugin already registered.");
} else {
$newPlugins .= $intend.$namespace.'\\'.$plugin.$function."\n";
$newPlugins .= $intend . $namespace . '\\' . $plugin . $function . "\n";
}
}

Expand All @@ -155,7 +157,7 @@ public function registerPlugins(string $providerPath): void

$pluginsSection = " ->plugins([\n$newPlugins\n ]);";
$placeholderPattern = '/(\->authMiddleware\(\[.*?\]\))\s*\;/s';
$replacement = "$1\n".$pluginsSection;
$replacement = "$1\n" . $pluginsSection;
$newContent = preg_replace($placeholderPattern, $replacement, $content, 1);
}

Expand All @@ -182,7 +184,7 @@ public function getPanelProviderPath(): string|array
);
}
if (count($providers) == 1) {
$providerPath .= '/'.$providers[0]->getBasename();
$providerPath .= '/' . $providers[0]->getBasename();
}

return $providerPath;
Expand Down
2 changes: 2 additions & 0 deletions packages/builder/src/ItemPlugin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Moox\Builder;

use Filament\Contracts\Plugin;
Expand Down
2 changes: 2 additions & 0 deletions packages/builder/src/Models/Item.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Moox\Builder\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand Down
95 changes: 49 additions & 46 deletions packages/builder/src/Resources/ItemResource.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
<?php

declare(strict_types=1);

namespace Moox\Builder\Resources;

use Camya\Filament\Forms\Components\TitleWithSlugInput;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Form;
use Filament\Tables\Table;
use Moox\Builder\Models\Item;
use Filament\Resources\Resource;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Actions\RestoreBulkAction;
use Filament\Tables\Actions\ViewAction;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ImageColumn;
use Filament\Forms\Components\FileUpload;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Tables\Actions\DeleteBulkAction;
use Illuminate\Database\Eloquent\SoftDeletes;
use Moox\Builder\Models\Item;
use Moox\Builder\Resources\ItemResource\Pages\CreateItem;
use Filament\Tables\Actions\RestoreBulkAction;
use Camya\Filament\Forms\Components\TitleWithSlugInput;
use Moox\Builder\Resources\ItemResource\Pages\EditItem;
use Moox\Builder\Resources\ItemResource\Pages\ListItem;
use Moox\Builder\Resources\ItemResource\Pages\ViewItem;
use Moox\Builder\Resources\ItemResource\Pages\ListItems;
use Moox\Builder\Resources\ItemResource\Pages\CreateItem;
use Moox\Builder\Resources\ItemResource\Widgets\ItemWidgets;

//use Moox\Core\Forms\Components\TitleWithSlugInput;
Expand Down Expand Up @@ -64,17 +66,18 @@ public static function form(Form $form): Form
fieldSlug: 'slug', // The name of the field in your model that will store the slug.
),

/*
...TitleWithSlugInput::make('title')

/*TitleWithSlugInput::make('title')
->titleLabel(__('core::core.title'))
->slugLabel(__('core::core.slug'))
->showSlugInput(fn ($record) => ! $record ||
(config('builder.allow_slug_change_after_saved') || ! $record->exists) &&
(config('builder.allow_slug_change_after_publish') || ! $record->published_at)
->showSlugInput(
fn($record) => ! $record ||
(config('builder.allow_slug_change_after_saved') || ! $record->exists) &&
(config('builder.allow_slug_change_after_publish') || ! $record->published_at)
)
->slugPrefix(url('/').'/'.config('builder.url_slug', 'items/'))
->components(),
*/
->slugPrefix(url('/') . '/' . config('builder.url_slug', 'items/'))
->components(),*/

FileUpload::make('featured_image_url')
->label(__('core::core.featured_image_url')),
MarkdownEditor::make('content')
Expand All @@ -99,8 +102,8 @@ public static function form(Form $form): Form
->color('success')
->button()
->extraAttributes(['class' => 'w-full'])
->action(fn ($record) => $record->restore())
->visible(fn ($livewire, $record) => $record && $record->trashed() && $livewire instanceof ViewItem),
->action(fn($record) => $record->restore())
->visible(fn($livewire, $record) => $record && $record->trashed() && $livewire instanceof ViewItem),
Actions\Action::make('save')
->label(__('core::core.save'))
->color('primary')
Expand All @@ -109,7 +112,7 @@ public static function form(Form $form): Form
->action(function ($livewire) {
$livewire instanceof CreateItem ? $livewire->create() : $livewire->save();
})
->visible(fn ($livewire) => $livewire instanceof CreateItem || $livewire instanceof EditItem),
->visible(fn($livewire) => $livewire instanceof CreateItem || $livewire instanceof EditItem),
Actions\Action::make('publish')
->label(__('core::core.publish'))
->color('success')
Expand All @@ -123,7 +126,7 @@ public static function form(Form $form): Form
$livewire->form->fill($data);
$livewire instanceof CreateItem ? $livewire->create() : $livewire->save();
})
->hidden(fn ($livewire, $record) => $record && $record->trashed()),
->hidden(fn($livewire, $record) => $record && $record->trashed()),
Actions\Action::make('saveAndCreateAnother')
->label(__('core::core.save_and_create_another'))
->color('secondary')
Expand All @@ -132,35 +135,35 @@ public static function form(Form $form): Form
->action(function ($livewire) {
$livewire->saveAndCreateAnother();
})
->visible(fn ($livewire) => $livewire instanceof CreateItem),
->visible(fn($livewire) => $livewire instanceof CreateItem),
Actions\Action::make('cancel')
->label(__('core::core.cancel'))
->color('secondary')
->outlined()
->extraAttributes(['class' => 'w-full'])
->url(fn () => static::getUrl('index'))
->visible(fn ($livewire) => $livewire instanceof CreateItem),
->url(fn() => static::getUrl('index'))
->visible(fn($livewire) => $livewire instanceof CreateItem),
Actions\Action::make('edit')
->label(__('core::core.edit'))
->color('primary')
->button()
->extraAttributes(['class' => 'w-full'])
->url(fn ($record) => static::getUrl('edit', ['record' => $record]))
->visible(fn ($livewire, $record) => $livewire instanceof ViewItem && ! $record->trashed()),
->url(fn($record) => static::getUrl('edit', ['record' => $record]))
->visible(fn($livewire, $record) => $livewire instanceof ViewItem && ! $record->trashed()),
Actions\Action::make('restore')
->label(__('core::core.restore'))
->color('success')
->button()
->extraAttributes(['class' => 'w-full'])
->action(fn ($record) => $record->restore())
->visible(fn ($livewire, $record) => $record && $record->trashed() && $livewire instanceof EditItem),
->action(fn($record) => $record->restore())
->visible(fn($livewire, $record) => $record && $record->trashed() && $livewire instanceof EditItem),
Actions\Action::make('delete')
->label(__('core::core.delete'))
->color('danger')
->link()
->extraAttributes(['class' => 'w-full'])
->action(fn ($record) => $record->delete())
->visible(fn ($livewire, $record) => $record && ! $record->trashed() && $livewire instanceof EditItem),
->action(fn($record) => $record->delete())
->visible(fn($livewire, $record) => $record && ! $record->trashed() && $livewire instanceof EditItem),
]),
Select::make('type')
->options(static::getModel()::getTypeOptions())
Expand All @@ -172,11 +175,11 @@ public static function form(Form $form): Form

Select::make('author_id')
->label(__('core::core.author'))
->options(fn () => static::getAuthorOptions())
->default(fn () => auth()->id())
->options(fn() => static::getAuthorOptions())
->default(fn() => auth()->id())
->required()
->searchable()
->visible(fn () => static::shouldShowAuthorField()),
->visible(fn() => static::shouldShowAuthorField()),
]),
// TODO: Taxonomy Plugin
])
Expand Down Expand Up @@ -219,22 +222,22 @@ public static function table(Table $table): Table
->toggleable(),
ImageColumn::make('author.avatar_url')
->label(__('core::core.author'))
->tooltip(fn ($record) => $record->author?->name)
->tooltip(fn($record) => $record->author?->name)
->alignment('center')
->circular()
->visible(fn () => static::shouldShowAuthorField())
->visible(fn() => static::shouldShowAuthorField())
->toggleable(),
TextColumn::make('type')
->label(__('core::core.type'))
->visible(! empty(config('builder.types')))
->formatStateUsing(fn ($record): string => config('builder.types')[$record->type] ?? ucfirst($record->type))
->formatStateUsing(fn($record): string => config('builder.types')[$record->type] ?? ucfirst($record->type))
->sortable(),
TextColumn::make('status')
->label(__('core::core.status'))
->alignment('center')
->badge()
->formatStateUsing(fn (string $state): string => strtoupper($state))
->color(fn (string $state): string => match ($state) {
->formatStateUsing(fn(string $state): string => strtoupper($state))
->color(fn(string $state): string => match ($state) {
'draft' => 'primary',
'published' => 'success',
'scheduled' => 'info',
Expand All @@ -253,7 +256,7 @@ public static function table(Table $table): Table
->defaultSort('slug', 'desc')
->actions([
ViewAction::make(),
EditAction::make()->hidden(fn () => in_array(static::getCurrentTab(), ['trash', 'deleted'])),
EditAction::make()->hidden(fn() => in_array(static::getCurrentTab(), ['trash', 'deleted'])),
])
->bulkActions([
DeleteBulkAction::make()->hidden(function () use ($currentTab) {
Expand Down Expand Up @@ -284,7 +287,7 @@ public static function getRelations(): array
public static function getPages(): array
{
return [
'index' => ListItem::route('/'),
'index' => ListItems::route('/'),
'edit' => EditItem::route('/{record}/edit'),
'create' => CreateItem::route('/create'),
'view' => ViewItem::route('/{record}'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Moox\Builder\Resources\ItemResource\Pages;

use Filament\Resources\Pages\CreateRecord;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Moox\Builder\Resources\ItemResource\Pages;

use Filament\Actions\DeleteAction;
Expand Down
Loading

0 comments on commit f8e4f92

Please sign in to comment.