sidebar 처리 로직 추가

dev
박성영 5 months ago
parent 79e8c0936e
commit aa701d76b9

@ -6,6 +6,7 @@ import go.kr.project.common.notification.model.NotificationVO;
import go.kr.project.common.service.CommonHeaderService;
import go.kr.project.template.calendarSample.model.CalendarScheduleVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -13,12 +14,12 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RequestMapping("/common/header")
@ -86,4 +87,33 @@ public class CommonHeaderController {
return ApiResponseUtil.error("알림 읽음 처리 중 오류가 발생했습니다: " + e.getMessage());
}
}
/**
* API
*
* @param state (collapsed, expanded, )
* @param session HTTP
* @return
*/
@PostMapping("/sidebar/state.ajax")
@ResponseBody
@Operation(summary = "사이드바 상태 저장", description = "사이드바 상태를 세션에 저장합니다.")
public ResponseEntity<Map<String, Object>> saveSidebarState(
@Parameter(description = "사이드바 상태 (sidebar-collapse, 또는 빈 문자열)")
@RequestParam(value = "state", required = false, defaultValue = "") String state,
HttpSession session) {
// 세션에 사이드바 상태 저장
session.setAttribute("sidebarState", state);
log.debug("사이드바 상태 저장: {}", state);
// 응답 데이터 구성
Map<String, Object> response = new HashMap<>();
response.put("result", true);
response.put("message", "사이드바 상태가 저장되었습니다.");
return ResponseEntity.ok(response);
}
}

@ -79,7 +79,7 @@
<link rel="stylesheet" href="<c:url value="/css/xit-multi-fileupload.css"/>" />
</head>
<body>
<body class="${sessionScope.sidebarState}">
<!-- Sidebar -->
<div class="sidebar">
<tiles:insertAttribute name="menu_header" />

@ -7,7 +7,7 @@
<!-- Main header -->
<div class="main-header">
<!-- 사이드바 토글 버튼 -->
<a class="nav-link nav-link-faded rounded-circle nav-icon" href="#" data-toggle="sidebar">
<a class="nav-link nav-link-faded rounded-circle nav-icon" href="#" data-toggle="sidebar" id="saveSidebarState">
<i class="material-icons">menu</i>
</a>
@ -125,6 +125,28 @@ $(document).ready(function() {
// 세션 타이머 초기화
initSessionTimer();
$(document).on('click', '#saveSidebarState', function () {
var saveSidebarStateValue = "sidebar-collapse";
if( $("body").hasClass("sidebar-collapse") ){
saveSidebarStateValue = ""
}
console.log(saveSidebarStateValue);
// AJAX 요청으로 사이드바 상태 저장
$.ajax({
url: "<c:url value='/common/header/sidebar/state.ajax'/>",
type: "POST",
data: {"state":saveSidebarStateValue},
dataType: "json",
success: function(response) {
//console.log("사이드바 상태 저장 성공:", response);
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
}
});
});
/**
* 드롭다운 메뉴 초기화 함수
*/

@ -44,7 +44,7 @@ $(function() {
// 메뉴 경로가 있으면 content_header에 추가
if (currentMenuPath) {
$('.sub_title').text(currentMenuPath + ' ' +$('.sub_title').text());
$('.sub_title').text(currentMenuPath + ' ' +$('.sub_title').text()).show();
}
}
@ -53,5 +53,5 @@ $(function() {
setTimeout(function() {
//initializeMenuState();
displayMenuPath();
}, 300);
}, 30);
});

@ -91,7 +91,12 @@ $(document).ready(function() {
var activeAjaxCount = 0;
// Ajax 시작 시 Progress Block UI 표시
$(document).ajaxSend(function() {
$(document).ajaxSend(function(event, jqXHR, ajaxOptions) {
// 사이드바 상태 저장 요청인 경우 오버레이 표시하지 않음
if (ajaxOptions.url && ajaxOptions.url.indexOf('/common/header/sidebar/state.ajax') !== -1) {
// 사이드바 상태 저장 요청은 오버레이 카운트에서 제외
return;
}
activeAjaxCount++;
// 첫 번째 Ajax 요청일 때만 Progress Block UI 표시
if (activeAjaxCount === 1) {
@ -100,7 +105,12 @@ $(document).ajaxSend(function() {
});
// Ajax 완료 시 Progress Block UI 제거 (성공/실패 모든 경우)
$(document).ajaxComplete(function() {
$(document).ajaxComplete(function(event, jqXHR, ajaxOptions) {
// 사이드바 상태 저장 요청인 경우 오버레이 카운트에서 제외
if (ajaxOptions.url && ajaxOptions.url.indexOf('/common/header/sidebar/state.ajax') !== -1) {
// 사이드바 상태 저장 요청은 카운트 감소하지 않음
return;
}
activeAjaxCount--;
// 모든 Ajax 요청이 완료되었을 때만 Progress Block UI 숨김
if (activeAjaxCount <= 0) {

Loading…
Cancel
Save