게시판 분류 관리 편의성 작업중.

master
강석 최 2022-01-07 18:00:38 +09:00
parent dd36eda244
commit 14343075dc
6 changed files with 224 additions and 0 deletions

View File

@ -63,6 +63,18 @@ public class adminController {
boardCategoryService.deleteBoardCategory(categorySeq, depth); boardCategoryService.deleteBoardCategory(categorySeq, depth);
return categorySeq; return categorySeq;
} }
/*게시판 분류관리 개선*/
@GetMapping("/categoryMgt2")
public ModelAndView categoryMgt2(){
ModelAndView mav = new ModelAndView("admin/categoryMgt2");
return mav;
}
@GetMapping("/getCategoryList")
public List<BoardCategory> getCategoryList(){
return boardCategoryService.selectBoardCategoryListToFindAll();
}
@GetMapping("/userMgt") @GetMapping("/userMgt")
public ModelAndView userMgt(UserInfo userInfo) { public ModelAndView userMgt(UserInfo userInfo) {
ModelAndView mav = new ModelAndView("admin/userMgt"); ModelAndView mav = new ModelAndView("admin/userMgt");

View File

@ -30,4 +30,8 @@ public class BoardCategory {
private String categoryName; private String categoryName;
@Transient @Transient
private List<BoardCategory> childCategoryList; private List<BoardCategory> childCategoryList;
@Transient
private String status;
@Transient
private Integer tempSeq;
} }

View File

@ -25,6 +25,7 @@ public class BoardCategoryService {
public List<BoardCategory> selectBoardCategory(Integer parentSeq, Integer depth) { public List<BoardCategory> selectBoardCategory(Integer parentSeq, Integer depth) {
return boardCategoryRepository.findByParentSeqAndDepth(parentSeq, depth); return boardCategoryRepository.findByParentSeqAndDepth(parentSeq, depth);
} }
public List<BoardCategory> selectBoardCategoryAll(Integer parentSeq, Integer depth){ public List<BoardCategory> selectBoardCategoryAll(Integer parentSeq, Integer depth){
List<BoardCategory> categoryList = boardCategoryRepository.findByParentSeqAndDepth(parentSeq, depth); List<BoardCategory> categoryList = boardCategoryRepository.findByParentSeqAndDepth(parentSeq, depth);
for(BoardCategory category: categoryList){ for(BoardCategory category: categoryList){
@ -32,6 +33,11 @@ public class BoardCategoryService {
} }
return categoryList; return categoryList;
} }
public List<BoardCategory> selectBoardCategoryListToFindAll(){
return boardCategoryRepository.findAll();
}
@Transactional @Transactional
public void insertBoardCategory(List<BoardCategory> categoryList){ public void insertBoardCategory(List<BoardCategory> categoryList){
boardCategoryRepository.saveAll(categoryList); boardCategoryRepository.saveAll(categoryList);

View File

@ -0,0 +1,70 @@
const categoryList = []
let maxSeq = 0;
$(function (){
getCategoryList();
})
$(document).on('click', '.categoryTr', function (){
const chooseTr = $(this)
setCategoryTable(Number(chooseTr.attr("data-depth"))+1, Number(chooseTr.attr("data-categoryseq")));
})
function getCategoryList(){
$.ajax({
url: '/admin/getCategoryList',
type: 'GET',
success: function(data){
data.forEach(function (category){
categoryList.push({
categorySeq: category.categorySeq,
parentSeq: category.parentSeq,
categoryName: category.categoryName,
depth: category.depth,
status: "saved",
})
if(maxSeq<category.categorySeq){
maxSeq = category.categorySeq
}
})
setCategoryTable(1, null);
},
error:function(){
}
});
}
function setCategoryTable(depth, parentSeq){
let tbody = "";
const tableData = getTableData(categoryList, depth, parentSeq);
tableData.forEach(function (data){
tbody += "<tr class='categoryTr' data-depth='"+data.depth+"' " +
"data-categoryseq='"+data.categorySeq+"' data-parentseq='"+data.parentSeq+"'>";
tbody += "<td></td>"
tbody += "<td>"+data.categoryName+"</td>"
tbody += "</tr>";
})
clearChildTable(depth);
$("#depth"+depth+"Tbody").append(tbody);
}
function getTableData(categoryList, depth, parentSeq){
let targetList = [];
categoryList.forEach(function (category){
if(category.depth===depth && category.parentSeq===parentSeq){
targetList.push({
categorySeq: category.categorySeq,
categoryName: category.categoryName,
parentSeq: category.parentSeq,
depth: category.depth,
status: category.status
})
}
});
return targetList;
}
function clearChildTable(depth){
for(let i=depth; i<=4; i++){
$("#depth"+i+"Tbody").empty();
}
}

View File

@ -0,0 +1,131 @@
<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/layout}">
<th:block layout:fragment="script">
<script type="text/javascript" th:src="@{/js/admin/categoryMgt2.js}"></script>
</th:block>
<div layout:fragment="content">
<main class="pt-3">
<input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
<h4>게시판 분류 관리</h4>
<div class="row mx-0">
<div class="col-auto card text-center">
<div class="card-body">
<div class="row justify-content-end">
<input type="button" class="col-auto btn btn-primary mx-3" id="saveCategoryBtn" value="저장">
</div>
<div class="row justify-content-start">
<div class="col-auto m-3 p-3 border">
<div class="row-cols-6" id="depth1Div">
<table class="table table-striped">
<thead data-depth="1">
<tr>
<th></th>
<th>대분류</th>
</tr>
</thead>
<tbody id="depth1Tbody">
</tbody>
</table>
</div>
<div class="row justify-content-end">
<div class="col-auto">
<input type="button" class="btn btn-success addCategoryBtn" value="추가" data-depth="1">
</div>
<div class="col-auto">
<input type="button" class="btn btn-danger deleteCategoryBtn" value="삭제" data-depth="1">
</div>
</div>
</div>
<div class="col-auto m-3 p-3 border">
<div class="row-cols-6" id="depth2Div">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>연도</th>
</tr>
</thead>
<tbody id="depth2Tbody">
</tbody>
</table>
</div>
<div class="row justify-content-end">
<div class="col-auto">
<input type="button" class="btn btn-success addCategoryBtn" value="추가" data-depth="2">
</div>
<div class="col-auto">
<input type="button" class="btn btn-danger deleteCategoryBtn" value="삭제" data-depth="2">
</div>
</div>
</div>
<div class="col-auto m-3 p-3 border">
<div class="row-cols-6" id="depth3Div">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>중분류</th>
</tr>
</thead>
<tbody id="depth3Tbody">
</tbody>
</table>
</div>
<div class="row justify-content-end">
<div class="col-auto">
<input type="button" class="btn btn-success addCategoryBtn" value="추가" data-depth="3">
</div>
<div class="col-auto">
<input type="button" class="btn btn-danger deleteCategoryBtn" value="삭제" data-depth="3">
</div>
</div>
</div>
<div class="col-auto m-3 p-3 border">
<div class="row-cols-6" id="depth4Div">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>소분류</th>
</tr>
</thead>
<tbody id="depth4Tbody">
</tbody>
</table>
</div>
<div class="row justify-content-end">
<div class="col-auto">
<input type="button" class="btn btn-success addCategoryBtn" value="추가" data-depth="4">
</div>
<div class="col-auto">
<input type="button" class="btn btn-danger deleteCategoryBtn" value="삭제" data-depth="4">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<div style="display: none;">
<table>
<tbody id="appendTr">
<tr>
<td>
<input type="hidden" class="categorySeq">
<input type="checkbox" class="trCheckBox">
</td>
<td>
<input type="hidden" class="parentSeq">
<input type="hidden" class="depth">
<input type="text" class="form-control categoryName">
</td>
</tr>
</tbody>
</table>
</div>
</div>
</html>

View File

@ -6,6 +6,7 @@
<div sec:authorize="hasRole('ROLE_ADMIN')"> <div sec:authorize="hasRole('ROLE_ADMIN')">
<div class="list-group py-2"> <div class="list-group py-2">
<a href="/admin/categoryMgt" class="list-group-item list-group-item-action">게시판 분류 관리</a> <a href="/admin/categoryMgt" class="list-group-item list-group-item-action">게시판 분류 관리</a>
<a href="/admin/categoryMgt2" class="list-group-item list-group-item-action">게시판 분류 관리</a>
<a href="/admin/userMgt" class="list-group-item list-group-item-action">사용자 관리</a> <a href="/admin/userMgt" class="list-group-item list-group-item-action">사용자 관리</a>
<a href="/info/modifyRequestList" class="list-group-item list-group-item-action">수정 요청</a> <a href="/info/modifyRequestList" class="list-group-item list-group-item-action">수정 요청</a>
<a href="#" class="list-group-item list-group-item-action disabled">통계</a> <a href="#" class="list-group-item list-group-item-action disabled">통계</a>