@php
$pipelines = $task->pipeline->scrumBoard->pipelines; // Getting the pipelines for easier reference
$totalPipelines = $pipelines->count(); // Total number of pipelines
$currentOrder = $task->pipeline->order; // Current order of the task's pipeline
$currentIndex = $pipelines->search(function ($pl) use ($currentOrder) {
return $pl->order === $currentOrder;
}); // Find the index of the current pipeline
@endphp
@if ($totalPipelines > 0)
{{-- If total pipelines are less than or equal to 7, show all --}}
@if ($totalPipelines <= 7)
@foreach ($pipelines as $index => $pl)
{{ $index + 1 }}
{{ $pl->name }}
@endforeach
@else
{{-- Always show the first item --}}
1
{{ $pipelines[0]->name }}
@if ($currentIndex == 0) {{-- Current is the first index --}}
@for ($i = 1; $i < min($totalPipelines, 5); $i++) {{-- Show first four items --}}
{{ $i + 1 }}
{{ $pipelines[$i]->name }}
@endfor
@if ($totalPipelines > 5) {{-- Show ellipsis if there are more items --}}
...
@endif
{{-- Always show the last item --}}
{{ $totalPipelines }}
{{ $pipelines[$totalPipelines - 1]->name }}
@elseif ($currentIndex == $totalPipelines - 1) {{-- Current is the last index --}}
@if ($totalPipelines > 5) {{-- Show ellipsis if there are more than 5 total items --}}
...
@endif
@for ($i = max(1, $totalPipelines - 5); $i < $totalPipelines; $i++) {{-- Show last four items --}}
{{ $i + 1 }}
{{ $pipelines[$i]->name }}
@endfor
@else {{-- Current is in between first and last --}}
@if ($currentIndex > 2) {{-- Show ellipsis if needed --}}
...
@endif
@for ($i = $currentIndex - 1; $i <= $currentIndex + 1; $i++) {{-- Show one before and one after current --}}
@if ($i >= 1 && $i < $totalPipelines - 1) {{-- Ensure within bounds --}}
{{ $i + 1 }}
{{ $pipelines[$i]->name }}
@endif
@endfor
@if ($currentIndex < $totalPipelines - 2) {{-- Show ellipsis if needed --}}
...
@endif
{{-- Always show the last item --}}
{{ $totalPipelines }}
{{ $pipelines[$totalPipelines - 1]->name }}
@endif
@endif
@else
No pipelines available.
@endif