From 15a2cff453cf88b2906eae3ba6bb6109c643e683 Mon Sep 17 00:00:00 2001 From: hskwon Date: Tue, 16 Dec 2025 23:16:50 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20per=5Fpage=20=EC=84=A0=ED=83=9D=EA=B0=92=20?= =?UTF-8?q?=EB=B8=8C=EB=9D=BC=EC=9A=B0=EC=A0=80=20=EB=B3=B5=EC=9B=90=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pagination.blade.php: data-server-value 속성 추가, 즉시 실행 스크립트로 서버값 강제 설정 - pagination.js: htmx:afterSwap에서 쿠키값 대신 서버값(data-server-value) 우선 사용 - item-fields: 페이지네이션 추가, handlePageChange/handlePerPageChange 핸들러 구현 - 디버그 코드 제거 --- public/js/pagination.js | 9 ++- resources/views/item-fields/index.blade.php | 48 ++++++++++++ .../partials/custom-fields.blade.php | 74 ++++++++++++++++--- resources/views/partials/pagination.blade.php | 9 +++ 4 files changed, 129 insertions(+), 11 deletions(-) diff --git a/public/js/pagination.js b/public/js/pagination.js index b0dd2ac2..7f668007 100644 --- a/public/js/pagination.js +++ b/public/js/pagination.js @@ -114,8 +114,13 @@ document.body.addEventListener('htmx:afterSwap', function(event) { setTimeout(function() { const perPageSelect = document.getElementById('perPageSelect'); if (perPageSelect) { - const savedPerPage = getPerPageFromCookie(); - perPageSelect.value = savedPerPage; + // 서버에서 받은 값(data-server-value)을 우선 사용 + const serverValue = perPageSelect.dataset.serverValue; + if (serverValue) { + perPageSelect.value = serverValue; + // 쿠키도 서버 값으로 업데이트 + setCookie('pagination_per_page', serverValue); + } } }, 50); }); diff --git a/resources/views/item-fields/index.blade.php b/resources/views/item-fields/index.blade.php index e3eca22f..609c3238 100644 --- a/resources/views/item-fields/index.blade.php +++ b/resources/views/item-fields/index.blade.php @@ -1065,6 +1065,54 @@ function switchTab(tab) { htmx.trigger('#custom-fields', 'customRefresh'); }); + // 페이지 변경 핸들러 (pagination 컴포넌트에서 호출) + window.handlePageChange = function(page) { + const form = document.getElementById('customFilterForm'); + if (form) { + // hidden input으로 page 값 설정 + let pageInput = form.querySelector('input[name="page"]'); + if (!pageInput) { + pageInput = document.createElement('input'); + pageInput.type = 'hidden'; + pageInput.name = 'page'; + form.appendChild(pageInput); + } + pageInput.value = page; + + // customRefresh 이벤트 트리거 + htmx.trigger('#custom-fields', 'customRefresh'); + } + }; + + // 페이지당 항목 수 변경 핸들러 (pagination 컴포넌트에서 호출) + window.handlePerPageChange = function(perPage) { + const form = document.getElementById('customFilterForm'); + if (form) { + // hidden input으로 per_page 값 설정 + let perPageInput = form.querySelector('input[name="per_page"]'); + if (!perPageInput) { + perPageInput = document.createElement('input'); + perPageInput.type = 'hidden'; + perPageInput.name = 'per_page'; + form.appendChild(perPageInput); + } + perPageInput.value = perPage; + + // 페이지는 1로 리셋 + let pageInput = form.querySelector('input[name="page"]'); + if (!pageInput) { + pageInput = document.createElement('input'); + pageInput.type = 'hidden'; + pageInput.name = 'page'; + form.appendChild(pageInput); + } + pageInput.value = 1; + + // customRefresh 이벤트 트리거 + htmx.trigger('#custom-fields', 'customRefresh'); + } + }; + // 시딩 새로고침 function refreshSeeding() { htmx.trigger('#seeding-status', 'seedingRefresh'); diff --git a/resources/views/item-fields/partials/custom-fields.blade.php b/resources/views/item-fields/partials/custom-fields.blade.php index 8ce110fc..01625196 100644 --- a/resources/views/item-fields/partials/custom-fields.blade.php +++ b/resources/views/item-fields/partials/custom-fields.blade.php @@ -348,14 +348,15 @@ class="text-red-600 hover:text-red-800 p-1" title="삭제">
- 총 {{ $fields->count() }}개 @php - $systemCount = $fields->filter(fn($f) => $f->is_common || $f->storage_type === 'column')->count(); - $customCount = $fields->count() - $systemCount; - $activeCount = $fields->filter(fn($f) => $f->is_active)->count(); - $lockedCount = $fields->filter(fn($f) => $f->is_locked)->count(); - $withOptionsCount = $fields->filter(fn($f) => !empty($f->options))->count(); - $deletedCount = $fields->filter(fn($f) => !is_null($f->deleted_at))->count(); + // 현재 페이지의 항목으로 통계 계산 + $currentItems = $fields->getCollection(); + $systemCount = $currentItems->filter(fn($f) => $f->is_common || $f->storage_type === 'column')->count(); + $customCount = $currentItems->count() - $systemCount; + $activeCount = $currentItems->filter(fn($f) => $f->is_active)->count(); + $lockedCount = $currentItems->filter(fn($f) => $f->is_locked)->count(); + $withOptionsCount = $currentItems->filter(fn($f) => !empty($f->options))->count(); + $deletedCount = $currentItems->filter(fn($f) => !is_null($f->deleted_at))->count(); @endphp 시스템: {{ $systemCount }} 커스텀: {{ $customCount }} @@ -364,8 +365,8 @@ class="text-red-600 hover:text-red-800 p-1" title="삭제"> @if($deletedCount > 0) 삭제됨: {{ $deletedCount }}개 @endif - @if($activeCount < $fields->count()) - 비활성: {{ $fields->count() - $activeCount }}개 + @if($activeCount < $currentItems->count()) + 비활성: {{ $currentItems->count() - $activeCount }}개 @endif @if($lockedCount > 0) 잠금: {{ $lockedCount }}개 @@ -377,6 +378,13 @@ class="text-red-600 hover:text-red-800 p-1" title="삭제">
+ + @include('partials.pagination', [ + 'paginator' => $fields, + 'target' => '#custom-fields', + 'includeForm' => '#customFilterForm' + ]) + @endif \ No newline at end of file diff --git a/resources/views/partials/pagination.blade.php b/resources/views/partials/pagination.blade.php index 2142e7fc..720781e1 100644 --- a/resources/views/partials/pagination.blade.php +++ b/resources/views/partials/pagination.blade.php @@ -51,6 +51,8 @@ class="ml-3 relative inline-flex items-center px-4 py-2 border border-gray-300 t + {{-- 브라우저 form restoration 방지: 서버 값으로 강제 설정 --}} +