Skip to content

Commit 6a45a91

Browse files
Dodanie mozliwosci wytnij/wklej plikow
1 parent 8bf59e3 commit 6a45a91

File tree

3 files changed

+129
-35
lines changed

3 files changed

+129
-35
lines changed

src/main/java/pl/dfs/distributedfilesystem/controllers/FilesAccessController.java

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ public String mainPage(Model model, HttpSession session) {
5151
try {
5252
session.getAttribute("path");
5353
session.getAttribute("error");
54+
session.getAttribute("pathToMove");
5455
}
5556
catch (Exception e){
5657
session.setAttribute("path","/");
5758
session.setAttribute("error","");
59+
session.setAttribute("pathToMove","");
5860
}
5961

6062
List<ObjectOnTheList> objectsOnTheList = new ArrayList<>();
@@ -168,6 +170,9 @@ else if(filename.endsWith(".zip"))
168170
} else if(session.getAttribute("error").equals("fileNameAlreadyExists")) {
169171
session.setAttribute("error","");
170172
model.addAttribute("error","fileNameAlreadyExists");
173+
} else if(session.getAttribute("error").equals("moveFileFromCutNameAlreadyExists")) {
174+
session.setAttribute("error","");
175+
model.addAttribute("error","moveFileFromCutNameAlreadyExists");
171176
}
172177
else {
173178
model.addAttribute("error","");
@@ -396,7 +401,8 @@ public String changeFolder(@RequestParam String file,@RequestParam String folder
396401

397402
@RequestMapping("changeFolderName")
398403
public String changeFolderName(Model model, HttpSession session,@RequestParam String oldFolderName,@RequestParam String newFolderName) {
399-
404+
if(oldFolderName.equals(newFolderName))
405+
return "redirect:/";
400406
ArrayList<String> subfoldersWithoutSelectedOne = foldersRepository.subfoldersOfFolder(session.getAttribute("path").toString());
401407
subfoldersWithoutSelectedOne.remove(oldFolderName);
402408
if(subfoldersWithoutSelectedOne.contains(newFolderName)) {
@@ -434,7 +440,8 @@ public String changeFolderName(Model model, HttpSession session,@RequestParam St
434440

435441
@RequestMapping("changeFileName")
436442
public String changeFileName(Model model, HttpSession session,@RequestParam String oldFileName,@RequestParam String newFileName) {
437-
443+
if(oldFileName.equals(newFileName))
444+
return "redirect:/";
438445
int exists = 0;
439446
for(int i = 0; i < filesRepository.getAllFiles().size();i++) {
440447
if(filesRepository.getAllFiles().get(i).getName().equals(session.getAttribute("path") + newFileName + "/"))
@@ -460,7 +467,6 @@ public String changeFileName(Model model, HttpSession session,@RequestParam Stri
460467
divided.remove(i);
461468
}
462469
} catch (Exception e){
463-
//TODO Spójność zmiany nazwy między węzłami
464470
toChangeRepository.add(new ToChange(address,"renameFile ","\"" +session.getAttribute("path") + oldFileName + "/" + "\" ","\"" +session.getAttribute("path") + newFileName + "/" + "\" "));
465471
}
466472
}
@@ -477,6 +483,63 @@ public String changeFileName(Model model, HttpSession session,@RequestParam Stri
477483
return "redirect:/";
478484
}
479485

486+
@RequestMapping("/savePathToMove")
487+
public String savePathToMove(HttpSession session,Model model,@RequestParam String filename) {
488+
session.setAttribute("pathToMove",session.getAttribute("path") + filename + "/");
489+
return "redirect:/";
490+
}
491+
492+
@RequestMapping("/moveFile")
493+
public String moveFIle(HttpSession session) {
494+
String path = session.getAttribute("path").toString();
495+
String pathToMove = session.getAttribute("pathToMove").toString();
496+
String filenameToMove = session.getAttribute("pathToMove").toString().split("/")[session.getAttribute("pathToMove").toString().split("/").length-1];
497+
498+
boolean exists = false;
499+
for(int i = 0; i < filesRepository.getAllFiles().size();i++) {
500+
if(filesRepository.getAllFiles().get(i).getName().equals(path + filenameToMove+"/")) {
501+
exists = true;
502+
break;
503+
}
504+
}
505+
506+
if(exists) {
507+
session.setAttribute("error","moveFileFromCutNameAlreadyExists");
508+
}
509+
else {
510+
for(int i = 0; i < filesRepository.getAllFiles().size();i++) {
511+
if(filesRepository.getAllFiles().get(i).getName().equals(pathToMove)) {
512+
filesRepository.getAllFiles().get(i).setName(path + filenameToMove + "/");
513+
filesRepository.getAllFiles().get(i).setPath(path);
514+
515+
String addresses = filesRepository.getFileNode(session.getAttribute("path") + filenameToMove + "/");
516+
ArrayList<String> divided = new ArrayList<>(Arrays.asList(addresses.split(",")));
517+
for(int j = divided.size()-1;j>=0;j--) {
518+
String address = divided.get(j);
519+
try {
520+
dataNodesRepository.get(address).writeString("renameFile ");
521+
dataNodesRepository.get(address).writeString("\"" + pathToMove+ "\" ");
522+
dataNodesRepository.get(address).writeString("\"" + path + filenameToMove + "\" ");
523+
dataNodesRepository.get(address).writeFlush();
524+
String response = dataNodesRepository.get(address).readResponse();
525+
if (response.equals("success")) {
526+
divided.remove(i);
527+
}
528+
} catch (Exception e){
529+
toChangeRepository.add(new ToChange(address,"renameFile ","\"" + pathToMove + "\" ","\"" + path + filenameToMove + "\" "));
530+
}
531+
}
532+
filesRepository.writeFilesInformationFile();
533+
break;
534+
}
535+
}
536+
}
537+
538+
539+
540+
return "redirect:/";
541+
}
542+
480543
@RequestMapping("/about")
481544
public String about(Model model){
482545
ArrayList<DataNodeOnTheList> dataNodeOnTheListArrayList = new ArrayList<>();

src/main/resources/templates/about.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<title>DFS - About</title>
66
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css"/>
77
<script src="/js/loginPage.js"></script>
8+
<link rel="icon" type="image/png" href="/fileIcons/database.png">
89
</head>
910
<body class="bg-light">
1011
<div class="container">

src/main/resources/templates/index.html

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<script src="/js/Scripts.js"></script>
99
<link rel="icon" type="image/png" href="/fileIcons/database.png">
1010
<script>
11-
function enableEditFolder(name){
11+
function enableEditFolder(name) {
1212

1313
document.getElementById(name).innerHTML = "" +
1414
"" +
@@ -18,7 +18,8 @@
1818

1919
document.getElementById(name).action = "/changeFolderName";
2020
}
21-
function enableEditFile(name){
21+
22+
function enableEditFile(name) {
2223

2324
document.getElementById(name).innerHTML = "" +
2425
"" +
@@ -28,7 +29,11 @@
2829

2930
document.getElementById(name).action = "/changeFileName";
3031
}
32+
3133
</script>
34+
<script src="/js/jquery.js"></script>
35+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
36+
<script src="/bootstrap/js/bootstrap.bundle.js"></script>
3237
</head>
3338
<body class="bg-light">
3439
<div class="container">
@@ -57,6 +62,19 @@
5762
<div class="col-md-10 text-left">
5863
<p th:text="'Ścieżka: ' + ${session.path} "></p>
5964
</div>
65+
<div class="col-md-2">
66+
<div class="dropdown">
67+
<button class="btn btn-primary btn-sm dropdown-toggle" type="button" id="optionsDropdown"
68+
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
69+
Opcje
70+
</button>
71+
<div class="dropdown-menu" aria-labelledby="optionsDropdown">
72+
<form method="post" action="/moveFile">
73+
<input class="dropdown-item" type="submit" value="Wklej"/>
74+
</form>
75+
</div>
76+
</div>
77+
</div>
6078
</div>
6179
<hr>
6280
<div class="row mt-3">
@@ -65,11 +83,10 @@
6583
<thead class="thead-light">
6684
<tr>
6785
<th style="width: 10%">Typ</th>
68-
<th onclick="sortTable(1,'filesListTable')" style="width: 40%;">Nazwa</th>
86+
<th onclick="sortTable(1,'filesListTable')" style="width: 60%;">Nazwa</th>
6987
<th onclick="sortTable(2,'filesListTable')" style="width: 10%;">Rozmiar</th>
7088
<th onclick="sortTable(3,'filesListTable')" style="width: 10%;">Replikacja</th>
71-
<th style="width: 20%">Akcja</th>
72-
<th style="width: 10%;">Usuń</th>
89+
<th style="width: 10%">Akcja</th>
7390
</tr>
7491
</thead>
7592
<tr th:each="singleObject: ${objectsOnTheList}" th:object="${singleObject}">
@@ -78,45 +95,54 @@
7895
<td th:if="${singleObject.type}=='file'">
7996
<form method="post" action="/downloadFile" th:id="${singleObject.name}">
8097
<input type="hidden" th:name="filename" th:value="${singleObject.name}"/>
81-
<input class="buttonLink" type="submit" draggable="true" th:id="${singleObject.name}" ondragstart="drag(event)" th:value="${singleObject.name}"/>
98+
<input class="buttonLink" type="submit" draggable="true" th:id="${singleObject.name}"
99+
ondragstart="drag(event)" th:value="${singleObject.name}"/>
82100
</form>
83101
</td>
84102
<td th:if="${singleObject.type}=='folder'">
85103
<form method="post" action="/enterFolder" th:id="${singleObject.name}">
86104
<input type="hidden" th:name="foldername" th:value="${singleObject.name}"/>
87-
<input class="buttonLink" type="submit" ondragover="allowDrop(event)" th:id="${singleObject.name}" ondrop="drop(event)" th:value="${singleObject.name}"/>
105+
<input class="buttonLink" type="submit" ondragover="allowDrop(event)"
106+
th:id="${singleObject.name}" ondrop="drop(event)" th:value="${singleObject.name}"/>
88107
</form>
89108
</td>
90109
<td th:text="*{size}"></td>
91110
<td th:text="*{replication}"></td>
111+
<td th:if="${singleObject.type}=='file' or (${singleObject.type}=='folder'and ${singleObject.name}!='..')">
112+
<div class="dropdown">
113+
<button class="btn btn-primary btn-sm dropdown-toggle" type="button" id="dropdownMenuButton"
114+
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
115+
Opcje
116+
</button>
117+
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
92118

119+
<form th:if="${singleObject.type}=='file'" method="post" action="/savePathToMove">
120+
<input type="hidden" th:name="filename" th:value="${singleObject.name}"/>
121+
<input class="dropdown-item" type="submit" value="Wytnij"/>
122+
</form>
93123

94-
<td th:if="${singleObject.type}=='file'">
95-
<button name="changeName" id="changeNameFile" th:onclick="'enableEditFile(\'' + ${singleObject.name} + '\');'">Zmień nazwę</button>
96-
</td>
97-
<td th:if="${singleObject.type}=='folder'and ${singleObject.name}!='..'">
98-
<button name="changeName" id="changeNameFolder" th:onclick="'enableEditFolder(\'' + ${singleObject.name} + '\');'">Zmień nazwę</button>
99-
</td>
100-
<td th:if="${singleObject.type}=='folder'and ${singleObject.name}=='..'">
101-
-
102-
</td>
124+
<a class="dropdown-item" href="#" th:onclick="'enableEditFile(\'' + ${singleObject.name} + '\');'" th:if="${singleObject.type}=='file'">Zmień nazwę
125+
</a>
126+
<a class="dropdown-item" href="#" th:onclick="'enableEditFolder(\'' + ${singleObject.name} + '\');'" th:if="${singleObject.type}=='folder'and ${singleObject.name}!='..'">Zmień nazwę</a>
103127

104-
<td th:if="${singleObject.type}=='file'">
105-
<form method="post" action="/deleteFile">
106-
<input type="hidden" th:name="filename" th:value="${singleObject.name}"/>
107-
<input type="submit" value="usuń"/>
108-
</form>
109-
</td>
110-
<td th:if="${singleObject.type}=='folder'and ${singleObject.name}!='..'">
111-
<form method="post" action="/deleteFolder">
112-
<input type="hidden" th:name="foldername" th:value="${singleObject.name}"/>
113-
<input type="submit" value="usuń"/>
114-
</form>
128+
<div class="dropdown-divider"></div>
129+
130+
<form th:if="${singleObject.type}=='file'" method="post" action="/deleteFile">
131+
<input type="hidden" th:name="filename" th:value="${singleObject.name}"/>
132+
<input class="dropdown-item" type="submit" value="Usuń"/>
133+
</form>
134+
135+
<form th:if="${singleObject.type}=='folder'and ${singleObject.name}!='..'" method="post" action="/deleteFolder">
136+
<input type="hidden" th:name="foldername" th:value="${singleObject.name}"/>
137+
<input class="dropdown-item" type="submit" value="Usuń"/>
138+
</form>
139+
140+
</div>
141+
</div>
115142
</td>
116143
<td th:if="${singleObject.type}=='folder'and ${singleObject.name}=='..'">
117144
-
118145
</td>
119-
120146
</tr>
121147
</table>
122148
</div>
@@ -133,18 +159,22 @@
133159
<p id="errorField4" class="text-danger" th:if="${error}=='noFileToSend'">Nie wybrano pliko do
134160
wysłania.</p>
135161
<p id="errorField5" class="text-danger" th:if="${error}=='notEnoughSpace'">Za mało miejsca w
136-
systemie aby zapisać plik.</p>
162+
systemie aby zapisać plik.</p>
137163
<p id="errorField6" class="text-danger" th:if="${error}=='fileNotExist'">Wystąpił błąd wewnętrzy,
138-
plik nie istnieje w systemie. Sugeruje to zewnętrzą ingerencję w folder przechowujący pliki
139-
w węzłach danych.</p>
164+
plik nie istnieje w systemie. Sugeruje to zewnętrzą ingerencję w folder przechowujący pliki
165+
w węzłach danych.</p>
140166
<p id="errorField7" class="text-danger" th:if="${error}=='folderNameAlreadyExists'">Nie można było
141167
zmienić nazwy folderu. Taka nazwa jest już używana.</p>
142168
<p id="errorField8" class="text-danger" th:if="${error}=='fileNameAlreadyExists'">Nie można było
143169
zmienić nazwy pliku. Taka nazwa jest już używana. Każdy plik w systemie musi mieć unikatową nazwę.</p>
170+
<p id="errorField9" class="text-danger" th:if="${error}=='moveFileFromCutNameAlreadyExists'">Nie przenieść
171+
tutaj pliku, bo taka nazwa jest już używana, zmień nazwę pliku przed jego przeniesieniem.</p>
144172
</div>
145173
</div>
146174
<div class="fixed-bottom text-center">
147-
Icons made by <a href="https://www.flaticon.com/authors/smashicons" title="smashicons">smashicons</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> are licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
175+
Icons made by <a href="https://www.flaticon.com/authors/smashicons" title="smashicons">smashicons</a> from <a
176+
href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> are licensed by <a
177+
href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
148178
</div>
149179
</div>
150180
</body>

0 commit comments

Comments
 (0)