Showing
5 changed files
with
69 additions
and
9 deletions
... | @@ -73,10 +73,43 @@ app.get('/home/:directoryName/upload', (req, res) => { | ... | @@ -73,10 +73,43 @@ app.get('/home/:directoryName/upload', (req, res) => { |
73 | }); | 73 | }); |
74 | 74 | ||
75 | 75 | ||
76 | +// Modify Directory name | ||
77 | +app.get('/home/:directoryName/modify', (req, res) => { | ||
78 | + // exist query.newName | ||
79 | + var directoryName = new String(req.params.directoryName); | ||
80 | + var newName = new String(req.query.newName); | ||
81 | + if (req.query.newName) { | ||
82 | + // modify Directory name and Files | ||
83 | + var path = dataFolder + '/' + directoryName; | ||
84 | + fs.readdirSync(path).forEach(function(file,index){ | ||
85 | + var curPath = path + "/" + file; | ||
86 | + var fileNameArr = string.split("_"); | ||
87 | + var newPath = path + "/" + newName + "_" + fileNameArr[1]; | ||
88 | + fs.rename(curPath, newPath, function (err) { | ||
89 | + if (err) { | ||
90 | + console.log("File Rename error: " + err); | ||
91 | + } | ||
92 | + }); | ||
93 | + }); | ||
94 | + fs.rename(path, dataFolder + '/' + newName, function (err) { | ||
95 | + if (err) { | ||
96 | + console.log("Directory Rename error: " + err); | ||
97 | + } else { | ||
98 | + console.log("Directory Rename: " + directoryName + " -> " + newName); | ||
99 | + } | ||
100 | + }); | ||
101 | + res.redirect('/'); | ||
102 | + } | ||
103 | + else { | ||
104 | + res.render('directoryModifyCheck', {directoryName:JSON.stringify(directoryName)}); | ||
105 | + } | ||
106 | +}); | ||
107 | + | ||
108 | + | ||
76 | // Delete Directory | 109 | // Delete Directory |
77 | app.get('/home/:directoryName/delete', (req, res) => { | 110 | app.get('/home/:directoryName/delete', (req, res) => { |
78 | // exist query.real | 111 | // exist query.real |
79 | - var directoryName = req.params.directoryName; | 112 | + var directoryName = new String(req.params.directoryName); |
80 | if (req.query.real) { | 113 | if (req.query.real) { |
81 | // Remove Directory and Files | 114 | // Remove Directory and Files |
82 | var path = dataFolder + '/' + directoryName; | 115 | var path = dataFolder + '/' + directoryName; |
... | @@ -88,7 +121,7 @@ app.get('/home/:directoryName/delete', (req, res) => { | ... | @@ -88,7 +121,7 @@ app.get('/home/:directoryName/delete', (req, res) => { |
88 | res.redirect('/'); | 121 | res.redirect('/'); |
89 | } | 122 | } |
90 | else { | 123 | else { |
91 | - res.render('directoryDeleteCheck'); | 124 | + res.render('directoryDeleteCheck', {directoryName:JSON.stringify(directoryName)}); |
92 | } | 125 | } |
93 | }); | 126 | }); |
94 | 127 | ... | ... |
1 | script. | 1 | script. |
2 | - confirm("모든 이미지가 삭제됩니다. 정말 분류를 삭제하시겠습니까?") ? location.href = location + 'real=true' : history.back(); | 2 | + var directoryName= !{directoryName}; |
3 | + confirm('모든 이미지가 삭제됩니다.\n정말 ' + directoryName + ' 분류를 삭제하시겠습니까?') | ||
4 | + ? location.href = location + 'real=true' : history.back(); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
views/directoryModifyCheck.pug
0 → 100644
1 | +script. | ||
2 | + var directoryName= !{directoryName}; | ||
3 | + var result = prompt('새 분류명을 입력하세요. (기존: ' + directoryName + ')'); | ||
4 | + | ||
5 | + if (result) { | ||
6 | + location.href = location + 'newName=' + result; | ||
7 | + } else { | ||
8 | + alert('분류명을 수정하지 않습니다.'); | ||
9 | + history.back(); | ||
10 | + } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -3,22 +3,36 @@ html | ... | @@ -3,22 +3,36 @@ html |
3 | head | 3 | head |
4 | meta(charset='utf-8') | 4 | meta(charset='utf-8') |
5 | title 분류 리스트 | 5 | title 분류 리스트 |
6 | + | ||
7 | + | ||
8 | + | ||
6 | body | 9 | body |
7 | form(action="directory_check" method="post") | 10 | form(action="directory_check" method="post") |
8 | p 새로 만들 분류명: | 11 | p 새로 만들 분류명: |
9 | input(name="directoryName", type="text") | 12 | input(name="directoryName", type="text") |
10 | input(type="submit", value="생성") | 13 | input(type="submit", value="생성") |
11 | br | 14 | br |
15 | + | ||
16 | + | ||
12 | form(action="test" method="post" enctype="multipart/form-data") | 17 | form(action="test" method="post" enctype="multipart/form-data") |
13 | p 테스트할 이미지: | 18 | p 테스트할 이미지: |
14 | input(name="ImageTest", type="file") | 19 | input(name="ImageTest", type="file") |
15 | input(type="submit", value="테스트") | 20 | input(type="submit", value="테스트") |
16 | br | 21 | br |
22 | + | ||
23 | + | ||
17 | ul | 24 | ul |
18 | - var folderList=fileList | 25 | - var folderList=fileList |
19 | each folder in folderList | 26 | each folder in folderList |
20 | - li=folder | ||
21 | - form(action="home/"+folder method="get") | ||
22 | - input(type="submit", value="편집") | ||
23 | - form(action="home/"+folder+"/delete" method="get") | ||
24 | - input(type="submit", value="삭제") | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
27 | + div(style="margin-right:30px; float:left;") | ||
28 | + li | ||
29 | + a(href=location+folder)=folder | ||
30 | + | ||
31 | + div(style="margin-right:5px; float:left;") | ||
32 | + form(action="home/"+folder+"/modify" method="get") | ||
33 | + input(type="submit", value="수정") | ||
34 | + | ||
35 | + div | ||
36 | + form(action="home/"+folder+"/delete" method="get") | ||
37 | + input(type="submit", value="삭제") | ||
38 | + br | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment