diff --git a/app/Filament/Resources/FloorPlans/FloorPlanResource.php b/app/Filament/Resources/FloorPlans/FloorPlanResource.php new file mode 100644 index 0000000..a79db83 --- /dev/null +++ b/app/Filament/Resources/FloorPlans/FloorPlanResource.php @@ -0,0 +1,56 @@ + ListFloorPlans::route('/'), + 'create' => CreateFloorPlan::route('/create'), + 'edit' => EditFloorPlan::route('/{record}/edit'), + ]; + } +} diff --git a/app/Filament/Resources/FloorPlans/Pages/CreateFloorPlan.php b/app/Filament/Resources/FloorPlans/Pages/CreateFloorPlan.php new file mode 100644 index 0000000..d415d16 --- /dev/null +++ b/app/Filament/Resources/FloorPlans/Pages/CreateFloorPlan.php @@ -0,0 +1,11 @@ +columns(2) + ->components([ + Select::make('property_id') + ->label('Wohnung') + ->options(fn (): array => Property::query()->pluck('name', 'id')->all()) + ->default(fn (): ?int => Property::query()->value('id')) + ->unique(ignoreRecord: true) + ->validationMessages(['unique' => 'Für diese Wohnung gibt es schon einen Grundriss.']) + ->required() + ->live(), + PhotoSelect::make('photo_id') + ->label('Grundriss-Bild') + ->helperText('Rendering oder Plan aus Webseite › Fotos. Ein neues Bild im gleichen Ausschnitt behält die Räume.') + ->required() + ->live(), + Repeater::make('rooms') + ->label('Räume') + ->columnSpanFull() + ->defaultItems(0) + ->addActionLabel('Raum hinzufügen') + ->reorderable() + ->collapsible() + ->itemLabel(fn (array $state): string => filled($state['name'] ?? null) ? $state['name'] : 'Neuer Raum') + ->columns(2) + ->schema([ + Hidden::make('id')->default(fn (): string => (string) Str::uuid()), + TextInput::make('name')->label('Name')->placeholder('z. B. Schlafzimmer')->required()->maxLength(60)->live(onBlur: true), + Toggle::make('is_visible')->label('Auf der Website zeigen')->default(true)->inline(false), + ViewField::make('points') + ->label('Fläche auf dem Grundriss') + ->view('filament.forms.floor-plan-area') + ->columnSpanFull() + ->rules([ + fn (): Closure => function (string $attribute, mixed $value, Closure $fail): void { + if (count(FloorPlan::points(is_string($value) ? $value : null)) < 3) { + $fail('Bitte mindestens drei Ecken des Raums auf dem Bild anklicken.'); + } + }, + ]), + Textarea::make('description')->label('Beschreibung')->rows(3)->maxLength(400)->columnSpanFull(), + PhotoSelect::make('photo_ids')->label('Fotos')->multiple()->helperText('Das erste Foto steht oben, die weiteren als kleine Bilder darunter.'), + Select::make('amenity_ids') + ->label('Ausstattung') + ->multiple() + ->searchable() + ->options(fn (Get $get): array => Amenity::query()->where('property_id', $get('../../property_id'))->orderBy('sort_order')->pluck('name', 'id')->all()) + ->helperText('Aus Webseite › Ausstattung – nichts doppelt pflegen.'), + TextInput::make('hint') + ->label('Hinweis zur Barrierefreiheit (optional)') + ->placeholder('z. B. Flache Dusche mit kleiner Kante') + ->maxLength(160) + ->columnSpanFull(), + ]), + ]); + } +} diff --git a/app/Filament/Resources/FloorPlans/Tables/FloorPlansTable.php b/app/Filament/Resources/FloorPlans/Tables/FloorPlansTable.php new file mode 100644 index 0000000..c196bf9 --- /dev/null +++ b/app/Filament/Resources/FloorPlans/Tables/FloorPlansTable.php @@ -0,0 +1,26 @@ +paginated(false) + ->columns([ + TextColumn::make('property.name')->label('Wohnung'), + TextColumn::make('rooms')->label('Räume') + ->state(fn (FloorPlan $record): string => $record->visibleRooms()->pluck('name')->implode(', ') ?: 'noch keine'), + TextColumn::make('updated_at')->label('Geändert')->since(), + ]) + ->recordActions([ + EditAction::make(), + ]); + } +} diff --git a/app/Models/FloorPlan.php b/app/Models/FloorPlan.php new file mode 100644 index 0000000..7ce0f8d --- /dev/null +++ b/app/Models/FloorPlan.php @@ -0,0 +1,81 @@ +, amenity_ids?: list, is_visible?: bool}>|null $rooms + */ +#[Fillable(['property_id', 'photo_id', 'rooms'])] +class FloorPlan extends Model +{ + /** @use HasFactory */ + use BelongsToTenant, HasFactory; + + /** + * Get the attributes that should be cast. + * + * @return array + */ + protected function casts(): array + { + return [ + 'rooms' => 'array', + ]; + } + + /** + * @return BelongsTo + */ + public function property(): BelongsTo + { + return $this->belongsTo(Property::class); + } + + /** + * @return BelongsTo + */ + public function photo(): BelongsTo + { + return $this->belongsTo(Photo::class); + } + + /** + * Rooms shown on the website: visible and with an area of at least three corners. + * + * @return Collection> + */ + public function visibleRooms(): Collection + { + return collect($this->rooms ?? []) + ->filter(fn (array $room): bool => ($room['is_visible'] ?? true) && filled($room['name'] ?? null) && count(self::points($room['points'] ?? null)) >= 3) + ->values(); + } + + /** + * Parses "x,y x,y …" (percent) into points, ignoring anything outside 0–100. + * + * @return list + */ + public static function points(?string $points): array + { + $parsed = []; + foreach (preg_split('/\s+/', trim((string) $points)) ?: [] as $pair) { + if (preg_match('/^(\d{1,3}(?:\.\d+)?),(\d{1,3}(?:\.\d+)?)$/', $pair, $match) && (float) $match[1] <= 100 && (float) $match[2] <= 100) { + $parsed[] = [(float) $match[1], (float) $match[2]]; + } + } + + return $parsed; + } +} diff --git a/app/Models/Property.php b/app/Models/Property.php index d06906e..0b66ca8 100644 --- a/app/Models/Property.php +++ b/app/Models/Property.php @@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOne; /** * A rentable holiday apartment. All money amounts are stored in euro cents. @@ -115,6 +116,14 @@ public function amenities(): HasMany return $this->hasMany(Amenity::class)->orderBy('sort_order'); } + /** + * @return HasOne + */ + public function floorPlan(): HasOne + { + return $this->hasOne(FloorPlan::class); + } + /** * @return HasMany */ diff --git a/app/Policies/FloorPlanPolicy.php b/app/Policies/FloorPlanPolicy.php new file mode 100644 index 0000000..58e9450 --- /dev/null +++ b/app/Policies/FloorPlanPolicy.php @@ -0,0 +1,13 @@ +label('Überschrift')->default('Der Grundriss')->maxLength(120) + ->helperText('Bild und Räume pflegen Sie unter Webseite › Grundriss.'), + Textarea::make('text')->label('Text')->rows(2)->maxLength(300) + ->default('Tippen Sie auf einen Raum, um Fotos und Ausstattung zu sehen.'), + ]; + } + + public function data(Theme $theme, array $data): array + { + $plan = $theme->property()?->floorPlan()->with('photo')->first(); + $rooms = $plan?->photo ? $plan->visibleRooms() : collect(); + + $photos = Photo::query()->published()->with('media') + ->whereIn('id', $rooms->flatMap(fn (array $room): array => $room['photo_ids'] ?? [])->unique()->all()) + ->get()->keyBy('id'); + $amenities = Amenity::query() + ->whereIn('id', $rooms->flatMap(fn (array $room): array => $room['amenity_ids'] ?? [])->unique()->all()) + ->pluck('name', 'id'); + + return [ + 'heading' => $data['heading'] ?? 'Der Grundriss', + 'text' => $data['text'] ?? null, + 'photo' => $plan?->photo, + 'rooms' => $rooms->map(fn (array $room, int $index): array => [ + 'key' => 'raum-'.Str::slug($room['name']).'-'.($index + 1), + 'name' => $room['name'], + 'description' => $room['description'] ?? null, + 'hint' => $room['hint'] ?? null, + 'points' => collect(FloorPlan::points($room['points']))->map(fn (array $point): string => $point[0].','.$point[1])->implode(' '), + 'photos' => collect($room['photo_ids'] ?? [])->map(fn ($id) => $photos->get((int) $id))->filter()->values(), + 'amenities' => collect($room['amenity_ids'] ?? [])->map(fn ($id) => $amenities->get((int) $id))->filter()->values(), + ]), + ]; + } +} diff --git a/config/themes.php b/config/themes.php index 3760a4a..0036819 100644 --- a/config/themes.php +++ b/config/themes.php @@ -39,6 +39,7 @@ Sections\TextImageSection::class, Sections\GallerySection::class, Sections\AmenitiesSection::class, + Sections\FloorPlanSection::class, Sections\LocationSection::class, Sections\PricesSection::class, Sections\OffersSection::class, diff --git a/database/factories/FloorPlanFactory.php b/database/factories/FloorPlanFactory.php new file mode 100644 index 0000000..1df42ae --- /dev/null +++ b/database/factories/FloorPlanFactory.php @@ -0,0 +1,32 @@ + + */ +class FloorPlanFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'property_id' => Property::factory(), + 'photo_id' => Photo::factory(), + 'rooms' => [ + ['id' => (string) Str::uuid(), 'name' => 'Wohnbereich', 'description' => 'Helles Wohnzimmer mit Ledersofa.', 'hint' => null, 'points' => '10,20 50,20 50,65 10,65', 'photo_ids' => [], 'amenity_ids' => [], 'is_visible' => true], + ['id' => (string) Str::uuid(), 'name' => 'Bad', 'description' => 'Bad mit Glasdusche.', 'hint' => 'Flache Dusche mit kleiner Kante.', 'points' => '50,40 66,40 66,65 50,65', 'photo_ids' => [], 'amenity_ids' => [], 'is_visible' => true], + ], + ]; + } +} diff --git a/database/migrations/2026_10_23_151632_create_floor_plans_table.php b/database/migrations/2026_10_23_151632_create_floor_plans_table.php new file mode 100644 index 0000000..883c8cb --- /dev/null +++ b/database/migrations/2026_10_23_151632_create_floor_plans_table.php @@ -0,0 +1,28 @@ +id(); + $table->foreignId('tenant_id')->constrained()->restrictOnDelete(); + $table->foreignId('property_id')->unique()->constrained()->cascadeOnDelete(); + $table->foreignId('photo_id')->nullable()->constrained()->nullOnDelete(); + $table->json('rooms')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('floor_plans'); + } +}; diff --git a/docs/STATUS.md b/docs/STATUS.md index c0909df..057492d 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -121,7 +121,7 @@ ## 6. Design-Theme „Seebad“ (Abschnitt der Design-Session) | Baustein | Daten / Admin | Darstellung | Abhängig von | |---|---|---|---| -| Interaktiver Grundriss | je Wohnung: Grundriss (SVG/Bild) + Räume (Name, Text, Fotos, Fläche als Polygon in %); Editor im Admin | Inline-SVG, Räume antippen → Foto/Text; ohne JS als Liste | Mandanten-Umbau Phase 1 (Daten je Wohnung/Mandant) | +| Interaktiver Grundriss – **gebaut** (23.10.2026, Branch `feature/bausteine`) | Tabelle `floor_plans` (`tenant_id`, eine je Wohnung, Bild = Foto aus Webseite › Fotos, Räume als JSON: Name, Text, Hinweis, Fotos, Ausstattung, sichtbar, Ecken in %); Admin › Webseite › Grundriss mit Eckpunkt-Editor (`resources/views/filament/forms/floor-plan-area.blade.php`, nur Expertenansicht) | Baustein `floor_plan`; Seebad: Flächen und Raum-Tasten wählen einen Raum, Kartusche mit Foto/Ausstattung/Hinweis; ohne JS Liste. Rendering: `styles/grundriss/` | **Mandanten Phase 5:** `floor_plans` beim Export/Löschen eines Mandanten mitnehmen | | Tipps der Gastgeberin | eigene Liste je Website (Ort, Kategorie, Weg/Gehzeit, Text, Foto, Karten-Link, Saison) | Liste mit Vignette je Kategorie | Bildwelt (Vignetten je Kategorie) | | Gut zu wissen | strukturierte Felder an der Wohnung (Zugang, Dusche, Haustiere, An-/Abreise, Parken) – auch für Angebot/Mail/JSON-LD | Kartusche | – (klein) | | Belegungs-/Preiskalender (nur ansehen) | vorhandene Daten (`AvailabilityChecker`, `PriceCalculator`) | Monatsansicht, Livewire oder statisch gerendert | – | diff --git a/docs/THEMES.md b/docs/THEMES.md index 06d8808..45b4d76 100644 --- a/docs/THEMES.md +++ b/docs/THEMES.md @@ -106,6 +106,7 @@ ## 5. Bausteinkatalog – Vertrag der Vorlagen | `text_image` | Text mit Bildern | `$eyebrow`, `$heading`, `$text` (HtmlString\|null), `$photos` (≤3), `$imagePosition` (`left`\|`right`), `$linkLabel`, `$linkUrl` | | `gallery` | Bildergalerie | `$heading`, `$photos` – Lightbox: `` | | `amenities` | Ausstattung | `$heading`, `$groups` (Bereich ⇒ Collection) | +| `floor_plan` | Grundriss (interaktiv) | `$heading`, `$text`, `$photo` (Grundriss-Bild, `Photo`), `$rooms` (Collection von Arrays: `key` – Anker-ID, `name`, `description`, `hint` – Barrierefreiheit, `points` – „x,y x,y …“ in **Prozent** des Bildes → SVG `viewBox="0 0 100 100" preserveAspectRatio="none"` über dem Bild, `photos` – Collection, `amenities` – Collection). Rendert nichts ohne Bild oder Räume. Daten: Admin › Webseite › Grundriss (`FloorPlan`) | | `location` | Lage & Umgebung | `$eyebrow`, `$heading`, `$text`, `$address`, `$mapUrl` (OpenStreetMap-Link, keine eingebettete Karte), `$photos` | | `prices` | Preise & Saisons | `$eyebrow`, `$heading`, `$text`, `$property`, `$seasons` (nächste 12 Monate), `$extras`, `$featuredSeason` (Name des Erscheinungsbilds) | | `offers` | Sonderangebote | `$heading`, `$display` (`grid`\|`list`\|`rotating`), `$offers` (Collection<`App\Pricing\AdvertisedOffer`>: `title`, `description`, `advantage`, `conditions`, `arrival`/`departure`/`nights()` bei festen Terminen und Lücken, `quote` + `regularTotal()` für „statt …“, `bookingUrl()`). Rollierend: `data-rotator`, `data-rotator-slide`, `data-rotator-prev/next/dot` (theme.js) | diff --git a/docs/ZUSAMMENARBEIT.md b/docs/ZUSAMMENARBEIT.md index fb4845b..6ef645b 100644 --- a/docs/ZUSAMMENARBEIT.md +++ b/docs/ZUSAMMENARBEIT.md @@ -88,4 +88,5 @@ ## 6. Änderungsprotokoll Vorlagen-Vertrag | 22.10.2026 | Markengrafiken: `@include('theme::partials.brand', ['name' => 'mark', 'class' => '…'])` (mark, logo, wave-divider, icon-apartment/-sea/-terrace/-location); Farben über `--brand-navy/-teal/-wave/-sun` (navy = Textfarbe) | header, footer, facts, location, image | | 22.10.2026 | `hero`: `$featuredOffer` (wichtigstes hervorgehobenes Angebot oder null) | sections/hero | | 22.10.2026 | `offers`: `$display` (grid/list/rotating), `$offers` = `AdvertisedOffer` (Termin, Preis, `bookingUrl()`); rollierend über `data-rotator*` | sections/offers | +| 23.10.2026 | **Neuer Baustein `floor_plan`** (Grundriss interaktiv): Vertrag in THEMES.md §5; Basis-Vorlage `ostsee-licht/views/sections/floor_plan.blade.php` (ohne JS: Flächen springen zur Raumliste), Seebad interaktiv (`theme.js` `initFloorPlans`). Neue Themes brauchen keine eigene Vorlage (Vererbung) | sections/floor_plan | | 22.10.2026 | Seiten außerhalb der Bausteine, die das Theme-Layout nutzen: Angebotsseite `resources/views/offer.blade.php`, Bewertung `resources/views/review.blade.php` – beim Theme-Test mitprüfen | layouts/app | diff --git a/resources/themes/ostsee-licht/views/sections/floor_plan.blade.php b/resources/themes/ostsee-licht/views/sections/floor_plan.blade.php new file mode 100644 index 0000000..3be670e --- /dev/null +++ b/resources/themes/ostsee-licht/views/sections/floor_plan.blade.php @@ -0,0 +1,42 @@ +{{-- + Contract: $heading, $text, $photo (App\Models\Photo, the plan picture), $rooms (Collection of arrays: key, name, + description, hint, points = "x,y x,y …" in percent of the picture, photos = Collection, amenities = Collection). + Base version without JavaScript: the areas on the plan jump to the room descriptions below. +--}} +@if ($photo && $rooms->isNotEmpty()) +
+

