diff --git a/src/main/java/com/dbnt/faisp/config/BaseService.java b/src/main/java/com/dbnt/faisp/config/BaseService.java index 60fc895a..e36d5ac4 100644 --- a/src/main/java/com/dbnt/faisp/config/BaseService.java +++ b/src/main/java/com/dbnt/faisp/config/BaseService.java @@ -3,8 +3,10 @@ package com.dbnt.faisp.config; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; import java.io.File; +import java.io.IOException; @Service @RequiredArgsConstructor @@ -26,4 +28,23 @@ public class BaseService { public void deleteStoredFile(File deleteFile){ deleteFile.delete(); } + + public void saveFile(MultipartFile file, File saveFile){ + if(file.getSize()!=0){ // 저장될 파일 확인 + if(!saveFile.exists()){ // 저장될 경로 확인 + if(saveFile.getParentFile().mkdirs()){ + try{ + saveFile.createNewFile(); + }catch (IOException e){ + e.printStackTrace(); + } + } + } + try { + file.transferTo(saveFile); + }catch (IllegalStateException | IOException e){ + e.printStackTrace(); + } + } + } } diff --git a/src/main/java/com/dbnt/faisp/config/BoardType.java b/src/main/java/com/dbnt/faisp/config/BoardType.java deleted file mode 100644 index aa3526b8..00000000 --- a/src/main/java/com/dbnt/faisp/config/BoardType.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.dbnt.faisp.config; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@AllArgsConstructor -@Getter -public enum BoardType { - NOTICE("NOTICE"), - BOARD("BOARD"), - FILES("FILES"), - QNA("Q&A"); - - private String value; -} diff --git a/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/repository/PlanFileRepository.java b/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/repository/PlanFileRepository.java index ad6796a6..58bea35d 100644 --- a/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/repository/PlanFileRepository.java +++ b/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/repository/PlanFileRepository.java @@ -9,5 +9,5 @@ import java.util.Optional; public interface PlanFileRepository extends JpaRepository { List findByPlanKey(Integer planKey); - Optional findByPlanKeyOrderByFileSeqDesc(Integer planKey); + Optional findTopByPlanKeyOrderByFileSeqDesc(Integer planKey); } diff --git a/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/service/MonthPlanService.java b/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/service/MonthPlanService.java index b4144fe6..72c0e675 100644 --- a/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/service/MonthPlanService.java +++ b/src/main/java/com/dbnt/faisp/fpiMgt/monthPlan/service/MonthPlanService.java @@ -76,29 +76,12 @@ public class MonthPlanService extends BaseService { } private void saveUploadFiles(Integer planKey, List multipartFileList){ - PlanFile lastFileInfo = planFileRepository.findByPlanKeyOrderByFileSeqDesc(planKey).orElse(null); + PlanFile lastFileInfo = planFileRepository.findTopByPlanKeyOrderByFileSeqDesc(planKey).orElse(null); int fileSeq = lastFileInfo==null?1:(lastFileInfo.getFileSeq()+1); for(MultipartFile file : multipartFileList){ String saveName = UUID.randomUUID().toString(); String path = locationPath+File.separator+"monthPlan"+File.separator; - - File saveFile = new File(path+File.separator+saveName); - if(file.getSize()!=0){ // 저장될 파일 확인 - if(!saveFile.exists()){ // 저장될 경로 확인 - if(saveFile.getParentFile().mkdirs()){ - try{ - saveFile.createNewFile(); - }catch (IOException e){ - e.printStackTrace(); - } - } - } - try { - file.transferTo(saveFile); - }catch (IllegalStateException | IOException e){ - e.printStackTrace(); - } - } + saveFile(file, new File(path+File.separator+saveName)); String originalFilename = file.getOriginalFilename(); int extnIdx = originalFilename.lastIndexOf("."); diff --git a/src/main/java/com/dbnt/faisp/publicBoard/PublicBoardController.java b/src/main/java/com/dbnt/faisp/publicBoard/PublicBoardController.java index 0d3b6592..d9a4a71a 100644 --- a/src/main/java/com/dbnt/faisp/publicBoard/PublicBoardController.java +++ b/src/main/java/com/dbnt/faisp/publicBoard/PublicBoardController.java @@ -1,19 +1,18 @@ package com.dbnt.faisp.publicBoard; -import com.dbnt.faisp.config.BoardType; import com.dbnt.faisp.config.Role; -import com.dbnt.faisp.fpiMgt.monthPlan.model.PlanBoard; import com.dbnt.faisp.publicBoard.model.PublicBoard; +import com.dbnt.faisp.publicBoard.model.PublicComment; import com.dbnt.faisp.publicBoard.service.PublicBoardService; import com.dbnt.faisp.userInfo.model.UserInfo; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.Map; +import java.util.List; @RestController @@ -24,11 +23,12 @@ public class PublicBoardController { @GetMapping("/noticePage") public ModelAndView organMgtPage(@AuthenticationPrincipal UserInfo loginUser, PublicBoard publicBoard) { - ModelAndView mav = new ModelAndView("publicBoard/notice"); + ModelAndView mav = new ModelAndView("publicBoard/notice/noticePage"); publicBoard.setQueryInfo(); - publicBoard.setPublicType(BoardType.NOTICE.getValue()); - if(loginUser.getAuthorities().contains(Role.SUB_ADMIN)){ + publicBoard.setPublicType("PLB001"); + if(loginUser.getUserRole().contains(Role.SUB_ADMIN.getValue())){ publicBoard.setOrganCdList(loginUser.getOrganCdList()); + mav.addObject("mgtOrganList", loginUser.getOrganCdList()); } mav.addObject("noticeList", publicBoardService.selectContentList(publicBoard)); publicBoard.setContentCnt(publicBoardService.selectContentListCnt(publicBoard)); @@ -39,10 +39,23 @@ public class PublicBoardController { @GetMapping("/editModal") public ModelAndView editModal(@AuthenticationPrincipal UserInfo loginUser, PublicBoard publicBoard){ - ModelAndView mav = new ModelAndView("publicBoard/editModal"); - if(publicBoard.getPublicKey()!=null){ - publicBoard = publicBoardService.selectPublicBoard(publicBoard.getPublicKey()); - }else{ + ModelAndView mav = null; + switch (publicBoard.getPublicType()){ + case "PLB001": // 공지사항 + mav = new ModelAndView("publicBoard/notice/noticeEditModal"); + if(publicBoard.getPublicKey()!=null){ + publicBoard = publicBoardService.selectPublicBoard(publicBoard.getPublicKey()); + } + break; + case "PLB002": // 공용게시판 + break; + case "PLB003": // 자료실 + break; + case "PLB004": // Q&A + break; + } + + if(publicBoard.getPublicKey()==null){ publicBoard.setWrtOrgan(loginUser.getOgCd()); publicBoard.setWrtPart(loginUser.getOfcCd()); publicBoard.setWrtUserSeq(loginUser.getUserSeq()); @@ -53,12 +66,46 @@ public class PublicBoardController { return mav; } - @GetMapping("/planViewModal") - public ModelAndView planViewModal(@AuthenticationPrincipal UserInfo loginUser, PublicBoard publicBoard){ - ModelAndView mav = new ModelAndView("publicBoard/viewModal"); + @GetMapping("/viewModal") + public ModelAndView viewModal(@AuthenticationPrincipal UserInfo loginUser, PublicBoard publicBoard){ + ModelAndView mav = null; + switch (publicBoard.getPublicType()){ + case "PLB001": // 공지사항 + mav = new ModelAndView("publicBoard/notice/noticeViewModal"); + break; + case "PLB002": // 공용게시판 + break; + case "PLB003": // 자료실 + break; + case "PLB004": // Q&A + break; + } publicBoard = publicBoardService.selectPublicBoard(publicBoard.getPublicKey()); + mav.addObject("userSeq", loginUser.getUserSeq()); mav.addObject("info", publicBoard); return mav; } + @PostMapping("/saveContent") + public Integer saveContent(PublicBoard publicBoard, + MultipartHttpServletRequest request, + @RequestParam(value = "fileSeq", required = false) List deleteFileSeq){ + publicBoard.setMultipartFileList(request.getMultiFileMap().get("uploadFiles")); + return publicBoardService.saveContent(publicBoard, deleteFileSeq); + } + @PostMapping("/saveComment") + public Integer saveComment(@AuthenticationPrincipal UserInfo loginUser, PublicComment comment){ + comment.setWrtOrgan(loginUser.getOgCd()); + comment.setWrtPart(loginUser.getOfcCd()); + comment.setWrtUserSeq(loginUser.getUserSeq()); + comment.setWrtUserNm(loginUser.getUserNm()); + comment.setWrtDt(LocalDateTime.now()); + return publicBoardService.saveComment(comment); + } + + @PostMapping("/deleteComment") + @ResponseBody + public void deleteComment(Integer publicKey, Integer commentKey){ + publicBoardService.deleteComment(publicKey, commentKey); + } } diff --git a/src/main/java/com/dbnt/faisp/publicBoard/model/PublicBoard.java b/src/main/java/com/dbnt/faisp/publicBoard/model/PublicBoard.java index d1ebf8dc..1df90f44 100644 --- a/src/main/java/com/dbnt/faisp/publicBoard/model/PublicBoard.java +++ b/src/main/java/com/dbnt/faisp/publicBoard/model/PublicBoard.java @@ -6,9 +6,12 @@ import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.multipart.MultipartFile; import javax.persistence.*; import java.time.LocalDateTime; +import java.util.List; @Getter @Setter @@ -37,6 +40,19 @@ public class PublicBoard extends BaseModel { @Column(name = "wrt_user_nm") private String wrtUserNm; @Column(name = "wrt_dt") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm") private LocalDateTime wrtDt; + @Column(name = "organ_chk") + private String organChk; + @Transient + private Integer fileCnt; + @Transient + private Integer commentCnt; + @Transient + private List fileList; + @Transient + private List commentList; + @Transient + private List multipartFileList; } diff --git a/src/main/java/com/dbnt/faisp/publicBoard/model/PublicBoardComment.java b/src/main/java/com/dbnt/faisp/publicBoard/model/PublicComment.java similarity index 72% rename from src/main/java/com/dbnt/faisp/publicBoard/model/PublicBoardComment.java rename to src/main/java/com/dbnt/faisp/publicBoard/model/PublicComment.java index 31a984e2..1c9fe69f 100644 --- a/src/main/java/com/dbnt/faisp/publicBoard/model/PublicBoardComment.java +++ b/src/main/java/com/dbnt/faisp/publicBoard/model/PublicComment.java @@ -7,6 +7,7 @@ import org.hibernate.annotations.DynamicUpdate; import javax.persistence.*; import java.io.Serializable; import java.time.LocalDateTime; +import java.util.List; @Getter @Setter @@ -14,25 +15,23 @@ import java.time.LocalDateTime; @NoArgsConstructor @DynamicInsert @DynamicUpdate -@Table(name = "public_board_comment") -@IdClass(PublicBoardComment.PublicBoardCommentId.class) -public class PublicBoardComment { +@Table(name = "public_comment") +@IdClass(PublicComment.PublicCommentId.class) +public class PublicComment { @Id @Column(name = "public_key") private Integer publicKey; @Id @Column(name = "comment_key") private Integer commentKey; - @Column(name = "public_type") - private String public_type; - @Column(name = "content") - private String content; + @Column(name = "comment") + private String comment; @Column(name = "wrt_organ") private String wrtOrgan; @Column(name = "wrt_part") private String wrtPart; @Column(name = "wrt_user_seq") - private String wrtUserSeq; + private Integer wrtUserSeq; @Column(name = "wrt_user_nm") private String wrtUserNm; @Column(name = "wrt_dt") @@ -40,11 +39,14 @@ public class PublicBoardComment { @Column(name = "parent_comment") private Integer parentComment; + @Transient + private List childCommentList; + @Embeddable @Data @NoArgsConstructor @AllArgsConstructor - public static class PublicBoardCommentId implements Serializable { + public static class PublicCommentId implements Serializable { private Integer publicKey; private Integer commentKey; } diff --git a/src/main/java/com/dbnt/faisp/publicBoard/model/PublicFile.java b/src/main/java/com/dbnt/faisp/publicBoard/model/PublicFile.java index c863cafd..079a2b9b 100644 --- a/src/main/java/com/dbnt/faisp/publicBoard/model/PublicFile.java +++ b/src/main/java/com/dbnt/faisp/publicBoard/model/PublicFile.java @@ -14,7 +14,7 @@ import java.io.Serializable; @NoArgsConstructor @DynamicInsert @DynamicUpdate -@Table(name = "plan_file") +@Table(name = "public_file") @IdClass(PublicFile.PublicFileId.class) public class PublicFile extends FileInfo { @Id diff --git a/src/main/java/com/dbnt/faisp/publicBoard/repository/PublicBoardCommentRepository.java b/src/main/java/com/dbnt/faisp/publicBoard/repository/PublicBoardCommentRepository.java deleted file mode 100644 index 72ad24fe..00000000 --- a/src/main/java/com/dbnt/faisp/publicBoard/repository/PublicBoardCommentRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.dbnt.faisp.publicBoard.repository; - -import com.dbnt.faisp.publicBoard.model.PublicBoardComment; -import org.springframework.data.jpa.repository.JpaRepository; - - -public interface PublicBoardCommentRepository extends JpaRepository { - -} diff --git a/src/main/java/com/dbnt/faisp/publicBoard/repository/PublicCommentRepository.java b/src/main/java/com/dbnt/faisp/publicBoard/repository/PublicCommentRepository.java new file mode 100644 index 00000000..250fd209 --- /dev/null +++ b/src/main/java/com/dbnt/faisp/publicBoard/repository/PublicCommentRepository.java @@ -0,0 +1,15 @@ +package com.dbnt.faisp.publicBoard.repository; + +import com.dbnt.faisp.publicBoard.model.PublicComment; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; +import java.util.Optional; + + +public interface PublicCommentRepository extends JpaRepository { + + List findByPublicKeyAndParentCommentOrderByCommentKeyAsc(Integer publicKey, Integer parentComment); + Optional findTopByPublicKeyOrderByCommentKeyDesc(Integer publicKey); + +} diff --git a/src/main/java/com/dbnt/faisp/publicBoard/repository/PublicFileRepository.java b/src/main/java/com/dbnt/faisp/publicBoard/repository/PublicFileRepository.java index fac049a4..af4862e1 100644 --- a/src/main/java/com/dbnt/faisp/publicBoard/repository/PublicFileRepository.java +++ b/src/main/java/com/dbnt/faisp/publicBoard/repository/PublicFileRepository.java @@ -3,7 +3,12 @@ package com.dbnt.faisp.publicBoard.repository; import com.dbnt.faisp.publicBoard.model.PublicFile; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; +import java.util.Optional; + public interface PublicFileRepository extends JpaRepository { + List findByPublicKey(Integer publicKey); + Optional findTopByPublicKeyOrderByFileSeq(Integer publicKey); } diff --git a/src/main/java/com/dbnt/faisp/publicBoard/service/PublicBoardService.java b/src/main/java/com/dbnt/faisp/publicBoard/service/PublicBoardService.java index 47f09671..eab51ac6 100644 --- a/src/main/java/com/dbnt/faisp/publicBoard/service/PublicBoardService.java +++ b/src/main/java/com/dbnt/faisp/publicBoard/service/PublicBoardService.java @@ -1,21 +1,28 @@ package com.dbnt.faisp.publicBoard.service; +import com.dbnt.faisp.config.BaseService; import com.dbnt.faisp.publicBoard.mapper.PublicBoardMapper; import com.dbnt.faisp.publicBoard.model.PublicBoard; -import com.dbnt.faisp.publicBoard.repository.PublicBoardCommentRepository; +import com.dbnt.faisp.publicBoard.model.PublicComment; +import com.dbnt.faisp.publicBoard.model.PublicFile; +import com.dbnt.faisp.publicBoard.repository.PublicCommentRepository; import com.dbnt.faisp.publicBoard.repository.PublicBoardRepository; import com.dbnt.faisp.publicBoard.repository.PublicFileRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import java.io.File; import java.util.List; +import java.util.UUID; @Service @RequiredArgsConstructor -public class PublicBoardService { +public class PublicBoardService extends BaseService { private final PublicBoardRepository publicBoardRepository; - private final PublicBoardCommentRepository publicBoardCommentRepository; + private final PublicCommentRepository publicCommentRepository; private final PublicFileRepository publicFileRepository; private final PublicBoardMapper publicBoardMapper; @@ -28,6 +35,71 @@ public class PublicBoardService { } public PublicBoard selectPublicBoard(Integer publicKey) { - return publicBoardRepository.findById(publicKey).orElse(null); + PublicBoard publicBoard = publicBoardRepository.findById(publicKey).orElse(null); + publicBoard.setFileList(publicFileRepository.findByPublicKey(publicKey)); + List commentList = publicCommentRepository.findByPublicKeyAndParentCommentOrderByCommentKeyAsc(publicKey, null); + for(PublicComment comment: commentList){ + comment.setChildCommentList(publicCommentRepository.findByPublicKeyAndParentCommentOrderByCommentKeyAsc(publicKey, comment.getCommentKey())); + } + publicBoard.setCommentList(commentList); + return publicBoard; + } + + @Transactional + public Integer saveContent(PublicBoard publicBoard, List deleteFileSeq) { + Integer publicKey = publicBoardRepository.save(publicBoard).getPublicKey(); + if(deleteFileSeq!=null && deleteFileSeq.size()>0){ + deletePublicFile(publicKey, deleteFileSeq); + } + if(publicBoard.getMultipartFileList()!= null){ + saveUploadFiles(publicKey, publicBoard.getMultipartFileList()); + } + return publicKey; + } + + private void saveUploadFiles(Integer publicKey, List multipartFileList) { + PublicFile lastFileInfo = publicFileRepository.findTopByPublicKeyOrderByFileSeq(publicKey).orElse(null); + int fileSeq = lastFileInfo==null?1:(lastFileInfo.getFileSeq()+1); + for(MultipartFile file : multipartFileList){ + String saveName = UUID.randomUUID().toString(); + String path = locationPath+File.separator+"publicFile"+File.separator; + saveFile(file, new File(path+File.separator+saveName)); + + String originalFilename = file.getOriginalFilename(); + int extnIdx = originalFilename.lastIndexOf("."); + PublicFile fileInfo = new PublicFile(); + fileInfo.setPublicKey(publicKey); + fileInfo.setFileSeq(fileSeq++); + fileInfo.setOrigNm(originalFilename.substring(0, extnIdx)); + fileInfo.setFileExtn(originalFilename.substring(extnIdx+1)); + fileInfo.setConvNm(saveName); + fileInfo.setFileSize(calculationSize(file.getSize())); + fileInfo.setSavePath(path); + publicFileRepository.save(fileInfo); + } + } + + private void deletePublicFile(Integer publicKey, List deleteFileSeq) { + List publicFileList = publicFileRepository.findByPublicKey(publicKey); + for(PublicFile file: publicFileList){ + if(deleteFileSeq.contains(file.getFileSeq())){ + deleteStoredFile(new File(file.getSavePath(), file.getConvNm())); + publicFileRepository.delete(file); + } + } + } + + public Integer saveComment(PublicComment comment) { + PublicComment lastComment = publicCommentRepository + .findTopByPublicKeyOrderByCommentKeyDesc(comment.getPublicKey()).orElse(null); + comment.setCommentKey(lastComment==null?1:(lastComment.getCommentKey()+1)); + return publicCommentRepository.save(comment).getCommentKey(); + } + + @Transactional + public void deleteComment(Integer publicKey, Integer commentKey) { + List childList = publicCommentRepository.findByPublicKeyAndParentCommentOrderByCommentKeyAsc(publicKey, commentKey); + publicCommentRepository.deleteAll(childList); + publicCommentRepository.deleteById(new PublicComment.PublicCommentId(publicKey, commentKey)); } } diff --git a/src/main/resources/mybatisMapper/PublicBoardMapper.xml b/src/main/resources/mybatisMapper/PublicBoardMapper.xml index 7d4b7179..9f03e872 100644 --- a/src/main/resources/mybatisMapper/PublicBoardMapper.xml +++ b/src/main/resources/mybatisMapper/PublicBoardMapper.xml @@ -33,6 +33,7 @@ a.wrt_user_nm, a.wrt_user_seq, a.wrt_dt, + a.organ_chk, b.fileCnt, c.commentCnt from public_board a @@ -43,7 +44,7 @@ on a.public_key = b.public_key left outer join (select public_key, count(comment_key) as commentCnt - from public_board_comment + from public_comment group by public_key) c on a.public_key = c.public_key diff --git a/src/main/resources/static/js/common.js b/src/main/resources/static/js/common.js index d0d011c4..e2de4e7f 100644 --- a/src/main/resources/static/js/common.js +++ b/src/main/resources/static/js/common.js @@ -88,4 +88,39 @@ $(document).on('click', '.fileDownLink', function (){ url += "&parentKey="+Number($("#viewModalPlanKey").val()); url += "&fileSeq="+$(this).attr("data-fileseq"); window.open(encodeURI(url)); -}) \ No newline at end of file +}) + + +function setUploadDiv(){ + files = []; + $("#uploadDiv").on("dragenter", function(e) { + // $(this).addClass('drag-over'); + }).on("dragleave", function(e) { + // $(this).removeClass('drag-over'); + }).on("dragover", function(e) { + e.stopPropagation(); + e.preventDefault(); + }).on('drop', function(e) { + e.preventDefault(); + // $(this).removeClass('drag-over'); + for(const file of e.originalEvent.dataTransfer.files){ + setFileDiv(file, files.push(file)); + } + }).on('click', function (e){ + if(e.target.className.indexOf("ileDelete")<0){ + $("#fileInputer").click(); + } + }); +} + +function setFileDiv(file, idx){ + const uploadDiv = $("#uploadDiv"); + if($(".uploadedFileDelete").length===0 && $(".fileDelete").length === 0){ + uploadDiv.empty(); + } + let fileInfo = "
"; + fileInfo += file.name+" "+byteCalculation(file.size)+" "; + fileInfo += "삭제"; + fileInfo += "
"; + uploadDiv.append(fileInfo); +} \ No newline at end of file diff --git a/src/main/resources/static/js/igActivities/fpiMgt/monthPlan.js b/src/main/resources/static/js/igActivities/fpiMgt/monthPlan.js index f38c7ef9..b62ea1c3 100644 --- a/src/main/resources/static/js/igActivities/fpiMgt/monthPlan.js +++ b/src/main/resources/static/js/igActivities/fpiMgt/monthPlan.js @@ -81,27 +81,6 @@ function getEditModal(planKey){ } }); } -function setUploadDiv(){ - files = []; - $("#uploadDiv").on("dragenter", function(e) { - // $(this).addClass('drag-over'); - }).on("dragleave", function(e) { - // $(this).removeClass('drag-over'); - }).on("dragover", function(e) { - e.stopPropagation(); - e.preventDefault(); - }).on('drop', function(e) { - e.preventDefault(); - // $(this).removeClass('drag-over'); - for(const file of e.originalEvent.dataTransfer.files){ - setFileDiv(file, files.push(file)); - } - }).on('click', function (e){ - if(e.target.className.indexOf("ileDelete")<0){ - $("#fileInputer").click(); - } - }); -} function savePlan(planState){ if(contentCheck()){ if(confirm("저장하시겠습니까?")){ @@ -136,17 +115,6 @@ function savePlan(planState){ } } -function setFileDiv(file, idx){ - const uploadDiv = $("#uploadDiv"); - if($(".uploadedFileDelete").length===0 && $(".fileDelete").length === 0){ - uploadDiv.empty(); - } - let fileInfo = "
"; - fileInfo += file.name+" "+byteCalculation(file.size)+" "; - fileInfo += "삭제"; - fileInfo += "
"; - uploadDiv.append(fileInfo); -} function contentCheck(){ let flag = true; diff --git a/src/main/resources/static/js/publicBoard/notice.js b/src/main/resources/static/js/publicBoard/notice.js index e69de29b..e8e84803 100644 --- a/src/main/resources/static/js/publicBoard/notice.js +++ b/src/main/resources/static/js/publicBoard/notice.js @@ -0,0 +1,15 @@ +let files = []; + +$(document).on('click', '#addNoticeBtn', function (){ + getEditModal(null, "PLB001") +}) + +$(document).on('click', '.planTr', function (){ + $(".trChkBox").prop("checked", false); + $(this).find(".trChkBox").prop("checked", true); + getViewModal(Number($(this).find(".planKey").val()), "PLB001"); +}) + +$(document).on('click', '#saveBtn', function (){ + savePublicBoard("noticeEditForm") +}) \ No newline at end of file diff --git a/src/main/resources/static/js/publicBoard/publicBoard.js b/src/main/resources/static/js/publicBoard/publicBoard.js index e69de29b..e7b3c806 100644 --- a/src/main/resources/static/js/publicBoard/publicBoard.js +++ b/src/main/resources/static/js/publicBoard/publicBoard.js @@ -0,0 +1,167 @@ +$(document).on('click', '#commentSaveBtn', function (){ + if(!$("#comment").val()) { + alert("댓글을 입력해주세요.") + }else{ + if (confirm("등록하시겠습니까?")) { + contentFade("in") + const formData = new FormData($("#commentForm")[0]); + $.ajax({ + type : 'POST', + data : formData, + url : "/publicBoard/saveComment", + processData: false, + contentType: false, + beforeSend: function (xhr){ + xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val()); + }, + success : function(result) { + alert("저장되었습니다."); + contentFade("out"); + }, + error : function(xhr, status) { + alert("저장에 실패하였습니다.") + contentFade("out"); + } + }) + } + } +}) + +$(document).on('click', '.childCommentBtn', function (){ + const childCommentDiv = $(this).parents(".commentRow").find(".childCommentDiv") + childCommentDiv.show(); + $("#parentComment").val($(this).parents(".commentRow").find(".commentKey").val()); + childCommentDiv.empty().append($("#commentForm")) +}) +$(document).on('click', '.deleteCommentBtn', function (){ + const publicKey = $(this).parents(".commentRow").find(".publicKey"); + const commentKey = $(this).parents(".commentRow").find(".commentKey"); + $.ajax({ + type : 'POST', + data : {publicKey: publicKey, commentKey: commentKey}, + url : "/publicBoard/deleteComment", + beforeSend: function (xhr){ + xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val()); + }, + success : function(result) { + alert("삭제되었습니다."); + contentFade("out"); + }, + error : function(xhr, status) { + alert("삭제를 실패하였습니다.") + contentFade("out"); + } + }) +}) +function getEditModal(publicKey, publicType){ + $.ajax({ + url: '/publicBoard/editModal', + data: {publicKey: publicKey, publicType: publicType}, + type: 'GET', + dataType:"html", + success: function(html){ + $("#editContent").empty().append(html) + $("#content").summernote({ + lang:'ko-KR', + height: 350, + disableDragAndDrop: true, + toolbar: [ + ['style', ['style']], + ['font', ['bold', 'underline', 'clear']], + ['color', ['color']], + ['para', ['ul', 'ol', 'paragraph']], + ['table', ['table']] + ] + }); + setUploadDiv(); + $("#editModal").modal('show'); + }, + error:function(){ + + } + }); +} + +function getViewModal(publicKey, publicType){ + $.ajax({ + url: '/publicBoard/viewModal', + data: {publicKey: publicKey, publicType: publicType}, + type: 'GET', + dataType:"html", + success: function(html){ + $("#viewContent").empty().append(html) + $("#comment").summernote({ + lang:'ko-KR', + height: 100, + disableDragAndDrop: true, + toolbar: [ + ['style', ['style']], + ['font', ['bold', 'underline', 'clear']], + ['color', ['color']], + ['para', ['ul', 'ol', 'paragraph']], + ['table', ['table']] + ] + }); + $("#viewModal").modal('show'); + }, + error:function(){ + + } + }); +} + +function savePublicBoard(formId){ + if(contentCheck(formId)){ + if(confirm("저장하시겠습니까?")){ + contentFade("in"); + const formData = new FormData($("#"+formId)[0]); + for(const file of files) { + if(!file.isDelete) + formData.append('uploadFiles', file, file.name); + } + $(".text-decoration-line-through").each(function (idx, el){ + formData.append('fileSeq', $(el).attr("data-fileseq")); + }) + $.ajax({ + type : 'POST', + data : formData, + url : "/publicBoard/saveContent", + processData: false, + contentType: false, + success : function(result) { + alert("저장되었습니다."); + contentFade("out"); + $("#editModal").modal('hide'); + getViewModal(result); + }, + error : function(xhr, status) { + alert("저장에 실패하였습니다.") + contentFade("out"); + } + }) + } + } +} + +function contentCheck(formId){ + let flag = true; + if(!$("#title").val()){ + alert("제목을 입력해주세요.") + flag = false; + } + let totalSize = 0; + for(const file of files) { + if(!file.isDelete){ + totalSize+=file.size; + if(file.size>209715200){ + alert("파일당 사이즈는 200MB을 넘길 수 없습니다.") + flag = false; + } + } + } + if(totalSize>524288000){ + alert("첨부파일의 용량 합은 500MB를 넘길 수 없습니다.") + flag = false; + } + return flag; +} \ No newline at end of file diff --git a/src/main/resources/templates/publicBoard/notice/noticeEditModal.html b/src/main/resources/templates/publicBoard/notice/noticeEditModal.html new file mode 100644 index 00000000..d0eb9932 --- /dev/null +++ b/src/main/resources/templates/publicBoard/notice/noticeEditModal.html @@ -0,0 +1,64 @@ + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/publicBoard/notice/noticePage.html b/src/main/resources/templates/publicBoard/notice/noticePage.html new file mode 100644 index 00000000..4ba65eb2 --- /dev/null +++ b/src/main/resources/templates/publicBoard/notice/noticePage.html @@ -0,0 +1,146 @@ + + + + + + +
+
+

공지사항

+ + +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+ + +
+
+ +
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
제목관서부서작성자작성일시첨부파일댓글
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+ + + +
+ \ No newline at end of file diff --git a/src/main/resources/templates/publicBoard/notice/noticeViewModal.html b/src/main/resources/templates/publicBoard/notice/noticeViewModal.html new file mode 100644 index 00000000..2a153caf --- /dev/null +++ b/src/main/resources/templates/publicBoard/notice/noticeViewModal.html @@ -0,0 +1,142 @@ + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/publicBoard/notice.html b/src/main/resources/templates/publicBoard/qna/qnaPage.html similarity index 99% rename from src/main/resources/templates/publicBoard/notice.html rename to src/main/resources/templates/publicBoard/qna/qnaPage.html index 7cd5533e..2702b240 100644 --- a/src/main/resources/templates/publicBoard/notice.html +++ b/src/main/resources/templates/publicBoard/qna/qnaPage.html @@ -8,7 +8,7 @@
-

공지사항

+

Q&A