Commit b3ef31e7 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix grid using 1-based segment indices: eliminate phantom empty row/column

Segments use 1-based row/col (R1C1 = row:1, col:1). The loop was starting
at 0, creating an empty row and column with no matching segments.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent df0b1caa
...@@ -296,11 +296,13 @@ class="relative border rounded-xl p-3 sm:p-4 text-start transition-all hover:sha ...@@ -296,11 +296,13 @@ class="relative border rounded-xl p-3 sm:p-4 text-start transition-all hover:sha
<div class="flex-1 overflow-auto p-3 sm:p-4"> <div class="flex-1 overflow-auto p-3 sm:p-4">
@if(!empty($gridSegments)) @if(!empty($gridSegments))
@php @php
$minRow = collect($gridSegments)->min('row') ?? 0;
$maxRow = collect($gridSegments)->max('row') ?? 0; $maxRow = collect($gridSegments)->max('row') ?? 0;
$minCol = collect($gridSegments)->min('col') ?? 0;
$maxCol = collect($gridSegments)->max('col') ?? 0; $maxCol = collect($gridSegments)->max('col') ?? 0;
$isGrid = $maxRow > 0 || $maxCol > 0; $isGrid = $maxRow > 0 || $maxCol > 0;
$cols = $isGrid ? $maxCol + 1 : count($gridSegments); $cols = $isGrid ? ($maxCol - $minCol + 1) : count($gridSegments);
$rows = $isGrid ? $maxRow + 1 : 1; $rows = $isGrid ? ($maxRow - $minRow + 1) : 1;
$surfaceType = $facility->type->value ?? 'other'; $surfaceType = $facility->type->value ?? 'other';
@endphp @endphp
...@@ -315,25 +317,25 @@ class="flex items-center justify-center rounded-ss-lg bg-gray-100 hover:bg-blue- ...@@ -315,25 +317,25 @@ class="flex items-center justify-center rounded-ss-lg bg-gray-100 hover:bg-blue-
</button> </button>
{{-- Column headers --}} {{-- Column headers --}}
@for($c = 0; $c < $cols; $c++) @for($c = $minCol; $c <= $maxCol; $c++)
<button @click="selectColByIndex({{ $c }})" type="button" <button @click="selectColByIndex({{ $c }})" type="button"
class="flex items-center justify-center bg-gray-50 hover:bg-blue-50 border-e border-b border-gray-200 text-[11px] font-semibold text-gray-500 hover:text-blue-700 transition-colors {{ $c === $cols - 1 ? 'rounded-se-lg' : '' }}" class="flex items-center justify-center bg-gray-50 hover:bg-blue-50 border-e border-b border-gray-200 text-[11px] font-semibold text-gray-500 hover:text-blue-700 transition-colors {{ $c === $maxCol ? 'rounded-se-lg' : '' }}"
title="{{ __('تحديد العمود') }} {{ $c + 1 }}"> title="{{ __('تحديد العمود') }} {{ $c }}">
C{{ $c + 1 }} C{{ $c }}
</button> </button>
@endfor @endfor
{{-- Rows with row headers --}} {{-- Rows with row headers --}}
@for($r = 0; $r < $rows; $r++) @for($r = $minRow; $r <= $maxRow; $r++)
{{-- Row header --}} {{-- Row header --}}
<button @click="selectRowByIndex({{ $r }})" type="button" <button @click="selectRowByIndex({{ $r }})" type="button"
class="flex items-center justify-center bg-gray-50 hover:bg-blue-50 border-e border-b border-gray-200 text-[11px] font-semibold text-gray-500 hover:text-blue-700 transition-colors {{ $r === $rows - 1 ? 'rounded-es-lg' : '' }}" class="flex items-center justify-center bg-gray-50 hover:bg-blue-50 border-e border-b border-gray-200 text-[11px] font-semibold text-gray-500 hover:text-blue-700 transition-colors {{ $r === $maxRow ? 'rounded-es-lg' : '' }}"
title="{{ __('تحديد الصف') }} {{ $r + 1 }}"> title="{{ __('تحديد الصف') }} {{ $r }}">
R{{ $r + 1 }} R{{ $r }}
</button> </button>
{{-- Row cells --}} {{-- Row cells --}}
@for($c = 0; $c < $cols; $c++) @for($c = $minCol; $c <= $maxCol; $c++)
@php @php
$seg = collect($gridSegments)->first(fn($s) => ($s['row'] ?? 0) === $r && ($s['col'] ?? 0) === $c); $seg = collect($gridSegments)->first(fn($s) => ($s['row'] ?? 0) === $r && ($s['col'] ?? 0) === $c);
@endphp @endphp
...@@ -344,8 +346,8 @@ class="flex items-center justify-center bg-gray-50 hover:bg-blue-50 border-e bor ...@@ -344,8 +346,8 @@ class="flex items-center justify-center bg-gray-50 hover:bg-blue-50 border-e bor
$isExisting = $isOccupied && ($segAssignment['type'] ?? '') === 'existing'; $isExisting = $isOccupied && ($segAssignment['type'] ?? '') === 'existing';
$isNewGroup = $isOccupied && ($segAssignment['type'] ?? '') === 'group'; $isNewGroup = $isOccupied && ($segAssignment['type'] ?? '') === 'group';
$isNewTrainer = $isOccupied && ($segAssignment['type'] ?? '') === 'trainer'; $isNewTrainer = $isOccupied && ($segAssignment['type'] ?? '') === 'trainer';
$isLastCol = $c === $cols - 1; $isLastCol = $c === $maxCol;
$isLastRow = $r === $rows - 1; $isLastRow = $r === $maxRow;
@endphp @endphp
<div <div
@dragover.prevent="highlightSegment({{ $seg['id'] }})" @dragover.prevent="highlightSegment({{ $seg['id'] }})"
...@@ -439,7 +441,7 @@ class="text-[10px] text-red-500 hover:text-red-700 hover:underline">{{ __('ال ...@@ -439,7 +441,7 @@ class="text-[10px] text-red-500 hover:text-red-700 hover:underline">{{ __('ال
</div> </div>
@else @else
{{-- Empty grid cell (no segment) --}} {{-- Empty grid cell (no segment) --}}
<div class="bg-gray-50/50 {{ $c < $cols - 1 ? 'border-e' : '' }} {{ $r < $rows - 1 ? 'border-b' : '' }} border-gray-200"></div> <div class="bg-gray-50/50 {{ $c < $maxCol ? 'border-e' : '' }} {{ $r < $maxRow ? 'border-b' : '' }} border-gray-200"></div>
@endif @endif
@endfor @endfor
@endfor @endfor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment