SourcePaperResource.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Filament\Resources;
  3. use App\Filament\Resources\SourcePaperResource\Pages;
  4. use App\Filament\Resources\SourcePaperResource\RelationManagers\PaperPartsRelationManager;
  5. use App\Models\SourcePaper;
  6. use Filament\Forms;
  7. use Filament\Resources\Resource;
  8. use Filament\Schemas\Schema;
  9. use Filament\Tables;
  10. use Filament\Tables\Table;
  11. use Filament\Actions\ViewAction;
  12. use Illuminate\Database\Eloquent\Model;
  13. use BackedEnum;
  14. use UnitEnum;
  15. class SourcePaperResource extends Resource
  16. {
  17. protected static ?string $model = SourcePaper::class;
  18. protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-document-text';
  19. protected static UnitEnum|string|null $navigationGroup = 'Markdown 解析';
  20. protected static ?string $navigationLabel = '源卷子';
  21. protected static ?int $navigationSort = 2;
  22. public static function canCreate(): bool
  23. {
  24. return false;
  25. }
  26. public static function canEdit(Model $record): bool
  27. {
  28. return false;
  29. }
  30. public static function form(Schema $schema): Schema
  31. {
  32. return $schema->schema([
  33. Forms\Components\TextInput::make('title')->label('标题')->disabled(),
  34. Forms\Components\TextInput::make('full_title')->label('完整标题')->disabled(),
  35. Forms\Components\TextInput::make('chapter')->label('章节')->disabled(),
  36. Forms\Components\TextInput::make('grade')->label('年级')->disabled(),
  37. Forms\Components\TextInput::make('term')->label('学期')->disabled(),
  38. Forms\Components\Textarea::make('raw_markdown')
  39. ->label('卷子原始 Markdown')
  40. ->rows(12)
  41. ->disabled(),
  42. ]);
  43. }
  44. public static function table(Table $table): Table
  45. {
  46. return $table
  47. ->columns([
  48. Tables\Columns\TextColumn::make('order')->label('顺序')->sortable(),
  49. Tables\Columns\TextColumn::make('title')->label('卷标题')->searchable(),
  50. Tables\Columns\TextColumn::make('grade')->label('年级'),
  51. Tables\Columns\TextColumn::make('term')->label('学期'),
  52. Tables\Columns\TextColumn::make('source_type')->label('类型'),
  53. ])
  54. ->actions([
  55. ViewAction::make(),
  56. ]);
  57. }
  58. public static function getRelations(): array
  59. {
  60. return [
  61. PaperPartsRelationManager::class,
  62. ];
  63. }
  64. public static function getPages(): array
  65. {
  66. return [
  67. 'index' => Pages\ListSourcePapers::route('/'),
  68. 'view' => Pages\ViewSourcePaper::route('/{record}'),
  69. ];
  70. }
  71. }