diff --git a/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java b/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java index cef90d6..30b648a 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java +++ b/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java @@ -1,16 +1,18 @@ package com.dbnt.kcgfilemanager.controller; +import com.dbnt.kcgfilemanager.model.Board; import com.dbnt.kcgfilemanager.model.UserInfo; import com.dbnt.kcgfilemanager.service.UserInfoService; import lombok.RequiredArgsConstructor; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import java.security.Principal; import java.time.LocalDateTime; +import java.util.List; @RestController @RequiredArgsConstructor @@ -32,8 +34,16 @@ public class BoardController { UserInfo loginUser = ((UserInfo)((UsernamePasswordAuthenticationToken) principal).getPrincipal()); mav.addObject("userId", loginUser.getUserId()); mav.addObject("userName", loginUser.getName()); - mav.addObject("nowDate", LocalDateTime.now()); return mav; } + @PostMapping("/saveContent") + public Integer saveContent(Board board){ + System.out.println("controller coming"); + return board.getContentSeq(); + } + @PostMapping("/uploadFiles") + public void uploadFiles(Integer contentSeq, MultipartHttpServletRequest request){ + System.out.println("controller coming"); + } } diff --git a/src/main/java/com/dbnt/kcgfilemanager/model/Board.java b/src/main/java/com/dbnt/kcgfilemanager/model/Board.java index fca7086..a99136e 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/model/Board.java +++ b/src/main/java/com/dbnt/kcgfilemanager/model/Board.java @@ -5,9 +5,11 @@ import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; +import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.persistence.*; import java.time.LocalDateTime; +import java.util.List; @Getter @Setter @@ -33,4 +35,11 @@ public class Board extends BaseModel{ private String createId; @Column(name = "CREATE_DATE") private LocalDateTime createDate; + + @Transient + private List childFiles; + @Transient + private List hashTags; + @Transient + private String hashTagStr; } diff --git a/src/main/resources/static/js/board/contentWrite.js b/src/main/resources/static/js/board/contentWrite.js index 67a66de..91b59e9 100644 --- a/src/main/resources/static/js/board/contentWrite.js +++ b/src/main/resources/static/js/board/contentWrite.js @@ -1,7 +1,29 @@ +const files = []; + $(function(){ + $("#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("fileDelete")<0){ + $("#fileInputer").click(); + } + }); + $("#description").summernote({ lang:'ko-KR', height: 120, + disableDragAndDrop: true, toolbar: [ ['style', ['style']], ['font', ['bold', 'underline', 'clear']], @@ -11,6 +33,38 @@ $(function(){ ] }) }) +$(document).on('change', '#fileInputer', function (){ + for(const file of this.files){ + setFileDiv(file, files.push(file)); + } + this.value = null; +}) +$(document).on('click', '.fileDelete', function (){ + const target = $(this); + files[Number(target.attr("data-fileidx"))].isDelete = true; + target.parent().remove(); + const uploadDiv = $("#uploadDiv"); + if(uploadDiv.children().length === 0){ + uploadDiv.append("
파일을 업로드 해주세요."); + } +}) +$(document).on('click', '#saveBtn', function (){ + const formData = new FormData($("#contentForm")[0]); + $.ajax({ + type : 'POST', + data : formData, + url : "/board/saveContent", + processData: false, + contentType: false, + success : function(data) { + $("#contentSeq").val(data); + uploadFiles(); + }, + error : function(xhr, status) { + + } + }) +}) $(document).on('change', '.categorySelector', function (){ const categorySeq = Number(this.value); @@ -46,4 +100,45 @@ function selectorDisabler(depth){ this[0].selected = true; } }) +} + +function uploadFiles(){ + const formData = new FormData($("#fileForm")[0]); + $.ajax({ + type : 'POST', + data : formData, + url : "/board/uploadFiles", + enctype: "multipart/form-data", + processData: false, + contentType: false, + success : function(data) { + alert("저장되었습니다.") + }, + error : function(xhr, status) { + + } + }) +} + +function setFileDiv(file, idx){ + const uploadDiv = $("#uploadDiv"); + if(files.length===1){ + uploadDiv.empty(); + } + let fileInfo = "
"; + fileInfo += file.name+" "+byteCalculation(file.size)+" "; + fileInfo += "삭제"; + fileInfo += "
"; + uploadDiv.append(fileInfo); +} + +function byteCalculation(size) { + const bytes = parseInt(size); + const s = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB']; + const e = Math.floor(Math.log(bytes)/Math.log(1024)); + + if(e === "-Infinity") return "0 "+s[0]; + else + return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e]; + } \ No newline at end of file diff --git a/src/main/resources/templates/board/contentWrite.html b/src/main/resources/templates/board/contentWrite.html index d9d1c31..f0bcf37 100644 --- a/src/main/resources/templates/board/contentWrite.html +++ b/src/main/resources/templates/board/contentWrite.html @@ -20,90 +20,101 @@
-
- -
- +
+
+
-
- + + + - - -
-
- +
+
+ -
-
- +
+
+ -
-
-
- -
- -
-
-
- -
- - -
- -
- -
-
-
- -
-
-
파일을 업로드 해주세요. + +
+
+
-
-
- -
-
+
+ +
+ +
-
-
- -
- +
+ +
+ + +
+ +
+ +
-
+
+ +
+
+
파일을 업로드 해주세요. +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ + +
diff --git a/src/main/resources/templates/fragments/leftMenu.html b/src/main/resources/templates/fragments/leftMenu.html index d7ac4b2..fba1dc8 100644 --- a/src/main/resources/templates/fragments/leftMenu.html +++ b/src/main/resources/templates/fragments/leftMenu.html @@ -13,10 +13,10 @@
- +