wip
This commit is contained in:
1 parent
30563ee98d
commit
622b37bb90
12 files changed
+56
-56
No files matched your search
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Projektes\Widgets;
|
||||
|
||||
use App\Models\ProjektMerkmale;
|
||||
use App\Models\ProjektObjekte;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class WidgetProjektMerkmale extends TableWidget
|
||||
{
|
||||
protected static ?string $navigationLabel = 'Merkmal';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'ProjektMerkmale';
|
||||
|
||||
protected static ?string $modelLabel = 'Merkmal';
|
||||
|
||||
protected static ?string $title = 'Merkmal';
|
||||
|
||||
public $projekte_id;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->striped()
|
||||
->query(fn (): Builder => ProjektMerkmale::where('projekte_id', $this->projekte_id))
|
||||
->defaultSort('code')
|
||||
->columns([
|
||||
TextColumn::make('name'),
|
||||
])
|
||||
->paginated(false)
|
||||
->recordActions([
|
||||
EditAction::make()
|
||||
->color('gray')
|
||||
->iconButton()
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]),
|
||||
DeleteAction::make()
|
||||
->modalHeading('Merkmal löschen')
|
||||
->color('gray')
|
||||
->iconButton()
|
||||
->after(function ($record) {
|
||||
ProjektObjekte::where('projekte_id', '=', $record->projekte_id)
|
||||
->update(
|
||||
[$record->code => 0]
|
||||
);
|
||||
$res = ProjektObjekte::where('projekte_id', '=', $record->projekte_id)->get();
|
||||
foreach ($res as $value) {
|
||||
$nutzwert = round($value->a + $value->b + $value->c + $value->d + $value->e + $value->f + $value->g + $value->h + $value->i + $value->j);
|
||||
ProjektObjekte::where('id', '=', $value->id)
|
||||
->update(
|
||||
['nutzwert' => $nutzwert]
|
||||
);
|
||||
}
|
||||
|
||||
}),
|
||||
])
|
||||
->headerActions([
|
||||
Action::make('name')
|
||||
->icon('phosphor-plus')
|
||||
->label('Merkmal')
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->prefixIcon('phosphor-house-simple'),
|
||||
])
|
||||
->action(function (array $data) {
|
||||
$code = ProjektMerkmale::getfreecode($this->projekte_id);
|
||||
if ($code) {
|
||||
$merkmal = new ProjektMerkmale;
|
||||
$merkmal->projekte_id = $this->projekte_id;
|
||||
$merkmal->code = $code;
|
||||
$merkmal->name = $data['name'];
|
||||
$merkmal->save();
|
||||
}
|
||||
}),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user