최고관리자 메인화면 수정(폴더 생성, 파일 추가)

main
이범준 1 year ago
parent a172e08629
commit 0a9a1c01bc

@ -6,6 +6,8 @@ import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import cokr.xit.base.user.ManagedUser;
@ -25,7 +27,7 @@ public class UserController extends cokr.xit.base.user.web.UserController<Manage
return mav;
}
@RequestMapping(name="배치실행",value="/superUser/executeBatch.do")
@RequestMapping(name="배치 수동 실행",value="/superUser/executeBatch.do")
public ModelAndView executeBatch(String batch) {
ModelAndView mav = new ModelAndView();
@ -54,7 +56,7 @@ public class UserController extends cokr.xit.base.user.web.UserController<Manage
}
@RequestMapping(name="파일 현황 조회",value="/superUser/getFileTree.do")
@RequestMapping(name="서버 파일 현황 조회",value="/superUser/getFileTree.do")
public ModelAndView getFileTree() throws Exception {
ModelAndView mav = new ModelAndView();
@ -63,4 +65,38 @@ public class UserController extends cokr.xit.base.user.web.UserController<Manage
mav.addObject("tree", tree);
return mav;
}
@RequestMapping(name="최고관리자 서버 폴더 생성", value="/superUser/createDirectory.do")
public ModelAndView createDirectory(@RequestParam(value="directories[]") String... directories) throws Exception {
boolean saved = false;
String path = String.join(File.separator, directories);
File newDir = new File(path);
saved = newDir.mkdir();
ModelAndView mav = new ModelAndView();
mav.setViewName("jsonView");
mav.addObject("saved", saved);
return mav;
}
@RequestMapping(name="최고관리자 서버 파일 추가", value="/superUser/importFile.do")
public ModelAndView importFile(MultipartFile newFile, @RequestParam(value="directories[]") String... directories) throws Exception {
boolean saved = false;
String path = String.join(File.separator, directories);
path = path + File.separator + newFile.getOriginalFilename();
File file = new File(path);
newFile.transferTo(file);
saved = file.exists();
ModelAndView mav = new ModelAndView();
mav.setViewName("jsonView");
mav.addObject("saved", saved);
return mav;
}
}

@ -56,7 +56,7 @@
</div>
<input type="file" id="serverFile" name="serverFile" hidden onchange="fnImportFile(this);" />
<jsp:include page="/WEB-INF/jsp/include/bottom.jsp" />
@ -66,7 +66,9 @@
<script>
/**
* 수동 배치 실행
*/
function exceuteBatch(batch){
ajax.get({
url : wctx.url("/user/superUser/executeBatch.do"),
@ -77,28 +79,89 @@ function exceuteBatch(batch){
});
}
var tempPathArray = [];
/**
* 파일트리 컨텍스트 메뉴
*/
function customContextMenu(node){
var items = {
newDirectory : {
label:"디렉토리 추가",
action:function(data){
var inst = $.jstree.reference(data.reference);
var obj = inst.get_node(data.reference);
var pathArray = $("#fileTree").jstree("get_path", obj.id);
var directoryName = prompt("디렉토리명을 입력하세요");
if(directoryName != null && directoryName != ""){
pathArray.push(directoryName);
ajax.post({
url : wctx.url("/user/superUser/createDirectory.do"),
data : {
directories : pathArray
},
success : resp => {
if(resp.saved){
getFileTree();
} else {
alert("폴더 생성에 실패하였습니다.");
}
}
});
}
}
},
newFile : {
label:"파일 추가",
action:function(data){
var inst = $.jstree.reference(data.reference);
var obj = inst.get_node(data.reference);
var pathArray = $("#fileTree").jstree("get_path", obj.id);
tempPathArray = pathArray;
$("#serverFile").click();
}
}
};
if(node.type == "file") {
delete items.newDirectory;
delete items.newFile;
}
return items;
}
$('#fileTree').jstree({
"core" : {
"data": {}
},
"plugins": ["types"],
"plugins": ["types","contextmenu"],
"types" : {
"directory" : { "icon" : "fa fa-folder" },
"file" : { "icon" : "fa fa-file" }
},
trace: true,
core:{check_callback:true,
multiple:false
},
checkbox:{
whole_node:false,
tie_selection:false
core : {
check_callback:true,
multiple:false
},
contextmenu : {
items : customContextMenu
}
});
$("#fileTree").bind("refresh.jstree", function(){
$(this).jstree("open_all");
});
/**
* 파일트리 조회
*/
function getFileTree(){
ajax.get({
url : wctx.url("/user/superUser/getFileTree.do"),
@ -113,6 +176,33 @@ function getFileTree(){
});
}
/**
* 파일 추가
*/
function fnImportFile(obj){
if(obj.files.length == 0){
return;
}
var form = new FormData();
form.append("newFile", obj.files[0]);
form.append("directories[]", tempPathArray);
ajax.post({
url : wctx.url("/user/superUser/importFile.do"),
data : form,
processData : false,
contentType : false,
success : resp => {
if(resp.saved){
getFileTree();
} else {
alert("파일 추가에 실패하였습니다.");
}
}
});
}
$(document).ready(function(){
getFileTree();
});

Loading…
Cancel
Save