{{ $heading }}

+ @if ($text)

{{ $text }}

@endif + +
+ @include('theme::partials.image', ['photo' => $photo, 'sizes' => '(min-width: 1280px) 80rem, 100vw', 'class' => 'h-auto w-full']) + + @foreach ($rooms as $room) + + {{ $room['name'] }} + + @endforeach + +
+ +
    + @foreach ($rooms as $room) +
  • + @if ($room['photos']->isNotEmpty()) + @include('theme::partials.image', ['photo' => $room['photos']->first(), 'sizes' => '(min-width: 1024px) 25vw, 100vw', 'class' => 'mb-4 h-44 w-full rounded-sm object-cover']) + @endif +

    {{ $room['name'] }}

    + @if ($room['description'])

    {{ $room['description'] }}

    @endif + @if ($room['amenities']->isNotEmpty()) +
      + @foreach ($room['amenities'] as $amenity) +
    • {{ $amenity }}
    • + @endforeach +
    + @endif + @if ($room['hint'])

    {{ $room['hint'] }}

    @endif +
  • + @endforeach +
+
+@endif diff --git a/resources/themes/seebad/theme.js b/resources/themes/seebad/theme.js index e56556d..0ce402b 100644 --- a/resources/themes/seebad/theme.js +++ b/resources/themes/seebad/theme.js @@ -50,3 +50,50 @@ function initMenuPanels() { } initMenuPanels(); + +/** + * Floor plan (sections/floor_plan): one room at a time. Areas and room buttons select a room; on narrow + * screens the description below the plan is scrolled into view. Without JavaScript all rooms are listed. + */ +function initFloorPlans() { + const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; + + document.querySelectorAll('[data-floor-plan]').forEach((plan) => { + const rooms = [...plan.querySelectorAll('[data-floor-room]')]; + const links = [...plan.querySelectorAll('[data-floor-room-link]')]; + if (rooms.length === 0) { + return; + } + + const select = (key, scroll) => { + rooms.forEach((room) => { + room.hidden = room.id !== key; + }); + links.forEach((link) => { + const active = link.dataset.floorRoomLink === key; + link.toggleAttribute('data-active', active); + if (active) { + link.setAttribute('aria-current', 'true'); + } else { + link.removeAttribute('aria-current'); + } + }); + const room = rooms.find((candidate) => candidate.id === key); + if (scroll && room && room.getBoundingClientRect().top > window.innerHeight) { + room.scrollIntoView({ behavior: reduceMotion ? 'auto' : 'smooth', block: 'nearest' }); + } + }; + + links.forEach((link) => { + link.addEventListener('click', (event) => { + event.preventDefault(); + select(link.dataset.floorRoomLink, true); + }); + }); + + const fromHash = rooms.find((room) => `#${room.id}` === window.location.hash); + select((fromHash ?? rooms[0]).id, false); + }); +} + +initFloorPlans(); diff --git a/resources/themes/seebad/views/sections/floor_plan.blade.php b/resources/themes/seebad/views/sections/floor_plan.blade.php new file mode 100644 index 0000000..e668e6d --- /dev/null +++ b/resources/themes/seebad/views/sections/floor_plan.blade.php @@ -0,0 +1,67 @@ +{{-- + Contract: $heading, $text, $photo, $rooms (see ostsee-licht/views/sections/floor_plan.blade.php). + theme.js (initFloorPlans) shows one room at a time; without JavaScript all rooms are listed and the areas jump to them. +--}} +@if ($photo && $rooms->isNotEmpty()) +
+
+

