diff --git a/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java b/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java index 0abd78c..81333dd 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java +++ b/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java @@ -36,11 +36,16 @@ public class BoardController { private final BoardService boardService; @GetMapping("/contentWrite") - public ModelAndView contentWrite(Principal principal) { + public ModelAndView contentWrite(@AuthenticationPrincipal UserInfo loginUser, Board content) { ModelAndView mav = new ModelAndView("board/contentWrite"); - UserInfo loginUser = ((UserInfo)((UsernamePasswordAuthenticationToken) principal).getPrincipal()); - mav.addObject("userId", loginUser.getUserId()); - mav.addObject("userName", loginUser.getName()); + if(content == null) { + mav.addObject("type", "new"); + mav.addObject("userId", loginUser.getUserId()); + mav.addObject("userName", loginUser.getName()); + }else{ + mav.addObject("type", "modify"); + mav.addObject("content", boardService.selectContentModifyInfo(content.getContentSeq())); + } return mav; } @@ -50,6 +55,13 @@ public class BoardController { return boardService.saveContent(content); } + @PostMapping("/updateContent") + public Integer updateContent(Board content, @RequestParam(value = "fileSeq") List deleteFileSeq, MultipartHttpServletRequest request, @AuthenticationPrincipal UserInfo loginUser){ + content.setFileList(request.getMultiFileMap().get("uploadFiles")); + return 0; + // return boardService.updateContent(content, loginUser); + } + @GetMapping("/contentList") public ModelAndView contentList(Board board){ ModelAndView mav = new ModelAndView("board/contentList"); @@ -66,7 +78,7 @@ public class BoardController { public ModelAndView selectBoardContent(Board content, @AuthenticationPrincipal UserInfo loginUser){ ModelAndView mav = new ModelAndView("board/contentDetail"); Board target = boardService.selectContentByContentSeqAndViewCntUp(content.getContentSeq()); - mav.addObject("content", boardService.SelectContentForeignAttribute(target)); + mav.addObject("content", boardService.selectContentForeignAttribute(target)); mav.addObject("loginUser", loginUser); return mav; } diff --git a/src/main/java/com/dbnt/kcgfilemanager/service/BoardService.java b/src/main/java/com/dbnt/kcgfilemanager/service/BoardService.java index ac4f566..9d2ae01 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/service/BoardService.java +++ b/src/main/java/com/dbnt/kcgfilemanager/service/BoardService.java @@ -27,6 +27,7 @@ public class BoardService { private final FileInfoRepository fileInfoRepository; private final BoardCategoryRepository boardCategoryRepository; private final BoardMapper boardMapper; + private final UserInfoRepository userInfoRepository; @Transactional public Integer saveContent(Board content){ @@ -37,6 +38,17 @@ public class BoardService { return contentSeq; } + @Transactional + public Integer updateContent(Board updateContent, UserInfo userInfo) { + int contentSeq = updateContent.getContentSeq(); + Board savedContent = boardRepository.findById(contentSeq).orElse(null); + savedContent.setCategorySeq(updateContent.getCategorySeq()); + savedContent.setTitle(updateContent.getTitle()); + savedContent.setDescription(updateContent.getDescription()); + saveBoardLog(contentSeq, LogStatus.MODIFY, null, userInfo.getUserId()); + return contentSeq; + } + private void saveBoardLog(Integer contentSeq, LogStatus status, String description, String createId){ BoardLog lastLog = boardLogRepository.findTopByContentSeqOrderByLogSeqDesc(contentSeq).orElse(null); BoardLog log = new BoardLog(); @@ -125,13 +137,30 @@ public class BoardService { @Transactional public Board selectContentByContentSeqAndViewCntUp(Integer contentSeq) { - Board target = boardRepository.findById(contentSeq).orElse(null); + Board target = selectContent(contentSeq); if(target.getStatus()==null){ target.setViewCnt(target.getViewCnt()+1); } return target; } - + public Board selectContent(int contentSeq){ + Board content = boardRepository.findById(contentSeq).orElse(null); + content.setCreateName(userInfoRepository.findByUserId(content.getCreateId()).orElse(null).getUserId()); + return content; + } + public Board selectContentModifyInfo(int contentSeq){ + Board content = selectContent(contentSeq); + content = selectContentForeignAttribute(content); + StringBuilder hashTagStr = new StringBuilder(); + for(HashTag tag : content.getHashTagList()){ + hashTagStr.append("#").append(tag.getTagName()).append(", "); + } + if(!hashTagStr.toString().equals("")) { + hashTagStr = new StringBuilder(hashTagStr.substring(0, hashTagStr.length() - 2)); + content.setHashTagStr(hashTagStr.toString()); + } + return content; + } public List selectDownloadFileInfoList(Integer contentSeq, List fileSeqList, String userId) { List fileList = fileInfoRepository.findByContentSeqOrderByFileSeqAsc(contentSeq); List targetList = new ArrayList<>(); @@ -153,7 +182,7 @@ public class BoardService { return boardMapper.selectBoardLogFromContentSeq(contentSeq); } - public Board SelectContentForeignAttribute(Board target) { + public Board selectContentForeignAttribute(Board target) { target.setHashTagList(boardMapper.selectHashTagListFromContentSeq(target.getContentSeq())); target.setChildFileList(fileInfoRepository.findByContentSeqOrderByFileSeqAsc(target.getContentSeq())); return target; diff --git a/src/main/resources/static/js/board/contentList.js b/src/main/resources/static/js/board/contentList.js index 2311bac..b4785a8 100644 --- a/src/main/resources/static/js/board/contentList.js +++ b/src/main/resources/static/js/board/contentList.js @@ -69,7 +69,7 @@ $(document).on('click', '#deleteBtn', function (){ } }) $(document).on('click', '#modifyBtn', function (){ - + location.href = "/board/contentWrite?contentSeq="+Number($(this).attr("data-contentseq")); }) function getContentSeq(){ return $(".contentCheckBox:checked").val(); diff --git a/src/main/resources/static/js/board/contentWrite.js b/src/main/resources/static/js/board/contentWrite.js index a849bbb..7d1a61e 100644 --- a/src/main/resources/static/js/board/contentWrite.js +++ b/src/main/resources/static/js/board/contentWrite.js @@ -1,6 +1,11 @@ const files = []; $(function(){ + if(pageType === "modify"){ + $(".categorySelector").removeAttr("disabled"); + setParentCategory(4, $("#categorySeq").find("[selected]").attr("data-parentseq")); + } + $("#uploadDiv").on("dragenter", function(e) { // $(this).addClass('drag-over'); }).on("dragleave", function(e) { @@ -15,7 +20,7 @@ $(function(){ setFileDiv(file, files.push(file)); } }).on('click', function (e){ - if(e.target.className.indexOf("fileDelete")<0){ + if(e.target.className.indexOf("ileDelete")<0){ $("#fileInputer").click(); } }); @@ -48,18 +53,33 @@ $(document).on('click', '.fileDelete', function (){ uploadDiv.append("
파일을 업로드 해주세요."); } }) +$(document).on('click', '.uploadedFileDelete', function (){ + const target = $(this).parent().find("span")[0]; + if(target.className===""){ + target.className = "text-decoration-line-through"; + }else{ + target.className = ""; + } +}) $(document).on('click', '#saveBtn', function (){ if(contentCheck()){ if(confirm("저장하시겠습니까?")){ + let ajaxUrl = "/board/saveContent"; const formData = new FormData($("#contentForm")[0]); for(const file of files) { if(!file.isDelete) formData.append('uploadFiles', file, file.name); } + if(pageType==='modify'){ + ajaxUrl = "/board/updateContent"; + $(".text-decoration-line-through").each(function (idx, el){ + formData.append('fileSeq', $(el).attr("data-fileseq")); + }) + } $.ajax({ type : 'POST', data : formData, - url : "/board/saveContent", + url : ajaxUrl, processData: false, contentType: false, success : function(result) { @@ -112,6 +132,22 @@ function selectorDisabler(depth){ }) } +function setParentCategory(depth, parentSeq){ + $("[data-depth='"+depth+"']").children().each(function (){ + const option = $(this) + if(parentSeq === option.attr("data-parentseq")){ + option.removeAttr("style"); + }else{ + option.css("display", "none"); + } + }) + const nextTarget = $("[value='"+parentSeq+"']"); + nextTarget.attr("selected", "selected"); + if(depth!==1){ + setParentCategory(depth-1, nextTarget.attr("data-parentseq")); + } +} + function setFileDiv(file, idx){ const uploadDiv = $("#uploadDiv"); if(files.length===1){ @@ -134,21 +170,23 @@ function contentCheck(){ alert("제목을 입력해주세요.") flag = false; } - if($(".fileDelete ").length===0){ - alert("업로드 할 파일이 없습니다.") - flag = false; - } - let totalSize = 0; - for(const file of files) { - if(!file.isDelete){ - totalSize+=file.size; - if(file.size>20971520){ - alert("파일당 사이즈는 20MB을 넘길 수 없습니다.") + if(pageType === "new"){ + if($(".fileDelete ").length===0){ + alert("업로드 할 파일이 없습니다.") + flag = false; + } + let totalSize = 0; + for(const file of files) { + if(!file.isDelete){ + totalSize+=file.size; + if(file.size>20971520){ + alert("파일당 사이즈는 20MB을 넘길 수 없습니다.") + } } } - } - if(totalSize>104857600){ - alert("첨부파일의 용량 합은 100MB를 넘길 수 없습니다.") + if(totalSize>104857600){ + alert("첨부파일의 용량 합은 100MB를 넘길 수 없습니다.") + } } return flag; } diff --git a/src/main/resources/templates/board/contentWrite.html b/src/main/resources/templates/board/contentWrite.html index 30076c9..74b3bcb 100644 --- a/src/main/resources/templates/board/contentWrite.html +++ b/src/main/resources/templates/board/contentWrite.html @@ -12,11 +12,14 @@ +
-

자료 등록

+

@@ -26,6 +29,9 @@
+ + +
@@ -60,12 +66,13 @@
+
- - + +
- +
-
파일을 업로드 해주세요. + +
파일을 업로드 해주세요. +
+ +
+ + 삭제 +
+
@@ -102,13 +118,14 @@
- +
- +
diff --git a/src/main/resources/templates/layout/layout.html b/src/main/resources/templates/layout/layout.html index 212a8ba..4dfe40f 100644 --- a/src/main/resources/templates/layout/layout.html +++ b/src/main/resources/templates/layout/layout.html @@ -54,9 +54,9 @@
-
-
-
+
+
+