diff --git a/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java b/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java index d1d60d7..00e72d3 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java +++ b/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java @@ -36,6 +36,7 @@ public class adminController { mav.addObject("diskInfoList", boardService.getDiskInfoList()); return mav; } + @GetMapping("/categoryMgt") public ModelAndView categoryMgt(){ ModelAndView mav = new ModelAndView("admin/categoryMgt"); @@ -75,6 +76,13 @@ public class adminController { return boardCategoryService.selectBoardCategoryListToFindAll(); } + @PostMapping("/insertCategory2") + @ResponseBody + public int insertBoardCategory2(@RequestBody List categoryList) { + boardCategoryService.saveBoardCategory(categoryList); + return categoryList.get(0).getDepth(); + } + @GetMapping("/userMgt") public ModelAndView userMgt(UserInfo userInfo) { ModelAndView mav = new ModelAndView("admin/userMgt"); diff --git a/src/main/java/com/dbnt/kcgfilemanager/service/BoardCategoryService.java b/src/main/java/com/dbnt/kcgfilemanager/service/BoardCategoryService.java index f7d0c3b..b9ccffb 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/service/BoardCategoryService.java +++ b/src/main/java/com/dbnt/kcgfilemanager/service/BoardCategoryService.java @@ -12,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; +import java.util.Objects; @Service @RequiredArgsConstructor @@ -89,4 +90,28 @@ public class BoardCategoryService { } return makeFilePath(category.getParentSeq())+"\\"+category.getCategoryName(); } + + @Transactional + public void saveBoardCategory(List categoryList) { + for(BoardCategory category: categoryList){ + switch (category.getStatus()){ + case "deleted": + boardCategoryRepository.delete(category); + break; + case "modified": + boardCategoryRepository.save(category); + break; + case "added": + category.setTempSeq(category.getCategorySeq()); + category.setCategorySeq(null); + for(BoardCategory temp : categoryList){ + if(Objects.equals(temp.getTempSeq(), category.getParentSeq())){ + category.setParentSeq(temp.getCategorySeq()); + } + } + boardCategoryRepository.saveAndFlush(category); + break; + } + } + } } diff --git a/src/main/resources/static/js/admin/categoryMgt2.js b/src/main/resources/static/js/admin/categoryMgt2.js index 490f7a1..75f5f0d 100644 --- a/src/main/resources/static/js/admin/categoryMgt2.js +++ b/src/main/resources/static/js/admin/categoryMgt2.js @@ -1,12 +1,115 @@ -const categoryList = [] +let categoryList = [] let maxSeq = 0; $(function (){ getCategoryList(); }) $(document).on('click', '.categoryTr', function (){ const chooseTr = $(this) + chooseTr.parent().find(".trCheckBox").prop("checked", false); + chooseTr.find(".trCheckBox").prop("checked", true); setCategoryTable(Number(chooseTr.attr("data-depth"))+1, Number(chooseTr.attr("data-categoryseq"))); }) +$(document).on('change', '.categoryName', function (){ + const categoryInfo = $(this).parents("tr"); + const changedName = this.value; + if(changedName !== categoryInfo.attr("data-categoryname")){ + categoryList.forEach(function (category){ + if(category.categorySeq === Number(categoryInfo.attr("data-categoryseq"))){ + category.categoryName = changedName; + if(category.status !== "added"){ + category.status = "modified"; + } + } + }) + categoryInfo[0].className += "bg-warning bg-opacity-25"; + } +}) +$(document).on('click', '.addCategoryBtn', function (){ + const depth = Number($(this).attr("data-depth")); + const parentCategory = $("#depth"+(depth-1)+"Tbody").find(".trCheckBox:checked").parents("tr"); + if(parentCategory.attr("data-status")==="deleted"){ + alert("삭제될 상위 분류에는 추가할 수 없습니다."); + }else{ + const parentSeq = parentCategory.attr("data-categoryseq"); + categoryList.push({ + categorySeq: maxSeq++, + parentSeq: depth===1?null:Number(parentSeq), + categoryName: "신규", + depth: depth, + status: "added" + }) + setCategoryTable(depth, depth===1?null:Number(parentSeq)); + } +}) +$(document).on('click', '.copyCategory', function (){ + const copyInfo = $(this).parents("tr") + if(confirm(copyInfo.attr("data-categoryname")+"을 복사하시겠습니까?")){ + const depth = Number(copyInfo.attr("data-depth")); + const parentSeq = copyInfo.attr("data-parentseq"); + const lastSeq = maxSeq++; + let copyList = [{ + categorySeq: lastSeq, + parentSeq: depth===1?null:Number(parentSeq), + categoryName: "복사된 분류", + depth: depth, + status: "added" + }]; + copyList = copyList.concat(getCopyData(depth+1, Number(copyInfo.attr("data-categoryseq")), lastSeq)); + categoryList = categoryList.concat(copyList); + setCategoryTable(depth, depth===1?null:Number(parentSeq)); + $("[data-categoryseq="+copyInfo.attr("data-categoryseq")+"]").find(".trCheckBox").click(); + } +}) +$(document).on('click', '.deleteCategory', function (){ + const categoryInfo = $(this).parents("tr"); + const categorySeq = categoryInfo.attr("data-categoryseq"); + if(categoryInfo.attr("data-status") !== "deleted"){ + if(confirm("선택된 분류와 하위 분류를 삭제하시겠습니까?")){ + statusChange("deleted", Number(categorySeq)); + } + }else{ + if(confirm("삭제를 취소 하시겠습니까?")){ + statusChange("saved", Number(categorySeq)); + } + } + const parentSeq = categoryInfo.attr("data-parentseq"); + setCategoryTable(Number(categoryInfo.attr("data-depth")), parentSeq!=="null"?Number(parentSeq):null); + $("[data-categoryseq="+categorySeq+"]").find(".trCheckBox").prop("checked", true); +}) + +$(document).on('click', '#saveCategoryBtn', function (){ + const saveList = []; + categoryList.forEach(function (category){ + // 변경 내용이 없는 분류, 추가 되었으면서 삭제된 분류 제외 + if(category.status !== "saved" && + !(category.status === "deleted" && category.originalName === undefined)){ + saveList.push(category); + } + }) + if(saveList.length !== 0) { + if (confirm(saveList.length + "건을 저장하시겠습니까?")) { + $.ajax({ + type : 'POST', + url : "/admin/insertCategory2", + data : JSON.stringify(saveList), + contentType: 'application/json', + beforeSend: function (xhr){ + xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val()); + }, + success : function(data) { + alert("저장되었습니다."); + sessionReload(); + }, + error : function(xhr, status) { + + } + }) + } + }else{ + alert("저장 대상이 없습니다."); + } +}) + function getCategoryList(){ $.ajax({ url: '/admin/getCategoryList', @@ -17,11 +120,12 @@ function getCategoryList(){ categorySeq: category.categorySeq, parentSeq: category.parentSeq, categoryName: category.categoryName, + originalName: category.categoryName, depth: category.depth, status: "saved", }) - if(maxSeq"; - tbody += "" - tbody += ""+data.categoryName+"" + let statusColor = ""; + switch (data.status){ + case "modified": statusColor = "bg-warning bg-opacity-25"; break; + case "added": statusColor = "bg-success bg-opacity-25"; break; + case "deleted": statusColor = "bg-danger bg-opacity-25"; break; + } + tbody += ""; + tbody += "" + tbody += "" + tbody += ""; + tbody += ""; tbody += ""; }) clearChildTable(depth); $("#depth"+depth+"Tbody").append(tbody); +} +function getCopyData(depth, parentSeq, lastSeq){ + let copyList = getTableData(categoryList, depth, parentSeq); + let childList = []; + copyList.forEach(function (category){ + const tempList = getCopyData(category.depth+1, category.categorySeq) + category.categorySeq = maxSeq++; + category.parentSeq = lastSeq; + category.status = "added"; + tempList.forEach(function (child){ + child.parentSeq = category.categorySeq; + child.categorySeq = maxSeq++; + child.status = "added"; + }) + childList = childList.concat(tempList); + }) + copyList = copyList.concat(childList); + return copyList; } function getTableData(categoryList, depth, parentSeq){ @@ -67,4 +198,21 @@ function clearChildTable(depth){ for(let i=depth; i<=4; i++){ $("#depth"+i+"Tbody").empty(); } +} + +function statusChange(status, categorySeq){ + categoryList.forEach(function (category){ + if(category.categorySeq === categorySeq){ + if(status==="saved" && category.originalName===undefined){ + category.status = "added"; + }else if(status==="saved" && category.originalName !== category.categoryName){ + category.status = "modified"; + }else{ + category.status = status; + } + } + if(category.parentSeq === categorySeq){ + statusChange(status, category.categorySeq) + } + }) } \ No newline at end of file diff --git a/src/main/resources/templates/admin/categoryMgt2.html b/src/main/resources/templates/admin/categoryMgt2.html index 8f3e8d4..64759e5 100644 --- a/src/main/resources/templates/admin/categoryMgt2.html +++ b/src/main/resources/templates/admin/categoryMgt2.html @@ -19,11 +19,13 @@
- +
+ + @@ -34,18 +36,17 @@
-
- -
-
대분류
+
+ + @@ -56,18 +57,17 @@
-
- -
-
연도
+
+ + @@ -78,18 +78,17 @@
-
- -
-
중분류
+
+ + @@ -100,9 +99,6 @@
-
- -
@@ -110,22 +106,5 @@ -
-
소분류
- - - - - - -
- - - - - - -
-
\ No newline at end of file diff --git a/src/main/resources/templates/fragments/leftMenu.html b/src/main/resources/templates/fragments/leftMenu.html index 599d601..6d1b584 100644 --- a/src/main/resources/templates/fragments/leftMenu.html +++ b/src/main/resources/templates/fragments/leftMenu.html @@ -5,7 +5,7 @@
- 게시판 분류 관리 + 게시판 분류 관리 사용자 관리 수정 요청 diff --git a/src/main/resources/templates/layout/layout.html b/src/main/resources/templates/layout/layout.html index 0e36675..0d36431 100644 --- a/src/main/resources/templates/layout/layout.html +++ b/src/main/resources/templates/layout/layout.html @@ -40,15 +40,18 @@ const positionList = '[[${session.positionList}]]'; const departmentList = '[[${session.departmentList}]]'; const categoryList = '[[${session.categoryList}]]'; - if(!positionList && !departmentList && !categoryList){ - $.ajax({ - url: '/refreshSession', - type: 'GET', - success: function(){location.reload();}, - error:function(){} - }); + if(!positionList && !departmentList && !categoryList) { + sessionReload() } }) + function sessionReload(){ + $.ajax({ + url: '/refreshSession', + type: 'GET', + success: function(){location.reload();}, + error:function(){} + }); + }