@extends('layouts.app') @section('page-pretitle', __('Management')) @section('page-title', __('To-Do List')) @section('content') @if ($errors->any()) @endif @if (session('success')) @endif @php use Carbon\Carbon; $weekOffset = intval(request('week', 0)); $today = Carbon::today(); // Dynamically calculate the start and end of the shifted week $startOfWeek = $today->copy()->startOfWeek()->addWeeks($weekOffset); $endOfWeek = $startOfWeek->copy()->endOfWeek(); $showStart = $startOfWeek; $showEnd = $endOfWeek; function filterTodos($todos, $start, $end) { return $todos->filter(function($todo) use ($start, $end) { return $todo->due_date && $todo->due_date->between($start, $end); }); } $weekTodos = filterTodos($todos, $showStart, $showEnd); @endphp
{{--

{{ __('To-Do Calendar View') }}

@php $weekOffset = intval(request('week', 0)); @endphp {{ __('Previous Week') }} {{ __('This Week') }} {{ __('Next Week') }}
--}} @php $week = request('week', 'this'); if ($week === 'prev') { $showStart = $prevWeekStart; $showEnd = $prevWeekEnd; } elseif ($week === 'next') { $showStart = $nextWeekStart; $showEnd = $nextWeekEnd; } else { $showStart = $startOfWeek; $showEnd = $endOfWeek; } $weekTodos = filterTodos($todos, $showStart, $showEnd); @endphp

{{ $showStart->format('M d') }} - {{ $showEnd->format('M d, Y') }}

@if (auth()->user()->role == 'admin') @endif

{{ __('Search Filter') }}

@php $weekOffset = intval(request('week', 0)); @endphp {{ __('Previous Week') }} {{ __('This Week') }} {{ __('Next Week') }}
@for($d = 0; $d < 7; $d++) @endfor @php // Prepare tasks and their date ranges clamped within week $tasks = $weekTodos->map(function($todo) use ($showStart, $showEnd) { $start = $todo->date_received ? $todo->date_received->copy() : $showStart->copy(); $end = $todo->due_date ? $todo->due_date->copy() : $start->copy(); if ($start->lt($showStart)) $start = $showStart->copy(); if ($end->gt($showEnd)) $end = $showEnd->copy(); return [ 'todo' => $todo, 'start' => $start, 'end' => $end, 'startOffset' => $showStart->diffInDays($start), 'colspan' => $start->diffInDays($end) + 1, 'row' => null, ]; })->sortBy('start')->values(); // Assign rows to avoid horizontal overlap $rows = []; foreach ($tasks as &$task) { $assignedRow = 0; while (true) { $conflict = false; if (!isset($rows[$assignedRow])) { $rows[$assignedRow] = []; } foreach ($rows[$assignedRow] as $existingTask) { $existingStart = $existingTask['startOffset']; $existingEnd = $existingTask['startOffset'] + $existingTask['colspan'] - 1; $taskStart = $task['startOffset']; $taskEnd = $taskStart + $task['colspan'] - 1; // Check for horizontal overlap if (!($taskEnd < $existingStart || $taskStart > $existingEnd)) { $conflict = true; break; } } if (!$conflict) { $task['row'] = $assignedRow; $rows[$assignedRow][] = $task; break; } $assignedRow++; } } unset($task); // break reference $maxRows = count($rows); @endphp @if ($maxRows === 0 || empty($rows) || collect($rows)->flatten()->isEmpty()) @else {{-- Render rows --}} @for ($r = 0; $r < $maxRows; $r++) @php $tasksInRow = $rows[$r]; $pos = 0; @endphp @foreach ($tasksInRow as $task) {{-- Empty cells before the task starts --}} @for (; $pos < $task['startOffset']; $pos++) @endfor {{-- Task cell --}} @php $pos += $task['colspan']; @endphp @endforeach {{-- Empty cells after the last task --}} @for (; $pos < 7; $pos++) @endfor @endfor @endif
{{ $showStart->copy()->addDays($d)->format('D') }}
{{ $showStart->copy()->addDays($d)->format('M d') }}
{{ __('No todo available') }}
@php $todo = $task['todo']; $statusColor = $todo->is_done ? 'success' : ($todo->status && strtolower($todo->status->name) === 'pending' ? 'danger' : 'warning'); @endphp
{{ $todo->title }}
{{ $todo->project->ref_no ?? '-' }}
{{ $todo->is_done ? 'Completed' : (\Illuminate\Support\Str::title($todo->status->name ?? '-')) }}
@if (auth()->user()->role == 'admin') @endif
@csrf @method('PATCH')
@if (auth()->user()->role == 'admin') is_done ? 'checked' : '' }} class="form-check-input me-1"> @endif
{{ $todo->user->name ?? '-' }}
@foreach($todos as $todo) @endforeach @endsection @section('script') @endsection