{{ $heading }}

+ @if ($text)

{{ $text }}

@endif +
+ +
+ + +
+ @foreach ($rooms as $room) +
+ + + @if ($room['photos']->isNotEmpty()) + @include('theme::partials.image', ['photo' => $room['photos']->first(), 'sizes' => '(min-width: 1024px) 26rem, 100vw', 'class' => 'mb-5 h-56 w-full rounded object-cover']) + @endif +

{{ $room['name'] }}

+ @if ($room['description'])

{{ $room['description'] }}

@endif + @if ($room['amenities']->isNotEmpty()) +
    + @foreach ($room['amenities'] as $amenity) +
  • + @endforeach +
+ @endif + @if ($room['hint'])

{{ $room['hint'] }}

@endif + @if ($room['photos']->count() > 1) + + @endif +
+ @endforeach +
+
+
+@endif diff --git a/resources/views/filament/forms/floor-plan-area.blade.php b/resources/views/filament/forms/floor-plan-area.blade.php new file mode 100644 index 0000000..195f83f --- /dev/null +++ b/resources/views/filament/forms/floor-plan-area.blade.php @@ -0,0 +1,52 @@ +{{-- + Room area editor (FloorPlanForm): click the corners of a room on the plan picture; stored as "x,y x,y …" in + percent of the picture. The other rooms are shown as blue outlines for orientation. +--}} +@php + $planPhoto = \App\Models\Photo::query()->find($get('../../photo_id')); + $currentRoomId = $get('id'); + $otherAreas = collect($get('../../rooms') ?? []) + ->reject(fn ($room): bool => ($room['id'] ?? null) === $currentRoomId) + ->map(fn ($room): string => collect(\App\Models\FloorPlan::points($room['points'] ?? null))->map(fn ($point): string => $point[0].','.$point[1])->implode(' ')) + ->filter() + ->values(); +@endphp + + @if (! $planPhoto) +

