- 트리 구조 정렬 및 표시 (무제한 depth 지원) - 접기/펼치기 기능 추가 (재귀적 처리) - 활성/숨김 상태 토글 기능 (실시간 업데이트) - 테넌트 필터링 (전체 선택 시 마스터 메뉴만 표시) - UI 개선 (토글 버튼, 외부 메뉴 표시) 추가된 파일: - MenuService: 비즈니스 로직 처리 - MenuController (API/Web): 라우트 처리 - MenuRequest: 유효성 검증 - views/menus/: 메뉴 관리 뷰 수정된 파일: - routes/api.php, web.php: 메뉴 라우트 추가
195 lines
6.9 KiB
PHP
195 lines
6.9 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('title', '메뉴 관리')
|
|
|
|
@section('content')
|
|
<!-- Tenant Selector -->
|
|
@include('partials.tenant-selector')
|
|
|
|
<!-- 페이지 헤더 -->
|
|
<div class="flex justify-between items-center mt-6 mb-6">
|
|
<h1 class="text-2xl font-bold text-gray-800">📋 메뉴 관리</h1>
|
|
<a href="{{ route('menus.create') }}" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition">
|
|
+ 새 메뉴
|
|
</a>
|
|
</div>
|
|
|
|
<!-- 필터 영역 -->
|
|
<div class="bg-white rounded-lg shadow-sm p-4 mb-6">
|
|
<form id="filterForm" class="flex gap-4">
|
|
<!-- 검색 -->
|
|
<div class="flex-1">
|
|
<input type="text"
|
|
name="search"
|
|
placeholder="메뉴명, URL로 검색..."
|
|
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
|
|
</div>
|
|
|
|
<!-- 활성 상태 필터 -->
|
|
<div class="w-48">
|
|
<select name="is_active" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
|
|
<option value="">전체 상태</option>
|
|
<option value="1">활성</option>
|
|
<option value="0">비활성</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- 검색 버튼 -->
|
|
<button type="submit" class="bg-gray-600 hover:bg-gray-700 text-white px-6 py-2 rounded-lg transition">
|
|
검색
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- 테이블 영역 (HTMX로 로드) -->
|
|
<div id="menu-table"
|
|
hx-get="/api/admin/menus"
|
|
hx-trigger="load, filterSubmit from:body"
|
|
hx-include="#filterForm"
|
|
hx-headers='{"X-CSRF-TOKEN": "{{ csrf_token() }}"}'
|
|
class="bg-white rounded-lg shadow-sm overflow-hidden">
|
|
<!-- 로딩 스피너 -->
|
|
<div class="flex justify-center items-center p-12">
|
|
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
|
|
<script>
|
|
// 폼 제출 시 HTMX 이벤트 트리거
|
|
document.getElementById('filterForm').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
htmx.trigger('#menu-table', 'filterSubmit');
|
|
});
|
|
|
|
// HTMX 응답 처리
|
|
document.body.addEventListener('htmx:afterSwap', function(event) {
|
|
if (event.detail.target.id === 'menu-table') {
|
|
const response = JSON.parse(event.detail.xhr.response);
|
|
if (response.html) {
|
|
event.detail.target.innerHTML = response.html;
|
|
}
|
|
}
|
|
});
|
|
|
|
// 삭제 확인
|
|
window.confirmDelete = function(id, name) {
|
|
if (confirm(`"${name}" 메뉴를 삭제하시겠습니까?`)) {
|
|
htmx.ajax('DELETE', `/api/admin/menus/${id}`, {
|
|
target: '#menu-table',
|
|
swap: 'none',
|
|
headers: {
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
}).then(() => {
|
|
htmx.trigger('#menu-table', 'filterSubmit');
|
|
});
|
|
}
|
|
};
|
|
|
|
// 복원 확인
|
|
window.confirmRestore = function(id, name) {
|
|
if (confirm(`"${name}" 메뉴를 복원하시겠습니까?`)) {
|
|
htmx.ajax('POST', `/api/admin/menus/${id}/restore`, {
|
|
target: '#menu-table',
|
|
swap: 'none',
|
|
headers: {
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
}).then(() => {
|
|
htmx.trigger('#menu-table', 'filterSubmit');
|
|
});
|
|
}
|
|
};
|
|
|
|
// 영구삭제 확인
|
|
window.confirmForceDelete = function(id, name) {
|
|
if (confirm(`⚠️ 경고: "${name}" 메뉴를 영구 삭제하시겠습니까?\n\n이 작업은 되돌릴 수 없습니다!`)) {
|
|
htmx.ajax('DELETE', `/api/admin/menus/${id}/force`, {
|
|
target: '#menu-table',
|
|
swap: 'none',
|
|
headers: {
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
}).then(() => {
|
|
htmx.trigger('#menu-table', 'filterSubmit');
|
|
});
|
|
}
|
|
};
|
|
|
|
// 활성 토글
|
|
window.toggleActive = function(id) {
|
|
htmx.ajax('POST', `/api/admin/menus/${id}/toggle-active`, {
|
|
target: '#menu-table',
|
|
swap: 'none',
|
|
headers: {
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
}).then(() => {
|
|
htmx.trigger('#menu-table', 'filterSubmit');
|
|
});
|
|
};
|
|
|
|
// 숨김 토글
|
|
window.toggleHidden = function(id) {
|
|
htmx.ajax('POST', `/api/admin/menus/${id}/toggle-hidden`, {
|
|
target: '#menu-table',
|
|
swap: 'none',
|
|
headers: {
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
}).then(() => {
|
|
htmx.trigger('#menu-table', 'filterSubmit');
|
|
});
|
|
};
|
|
|
|
// 자식 메뉴 접기/펼치기
|
|
window.toggleChildren = function(menuId) {
|
|
const button = document.querySelector(`.toggle-btn[data-menu-id="${menuId}"]`);
|
|
const svg = button.querySelector('svg');
|
|
const isCollapsed = svg.classList.contains('rotate-[-90deg]');
|
|
|
|
if (isCollapsed) {
|
|
// 펼치기
|
|
svg.classList.remove('rotate-[-90deg]');
|
|
showChildren(menuId);
|
|
} else {
|
|
// 접기
|
|
svg.classList.add('rotate-[-90deg]');
|
|
hideChildren(menuId);
|
|
}
|
|
};
|
|
|
|
// 재귀적으로 자식 메뉴 숨기기
|
|
function hideChildren(parentId) {
|
|
const children = document.querySelectorAll(`tr.menu-row[data-parent-id="${parentId}"]`);
|
|
children.forEach(child => {
|
|
child.style.display = 'none';
|
|
const childId = child.getAttribute('data-menu-id');
|
|
// 하위의 하위도 숨기기
|
|
hideChildren(childId);
|
|
});
|
|
}
|
|
|
|
// 재귀적으로 직계 자식만 표시
|
|
function showChildren(parentId) {
|
|
const children = document.querySelectorAll(`tr.menu-row[data-parent-id="${parentId}"]`);
|
|
children.forEach(child => {
|
|
child.style.display = '';
|
|
// 하위 메뉴는 해당 메뉴가 펼쳐져 있을 때만 표시
|
|
const childId = child.getAttribute('data-menu-id');
|
|
const childButton = child.querySelector(`.toggle-btn[data-menu-id="${childId}"]`);
|
|
if (childButton) {
|
|
const childSvg = childButton.querySelector('svg');
|
|
// 자식이 접혀있으면 그 하위는 보여주지 않음
|
|
if (!childSvg.classList.contains('rotate-[-90deg]')) {
|
|
showChildren(childId);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
@endpush
|