components([ TextInput::make('top_nummer') ->label('Top Nummer') ->required() ->maxLength(255), ])->columns(1); } public function table(Table $table): Table { $spalten = ProjektMerkmale::where('projekte_id', $this->ownerRecord->id)->pluck('name', 'code'); return $table // ->striped() ->emptyStateDescription('Schalten Sie das Projekt frei und importieren Sie die Daten der Objekte.') ->recordTitleAttribute('top_nummer') ->description(new HtmlString('Orientierungen, Zu- und Abschläge, '.Blade::render('').' Nicht in Orientierung')) ->columns([ TextColumn::make('top_nummer') ->alignCenter() ->label('Top Nummer') ->searchable() ->extraHeaderAttributes([ 'style' => 'position: sticky; left: 0; z-index: 1;', 'class' => 'bg-gray-50 dark:bg-gray-800 border-x border-gray-200 dark:border-gray-800', ]) ->extraCellAttributes([ 'style' => 'position: sticky; left: 0; z-index: 1;', 'class' => 'bg-gray-50 dark:bg-gray-900 border-x border-gray-200 dark:border-gray-800', ]), CheckboxColumn::make('nicht_in_orientierung') ->tooltip('Nicht in Orientierung') ->label(new HtmlString(Blade::render(''))) ->toggleable() ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextInputColumn::make('type') ->extraInputAttributes(['onClick' => 'this.select()']) ->toggleable() ->disabled(fn ($record): bool => $record->nicht_in_orientierung) ->width('2rem') ->searchable(), SelectColumn::make('orientierung_id') ->toggleable() ->width('2rem') ->label('Orientierung') ->selectablePlaceholder(true) ->options(Orientierung::pluck('name', 'id')) ->selectablePlaceholder(false) ->disableOptionWhen(fn (string $value): bool => in_array($value, [2, 11, 24, 33, 36])) ->preloadOptions()->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextInputColumn::make('a')->label($spalten['a'] ?? '') ->extraInputAttributes(['onClick' => 'this.select()']) ->hidden(isset($spalten['a']) ? false : true) ->toggleable() ->rules(['numeric']) ->alignCenter() ->beforeStateUpdated(function ($record, $state) { $record['nutzwert'] = $this->sum_nutzwerte('a', $state, $record); }) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextInputColumn::make('b')->label($spalten['b'] ?? '') ->extraInputAttributes(['onClick' => 'this.select()']) ->hidden(isset($spalten['b']) ? false : true) ->toggleable() ->rules(['numeric']) ->alignCenter() ->beforeStateUpdated(function ($record, $state) { $record['nutzwert'] = $this->sum_nutzwerte('b', $state, $record); })->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextInputColumn::make('c')->label($spalten['c'] ?? '') ->extraInputAttributes(['onClick' => 'this.select()']) ->hidden(isset($spalten['c']) ? false : true) ->toggleable() ->rules(['numeric']) ->alignCenter() ->beforeStateUpdated(function ($record, $state) { $record['nutzwert'] = $this->sum_nutzwerte('c', $state, $record); }) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextInputColumn::make('d')->label($spalten['d'] ?? '') ->extraInputAttributes(['onClick' => 'this.select()']) ->hidden(isset($spalten['d']) ? false : true) ->toggleable() ->rules(['numeric']) ->alignCenter() ->beforeStateUpdated(function ($record, $state) { $record['nutzwert'] = $this->sum_nutzwerte('d', $state, $record); }) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextInputColumn::make('e')->label($spalten['e'] ?? '') ->extraInputAttributes(['onClick' => 'this.select()']) ->hidden(isset($spalten['e']) ? false : true) ->toggleable() ->rules(['numeric']) ->alignCenter() ->beforeStateUpdated(function ($record, $state) { $record['nutzwert'] = $this->sum_nutzwerte('e', $state, $record); }) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextInputColumn::make('f')->label($spalten['f'] ?? '') ->extraInputAttributes(['onClick' => 'this.select()']) ->hidden(isset($spalten['f']) ? false : true) ->toggleable() ->rules(['numeric']) ->alignCenter() ->beforeStateUpdated(function ($record, $state) { $record['nutzwert'] = $this->sum_nutzwerte('f', $state, $record); }) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextInputColumn::make('g')->label($spalten['g'] ?? '') ->extraInputAttributes(['onClick' => 'this.select()']) ->hidden(isset($spalten['g']) ? false : true) ->toggleable() ->rules(['numeric']) ->alignCenter() ->beforeStateUpdated(function ($record, $state) { $record['nutzwert'] = $this->sum_nutzwerte('g', $state, $record); }) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextInputColumn::make('h')->label($spalten['h'] ?? '') ->extraInputAttributes(['onClick' => 'this.select()']) ->hidden(isset($spalten['h']) ? false : true) ->toggleable()->rules(['numeric']) ->alignCenter() ->beforeStateUpdated(function ($record, $state) { $record['nutzwert'] = $this->sum_nutzwerte('h', $state, $record); }) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextInputColumn::make('i')->label($spalten['i'] ?? '') ->extraInputAttributes(['onClick' => 'this.select()']) ->hidden(isset($spalten['i']) ? false : true) ->toggleable()->rules(['numeric']) ->alignCenter() ->beforeStateUpdated(function ($record, $state) { $record['nutzwert'] = $this->sum_nutzwerte('i', $state, $record); }) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextInputColumn::make('j')->label($spalten['j'] ?? '') ->extraInputAttributes(['onClick' => 'this.select()']) ->hidden(isset($spalten['j']) ? false : true) ->toggleable()->rules(['numeric']) ->alignCenter() ->beforeStateUpdated(function ($record, $state) { $record['nutzwert'] = $this->sum_nutzwerte('j', $state, $record); }) ->afterStateUpdated(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), TextColumn::make('nutzwert') ->extraHeaderAttributes([ 'style' => 'position: sticky; right: 0; z-index: 1;', 'class' => 'bg-gray-50 dark:bg-gray-900 border-x border-gray-200 dark:border-gray-800', ]) ->extraCellAttributes([ 'style' => 'position: sticky; right: 0; z-index: 1;', 'class' => 'bg-gray-50 dark:bg-gray-900 border-x border-gray-200 dark:border-gray-800', ]) ->summarize(Sum::make()->label('Gesammt')) ->alignCenter(), ]) ->filters([ TernaryFilter::make('nicht_in_orientierung') ->default(0) ->label('Objekte "Nicht in Orientierung" anzeigen'), ]) ->recordActions([ EditAction::make()->iconButton() ->mutateDataUsing(function (array $data): array { $data['projekte_id'] = $this->ownerRecord->id; return $data; })->after(function (Component $livewire) { $livewire->dispatch('refreshProjektObjekteImDetail'); }), DeleteAction::make()->iconButton()->after(function (Component $livewire) { $livewire->dispatch('refreshProjektObjekteImDetail'); }), ]) ->headerActions([ CreateAction::make() ->modalHeading('Objekt erstellen') ->modalDescription('Die dazugehörigen Räume werde in "Objekte im Detail" erstellt.') ->icon('phosphor-file-plus') ->createAnother(false), Action::make('projekt_merkmale') ->icon('phosphor-pen') ->modalCancelAction(fn (Action $action) => $action->label('Schließen')) ->modalSubmitAction(false) ->modalHeading('ProjektMerkmale') ->slideOver() // ->modalWidth(Width::Medium) ->modalContent(view('filament.pages.actions.projekt_merkmale')) ->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), ]) ->toolbarActions([ BulkActionGroup::make([ BulkAction::make('type') ->color('primary') ->schema([ TextInput::make('type') ->label('Name eingeben') ->prefixIcon('phosphor-align-center-horizontal-simple'), ]) ->icon('phosphor-align-center-horizontal-simple') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { ProjektObjekte::where('id', '=', $record->id) ->where('nicht_in_orientierung', '=', false) ->update( ['type' => $data['type']] ); } }) ->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('methode') ->color('primary') ->label('Orientierung') ->schema([ Select::make('methode_id') ->label('Orientierung wählen') ->prefixIcon('phosphor-compass') ->options(Orientierung::pluck('name', 'id')) ->disableOptionWhen(fn (string $value): bool => in_array($value, [2, 11, 24, 33, 36])) ->required(), ]) ->icon('phosphor-compass') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { ProjektObjekte::where('id', '=', $record->id) ->update( ['orientierung_id' => $data['methode_id']] ); } }) ->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('nicht_in_orientierung') ->color('primary') ->label('Nicht In Orientierung') ->schema([ Radio::make('nicht_in_orientierung') ->hiddenLabel() ->default(1) ->options([ '1' => 'Ja', '0' => 'Nein', ]), ]) ->icon('phosphor-check-square') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { ProjektObjekte::where('id', '=', $record->id) ->update( ['nicht_in_orientierung' => 1] ); } }) ->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('a') ->label($spalten['a'] ?? '') ->color('info') ->hidden(isset($spalten['a']) ? false : true) ->schema([ TextInput::make('a') ->prefixIcon('phosphor-math-operations'), ]) ->icon('phosphor-math-operations') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $nutzwert = $this->sum_nutzwerte('a', $data['a'], $record); ProjektObjekte::where('id', '=', $record->id) ->update( [ 'a' => $data['a'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('b') ->label($spalten['b'] ?? '') ->color('info') ->hidden(isset($spalten['b']) ? false : true) ->schema([ TextInput::make('b') ->prefixIcon('phosphor-math-operations'), ]) ->icon('phosphor-math-operations') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $nutzwert = $this->sum_nutzwerte('b', $data['b'], $record); ProjektObjekte::where('id', '=', $record->id) ->update( [ 'b' => $data['b'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('c') ->label($spalten['c'] ?? '') ->color('info') ->hidden(isset($spalten['c']) ? false : true) ->schema([ TextInput::make('c') ->prefixIcon('phosphor-math-operations'), ]) ->icon('phosphor-math-operations') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $nutzwert = $this->sum_nutzwerte('c', $data['c'], $record); ProjektObjekte::where('id', '=', $record->id) ->update( [ 'c' => $data['c'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('d') ->label($spalten['d'] ?? '') ->color('info') ->hidden(isset($spalten['d']) ? false : true) ->schema([ TextInput::make('d') ->prefixIcon('phosphor-math-operations'), ]) ->icon('phosphor-math-operations') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $nutzwert = $this->sum_nutzwerte('d', $data['d'], $record); ProjektObjekte::where('id', '=', $record->id) ->update( [ 'd' => $data['d'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('e') ->label($spalten['e'] ?? '') ->color('info') ->hidden(isset($spalten['e']) ? false : true) ->schema([ TextInput::make('e') ->prefixIcon('phosphor-math-operations'), ]) ->icon('phosphor-math-operations') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $nutzwert = $this->sum_nutzwerte('e', $data['e'], $record); ProjektObjekte::where('id', '=', $record->id) ->update( [ 'e' => $data['e'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('f') ->label($spalten['f'] ?? '') ->color('info') ->hidden(isset($spalten['f']) ? false : true) ->schema([ TextInput::make('f') ->prefixIcon('phosphor-math-operations'), ]) ->icon('phosphor-math-operations') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $nutzwert = $this->sum_nutzwerte('f', $data['f'], $record); ProjektObjekte::where('id', '=', $record->id) ->update( [ 'f' => $data['f'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('g') ->label($spalten['g'] ?? '') ->color('info') ->hidden(isset($spalten['g']) ? false : true) ->schema([ TextInput::make('g') ->prefixIcon('phosphor-math-operations'), ]) ->icon('phosphor-math-operations') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $nutzwert = $this->sum_nutzwerte('g', $data['g'], $record); ProjektObjekte::where('id', '=', $record->id) ->update( [ 'g' => $data['g'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('h') ->label($spalten['h'] ?? '') ->color('info') ->hidden(isset($spalten['h']) ? false : true) ->schema([ TextInput::make('h') ->prefixIcon('phosphor-math-operations'), ]) ->icon('phosphor-math-operations') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $nutzwert = $this->sum_nutzwerte('h', $data['h'], $record); ProjektObjekte::where('id', '=', $record->id) ->update( [ 'h' => $data['h'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('i') ->label($spalten['i'] ?? '') ->color('info') ->hidden(isset($spalten['i']) ? false : true) ->schema([ TextInput::make('i') ->prefixIcon('phosphor-math-operations'), ]) ->icon('phosphor-math-operations') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $nutzwert = $this->sum_nutzwerte('i', $data['i'], $record); ProjektObjekte::where('id', '=', $record->id) ->update( [ 'i' => $data['i'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), BulkAction::make('j') ->label($spalten['j'] ?? '') ->color('info') ->hidden(isset($spalten['j']) ? false : true) ->schema([ TextInput::make('j') ->prefixIcon('phosphor-math-operations'), ]) ->icon('phosphor-math-operations') ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $nutzwert = $this->sum_nutzwerte('j', $data['j'], $record); ProjektObjekte::where('id', '=', $record->id) ->update( [ 'j' => $data['j'], 'nutzwert' => $nutzwert, ] ); } })->after(function (Component $livewire) { $livewire->dispatch('refreshOrientierung'); }), ]), ]); } public function sum_nutzwerte($char, $state, $record) { $range = range('a', 'j'); $sum = 0; foreach ($range as $val) { if ($val == $char) { $sum += $state; } else { $sum += $record[$val]; } } return $sum; } }