Skip to content

Commit

Permalink
Merge branch 'main' into feature/FILACMS-23
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-layson committed Apr 8, 2024
2 parents be6d47d + 92c91cc commit cdd8200
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 17 deletions.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ From the project directory, run `./vendor/bin/pest`
## Interacting with the package

During development, you may like to actually interact with the FilaCMS UI. In your console, run
```./vendor/bin/workbench serve```
```./vendor/bin/testbench serve```

You can now load the application at http://localhost:8000/admin

Expand All @@ -53,3 +53,45 @@ Password: password
## Protecting resources

Add the `IsProtectedResource` trait to your Filament resources to have them automatically obey `view <resource-name>` and `manage <resource-name>` permissions.

## Extending the Abstract Content

To add additional models or tables that extends the AbstractContent, you start by executing `php artisan make:filament-resource {Resource}`.

This command will generate a Resource file in your App\Filament\Resources folder. Add the next line in your class:
`use Portable\FilaCms\Filament\Resources\AbstractContentResource;`

Then go to your generated Resource file (e.g. `RecipeResource.php`), and change the `extends Resource` part to `extends AbstractContentResource`.

You should declare the proper model in your `$model` variable.

Then go to your model and add the following line:
`use Portable\FilaCms\Models\AbstractContentModel;`
Then change the `extends Model` to `extends AbstractContentModel`

Next is to create a Plugin class in your `app/Plugins` folder (or create the folder if it's not present yet). The content should look like this (change the appropriate values such as the Resource and the ID):

~~~
namespace App\Plugins;
use App\Filament\Resources\RecipeResource;
use Filament\Panel;
use Filament\Contracts\Plugin;
class RecipesPlugin implements Plugin
{
public function getId(): string
{
return 'filacms-recipes';
}
public function register(Panel $panel): void
{
$panel->resources([
RecipeResource::class
]);
}
}
~~~

Finally, add the plugin in your `app/config/fila-cms.php` file
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"mistralys/text-diff": "^2.0",
"spatie/laravel-permission": "^6.3",
"laravel/framework": "^10.0",
"rawilk/filament-password-input": "^2.0",
"ralphjsmit/laravel-filament-seo": "^1.3"
},
"require-dev": {
Expand Down
79 changes: 78 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions src/Filament/Resources/AbstractContentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Portable\FilaCms\Filament\Resources;

use Filament\Forms\Form;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Fieldset;
Expand All @@ -13,16 +14,16 @@
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Components\View;
use Filament\Forms\Form;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\TernaryFilter;

use FilamentTiptapEditor\TiptapEditor;
use FilamentTiptapEditor\Enums\TiptapOutput;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Str;
use Portable\FilaCms\Filament\Forms\Components\StatusBadge;
use Portable\FilaCms\Filament\Resources\AbstractContentResource\Pages;
use Portable\FilaCms\Filament\Resources\AbstractContentResource\RelationManagers;
Expand All @@ -32,6 +33,7 @@
use Portable\FilaCms\Models\Scopes\PublishedScope;
use Portable\FilaCms\Models\TaxonomyResource;
use RalphJSmit\Filament\SEO\SEO;
use Str;

class AbstractContentResource extends AbstractResource
{
Expand Down Expand Up @@ -65,7 +67,7 @@ public static function form(Form $form): Form
->columnSpanFull()
->required(),
static::tiptapEditor()->output(\FilamentTiptapEditor\Enums\TiptapOutput::Json),
SEO::make(['description']),
SEO::make(['description']),
]),
Tabs\Tab::make('Taxonomies')
->schema([
Expand Down Expand Up @@ -177,6 +179,17 @@ public static function table(Table $table): Table
])
->filters([
Tables\Filters\TrashedFilter::make(),
TernaryFilter::make('is_draft')
->label('Draft')
->attribute('is_draft')
->nullable()
->placeholder('All Records')
->falseLabel('Non-Drafts Only')
->trueLabel('Drafts Only')
->queries(
true: fn (Builder $query) => $query->where('is_draft', true),
false: fn (Builder $query) => $query->where('is_draft', false),
)
])
->actions([
Tables\Actions\DeleteAction::make(),
Expand Down
20 changes: 20 additions & 0 deletions src/Filament/Resources/PageResource/Pages/ListPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,28 @@

use Portable\FilaCms\Filament\Resources\AbstractContentResource\Pages\ListAbstractContentResources;
use Portable\FilaCms\Filament\Resources\PageResource;
use Illuminate\Database\Eloquent\Builder;

class ListPages extends ListAbstractContentResources
{
protected static string $resource = PageResource::class;

public function isTableSearchable(): bool
{
return true;
}

protected function applySearchToTableQuery(Builder $query): Builder
{
if (filled($searchQuery = $this->getTableSearch())) {
$searchQuery = '%' . $searchQuery . '%';
$query->where('title', 'LIKE', $searchQuery)
->orWhere('slug', 'LIKE', $searchQuery)
->orWhere('contents', 'LIKE', $searchQuery)
->orWhere('slug', 'LIKE', $searchQuery)
->orWhere('slug', 'LIKE', $searchQuery);
}

return $query;
}
}
9 changes: 6 additions & 3 deletions src/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Filament\Tables\Table;
use Portable\FilaCms\Filament\Resources\UserResource\Pages;
use Portable\FilaCms\Filament\Traits\IsProtectedResource;
use Rawilk\FilamentPasswordInput\Password;

class UserResource extends AbstractConfigurableResource
{
Expand All @@ -31,9 +32,11 @@ public static function form(Form $form): Form
->email()
->prefixIcon('heroicon-m-envelope')
->required(),
Forms\Components\TextInput::make('password')
->password()
->revealable(),
Password::make('password')
->regeneratePassword(color: 'warning')
->copyable(color: 'info')
->newPasswordLength(16)
->required(),
Forms\Components\Select::make('roles')
->relationship('roles', 'name')
->multiple()
Expand Down
15 changes: 9 additions & 6 deletions src/Providers/FilaCmsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ public function boot()
}

if (config('fila-cms.publish_content_routes')) {
$this->loadRoutesFrom(__DIR__.'/../../routes/frontend-routes.php');
$this->loadRoutesFrom(__DIR__ . '/../../routes/frontend-routes.php');
}
//$this->loadRoutesFrom(__DIR__.'/../Routes/web.php');

$this->loadViewsFrom(__DIR__.'/../../views', 'fila-cms');
$this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
$this->loadViewsFrom(__DIR__ . '/../../views', 'fila-cms');
$this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');

\Filament\Support\Facades\FilamentIcon::register([
'filament-password-input::regenerate' => 'heroicon-m-key',
]);

Livewire::component('portable.fila-cms.livewire.content-resource-list', \Portable\FilaCms\Livewire\ContentResourceList::class);
Livewire::component('portable.fila-cms.livewire.content-resource-show', \Portable\FilaCms\Livewire\ContentResourceShow::class);
Expand All @@ -51,12 +55,12 @@ public function register()
});

