-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 添加 ProductSeriesResource 类,实现产品系列资源的基本功能 - 新增 CreateProductSeries、EditProductSeries、ListProductSeries 和 ViewProductSeries 页面 - 优化 ProductPropertyValueResource表单,使用 ToggleButtons 替代 Radio - 调整 composer.lock 文件中各包的引用版本
- Loading branch information
1 parent
2f96d87
commit 4896445
Showing
6 changed files
with
259 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
src/Clusters/Product/Resources/ProductSeriesResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
|
||
namespace RedJasmine\FilamentProduct\Clusters\Product\Resources; | ||
|
||
use Filament\Forms; | ||
use Filament\Forms\Components\Component; | ||
use Filament\Forms\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Filament\Tables\Table; | ||
use Illuminate\Database\Eloquent\Model; | ||
use RedJasmine\FilamentCore\FilamentResource\ResourcePageHelper; | ||
use RedJasmine\FilamentProduct\Clusters\Product; | ||
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductSeriesResource\Pages; | ||
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductSeriesResource\RelationManagers; | ||
use RedJasmine\Product\Application\Series\Services\ProductSeriesCommandService; | ||
use RedJasmine\Product\Application\Series\Services\ProductSeriesQueryService; | ||
use RedJasmine\Product\Application\Series\UserCases\Commands\ProductSeriesCreateCommand; | ||
use RedJasmine\Product\Application\Series\UserCases\Commands\ProductSeriesDeleteCommand; | ||
use RedJasmine\Product\Application\Series\UserCases\Commands\ProductSeriesUpdateCommand; | ||
use RedJasmine\Product\Domain\Series\Models\ProductSeries; | ||
use RedJasmine\Support\Domain\Data\Queries\FindQuery; | ||
|
||
class ProductSeriesResource extends Resource | ||
{ | ||
protected static ?string $model = ProductSeries::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; | ||
|
||
protected static ?string $cluster = Product::class; | ||
|
||
use ResourcePageHelper; | ||
|
||
protected static ?string $commandService = ProductSeriesCommandService::class; | ||
protected static ?string $queryService = ProductSeriesQueryService::class; | ||
protected static ?string $createCommand = ProductSeriesCreateCommand::class; | ||
protected static ?string $updateCommand = ProductSeriesUpdateCommand::class; | ||
protected static ?string $deleteCommand = ProductSeriesDeleteCommand::class; | ||
|
||
|
||
public static function callFindQuery(FindQuery $findQuery) : FindQuery | ||
{ | ||
$findQuery->include = [ 'products' ]; | ||
return $findQuery; | ||
} | ||
|
||
public static function callResolveRecord(Model $model) : Model | ||
{ | ||
$model->products = $model->products->toArray(); | ||
return $model; | ||
} | ||
|
||
public static function form(Form $form) : Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\TextInput::make('owner_type') | ||
->required() | ||
->maxLength(255), | ||
Forms\Components\TextInput::make('owner_id') | ||
->required() | ||
->numeric(), | ||
Forms\Components\TextInput::make('name') | ||
->required() | ||
->maxLength(255), | ||
Forms\Components\TextInput::make('remarks') | ||
->maxLength(255), | ||
|
||
|
||
Forms\Components\Repeater::make('products') | ||
->relationship() | ||
->dehydrated(true) | ||
// TODO | ||
->saveRelationshipsUsing(function (){}) | ||
->schema( | ||
[ | ||
Forms\Components\Select::make('product_id')->relationship('product', 'title')->required(), | ||
Forms\Components\TextInput::make('name')->required()->maxLength(10) | ||
] | ||
|
||
), | ||
|
||
Forms\Components\TextInput::make('creator_type')->label(__('red-jasmine-product::product-property-value.fields.creator_type'))->readOnly()->visibleOn('view'), | ||
Forms\Components\TextInput::make('creator_id')->label(__('red-jasmine-product::product-property-value.fields.creator_id'))->readOnly()->visibleOn('view'), | ||
Forms\Components\TextInput::make('updater_type')->label(__('red-jasmine-product::product-property-value.fields.updater_type'))->readOnly()->visibleOn('view'), | ||
Forms\Components\TextInput::make('updater_id')->label(__('red-jasmine-product::product-property-value.fields.updater_id'))->readOnly()->visibleOn('view'), | ||
]) | ||
|
||
; | ||
} | ||
|
||
public static function table(Table $table) : Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('id') | ||
->label('ID') | ||
->sortable(), | ||
Tables\Columns\TextColumn::make('owner_type') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('owner_id') | ||
->numeric() | ||
->sortable(), | ||
Tables\Columns\TextColumn::make('name') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('remarks') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('creator_type') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('creator_id') | ||
->numeric() | ||
->sortable(), | ||
Tables\Columns\TextColumn::make('updater_type') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('updater_id') | ||
->numeric() | ||
->sortable(), | ||
Tables\Columns\TextColumn::make('created_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
Tables\Columns\TextColumn::make('updated_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
Tables\Actions\ViewAction::make(), | ||
Tables\Actions\EditAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
|
||
public static function getRelations() : array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
public static function getPages() : array | ||
{ | ||
return [ | ||
'index' => Pages\ListProductSeries::route('/'), | ||
'create' => Pages\CreateProductSeries::route('/create'), | ||
'view' => Pages\ViewProductSeries::route('/{record}'), | ||
'edit' => Pages\EditProductSeries::route('/{record}/edit'), | ||
]; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Clusters/Product/Resources/ProductSeriesResource/Pages/CreateProductSeries.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductSeriesResource\Pages; | ||
|
||
use RedJasmine\FilamentCore\FilamentResource\ResourcePageHelper; | ||
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductSeriesResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateProductSeries extends CreateRecord | ||
{ | ||
protected static string $resource = ProductSeriesResource::class; | ||
|
||
use ResourcePageHelper; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Clusters/Product/Resources/ProductSeriesResource/Pages/EditProductSeries.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductSeriesResource\Pages; | ||
|
||
use RedJasmine\FilamentCore\FilamentResource\ResourcePageHelper; | ||
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductSeriesResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditProductSeries extends EditRecord | ||
{ | ||
use ResourcePageHelper; | ||
|
||
protected static string $resource = ProductSeriesResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\ViewAction::make(), | ||
Actions\DeleteAction::make(), | ||
]; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Clusters/Product/Resources/ProductSeriesResource/Pages/ListProductSeries.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductSeriesResource\Pages; | ||
|
||
use RedJasmine\FilamentCore\FilamentResource\ResourcePageHelper; | ||
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductSeriesResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListProductSeries extends ListRecords | ||
{ | ||
use ResourcePageHelper; | ||
protected static string $resource = ProductSeriesResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Clusters/Product/Resources/ProductSeriesResource/Pages/ViewProductSeries.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductSeriesResource\Pages; | ||
|
||
use RedJasmine\FilamentCore\FilamentResource\ResourcePageHelper; | ||
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductSeriesResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ViewRecord; | ||
|
||
class ViewProductSeries extends ViewRecord | ||
{ | ||
|
||
use ResourcePageHelper; | ||
protected static string $resource = ProductSeriesResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\EditAction::make(), | ||
]; | ||
} | ||
} |