feat: implement CreateAssignmentAction and CreateMaterialAction for enhanced assignment and material management, updating relevant pages to utilize new actions
This commit is contained in:
parent
5f601d8cba
commit
c15f429032
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Learning\Assignments\Actions;
|
||||
|
||||
use App\Filament\Actions\Cheerful\CreateAction;
|
||||
|
||||
class CreateAssignmentAction extends CreateAction
|
||||
{
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return 'createAssignment';
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->label('Tambah');
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
namespace App\Filament\Resources\Learning\Assignments\Pages;
|
||||
|
||||
use App\Enums\AssignmentType;
|
||||
use App\Filament\Actions\Cheerful\CreateAction;
|
||||
use App\Filament\Resources\Learning\Assignments\Actions\CreateAssignmentAction;
|
||||
use App\Filament\Resources\Learning\Assignments\Actions\DeleteAssignmentAction;
|
||||
use App\Filament\Resources\Learning\Assignments\Actions\EditAssignmentAction;
|
||||
use App\Filament\Resources\Learning\Assignments\Actions\PinAction;
|
||||
@ -30,8 +30,7 @@ class ListAssignments extends Page
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()
|
||||
->label('Tambah'),
|
||||
CreateAssignmentAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Learning\ClassSessions\Actions;
|
||||
|
||||
use App\Filament\Actions\Cheerful\CreateAction;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
class CreateSessionAction extends CreateAction
|
||||
{
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return 'createSession';
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->label('Tambah')
|
||||
->modalHeading('Tambah Sesi')
|
||||
->modalSubmitActionLabel('Simpan')
|
||||
->modalCancelActionLabel('Batal')
|
||||
->schema(function ($schema, $livewire) {
|
||||
return $livewire->form($schema);
|
||||
})
|
||||
->mutateDataUsing(function (array $data, $livewire): array {
|
||||
$data['course_id'] = $livewire->courseId;
|
||||
|
||||
return $data;
|
||||
})
|
||||
->extraModalFooterActions(fn (CreateAction $action): array => [
|
||||
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
|
||||
->label('Simpan dan Tambah Lagi'),
|
||||
])
|
||||
->modalWidth(Width::TwoExtraLarge);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Learning\Materials\Actions;
|
||||
|
||||
use App\Filament\Actions\Cheerful\CreateAction;
|
||||
use App\Models\Material;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
class CreateMaterialAction extends CreateAction
|
||||
{
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return 'createMaterial';
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->label('Tambah')
|
||||
->modalHeading('Tambah Materi')
|
||||
->modalSubmitActionLabel('Simpan')
|
||||
->modalCancelActionLabel('Batal')
|
||||
->extraModalFooterActions(fn (CreateAction $action): array => [
|
||||
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
|
||||
->label('Simpan dan Tambah Lagi'),
|
||||
])
|
||||
->using(function (array $data): Material {
|
||||
$pdf = $data['pdf'] ?? [];
|
||||
unset($data['pdf']);
|
||||
|
||||
$record = Material::create($data);
|
||||
|
||||
if (! empty($pdf)) {
|
||||
foreach ($pdf as $filePath) {
|
||||
$record->addMediaFromDisk($filePath, config('filesystems.default'))
|
||||
->preservingOriginal()
|
||||
->withCustomProperties([
|
||||
'feature' => 'materials',
|
||||
'date' => now()->toDateString(),
|
||||
'doc_type' => 'pdf',
|
||||
])
|
||||
->toMediaCollection('materials');
|
||||
}
|
||||
}
|
||||
|
||||
return $record;
|
||||
})
|
||||
->modalWidth(Width::FourExtraLarge);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Learning\Materials\Actions;
|
||||
|
||||
use App\Filament\Actions\Cheerful\EditAction;
|
||||
use App\Models\Material;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
class EditMaterialAction extends EditAction
|
||||
{
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return 'editMaterial';
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->modalWidth(Width::FourExtraLarge)
|
||||
->fillForm(function (Material $record): array {
|
||||
$data = $record->toArray();
|
||||
|
||||
$data['pdf'] = $record->getMedia('materials')
|
||||
->map(fn ($media) => $media->getPathRelativeToRoot())
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
})
|
||||
->using(function (Material $record, array $data): Material {
|
||||
$pdf = $data['pdf'] ?? [];
|
||||
unset($data['pdf']);
|
||||
|
||||
$record->update($data);
|
||||
|
||||
$existingMedia = $record->getMedia('materials');
|
||||
$mediaMap = [];
|
||||
|
||||
foreach ($existingMedia as $media) {
|
||||
if (in_array($media->getPathRelativeToRoot(), $pdf)) {
|
||||
$mediaMap[$media->getPathRelativeToRoot()] = $media;
|
||||
} else {
|
||||
$media->delete();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($pdf as $path) {
|
||||
if (! isset($mediaMap[$path])) {
|
||||
$newMedia = $record->addMediaFromDisk($path, config('filesystems.default'))
|
||||
->preservingOriginal()
|
||||
->withCustomProperties([
|
||||
'feature' => 'materials',
|
||||
'date' => now()->toDateString(),
|
||||
'doc_type' => 'pdf',
|
||||
])
|
||||
->toMediaCollection('materials');
|
||||
$mediaMap[$path] = $newMedia;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($pdf as $index => $path) {
|
||||
if (isset($mediaMap[$path])) {
|
||||
$mediaMap[$path]->order_column = $index + 1;
|
||||
$mediaMap[$path]->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $record;
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Learning\Materials\Actions;
|
||||
|
||||
use App\Models\Material;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry;
|
||||
|
||||
class ViewMaterialAction extends ViewAction
|
||||
{
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return 'viewMaterial';
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->modalWidth(Width::FourExtraLarge)
|
||||
->schema(function (Material $record) {
|
||||
return $record->getMedia('materials')->map(function ($item, $index) {
|
||||
return PdfViewerEntry::make('pdf_'.$index)
|
||||
->hiddenLabel()
|
||||
->fileUrl($item->getUrl())
|
||||
->columnSpanFull();
|
||||
})->toArray();
|
||||
})
|
||||
->visible(fn (Material $record) => $record->hasMedia('materials'));
|
||||
}
|
||||
}
|
||||
@ -4,11 +4,12 @@
|
||||
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Actions\Cheerful\DeleteAction;
|
||||
use App\Filament\Actions\Cheerful\EditAction;
|
||||
use App\Filament\Actions\Cheerful\ForceDeleteAction;
|
||||
use App\Filament\Actions\Cheerful\RestoreAction;
|
||||
use App\Filament\Actions\DefaultBulkActions;
|
||||
use App\Filament\Columns\TimestampColumns;
|
||||
use App\Filament\Resources\Learning\Materials\Actions\EditMaterialAction;
|
||||
use App\Filament\Resources\Learning\Materials\Actions\ViewMaterialAction;
|
||||
use App\Filament\Resources\Learning\Materials\Pages\ManageMaterials;
|
||||
use App\Models\ClassSession;
|
||||
use App\Models\Course;
|
||||
@ -18,7 +19,6 @@
|
||||
use Asmit\FilamentUpload\Forms\Components\AdvancedFileUpload;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
@ -26,7 +26,6 @@
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
@ -35,7 +34,6 @@
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry;
|
||||
use UnitEnum;
|
||||
|
||||
class MaterialResource extends Resource
|
||||
@ -178,69 +176,9 @@ public static function table(Table $table): Table
|
||||
->visible(fn () => auth()->user()->hasRole(RoleEnum::Developer)),
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make()
|
||||
->modalWidth(Width::FourExtraLarge)
|
||||
->schema(function (Material $record) {
|
||||
return $record->getMedia('materials')->map(function ($item, $index) {
|
||||
return PdfViewerEntry::make('pdf_'.$index)
|
||||
->hiddenLabel()
|
||||
->fileUrl($item->getUrl())
|
||||
->columnSpanFull();
|
||||
})->toArray();
|
||||
})
|
||||
->visible(fn (Material $record) => $record->hasMedia('materials')),
|
||||
ViewMaterialAction::make(),
|
||||
|
||||
EditAction::make()
|
||||
->modalWidth(Width::FourExtraLarge)
|
||||
->fillForm(function (Material $record): array {
|
||||
$data = $record->toArray();
|
||||
|
||||
$data['pdf'] = $record->getMedia('materials')
|
||||
->map(fn ($media) => $media->getPathRelativeToRoot())
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
})
|
||||
->using(function (Material $record, array $data): Material {
|
||||
$pdf = $data['pdf'] ?? [];
|
||||
unset($data['pdf']);
|
||||
|
||||
$record->update($data);
|
||||
|
||||
$existingMedia = $record->getMedia('materials');
|
||||
$mediaMap = [];
|
||||
|
||||
foreach ($existingMedia as $media) {
|
||||
if (in_array($media->getPathRelativeToRoot(), $pdf)) {
|
||||
$mediaMap[$media->getPathRelativeToRoot()] = $media;
|
||||
} else {
|
||||
$media->delete();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($pdf as $path) {
|
||||
if (! isset($mediaMap[$path])) {
|
||||
$newMedia = $record->addMediaFromDisk($path, config('filesystems.default'))
|
||||
->preservingOriginal()
|
||||
->withCustomProperties([
|
||||
'feature' => 'materials',
|
||||
'date' => now()->toDateString(),
|
||||
'doc_type' => 'pdf',
|
||||
])
|
||||
->toMediaCollection('materials');
|
||||
$mediaMap[$path] = $newMedia;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($pdf as $index => $path) {
|
||||
if (isset($mediaMap[$path])) {
|
||||
$mediaMap[$path]->order_column = $index + 1;
|
||||
$mediaMap[$path]->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $record;
|
||||
}),
|
||||
EditMaterialAction::make(),
|
||||
|
||||
DeleteAction::make(),
|
||||
|
||||
|
||||
@ -2,11 +2,9 @@
|
||||
|
||||
namespace App\Filament\Resources\Learning\Materials\Pages;
|
||||
|
||||
use App\Filament\Actions\Cheerful\CreateAction;
|
||||
use App\Filament\Resources\Learning\Materials\Actions\CreateMaterialAction;
|
||||
use App\Filament\Resources\Learning\Materials\MaterialResource;
|
||||
use App\Models\Material;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
class ManageMaterials extends ManageRecords
|
||||
{
|
||||
@ -17,37 +15,7 @@ class ManageMaterials extends ManageRecords
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()
|
||||
->label('Tambah')
|
||||
->modalHeading('Tambah Materi')
|
||||
->modalSubmitActionLabel('Simpan')
|
||||
->modalCancelActionLabel('Batal')
|
||||
->extraModalFooterActions(fn (CreateAction $action): array => [
|
||||
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
|
||||
->label('Simpan dan Tambah Lagi'),
|
||||
])
|
||||
->using(function (array $data): Material {
|
||||
$pdf = $data['pdf'] ?? [];
|
||||
unset($data['pdf']);
|
||||
|
||||
$record = Material::create($data);
|
||||
|
||||
if (! empty($pdf)) {
|
||||
foreach ($pdf as $filePath) {
|
||||
$record->addMediaFromDisk($filePath, config('filesystems.default'))
|
||||
->preservingOriginal()
|
||||
->withCustomProperties([
|
||||
'feature' => 'materials',
|
||||
'date' => now()->toDateString(),
|
||||
'doc_type' => 'pdf',
|
||||
])
|
||||
->toMediaCollection('materials');
|
||||
}
|
||||
}
|
||||
|
||||
return $record;
|
||||
})
|
||||
->modalWidth(Width::FourExtraLarge),
|
||||
CreateMaterialAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Master\Courses\Actions;
|
||||
|
||||
use App\Filament\Actions\Cheerful\CreateAction;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
class CreateCourseAction extends CreateAction
|
||||
{
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return 'createCourse';
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->label('Tambah')
|
||||
->modalHeading('Tambah Mata Kuliah')
|
||||
->modalSubmitActionLabel('Simpan')
|
||||
->modalCancelActionLabel('Batal')
|
||||
->extraModalFooterActions(fn (CreateAction $action): array => [
|
||||
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
|
||||
->label('Simpan dan Tambah Lagi'),
|
||||
])
|
||||
->modalWidth(Width::Large);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Master\Courses\Actions;
|
||||
|
||||
use App\Filament\Actions\Cheerful\EditAction;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
class EditCourseAction extends EditAction
|
||||
{
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return 'editCourse';
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->modalWidth(Width::Large);
|
||||
}
|
||||
}
|
||||
@ -4,11 +4,11 @@
|
||||
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Actions\Cheerful\DeleteAction;
|
||||
use App\Filament\Actions\Cheerful\EditAction;
|
||||
use App\Filament\Actions\Cheerful\ForceDeleteAction;
|
||||
use App\Filament\Actions\Cheerful\RestoreAction;
|
||||
use App\Filament\Actions\DefaultBulkActions;
|
||||
use App\Filament\Columns\TimestampColumns;
|
||||
use App\Filament\Resources\Master\Courses\Actions\EditCourseAction;
|
||||
use App\Filament\Resources\Master\Courses\Pages\ManageCourses;
|
||||
use App\Models\Course;
|
||||
use BackedEnum;
|
||||
@ -16,7 +16,6 @@
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
@ -122,8 +121,7 @@ public static function table(Table $table): Table
|
||||
->visible(fn () => auth()->user()->hasRole(RoleEnum::Developer)),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make()
|
||||
->modalWidth(Width::Large),
|
||||
EditCourseAction::make(),
|
||||
|
||||
DeleteAction::make(),
|
||||
|
||||
|
||||
@ -2,10 +2,9 @@
|
||||
|
||||
namespace App\Filament\Resources\Master\Courses\Pages;
|
||||
|
||||
use App\Filament\Actions\Cheerful\CreateAction;
|
||||
use App\Filament\Resources\Master\Courses\Actions\CreateCourseAction;
|
||||
use App\Filament\Resources\Master\Courses\CourseResource;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
class ManageCourses extends ManageRecords
|
||||
{
|
||||
@ -16,16 +15,7 @@ class ManageCourses extends ManageRecords
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()
|
||||
->label('Tambah')
|
||||
->modalHeading('Tambah Mata Kuliah')
|
||||
->modalSubmitActionLabel('Simpan')
|
||||
->modalCancelActionLabel('Batal')
|
||||
->extraModalFooterActions(fn (CreateAction $action): array => [
|
||||
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
|
||||
->label('Simpan dan Tambah Lagi'),
|
||||
])
|
||||
->modalWidth(Width::Large),
|
||||
CreateCourseAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Master\Students\Actions;
|
||||
|
||||
use App\Filament\Actions\Cheerful\CreateAction;
|
||||
|
||||
class CreateStudentAction extends CreateAction
|
||||
{
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return 'createStudent';
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->label('Tambah');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Master\Students\Actions;
|
||||
|
||||
use App\Filament\Actions\Cheerful\EditAction;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
class EditStudentAction extends EditAction
|
||||
{
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return 'editStudent';
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->modalWidth(Width::Large);
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\Master\Students\Pages;
|
||||
|
||||
use App\Filament\Actions\Cheerful\CreateAction;
|
||||
use App\Filament\Resources\Master\Students\Actions\CreateStudentAction;
|
||||
use App\Filament\Resources\Master\Students\StudentResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
@ -15,8 +15,7 @@ class ListStudents extends ListRecords
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()
|
||||
->label('Tambah'),
|
||||
CreateStudentAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,16 +6,15 @@
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Enums\Sex;
|
||||
use App\Filament\Actions\Cheerful\DeleteAction;
|
||||
use App\Filament\Actions\Cheerful\EditAction;
|
||||
use App\Filament\Actions\Cheerful\ForceDeleteAction;
|
||||
use App\Filament\Actions\Cheerful\RestoreAction;
|
||||
use App\Filament\Actions\DefaultBulkActions;
|
||||
use App\Filament\Columns\TimestampColumns;
|
||||
use App\Filament\Resources\Master\Students\Actions\ChangePasswordAction;
|
||||
use App\Filament\Resources\Master\Students\Actions\EditStudentAction;
|
||||
use App\Filament\Support\SystemNotification;
|
||||
use App\Models\Student;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
@ -131,8 +130,7 @@ public static function configure(Table $table): Table
|
||||
->recordActions([
|
||||
ChangePasswordAction::make('changePassword'),
|
||||
|
||||
EditAction::make()
|
||||
->modalWidth(Width::Large),
|
||||
EditStudentAction::make(),
|
||||
|
||||
DeleteAction::make(),
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user