$this->publishes([
__DIR__.'/../../config/fila-cms.php' => config_path('fila-cms.php'),
__DIR__ . '/../../config/fila-cms.php' => config_path('fila-cms.php'),
], 'fila-cms-config');

// use the vendor configuration file as fallback
$this->mergeConfigFrom(
__DIR__.'/../../config/fila-cms.php',
__DIR__ . '/../../config/fila-cms.php',
'fila-cms'
);

Expand All @@ -72,7 +76,6 @@ public function register()
} else {
return app('Illuminate\Foundation\Vite')('vendor/portable/filacms/resources/css/filacms.css');
}

} catch (\Exception $e) {
return '';
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Filament/PageResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Portable\FilaCms\Models\TaxonomyTerm;
use Portable\FilaCms\Tests\TestCase;
use Spatie\Permission\Models\Role;
use RalphJSmit\Laravel\SEO\Models\SEO;

class PageResourceTest extends TestCase
{
Expand Down Expand Up @@ -77,6 +78,26 @@ public function test_can_create_record(): void
]);
}

public function test_can_save_seo(): void
{
$data = $this->generateModel(true);
$data['seo.description'] = 'Test Description';
$data['is_draft'] = 0;
$data['publish_at'] = now()->subday();
$data['expire_at'] = now()->addDay();

Livewire::test(TargetResource\Pages\CreatePage::class)
->fillForm($data)
->call('create')
->assertHasNoFormErrors();

// check last record
$model = TargetModel::orderBy('id', 'desc')->first();

$this->assertTrue($model->Seo instanceof SEO);

}

public function test_can_render_edit_page(): void
{
$data = $this->generateModel();
Expand Down
5 changes: 3 additions & 2 deletions tests/Listeners/ServeCommandStartedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public function handle(): void
Artisan::call('fila-cms:install', ['--publish-config' => true,'--run-migrations' => true,'--add-user-traits' => true]);

// Ensure there's an admin user
$admin = User::where('email', '[email protected]')->first();
$userModel = config('auth.providers.users.model');
$admin = $userModel::where('email', '[email protected]')->first();
if(!$admin) {
$admin = new User();
$admin = new $userModel();
}
$admin->email = '[email protected]';
$admin->password = Hash::make('password');
Expand Down

0 comments on commit cdd8200

Please sign in to comment.