feat:대시보드 일정관리 달력 추가

- Schedule 모델 생성 (schedules 테이블, type별 색상 상수)
- DashboardCalendarController 생성 (CRUD + 달력 partial)
- 대시보드 뷰에 월간 달력 섹션 추가 (HTMX + Vanilla JS)
- 일정 생성/수정/삭제 모달 구현
- 공휴일 빨간색 표시, 일정 유형별 색상 뱃지

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
김보곤
2026-02-10 20:11:36 +09:00
parent 00dff8951c
commit 0281e4a8aa
5 changed files with 737 additions and 2 deletions

View File

@@ -0,0 +1,171 @@
<?php
namespace App\Http\Controllers;
use App\Models\System\Holiday;
use App\Models\System\Schedule;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Contracts\View\View;
class DashboardCalendarController extends Controller
{
/**
* 달력 partial 반환 (HTMX용)
*/
public function calendar(Request $request): View
{
$year = (int) $request->input('year', now()->year);
$month = (int) $request->input('month', now()->month);
$tenantId = session('selected_tenant_id', 1);
$firstDay = Carbon::create($year, $month, 1);
$lastDay = $firstDay->copy()->endOfMonth();
$startOfWeek = $firstDay->copy()->startOfWeek(Carbon::SUNDAY);
$endOfWeek = $lastDay->copy()->endOfWeek(Carbon::SATURDAY);
$calendarData = Schedule::forTenant($tenantId)
->active()
->betweenDates($startOfWeek->toDateString(), $endOfWeek->toDateString())
->orderBy('start_date')
->orderBy('start_time')
->get()
->groupBy(fn ($s) => $s->start_date->format('Y-m-d'));
$holidayMap = $this->getHolidayMap($tenantId, $year, $month);
return view('dashboard.partials.calendar', compact(
'year', 'month', 'calendarData', 'holidayMap'
));
}
/**
* 일정 등록
*/
public function store(Request $request): JsonResponse
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'description' => 'nullable|string|max:1000',
'start_date' => 'required|date',
'end_date' => 'nullable|date|after_or_equal:start_date',
'start_time' => 'nullable|date_format:H:i',
'end_time' => 'nullable|date_format:H:i',
'is_all_day' => 'boolean',
'type' => 'required|in:event,meeting,notice,other',
'color' => 'nullable|string|max:20',
]);
$tenantId = session('selected_tenant_id', 1);
$validated['tenant_id'] = $tenantId;
$validated['created_by'] = auth()->id();
$validated['is_all_day'] = $validated['is_all_day'] ?? true;
if (empty($validated['end_date'])) {
$validated['end_date'] = $validated['start_date'];
}
$schedule = Schedule::create($validated);
return response()->json([
'success' => true,
'message' => '일정이 등록되었습니다.',
'data' => $schedule,
]);
}
/**
* 일정 상세 (JSON)
*/
public function show(int $id): JsonResponse
{
$tenantId = session('selected_tenant_id', 1);
$schedule = Schedule::forTenant($tenantId)->findOrFail($id);
return response()->json([
'success' => true,
'data' => $schedule,
]);
}
/**
* 일정 수정
*/
public function update(Request $request, int $id): JsonResponse
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'description' => 'nullable|string|max:1000',
'start_date' => 'required|date',
'end_date' => 'nullable|date|after_or_equal:start_date',
'start_time' => 'nullable|date_format:H:i',
'end_time' => 'nullable|date_format:H:i',
'is_all_day' => 'boolean',
'type' => 'required|in:event,meeting,notice,other',
'color' => 'nullable|string|max:20',
]);
$tenantId = session('selected_tenant_id', 1);
$schedule = Schedule::forTenant($tenantId)->findOrFail($id);
$validated['updated_by'] = auth()->id();
$validated['is_all_day'] = $validated['is_all_day'] ?? true;
if (empty($validated['end_date'])) {
$validated['end_date'] = $validated['start_date'];
}
$schedule->update($validated);
return response()->json([
'success' => true,
'message' => '일정이 수정되었습니다.',
'data' => $schedule->fresh(),
]);
}
/**
* 일정 삭제
*/
public function destroy(int $id): JsonResponse
{
$tenantId = session('selected_tenant_id', 1);
$schedule = Schedule::forTenant($tenantId)->findOrFail($id);
$schedule->update(['deleted_by' => auth()->id()]);
$schedule->delete();
return response()->json([
'success' => true,
'message' => '일정이 삭제되었습니다.',
]);
}
/**
* 해당 월의 휴일 맵 생성 (날짜 => 휴일명)
*/
private function getHolidayMap(int $tenantId, int $year, int $month): array
{
$startOfMonth = Carbon::create($year, $month, 1)->startOfWeek(Carbon::SUNDAY);
$endOfMonth = Carbon::create($year, $month, 1)->endOfMonth()->endOfWeek(Carbon::SATURDAY);
$holidays = Holiday::forTenant($tenantId)
->where('start_date', '<=', $endOfMonth->toDateString())
->where('end_date', '>=', $startOfMonth->toDateString())
->get();
$map = [];
foreach ($holidays as $holiday) {
$start = $holiday->start_date->copy();
$end = $holiday->end_date->copy();
for ($d = $start; $d->lte($end); $d->addDay()) {
$map[$d->format('Y-m-d')] = $holiday->name;
}
}
return $map;
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace App\Models\System;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Schedule extends Model
{
use SoftDeletes;
protected $table = 'schedules';
protected $fillable = [
'tenant_id',
'title',
'description',
'start_date',
'end_date',
'start_time',
'end_time',
'is_all_day',
'type',
'is_recurring',
'recurrence_rule',
'color',
'is_active',
'created_by',
'updated_by',
'deleted_by',
];
protected $casts = [
'start_date' => 'date',
'end_date' => 'date',
'is_all_day' => 'boolean',
'is_recurring' => 'boolean',
'is_active' => 'boolean',
];
protected $attributes = [
'is_all_day' => true,
'type' => 'event',
'is_recurring' => false,
'is_active' => true,
];
public const TYPE_EVENT = 'event';
public const TYPE_MEETING = 'meeting';
public const TYPE_NOTICE = 'notice';
public const TYPE_OTHER = 'other';
public const TYPES = [
self::TYPE_EVENT => '일정',
self::TYPE_MEETING => '회의',
self::TYPE_NOTICE => '공지',
self::TYPE_OTHER => '기타',
];
public const TYPE_COLORS = [
self::TYPE_EVENT => ['bg' => 'bg-emerald-50', 'text' => 'text-emerald-700', 'border' => 'border-emerald-200'],
self::TYPE_MEETING => ['bg' => 'bg-blue-50', 'text' => 'text-blue-700', 'border' => 'border-blue-200'],
self::TYPE_NOTICE => ['bg' => 'bg-amber-50', 'text' => 'text-amber-700', 'border' => 'border-amber-200'],
self::TYPE_OTHER => ['bg' => 'bg-gray-50', 'text' => 'text-gray-700', 'border' => 'border-gray-200'],
];
public function scopeForTenant(Builder $query, int $tenantId): Builder
{
return $query->where(function ($q) use ($tenantId) {
$q->where('tenant_id', $tenantId)
->orWhereNull('tenant_id');
});
}
public function scopeActive(Builder $query): Builder
{
return $query->where('is_active', true);
}
public function scopeBetweenDates(Builder $query, string $startDate, string $endDate): Builder
{
return $query->where(function ($q) use ($startDate, $endDate) {
$q->where('start_date', '<=', $endDate)
->where(function ($inner) use ($startDate) {
$inner->where('end_date', '>=', $startDate)
->orWhereNull('end_date');
});
});
}
public function getTypeLabelAttribute(): string
{
return self::TYPES[$this->type] ?? $this->type;
}
public function getTypeColorsAttribute(): array
{
return self::TYPE_COLORS[$this->type] ?? self::TYPE_COLORS[self::TYPE_OTHER];
}
}

View File

@@ -30,7 +30,7 @@
</div>
</div>
<!-- Quick Actions (예시) -->
<!-- Quick Actions -->
<div class="mt-6 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<div class="bg-white rounded-lg shadow p-6 hover:shadow-lg transition-shadow">
<h3 class="text-lg font-semibold text-gray-900 mb-2">사용자 관리</h3>
@@ -65,4 +65,305 @@
</a>
</div>
</div>
@endsection
<!-- Calendar Section -->
<div class="mt-6 bg-white rounded-lg shadow p-6">
<div id="calendar-container"
hx-get="{{ route('dashboard.calendar', ['year' => now()->year, 'month' => now()->month]) }}"
hx-trigger="load"
hx-swap="innerHTML">
<div class="flex items-center justify-center py-12">
<svg class="animate-spin h-8 w-8 text-emerald-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
<span class="ml-3 text-gray-500">달력을 불러오는 ...</span>
</div>
</div>
</div>
<!-- Schedule Modal -->
<div id="schedule-modal" class="fixed inset-0 z-50 hidden">
<div class="fixed inset-0 bg-black/50" onclick="closeModal()"></div>
<div class="fixed inset-0 flex items-center justify-center p-4">
<div class="bg-white rounded-xl shadow-2xl w-full max-w-lg relative" onclick="event.stopPropagation()">
<!-- Modal Header -->
<div class="flex items-center justify-between px-6 py-4 border-b">
<h3 id="modal-title" class="text-lg font-bold text-gray-900">일정 추가</h3>
<button type="button" onclick="closeModal()" class="text-gray-400 hover:text-gray-600 transition-colors">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
</svg>
</button>
</div>
<!-- Modal Body -->
<form id="schedule-form" class="px-6 py-4 space-y-4">
<input type="hidden" id="schedule-id" value="">
<!-- 제목 -->
<div>
<label for="schedule-title" class="block text-sm font-medium text-gray-700 mb-1">제목 <span class="text-red-500">*</span></label>
<input type="text" id="schedule-title" name="title" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500 text-sm"
placeholder="일정 제목을 입력하세요">
</div>
<!-- 유형 -->
<div>
<label for="schedule-type" class="block text-sm font-medium text-gray-700 mb-1">유형</label>
<select id="schedule-type" name="type"
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500 text-sm">
<option value="event">일정</option>
<option value="meeting">회의</option>
<option value="notice">공지</option>
<option value="other">기타</option>
</select>
</div>
<!-- 날짜 -->
<div class="grid grid-cols-2 gap-3">
<div>
<label for="schedule-start-date" class="block text-sm font-medium text-gray-700 mb-1">시작일 <span class="text-red-500">*</span></label>
<input type="date" id="schedule-start-date" name="start_date" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500 text-sm">
</div>
<div>
<label for="schedule-end-date" class="block text-sm font-medium text-gray-700 mb-1">종료일</label>
<input type="date" id="schedule-end-date" name="end_date"
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500 text-sm">
</div>
</div>
<!-- 종일 체크 + 시간 -->
<div>
<label class="inline-flex items-center gap-2 cursor-pointer">
<input type="checkbox" id="schedule-all-day" name="is_all_day" checked
class="w-4 h-4 text-emerald-600 border-gray-300 rounded focus:ring-emerald-500"
onchange="toggleTimeFields()">
<span class="text-sm text-gray-700">종일</span>
</label>
</div>
<div id="time-fields" class="grid grid-cols-2 gap-3 hidden">
<div>
<label for="schedule-start-time" class="block text-sm font-medium text-gray-700 mb-1">시작 시간</label>
<input type="time" id="schedule-start-time" name="start_time"
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500 text-sm">
</div>
<div>
<label for="schedule-end-time" class="block text-sm font-medium text-gray-700 mb-1">종료 시간</label>
<input type="time" id="schedule-end-time" name="end_time"
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500 text-sm">
</div>
</div>
<!-- 설명 -->
<div>
<label for="schedule-description" class="block text-sm font-medium text-gray-700 mb-1">설명</label>
<textarea id="schedule-description" name="description" rows="3"
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500 text-sm"
placeholder="일정에 대한 설명을 입력하세요 (선택)"></textarea>
</div>
</form>
<!-- Modal Footer -->
<div class="flex items-center justify-between px-6 py-4 border-t bg-gray-50 rounded-b-xl">
<div>
<button type="button" id="btn-delete" onclick="deleteSchedule()" class="hidden px-4 py-2 text-sm text-red-600 hover:text-red-700 hover:bg-red-50 rounded-lg transition-colors">
삭제
</button>
</div>
<div class="flex items-center gap-2">
<button type="button" onclick="closeModal()" class="px-4 py-2 text-sm text-gray-600 hover:text-gray-700 hover:bg-gray-100 rounded-lg transition-colors">
취소
</button>
<button type="button" id="btn-save" onclick="saveSchedule()" class="px-4 py-2 text-sm bg-emerald-600 hover:bg-emerald-700 text-white rounded-lg transition-colors">
저장
</button>
</div>
</div>
</div>
</div>
</div>
@endsection
@push('scripts')
<script>
const CSRF_TOKEN = '{{ csrf_token() }}';
// 모달 열기 (생성 모드)
function openCreateModal(dateKey) {
document.getElementById('modal-title').textContent = '일정 추가';
document.getElementById('schedule-id').value = '';
document.getElementById('schedule-form').reset();
document.getElementById('schedule-all-day').checked = true;
document.getElementById('btn-delete').classList.add('hidden');
toggleTimeFields();
if (dateKey) {
document.getElementById('schedule-start-date').value = dateKey;
document.getElementById('schedule-end-date').value = dateKey;
} else {
const today = new Date().toISOString().split('T')[0];
document.getElementById('schedule-start-date').value = today;
document.getElementById('schedule-end-date').value = today;
}
document.getElementById('schedule-modal').classList.remove('hidden');
}
// 모달 열기 (수정 모드)
async function openEditModal(id) {
try {
const res = await fetch(`/dashboard/schedules/${id}`, {
headers: { 'Accept': 'application/json', 'X-CSRF-TOKEN': CSRF_TOKEN }
});
const json = await res.json();
if (!json.success) throw new Error(json.message || '일정을 불러올 수 없습니다.');
const s = json.data;
document.getElementById('modal-title').textContent = '일정 수정';
document.getElementById('schedule-id').value = s.id;
document.getElementById('schedule-title').value = s.title || '';
document.getElementById('schedule-type').value = s.type || 'event';
document.getElementById('schedule-start-date').value = s.start_date ? s.start_date.split('T')[0] : '';
document.getElementById('schedule-end-date').value = s.end_date ? s.end_date.split('T')[0] : '';
document.getElementById('schedule-all-day').checked = s.is_all_day;
document.getElementById('schedule-start-time').value = s.start_time ? s.start_time.substring(0, 5) : '';
document.getElementById('schedule-end-time').value = s.end_time ? s.end_time.substring(0, 5) : '';
document.getElementById('schedule-description').value = s.description || '';
document.getElementById('btn-delete').classList.remove('hidden');
toggleTimeFields();
document.getElementById('schedule-modal').classList.remove('hidden');
} catch (e) {
alert(e.message || '일정을 불러올 수 없습니다.');
}
}
// 모달 닫기
function closeModal() {
document.getElementById('schedule-modal').classList.add('hidden');
}
// 종일 토글
function toggleTimeFields() {
const allDay = document.getElementById('schedule-all-day').checked;
document.getElementById('time-fields').classList.toggle('hidden', allDay);
if (allDay) {
document.getElementById('schedule-start-time').value = '';
document.getElementById('schedule-end-time').value = '';
}
}
// 저장
async function saveSchedule() {
const id = document.getElementById('schedule-id').value;
const isEdit = !!id;
const body = {
title: document.getElementById('schedule-title').value.trim(),
type: document.getElementById('schedule-type').value,
start_date: document.getElementById('schedule-start-date').value,
end_date: document.getElementById('schedule-end-date').value || document.getElementById('schedule-start-date').value,
is_all_day: document.getElementById('schedule-all-day').checked,
start_time: document.getElementById('schedule-start-time').value || null,
end_time: document.getElementById('schedule-end-time').value || null,
description: document.getElementById('schedule-description').value.trim() || null,
};
if (!body.title) { alert('제목을 입력하세요.'); return; }
if (!body.start_date) { alert('시작일을 선택하세요.'); return; }
const url = isEdit ? `/dashboard/schedules/${id}` : '/dashboard/schedules';
const method = isEdit ? 'PUT' : 'POST';
try {
const res = await fetch(url, {
method,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-CSRF-TOKEN': CSRF_TOKEN,
},
body: JSON.stringify(body),
});
const json = await res.json();
if (!res.ok) {
if (json.errors) {
const msgs = Object.values(json.errors).flat().join('\n');
alert(msgs);
} else {
alert(json.message || '저장에 실패했습니다.');
}
return;
}
closeModal();
htmx.trigger('#calendar-container', 'htmx:load');
// HTMX로 달력 갱신
const calendarEl = document.getElementById('calendar-container');
const currentUrl = calendarEl.getAttribute('hx-get') || calendarEl.querySelector('[hx-get]')?.getAttribute('hx-get');
if (currentUrl) {
htmx.ajax('GET', currentUrl, { target: '#calendar-container', swap: 'innerHTML' });
} else {
refreshCalendar();
}
} catch (e) {
alert('저장 중 오류가 발생했습니다.');
}
}
// 삭제
async function deleteSchedule() {
const id = document.getElementById('schedule-id').value;
if (!id) return;
if (!confirm('이 일정을 삭제하시겠습니까?')) return;
try {
const res = await fetch(`/dashboard/schedules/${id}`, {
method: 'DELETE',
headers: {
'Accept': 'application/json',
'X-CSRF-TOKEN': CSRF_TOKEN,
},
});
const json = await res.json();
if (!res.ok) { alert(json.message || '삭제에 실패했습니다.'); return; }
closeModal();
refreshCalendar();
} catch (e) {
alert('삭제 중 오류가 발생했습니다.');
}
}
// 달력 갱신 헬퍼
function refreshCalendar() {
const container = document.getElementById('calendar-container');
// 현재 로드된 달력의 년/월 정보를 가져오기 위해 마지막 HTMX URL 추출
const prevBtn = container.querySelector('button[hx-get]');
if (prevBtn) {
const url = prevBtn.getAttribute('hx-get');
// URL에서 year, month 파라미터 추출 후 현재 달로 재요청
const params = new URLSearchParams(url.split('?')[1]);
// 이전달 버튼이므로 +1달이 현재달
let year = parseInt(params.get('year'));
let month = parseInt(params.get('month')) + 1;
if (month > 12) { month = 1; year++; }
htmx.ajax('GET', `/dashboard/calendar?year=${year}&month=${month}`, { target: '#calendar-container', swap: 'innerHTML' });
} else {
// 달력이 아직 로드 안됐으면 현재 월로 로드
const now = new Date();
htmx.ajax('GET', `/dashboard/calendar?year=${now.getFullYear()}&month=${now.getMonth()+1}`, { target: '#calendar-container', swap: 'innerHTML' });
}
}
// ESC 키로 모달 닫기
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') closeModal();
});
</script>
@endpush

