label('Paket anlegen') ->modalHeading('Neues Paket') ->modalDescription('Der Name genügt. Bestandteile stellst du danach am Paket zusammen.') ->modalSubmitActionLabel('Paket anlegen') ->schema([ TextInput::make('name')->label('Name')->required(), ])->action(function (array $data): void { $bundle = null; $this->report(function () use ($data, &$bundle): void { $bundle = app(BundleService::class)->create($data['name']); }, 'Das Paket ist angelegt.'); if ($bundle instanceof Bundle) { $this->redirect(BundleResource::getUrl('view', ['record' => $bundle])); } }), ]; } protected function catalogRows(): array { $rows = []; foreach (Bundle::query()->with(['versions.items'])->orderBy('name')->get() as $bundle) { $versions = $bundle->versions->sortByDesc('number'); $published = $versions->first(fn ($version): bool => StatusValue::of($version->status) === BundleStatus::Veroeffentlicht->value); $draft = $versions->first(fn ($version): bool => StatusValue::of($version->status) === BundleStatus::Entwurf->value); $chips = []; $zustand = []; if ($published !== null) { $chips[] = ['label' => 'Fassung '.$published->number.' veröffentlicht', 'ton' => 'gut']; $chips[] = ['label' => $published->items->count() === 1 ? '1 Bestandteil' : $published->items->count().' Bestandteile', 'ton' => 'leise']; $zustand[] = 'veroeffentlicht'; } else { $chips[] = ['label' => $versions->isEmpty() ? 'Noch keine Fassung' : 'Noch nicht veröffentlicht', 'ton' => 'offen']; $zustand[] = 'ohne'; } if ($draft !== null) { $chips[] = ['label' => 'Fassung '.$draft->number.' in Arbeit', 'ton' => 'offen']; $zustand[] = 'entwurf'; } if ($bundle->archived_at !== null) { $chips[] = ['label' => 'Archiviert', 'ton' => 'leise']; $zustand[] = 'archiviert'; } $url = BundleResource::getUrl('view', ['record' => $bundle]); $rows[] = [ 'schluessel' => 'p'.$bundle->id, 'titel' => $bundle->name, 'meta' => 'Paket', 'symbol' => 'modul', 'url' => $url, 'chips' => $chips, 'zustand' => $zustand, 'aktionen' => [['label' => 'Öffnen', 'href' => $url]], ]; } return $rows; } protected function zustandOptionen(): array { return ['alle' => 'Jeder Zustand', 'veroeffentlicht' => 'Veröffentlicht', 'ohne' => 'Noch nicht veröffentlicht', 'entwurf' => 'Fassung in Arbeit', 'archiviert' => 'Archiviert']; } protected function einheit(): array { return ['Paket', 'Pakete']; } protected function leer(): array { return ['titel' => 'Noch keine Pakete', 'text' => 'Mit „Paket anlegen“ oben entsteht das erste Paket.']; } }