Bitte oben zuerst das Grundriss-Bild wählen.

+ @else +
+
+ + + +
+
+ + Letzten Punkt entfernen + Fläche leeren +
+

Klicken Sie nacheinander die Ecken des Raums auf dem Bild an, im Uhrzeigersinn. Blau umrandet: die anderen Räume.

+
+ @endif +
diff --git a/styles/grundriss/grundriss-1712.webp b/styles/grundriss/grundriss-1712.webp index 27021fc..f8610ed 100644 Binary files a/styles/grundriss/grundriss-1712.webp and b/styles/grundriss/grundriss-1712.webp differ diff --git a/styles/grundriss/grundriss-900.webp b/styles/grundriss/grundriss-900.webp index 6a3e5ae..cf62fe3 100644 Binary files a/styles/grundriss/grundriss-900.webp and b/styles/grundriss/grundriss-900.webp differ diff --git a/styles/grundriss/grundriss-rendering.png b/styles/grundriss/grundriss-rendering.png index da96c46..fe69f01 100644 Binary files a/styles/grundriss/grundriss-rendering.png and b/styles/grundriss/grundriss-rendering.png differ diff --git a/styles/grundriss/raeume-stommer.json b/styles/grundriss/raeume-stommer.json new file mode 100644 index 0000000..ca3ba87 --- /dev/null +++ b/styles/grundriss/raeume-stommer.json @@ -0,0 +1,89 @@ +[ + { + "id": "terrasse", + "name": "Terrasse", + "description": "Eigene, überdachte Terrasse mit Gartenmöbeln. Im Frühsommer blühen die Rhododendren direkt davor.", + "hint": "Über den Garten stufenlos erreichbar.", + "points": "2.6,21.8 8.2,21.8 8.2,56.0 2.6,56.0", + "photo_ids": [ + 21 + ], + "amenity_ids": [], + "is_visible": true + }, + { + "id": "wohnen", + "name": "Wohnbereich", + "description": "Helles Wohnzimmer mit Fensterfront zur Terrasse. Das Schrankbett bietet Platz für eine dritte Person.", + "hint": null, + "points": "10.4,21.8 49.5,21.8 49.5,40.3 30.4,40.3 30.4,64.4 15.3,64.4 9.3,52.0 10.4,47.9", + "photo_ids": [ + 2, + 1, + 6 + ], + "amenity_ids": [], + "is_visible": true + }, + { + "id": "kueche", + "name": "Küche & Essplatz", + "description": "Einbauküche zum Selbstversorgen mit Essplatz für vier.", + "hint": null, + "points": "30.4,40.3 49.5,40.3 49.5,64.4 30.4,64.4", + "photo_ids": [ + 9, + 8 + ], + "amenity_ids": [], + "is_visible": true + }, + { + "id": "diele", + "name": "Diele", + "description": "Großer Einbauschrank. Von hier geht es zu Bad, Schlafzimmer und Eingang.", + "hint": null, + "points": "49.6,21.8 69.8,21.8 73.9,28.5 70.1,37.5 66.6,43.5 66.6,41.1 49.6,41.1", + "photo_ids": [ + 11 + ], + "amenity_ids": [], + "is_visible": true + }, + { + "id": "eingang", + "name": "Eingangsbereich", + "description": "Eigene Wohnungstür mit Fußabtreter.", + "hint": "Eingang im Erdgeschoss mit einer Stufe.", + "points": "75.9,8.9 88.5,8.9 88.5,28.8 74.2,28.8 70.7,22.3 70.7,16.3", + "photo_ids": [], + "amenity_ids": [], + "is_visible": true + }, + { + "id": "bad", + "name": "Bad", + "description": "Bad mit Glasdusche (90 × 90 cm) und beleuchtetem Spiegelschrank.", + "hint": "Flache Dusche mit kleiner Kante – die Wohnung ist nicht rollstuhlgerecht.", + "points": "49.8,41.3 66.3,41.3 66.3,64.7 49.8,64.7", + "photo_ids": [ + 16, + 17 + ], + "amenity_ids": [], + "is_visible": true + }, + { + "id": "schlafen", + "name": "Schlafzimmer", + "description": "Ruhiges Schlafzimmer zur Gartenseite mit Kingsize-Bett.", + "hint": null, + "points": "74.5,29.2 89.3,29.2 89.3,65.9 66.6,65.9 66.6,43.5 70.6,37.5", + "photo_ids": [ + 13, + 14 + ], + "amenity_ids": [], + "is_visible": true + } +] \ No newline at end of file diff --git a/tests/Feature/FloorPlanTest.php b/tests/Feature/FloorPlanTest.php new file mode 100644 index 0000000..8336022 --- /dev/null +++ b/tests/Feature/FloorPlanTest.php @@ -0,0 +1,123 @@ +travelTo(CarbonImmutable::parse('2026-10-22 10:00')); + $this->seed([PropertySeeder::class, WebsiteContentSeeder::class, SiteSeeder::class]); + $this->withoutVite(); + $this->property = Property::sole(); + } + + public function test_floor_plan_belongs_to_the_landlord_of_its_apartment(): void + { + $plan = FloorPlan::factory()->for($this->property)->create(); + + $this->assertSame($this->property->tenant_id, $plan->tenant_id); + $this->assertTrue($this->property->floorPlan->is($plan)); + } + + public function test_area_points_are_parsed_in_percent_and_invalid_pairs_are_dropped(): void + { + $this->assertSame([[10.0, 20.5], [50.0, 20.5], [50.0, 65.0]], FloorPlan::points(' 10,20.5 50,20.5 50,65 abc 150,3 ')); + $this->assertSame([], FloorPlan::points(null)); + } + + public function test_section_shows_visible_rooms_with_area_photo_equipment_and_hint(): void + { + $roomPhoto = Photo::factory()->create(['alt_text' => 'Glasdusche im Bad']); + $shower = Amenity::factory()->for($this->property)->create(['name' => 'Dusche mit niedrigem Einstieg']); + FloorPlan::factory()->for($this->property)->create([ + 'photo_id' => Photo::factory()->create(['alt_text' => 'Grundriss der Wohnung'])->id, + 'rooms' => [ + ['id' => 'a', 'name' => 'Bad', 'description' => 'Bad mit Glasdusche.', 'hint' => 'Flache Dusche mit kleiner Kante.', 'points' => '50,40 66,40 66,65', 'photo_ids' => [$roomPhoto->id], 'amenity_ids' => [$shower->id], 'is_visible' => true], + ['id' => 'b', 'name' => 'Abstellkammer', 'points' => '1,1 2,1 2,2', 'is_visible' => false], + ['id' => 'c', 'name' => 'Ohne Fläche', 'points' => '1,1 2,2', 'is_visible' => true], + ], + ]); + $this->placeSectionOnApartmentPage(); + + $this->get('/wohnung') + ->assertOk() + ->assertSee('Der Grundriss') + ->assertSee('points="50,40 66,40 66,65"', false) + ->assertSee('id="raum-bad-1"', false) + ->assertSee('Bad mit Glasdusche.') + ->assertSee('Flache Dusche mit kleiner Kante.') + ->assertSee('Dusche mit niedrigem Einstieg') + ->assertSee('Glasdusche im Bad') + ->assertDontSee('Abstellkammer') + ->assertDontSee('Ohne Fläche'); + } + + public function test_section_shows_nothing_without_a_floor_plan(): void + { + $this->placeSectionOnApartmentPage(); + + $this->get('/wohnung')->assertOk()->assertDontSee('Der Grundriss'); + } + + public function test_content_editor_creates_a_floor_plan_and_a_room_needs_an_area(): void + { + $this->actingAs(User::factory()->role(UserRole::Content)->create()); + $planPhoto = Photo::factory()->create(); + + $this->get(FloorPlanResource::getUrl('index'))->assertOk(); + + Livewire::test(CreateFloorPlan::class) + ->fillForm([ + 'property_id' => $this->property->id, + 'photo_id' => $planPhoto->id, + 'rooms' => ['diele' => ['id' => 'x', 'name' => 'Diele', 'points' => '10,10 20,10', 'is_visible' => true]], + ]) + ->call('create') + ->assertHasFormErrors(['rooms.diele.points']); + + Livewire::test(CreateFloorPlan::class) + ->fillForm([ + 'property_id' => $this->property->id, + 'photo_id' => $planPhoto->id, + 'rooms' => ['diele' => ['id' => 'x', 'name' => 'Diele', 'points' => '10,10 20,10 20,30 10,30', 'is_visible' => true]], + ]) + ->call('create') + ->assertHasNoFormErrors(); + + $plan = FloorPlan::sole(); + $this->assertSame($this->property->tenant_id, $plan->tenant_id); + $this->assertSame(['Diele'], $plan->visibleRooms()->pluck('name')->all()); + } + + private function placeSectionOnApartmentPage(): void + { + $page = Site::sole()->pages()->where('slug', 'wohnung')->sole(); + $page->update(['sections' => [...$page->sections, ['type' => 'floor_plan', 'data' => ['heading' => 'Der Grundriss']]]]); + $this->assertInstanceOf(Page::class, $page); + } +} diff --git a/tests/Feature/InstalledThemesRenderTest.php b/tests/Feature/InstalledThemesRenderTest.php index bf8840b..ede26fa 100644 --- a/tests/Feature/InstalledThemesRenderTest.php +++ b/tests/Feature/InstalledThemesRenderTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature; use App\Enums\ReviewStatus; +use App\Models\FloorPlan; use App\Models\Page; use App\Models\Property; use App\Models\Review; @@ -38,6 +39,10 @@ protected function setUp(): void Review::factory()->for($property)->count(2)->create(['status' => ReviewStatus::Approved]); SpecialOffer::factory()->for($property)->create(['name' => 'Herbstwochen', 'is_featured' => true]); SpecialOffer::factory()->for($property)->create(['name' => 'Ab 5 Nächten', 'min_nights' => 5]); + FloorPlan::factory()->for($property)->create(); + + $apartment = Page::query()->where('slug', 'wohnung')->sole(); + $apartment->update(['sections' => [...$apartment->sections, ['type' => 'floor_plan', 'data' => ['heading' => 'Der Grundriss']]]]); } public function test_every_installed_theme_renders_all_pages_with_offers_in_every_display_mode(): void @@ -60,6 +65,8 @@ public function test_every_installed_theme_renders_all_pages_with_offers_in_ever foreach (self::PAGES as $path) { $this->get($path)->assertOk(); } + + $this->get('/wohnung')->assertSee('Der Grundriss')->assertSee('Wohnbereich'); } } }