View File

@@ -0,0 +1,152 @@
{{-- 대시보드 달력 그리드 (HTMX로 로드) --}}
@php
use Carbon\Carbon;
use App\Models\System\Schedule;
$firstDay = Carbon::create($year, $month, 1);
$lastDay = $firstDay->copy()->endOfMonth();
$startOfWeek = $firstDay->copy()->startOfWeek(Carbon::SUNDAY);
$endOfWeek = $lastDay->copy()->endOfWeek(Carbon::SATURDAY);
$today = Carbon::today();
$prevMonth = $firstDay->copy()->subMonth();
$nextMonth = $firstDay->copy()->addMonth();
@endphp
{{-- 달력 헤더 --}}
<div class="flex items-center justify-between mb-4">
<div class="flex items-center gap-3">
<button type="button"
hx-get="{{ route('dashboard.calendar', ['year' => $prevMonth->year, 'month' => $prevMonth->month]) }}"
hx-target="#calendar-container"
hx-swap="innerHTML"
class="p-2 hover:bg-gray-100 rounded-lg transition-colors">
<svg class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
</svg>
</button>
<h2 class="text-xl font-bold text-gray-800">{{ $year }} {{ $month }}</h2>
<button type="button"
hx-get="{{ route('dashboard.calendar', ['year' => $nextMonth->year, 'month' => $nextMonth->month]) }}"
hx-target="#calendar-container"
hx-swap="innerHTML"
class="p-2 hover:bg-gray-100 rounded-lg transition-colors">
<svg class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
</svg>
</button>
@if(!$today->isSameMonth($firstDay))
<button type="button"
hx-get="{{ route('dashboard.calendar', ['year' => $today->year, 'month' => $today->month]) }}"
hx-target="#calendar-container"
hx-swap="innerHTML"
class="ml-2 px-3 py-1 text-sm bg-gray-100 hover:bg-gray-200 text-gray-600 rounded-lg transition-colors">
오늘
</button>
@endif
</div>
<button type="button" onclick="openCreateModal()"
class="inline-flex items-center gap-2 px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-white rounded-lg transition-colors text-sm">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
일정 추가
</button>
</div>
{{-- 달력 그리드 --}}
<div class="overflow-x-auto">
<table class="w-full border-collapse">
<thead>
<tr class="bg-gray-50">
<th class="px-2 py-3 text-center text-sm font-semibold text-red-500 border-b w-[14.28%]"></th>
<th class="px-2 py-3 text-center text-sm font-semibold text-gray-600 border-b w-[14.28%]"></th>
<th class="px-2 py-3 text-center text-sm font-semibold text-gray-600 border-b w-[14.28%]"></th>
<th class="px-2 py-3 text-center text-sm font-semibold text-gray-600 border-b w-[14.28%]"></th>
<th class="px-2 py-3 text-center text-sm font-semibold text-gray-600 border-b w-[14.28%]"></th>
<th class="px-2 py-3 text-center text-sm font-semibold text-gray-600 border-b w-[14.28%]"></th>
<th class="px-2 py-3 text-center text-sm font-semibold text-blue-500 border-b w-[14.28%]"></th>
</tr>
</thead>
<tbody>
@php
$currentDate = $startOfWeek->copy();
@endphp
@while($currentDate <= $endOfWeek)
<tr>
@for($i = 0; $i < 7; $i++)
@php
$dateKey = $currentDate->format('Y-m-d');
$isCurrentMonth = $currentDate->month === $month;
$isToday = $currentDate->isSameDay($today);
$isSunday = $currentDate->dayOfWeek === Carbon::SUNDAY;
$isSaturday = $currentDate->dayOfWeek === Carbon::SATURDAY;
$daySchedules = $calendarData[$dateKey] ?? collect();
$holidayName = $holidayMap[$dateKey] ?? null;
$isHoliday = $holidayName !== null;
@endphp
<td class="border border-gray-100 align-top {{ !$isCurrentMonth ? 'bg-gray-50/50' : '' }}">
<div class="p-1 min-h-[7rem]">
{{-- 날짜 헤더 --}}
<div class="flex items-center justify-between mb-1">
<div class="flex items-center gap-1.5">
<span class="{{ $isHoliday && $isCurrentMonth ? 'text-base font-bold' : 'text-sm font-medium' }}
{{ !$isCurrentMonth ? 'text-gray-300' : '' }}
{{ $isCurrentMonth && ($isSunday || $isHoliday) ? 'text-red-500' : '' }}
{{ $isCurrentMonth && $isSaturday && !$isHoliday ? 'text-blue-500' : '' }}
{{ $isCurrentMonth && !$isSunday && !$isSaturday && !$isHoliday ? 'text-gray-700' : '' }}
{{ $isToday ? 'bg-emerald-500 !text-white rounded-full w-6 h-6 flex items-center justify-center' : '' }}
">
{{ $currentDate->day }}
</span>
@if($isHoliday && $isCurrentMonth)
<span class="text-xs text-red-500 font-bold truncate max-w-[80px]" title="{{ $holidayName }}">{{ $holidayName }}</span>
@endif
</div>
@if($isCurrentMonth)
<button type="button" onclick="openCreateModal('{{ $dateKey }}')"
class="text-gray-300 hover:text-emerald-600 hover:bg-emerald-50 rounded transition-colors p-0.5"
title="{{ $currentDate->format('m/d') }} 일정 추가">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
</button>
@endif
</div>
{{-- 일정 목록 --}}
<div class="space-y-0.5">
@foreach($daySchedules as $schedule)
@php
$colors = $schedule->type_colors;
@endphp
<button type="button" onclick="openEditModal({{ $schedule->id }})"
class="block w-full text-left px-1.5 py-0.5 rounded text-xs truncate border cursor-pointer hover:opacity-80 transition-opacity
{{ $colors['bg'] }} {{ $colors['text'] }} {{ $colors['border'] }}"
title="{{ $schedule->title }}{{ !$schedule->is_all_day && $schedule->start_time ? ' ('.$schedule->start_time.')' : '' }}">
@if(!$schedule->is_all_day && $schedule->start_time)
<span class="font-medium">{{ \Carbon\Carbon::parse($schedule->start_time)->format('H:i') }}</span>
@endif
<span class="truncate">{{ $schedule->title }}</span>
</button>
@endforeach
</div>
</div>
</td>
@php
$currentDate->addDay();
@endphp
@endfor
</tr>
@endwhile
</tbody>
</table>
</div>

View File

@@ -618,9 +618,19 @@
// 대시보드
Route::get('/dashboard', function () {
if (request()->header('HX-Request')) {
return response('', 200)->header('HX-Redirect', route('dashboard'));
}
return view('dashboard.index');
})->name('dashboard');
// 대시보드 달력
Route::get('/dashboard/calendar', [\App\Http\Controllers\DashboardCalendarController::class, 'calendar'])->name('dashboard.calendar');
Route::post('/dashboard/schedules', [\App\Http\Controllers\DashboardCalendarController::class, 'store'])->name('dashboard.schedules.store');
Route::get('/dashboard/schedules/{id}', [\App\Http\Controllers\DashboardCalendarController::class, 'show'])->name('dashboard.schedules.show');
Route::put('/dashboard/schedules/{id}', [\App\Http\Controllers\DashboardCalendarController::class, 'update'])->name('dashboard.schedules.update');
Route::delete('/dashboard/schedules/{id}', [\App\Http\Controllers\DashboardCalendarController::class, 'destroy'])->name('dashboard.schedules.destroy');
// 루트 리다이렉트
Route::get('/', function () {
return redirect()->route('dashboard');