From 9a7e6fa24898b0ab5ba1ff37df1e33266c9dda7b Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 6 Oct 2025 08:57:21 +0200 Subject: [PATCH] ProjektMethodesRelationManager --- ARTISAN.md | 4 +- app/Actions/CreateProjektMethoden.php | 21 ++++ .../Resources/Methodes/MethodeResource.php | 2 +- .../Resources/Projektes/ProjekteResource.php | 6 +- .../ProjektMethodesRelationManager.php | 102 ++++++++++++++++++ .../RaeumeallesRelationManager.php | 2 +- app/Models/ProjektMethode.php | 21 ++++ app/Models/Projekte.php | 5 + bootstrap/cache/filament/panels/admin.php | 1 + bootstrap/cache/routes-v7.php | 42 ++++---- ...6_054823_create_projekt_methodes_table.php | 32 ++++++ 11 files changed, 209 insertions(+), 29 deletions(-) create mode 100644 app/Actions/CreateProjektMethoden.php create mode 100644 app/Filament/Resources/Projektes/RelationManagers/ProjektMethodesRelationManager.php create mode 100644 app/Models/ProjektMethode.php create mode 100644 database/migrations/2025_10_06_054823_create_projekt_methodes_table.php diff --git a/ARTISAN.md b/ARTISAN.md index 08b3664..b219567 100644 --- a/ARTISAN.md +++ b/ARTISAN.md @@ -1,4 +1,4 @@ -a make:model Customer -ms +a make:model ProjektMethode -ms a make:filament-resource Customer @@ -29,7 +29,7 @@ php artisan make:filament-importer Raeumealle A make:filament-resource Allgemeinflaechen --nested -php artisan make:filament-relation-manager Raeumealle lessons title +a make:filament-relation-manager Projekte;ethodeResource projekt_methodes raumart for import in prod run diff --git a/app/Actions/CreateProjektMethoden.php b/app/Actions/CreateProjektMethoden.php new file mode 100644 index 0000000..a502ba9 --- /dev/null +++ b/app/Actions/CreateProjektMethoden.php @@ -0,0 +1,21 @@ +id)->delete(); + $raeumealles = Raeumealle::where('projekte_id', $record->id)->get(); + foreach ($raeumealles as $raeumealle) { + ProjektMethode::firstOrCreate([ + 'projekte_id' => $record->id, + 'raumart' => $raeumealle->raumart, + ]); + } + } +} diff --git a/app/Filament/Resources/Methodes/MethodeResource.php b/app/Filament/Resources/Methodes/MethodeResource.php index 53f60e1..074c973 100644 --- a/app/Filament/Resources/Methodes/MethodeResource.php +++ b/app/Filament/Resources/Methodes/MethodeResource.php @@ -21,7 +21,7 @@ class MethodeResource extends Resource protected static string|UnitEnum|null $navigationGroup = 'Vorlagen'; - protected static string|BackedEnum|null $navigationIcon = 'lucide-calculator'; + protected static string|BackedEnum|null $navigationIcon = 'phosphor-calculator'; protected static ?string $navigationLabel = 'Methode'; diff --git a/app/Filament/Resources/Projektes/ProjekteResource.php b/app/Filament/Resources/Projektes/ProjekteResource.php index 82d6f55..a7a0194 100644 --- a/app/Filament/Resources/Projektes/ProjekteResource.php +++ b/app/Filament/Resources/Projektes/ProjekteResource.php @@ -2,11 +2,10 @@ namespace App\Filament\Resources\Projektes; -use App\Filament\Clusters\Projekte\ProjekteCluster; -use App\Filament\Resources\Projektes\Pages\CreateProjekte; use App\Filament\Resources\Projektes\Pages\EditProjekte; use App\Filament\Resources\Projektes\Pages\ListProjektes; use App\Filament\Resources\Projektes\RelationManagers\AllgemeinflaechensRelationManager; +use App\Filament\Resources\Projektes\RelationManagers\ProjektMethodesRelationManager; use App\Filament\Resources\Projektes\RelationManagers\RaeumeallesRelationManager; use App\Filament\Resources\Projektes\Schemas\ProjekteForm; use App\Filament\Resources\Projektes\Tables\ProjektesTable; @@ -24,8 +23,6 @@ class ProjekteResource extends Resource protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack; - // protected static ?string $cluster = ProjekteCluster::class; - protected static ?string $recordTitleAttribute = 'interner_name'; protected static ?string $navigationLabel = 'Projekte'; @@ -49,6 +46,7 @@ class ProjekteResource extends Resource return [ AllgemeinflaechensRelationManager::class, RaeumeallesRelationManager::class, + ProjektMethodesRelationManager::class, ]; } diff --git a/app/Filament/Resources/Projektes/RelationManagers/ProjektMethodesRelationManager.php b/app/Filament/Resources/Projektes/RelationManagers/ProjektMethodesRelationManager.php new file mode 100644 index 0000000..930b210 --- /dev/null +++ b/app/Filament/Resources/Projektes/RelationManagers/ProjektMethodesRelationManager.php @@ -0,0 +1,102 @@ +recordTitleAttribute('raumart') + ->columns([ + SelectColumn::make('methode_id') + ->options(Methode::query()->pluck('name', 'id')), + TextColumn::make('raumart') + ->searchable(), + TextInputColumn::make('faktor') + ->suffixIcon('phosphor-function') + ->width('1rem') + ->rules(['required', 'faktor' => 'decimal:0,2']) + ->searchable(), + ]) + ->filters([ + TernaryFilter::make('methode_id') + ->label('Methode zugeordnet'), + ]) + ->headerActions([ + Action::make('erstellen') + ->action(fn (CreateProjektMethoden $createProjektMethoden) => $createProjektMethoden->create($this->ownerRecord)) + ->requiresConfirmation() + ->modalHeading('Raum Methoden erstellen') + ->modalDescription('Alle bestehenden Daten in dieser Tabelle werden vorher gelöscht.') + ->modalSubmitActionLabel('Erstellen') + ->label('Erstellen') + ->tooltip('Daten werden aus "Räume Alle" Tabelle gefiltert.') + ->icon('heroicon-o-cog-8-tooth'), + ]) + ->toolbarActions([ + BulkActionGroup::make([ + BulkAction::make('faktor') + ->color('primary') + ->label('Faktor zuweisen') + ->schema([ + TextInput::make('faktor') + ->prefixIcon('phosphor-function') + ->numeric() + ->required(), + ]) + ->icon('phosphor-function') + ->action(function (Collection $records, array $data): void { + foreach ($records as $record) { + ProjektMethode::where('id', '=', $record->id) + ->update( + ['faktor' => $data['faktor']] + ); + } + }), + BulkAction::make('methode') + ->color('primary') + ->label('Methode zuweisen') + ->schema([ + TextInput::make('faktor') + ->prefixIcon('phosphor-calculator') + ->numeric() + ->required(), + ]) + ->icon('phosphor-calculator') + ->action(function (Collection $records, array $data): void { + foreach ($records as $record) { + ProjektMethode::where('id', '=', $record->id) + ->update( + ['faktor' => $data['faktor']] + ); + } + }), + ]), + ]); + } +} diff --git a/app/Filament/Resources/Projektes/RelationManagers/RaeumeallesRelationManager.php b/app/Filament/Resources/Projektes/RelationManagers/RaeumeallesRelationManager.php index 440cfbe..0bd4265 100644 --- a/app/Filament/Resources/Projektes/RelationManagers/RaeumeallesRelationManager.php +++ b/app/Filament/Resources/Projektes/RelationManagers/RaeumeallesRelationManager.php @@ -55,7 +55,7 @@ class RaeumeallesRelationManager extends RelationManager TextColumn::make('geschoss')->searchable(), TextColumn::make('raumart')->searchable(), TextInputColumn::make('faktor') - ->suffixIcon('phosphor-calculator') + ->suffixIcon('phosphor-function') ->width('1rem') ->rules(['required', 'faktor' => 'decimal:0,2']) ->searchable(), diff --git a/app/Models/ProjektMethode.php b/app/Models/ProjektMethode.php new file mode 100644 index 0000000..7faed4a --- /dev/null +++ b/app/Models/ProjektMethode.php @@ -0,0 +1,21 @@ +hasMany(Methode::class); + } +} diff --git a/app/Models/Projekte.php b/app/Models/Projekte.php index 6e9183b..0dbe9f9 100644 --- a/app/Models/Projekte.php +++ b/app/Models/Projekte.php @@ -36,4 +36,9 @@ class Projekte extends Model { return $this->hasMany(Raeumealle::class); } + + public function projekt_methodes() + { + return $this->hasMany(ProjektMethode::class); + } } diff --git a/bootstrap/cache/filament/panels/admin.php b/bootstrap/cache/filament/panels/admin.php index 0664ac7..bf3a7d2 100644 --- a/bootstrap/cache/filament/panels/admin.php +++ b/bootstrap/cache/filament/panels/admin.php @@ -29,6 +29,7 @@ 'app.filament.resources.projektes.pages.edit-projekte' => 'App\\Filament\\Resources\\Projektes\\Pages\\EditProjekte', 'app.filament.resources.projektes.pages.list-projektes' => 'App\\Filament\\Resources\\Projektes\\Pages\\ListProjektes', 'app.filament.resources.projektes.relation-managers.allgemeinflaechens-relation-manager' => 'App\\Filament\\Resources\\Projektes\\RelationManagers\\AllgemeinflaechensRelationManager', + 'app.filament.resources.projektes.relation-managers.projekt-methodes-relation-manager' => 'App\\Filament\\Resources\\Projektes\\RelationManagers\\ProjektMethodesRelationManager', 'app.filament.resources.projektes.relation-managers.raeumealles-relation-manager' => 'App\\Filament\\Resources\\Projektes\\RelationManagers\\RaeumeallesRelationManager', 'app.filament.resources.textblocks.pages.create-textblock' => 'App\\Filament\\Resources\\Textblocks\\Pages\\CreateTextblock', 'app.filament.resources.textblocks.pages.edit-textblock' => 'App\\Filament\\Resources\\Textblocks\\Pages\\EditTextblock', diff --git a/bootstrap/cache/routes-v7.php b/bootstrap/cache/routes-v7.php index 94b4b32..af103c0 100644 --- a/bootstrap/cache/routes-v7.php +++ b/bootstrap/cache/routes-v7.php @@ -511,7 +511,7 @@ app('router')->setCompiledRoutes( array ( 0 => array ( - '_route' => 'generated::ZKAnD1JupDI6nRdd', + '_route' => 'generated::NzP4VI5PeVTSNa8b', ), 1 => NULL, 2 => @@ -531,7 +531,7 @@ app('router')->setCompiledRoutes( array ( 0 => array ( - '_route' => 'generated::s39ttVgluaaTSPQs', + '_route' => 'generated::pt0LAwcB1sGBW4Oo', ), 1 => NULL, 2 => @@ -589,7 +589,7 @@ app('router')->setCompiledRoutes( array ( 0 => array ( - '_route' => 'generated::GTqxIeXqrS3yeXC2', + '_route' => 'generated::AOiPiqGBrqXDsS0D', ), 1 => NULL, 2 => @@ -609,7 +609,7 @@ app('router')->setCompiledRoutes( array ( 0 => array ( - '_route' => 'generated::CqHTEVGG8Ecd113F', + '_route' => 'generated::P6HogTayo2iWezmY', ), 1 => NULL, 2 => @@ -629,7 +629,7 @@ app('router')->setCompiledRoutes( array ( 0 => array ( - '_route' => 'generated::cIETyLf8UfA6kLWN', + '_route' => 'generated::MTlI6TBwxyNMQmB6', ), 1 => NULL, 2 => @@ -649,7 +649,7 @@ app('router')->setCompiledRoutes( array ( 0 => array ( - '_route' => 'generated::vAq2m1K8fDxzN7CD', + '_route' => 'generated::hTSXazyycB1PbjMf', ), 1 => NULL, 2 => @@ -669,7 +669,7 @@ app('router')->setCompiledRoutes( array ( 0 => array ( - '_route' => 'generated::PslwnVFq3OKf1wWj', + '_route' => 'generated::72CUCq6E4ZsFkqBN', ), 1 => NULL, 2 => @@ -2595,7 +2595,7 @@ app('router')->setCompiledRoutes( 'waitSeconds' => NULL, 'withTrashed' => false, ), - 'generated::ZKAnD1JupDI6nRdd' => + 'generated::NzP4VI5PeVTSNa8b' => array ( 'methods' => array ( @@ -2607,7 +2607,7 @@ app('router')->setCompiledRoutes( array ( 'uses' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@returnJavaScriptAsFile', 'controller' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@returnJavaScriptAsFile', - 'as' => 'generated::ZKAnD1JupDI6nRdd', + 'as' => 'generated::NzP4VI5PeVTSNa8b', ), 'fallback' => false, 'defaults' => @@ -2623,7 +2623,7 @@ app('router')->setCompiledRoutes( 'waitSeconds' => NULL, 'withTrashed' => false, ), - 'generated::s39ttVgluaaTSPQs' => + 'generated::pt0LAwcB1sGBW4Oo' => array ( 'methods' => array ( @@ -2635,7 +2635,7 @@ app('router')->setCompiledRoutes( array ( 'uses' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@maps', 'controller' => 'Livewire\\Mechanisms\\FrontendAssets\\FrontendAssets@maps', - 'as' => 'generated::s39ttVgluaaTSPQs', + 'as' => 'generated::pt0LAwcB1sGBW4Oo', ), 'fallback' => false, 'defaults' => @@ -2737,7 +2737,7 @@ app('router')->setCompiledRoutes( 'waitSeconds' => NULL, 'withTrashed' => false, ), - 'generated::GTqxIeXqrS3yeXC2' => + 'generated::AOiPiqGBrqXDsS0D' => array ( 'methods' => array ( @@ -2766,7 +2766,7 @@ app('router')->setCompiledRoutes( \'exception\' => $exception, ]), status: $exception ? 500 : 200); }";s:5:"scope";s:54:"Illuminate\\Foundation\\Configuration\\ApplicationBuilder";s:4:"this";N;s:4:"self";s:32:"0000000000000f2c0000000000000000";}}', - 'as' => 'generated::GTqxIeXqrS3yeXC2', + 'as' => 'generated::AOiPiqGBrqXDsS0D', ), 'fallback' => false, 'defaults' => @@ -2782,7 +2782,7 @@ app('router')->setCompiledRoutes( 'waitSeconds' => NULL, 'withTrashed' => false, ), - 'generated::CqHTEVGG8Ecd113F' => + 'generated::P6HogTayo2iWezmY' => array ( 'methods' => array ( @@ -2804,7 +2804,7 @@ app('router')->setCompiledRoutes( 'where' => array ( ), - 'as' => 'generated::CqHTEVGG8Ecd113F', + 'as' => 'generated::P6HogTayo2iWezmY', ), 'fallback' => false, 'defaults' => @@ -2820,7 +2820,7 @@ app('router')->setCompiledRoutes( 'waitSeconds' => NULL, 'withTrashed' => false, ), - 'generated::cIETyLf8UfA6kLWN' => + 'generated::MTlI6TBwxyNMQmB6' => array ( 'methods' => array ( @@ -2842,7 +2842,7 @@ app('router')->setCompiledRoutes( 'where' => array ( ), - 'as' => 'generated::cIETyLf8UfA6kLWN', + 'as' => 'generated::MTlI6TBwxyNMQmB6', ), 'fallback' => false, 'defaults' => @@ -2858,7 +2858,7 @@ app('router')->setCompiledRoutes( 'waitSeconds' => NULL, 'withTrashed' => false, ), - 'generated::vAq2m1K8fDxzN7CD' => + 'generated::hTSXazyycB1PbjMf' => array ( 'methods' => array ( @@ -2880,7 +2880,7 @@ app('router')->setCompiledRoutes( 'where' => array ( ), - 'as' => 'generated::vAq2m1K8fDxzN7CD', + 'as' => 'generated::hTSXazyycB1PbjMf', ), 'fallback' => false, 'defaults' => @@ -2896,7 +2896,7 @@ app('router')->setCompiledRoutes( 'waitSeconds' => NULL, 'withTrashed' => false, ), - 'generated::PslwnVFq3OKf1wWj' => + 'generated::72CUCq6E4ZsFkqBN' => array ( 'methods' => array ( @@ -2918,7 +2918,7 @@ app('router')->setCompiledRoutes( 'where' => array ( ), - 'as' => 'generated::PslwnVFq3OKf1wWj', + 'as' => 'generated::72CUCq6E4ZsFkqBN', ), 'fallback' => false, 'defaults' => diff --git a/database/migrations/2025_10_06_054823_create_projekt_methodes_table.php b/database/migrations/2025_10_06_054823_create_projekt_methodes_table.php new file mode 100644 index 0000000..2ed3cc6 --- /dev/null +++ b/database/migrations/2025_10_06_054823_create_projekt_methodes_table.php @@ -0,0 +1,32 @@ +id(); + $table->foreignId('projekte_id')->constrained()->cascadeOnDelete(); + $table->integer('methode_id')->default(0); + $table->string('geschoss')->nullable(); + $table->string('raumart')->nullable(); + $table->decimal('faktor', 5, 2)->default(0); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('projekt_methodes'); + } +};