Skip to content

Commit

Permalink
新增产品系列资源和相关页面,优化产品属性值表单
Browse files Browse the repository at this point in the history
- 添加 ProductSeriesResource 类,实现产品系列资源的基本功能
- 新增 CreateProductSeries、EditProductSeries、ListProductSeries 和 ViewProductSeries 页面
- 优化 ProductPropertyValueResource表单,使用 ToggleButtons 替代 Radio
- 调整 composer.lock 文件中各包的引用版本
  • Loading branch information
liushoukun committed Oct 9, 2024
1 parent 2f96d87 commit 4896445
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/Clusters/Product/Resources/ProductPropertyValueResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,39 @@ public static function form(Form $form) : Form
return $form
->schema([
Forms\Components\Select::make('pid')
->label(__('red-jasmine-product::product-property-value.fields.pid'))
->label(__('red-jasmine-product::product-property-value.fields.pid'))
->required()
->relationship('property', 'name')
->searchable([ 'name' ])
->preload()->optionsLimit(2)
->nullable(),

Forms\Components\Select::make('group_id')
->label(__('red-jasmine-product::product-property-value.fields.group_id'))

->relationship('group', 'name')
->label(__('red-jasmine-product::product-property-value.fields.group_id'))
->relationship('group', 'name')
->searchable([ 'name' ])
->preload()
->nullable(),
Forms\Components\TextInput::make('name')
->label(__('red-jasmine-product::product-property-value.fields.name'))
->label(__('red-jasmine-product::product-property-value.fields.name'))
->required()
->maxLength(64),
Forms\Components\TextInput::make('description')
->label(__('red-jasmine-product::product-property-value.fields.description'))->maxLength(255),
->label(__('red-jasmine-product::product-property-value.fields.description'))->maxLength(255),
Forms\Components\TextInput::make('sort')
->label(__('red-jasmine-product::product-property-value.fields.sort'))
->required()->integer()->default(0),
Forms\Components\Radio::make('status')
->label(__('red-jasmine-product::product-property-value.fields.status'))
->required()
->default(PropertyStatusEnum::ENABLE)->options(PropertyStatusEnum::options())
->inline()->inlineLabel(false)->required(),
Forms\Components\TextInput::make('creator_type')->label(__('red-jasmine-product::product-property-value.fields.status'))->readOnly()->visibleOn('view'),
Forms\Components\TextInput::make('creator_id')->label(__('red-jasmine-product::product-property-value.fields.status'))->readOnly()->visibleOn('view'),
Forms\Components\TextInput::make('updater_type')->label(__('red-jasmine-product::product-property-value.fields.status'))->readOnly()->visibleOn('view'),
Forms\Components\TextInput::make('updater_id')->label(__('red-jasmine-product::product-property-value.fields.status'))->readOnly()->visibleOn('view'),
->label(__('red-jasmine-product::product-property-value.fields.sort'))
->required()->integer()->default(0),
Forms\Components\ToggleButtons::make('status')
->label(__('red-jasmine-product::product-property-value.fields.status'))
->required()
->inline()->inlineLabel(false)
->default(PropertyStatusEnum::ENABLE)
->useEnum(PropertyStatusEnum::class),

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'),
]);
}

Expand All @@ -93,14 +94,14 @@ public static function table(Table $table) : Table
->columns([
Tables\Columns\TextColumn::make('id')
->label('ID')
->label(__('red-jasmine-product::product-property-value.fields.id'))
->label(__('red-jasmine-product::product-property-value.fields.id'))
->copyable()
->sortable(),
Tables\Columns\TextColumn::make('property.name')
->label(__('red-jasmine-product::product-property-value.fields.property.name')),
->label(__('red-jasmine-product::product-property-value.fields.property.name')),

Tables\Columns\TextColumn::make('name')
->label(__('red-jasmine-product::product-property-value.fields.name'))
->label(__('red-jasmine-product::product-property-value.fields.name'))
->copyable(),
Tables\Columns\TextColumn::make('group.name')->label(__('red-jasmine-product::product-property-value.fields.group.name')),
Tables\Columns\TextColumn::make('sort')->label(__('red-jasmine-product::product-property-value.fields.sort'))->sortable(),
Expand Down
157 changes: 157 additions & 0 deletions src/Clusters/Product/Resources/ProductSeriesResource.php
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'),
];
}
}
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;
}
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(),
];
}
}
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(),
];
}
}
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(),
];
}
}

0 comments on commit 4896445

Please sign in to comment.