feat: [menus] 메뉴 트리 상태 유지 및 활성 상태 연쇄 토글
- localStorage로 접힌 메뉴 상태 저장, HTMX 리로드 후 복원 - 상위 메뉴 활성/비활성 시 하위 메뉴 연쇄 적용 (백엔드+프론트) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -455,7 +455,7 @@ public function forceDeleteMenu(int $id): array
|
||||
}
|
||||
|
||||
/**
|
||||
* 메뉴 활성 상태 토글
|
||||
* 메뉴 활성 상태 토글 (하위 메뉴 포함)
|
||||
*/
|
||||
public function toggleActive(int $id): bool
|
||||
{
|
||||
@@ -464,10 +464,34 @@ public function toggleActive(int $id): bool
|
||||
return false;
|
||||
}
|
||||
|
||||
$menu->is_active = ! $menu->is_active;
|
||||
$newState = ! $menu->is_active;
|
||||
$menu->is_active = $newState;
|
||||
$menu->updated_by = auth()->id();
|
||||
$menu->save();
|
||||
|
||||
return $menu->save();
|
||||
// 하위 메뉴도 동일한 상태로 변경
|
||||
$this->setChildrenActiveState($menu, $newState);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 하위 메뉴의 활성 상태를 재귀적으로 변경
|
||||
*/
|
||||
private function setChildrenActiveState($menu, bool $isActive): void
|
||||
{
|
||||
$children = $menu->children()->get();
|
||||
if ($children->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$userId = auth()->id();
|
||||
foreach ($children as $child) {
|
||||
$child->is_active = $isActive;
|
||||
$child->updated_by = $userId;
|
||||
$child->save();
|
||||
$this->setChildrenActiveState($child, $isActive);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user