Commit 2df8b52238e931eff627e5eb17bd03911e38b089
1 parent
f6a02b6c
Choix du fichier pour la sauvegarde d'une configuration
Seul les fichiers uploadés par l'utilisateur connecté sont affichés. Il faudra s'occuper du bouton : "Lancer la mise à jour" On peut imaginer lors de l'appuie, la création d'un fichier de métadonnées qui sera interprété par un autre programme pour faire le déploiement. Ce fichier serait détruit une fois traité.
Showing
6 changed files
with
47 additions
and
59 deletions
Show diff stats
PFE06/src/main/java/com/PFE/ServerManager/MainController.java
... | ... | @@ -18,7 +18,8 @@ import org.springframework.security.core.Authentication; |
18 | 18 | import javax.servlet.annotation.MultipartConfig; |
19 | 19 | |
20 | 20 | @Controller |
21 | -@MultipartConfig(fileSizeThreshold = 20971520) | |
21 | +@MultipartConfig(fileSizeThreshold = 20971520) //à changer, taille max des fichiers | |
22 | + | |
22 | 23 | public class MainController { |
23 | 24 | |
24 | 25 | @Autowired |
... | ... | @@ -57,6 +58,25 @@ public class MainController { |
57 | 58 | modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); |
58 | 59 | modelAndView.addObject("customerRole", customer.getRole()); |
59 | 60 | modelAndView.addObject("customerMaj", customer.getMaj()); |
61 | + | |
62 | + File file = new File("files"); | |
63 | + File[] dirs = file.listFiles(); | |
64 | + List<String> filesName = new ArrayList<String>(); | |
65 | + | |
66 | + if (dirs != null) { | |
67 | + for (int i = 0; i < dirs.length; i++) { | |
68 | + if (dirs[i].isDirectory() == true) { | |
69 | + if ((dirs[i].getName().split("_")[0]).equals(customer.getEmail().split("@")[0])) { | |
70 | + File dir = new File(dirs[i].getAbsolutePath()); | |
71 | + File[] f = dir.listFiles(); | |
72 | + filesName.add(f[0].getName()); | |
73 | + } | |
74 | + } | |
75 | + } | |
76 | + } | |
77 | + | |
78 | + modelAndView.addObject("customerFiles", filesName); | |
79 | + | |
60 | 80 | modelAndView.setViewName("session"); |
61 | 81 | return modelAndView; |
62 | 82 | } |
... | ... | @@ -158,10 +178,6 @@ public class MainController { |
158 | 178 | return modelAndView; |
159 | 179 | } |
160 | 180 | |
161 | - /*@GetMapping(path="/all") | |
162 | - public @ResponseBody Iterable<Customer> getAllUsers() { | |
163 | - return customerRepository.findAll(); | |
164 | - }*/ | |
165 | 181 | @GetMapping(path="/all") |
166 | 182 | public ModelAndView getAllUsers() { |
167 | 183 | ModelAndView modelAndView = new ModelAndView(); |
... | ... | @@ -172,11 +188,6 @@ public class MainController { |
172 | 188 | modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); |
173 | 189 | modelAndView.addObject("customerRole", customer.getRole()); |
174 | 190 | |
175 | - /*List<Customer> list = new ArrayList<Customer>(); | |
176 | - Iterator<Customer> listIterator = customerRepository.findAll().iterator(); | |
177 | - while (listIterator.hasNext()) { | |
178 | - list.add(listIterator.next()); | |
179 | - }*/ | |
180 | 191 | List<Customer> list = customerRepository.findAll(); // attention : la méthode findAll() de JpaRepository retourne une liste alors que celle de CrudRepository retourne un itérable |
181 | 192 | modelAndView.addObject("list", list); |
182 | 193 | return modelAndView; |
... | ... | @@ -194,13 +205,14 @@ public class MainController { |
194 | 205 | } |
195 | 206 | |
196 | 207 | @PostMapping(path="/savemaj") |
197 | - public String saveMaj(@RequestParam String name, @RequestParam String date, @RequestParam String nodes){ | |
208 | + public String saveMaj(@RequestParam String name, @RequestParam String date, @RequestParam String nodes, @RequestParam String file){ | |
198 | 209 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
199 | 210 | Customer customer = customerRepository.findByEmail(auth.getName()); |
200 | 211 | Maj maj_c = new Maj(); |
201 | 212 | maj_c.setMaj(name); |
202 | 213 | maj_c.setDate(date); |
203 | 214 | maj_c.setNodes(nodes); |
215 | + maj_c.setFile(file); | |
204 | 216 | maj_c.setMaj_id((int)(majRepository.count() + 1)); |
205 | 217 | majRepository.save(maj_c); // ajouter la mise a jour dans la table |
206 | 218 | HashSet<Maj> majs = new HashSet<Maj>(Arrays.asList(maj_c)); | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/Maj.java
... | ... | @@ -16,13 +16,8 @@ public class Maj { |
16 | 16 | @Column(name = "date") |
17 | 17 | private String date; |
18 | 18 | |
19 | - /* | |
20 | - @Column(name = "nodes") | |
21 | - private String nodes; | |
22 | - | |
23 | 19 | @Column(name = "file") |
24 | 20 | private String file; |
25 | - */ | |
26 | 21 | |
27 | 22 | @Column(name = "nodes") |
28 | 23 | private String nodes; |
... | ... | @@ -48,4 +43,9 @@ public class Maj { |
48 | 43 | public String getNodes() { |
49 | 44 | return nodes; |
50 | 45 | } |
46 | + | |
47 | + public void setFile(String file) { | |
48 | + this.file = file; | |
49 | + } | |
50 | + public String getFile() { return file; } | |
51 | 51 | } | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/MajRepository.java
PFE06/src/main/resources/static/js/home.js
1 | 1 | $(document).ready(function() { |
2 | 2 | |
3 | -/********** Tableau **********/ | |
4 | - | |
5 | -/* | |
6 | - var tableNodes = $('#nodes-table').DataTable( { | |
7 | - responsive: true, | |
8 | - select: { | |
9 | - style: 'multi' | |
10 | - } | |
11 | - } ); | |
12 | - | |
13 | - var nodeSet = new Set(); | |
14 | - | |
15 | - tableNodes.on('select', function (e, dt, type, indexes) { | |
16 | - var rowData = tableNodes.rows(indexes).data().toArray()[0]; | |
17 | - nodeSet.add(rowData[0]); | |
18 | - } ); | |
19 | - | |
20 | - tableNodes.on('deselect', function (e, dt, type, indexes) { | |
21 | - var rowData = tableNodes.rows(indexes).data().toArray()[0]; | |
22 | - nodeSet.delete(rowData[0]); | |
23 | - } ); | |
24 | - | |
25 | - document.getElementById("save_maj").addEventListener('click', function() { | |
26 | - var req = new XMLHttpRequest(); | |
27 | - req.open('POST','/test',true); | |
28 | - req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | |
29 | - req.onreadystatechange = function() {//Call a function when the state changes. | |
30 | - if(req.readyState == 4 && req.status == 200) { | |
31 | - alert(req.responseText); | |
32 | - } | |
33 | - } | |
34 | - req.send("salut"); | |
35 | - }); | |
36 | - | |
37 | - */ | |
38 | - | |
39 | 3 | /********** Drop Zone **********/ |
40 | 4 | |
41 | 5 | var formData = new FormData(); | ... | ... |
PFE06/src/main/resources/static/js/session.js
... | ... | @@ -28,9 +28,9 @@ $(document).ready(function() { |
28 | 28 | form.setAttribute('method', 'post'); |
29 | 29 | |
30 | 30 | var modalContent = document.getElementById("modal-content"); |
31 | - | |
32 | 31 | var majName = document.getElementById("majName").value; |
33 | 32 | var majDate = document.getElementById("majDate").value; |
33 | + var majFile = document.getElementById("file_choice").value; | |
34 | 34 | |
35 | 35 | if(nodeSet.size == 0) { |
36 | 36 | $("#warningFilesNumber").modal(); |
... | ... | @@ -46,9 +46,13 @@ $(document).ready(function() { |
46 | 46 | $("#warningFilesNumber").modal(); |
47 | 47 | } |
48 | 48 | |
49 | + else if(majFile == "" || majFile == "--") { | |
50 | + modalContent.innerHTML = "Veuillez choisir un fichier pour la mise à jour" | |
51 | + $("#warningFilesNumber").modal(); | |
52 | + } | |
53 | + | |
49 | 54 | else { |
50 | 55 | var nodes = Array.from(nodeSet); |
51 | - console.log(nodes); | |
52 | 56 | |
53 | 57 | var inputvar1 = document.createElement('input'); |
54 | 58 | inputvar1.setAttribute('type', 'hidden'); |
... | ... | @@ -68,6 +72,12 @@ $(document).ready(function() { |
68 | 72 | inputvar3.setAttribute('value', nodes.join(";")); |
69 | 73 | form.appendChild(inputvar3); |
70 | 74 | |
75 | + var inputvar4 = document.createElement('input'); | |
76 | + inputvar4.setAttribute('type', 'hidden'); | |
77 | + inputvar4.setAttribute('name', 'file'); | |
78 | + inputvar4.setAttribute('value', majFile); | |
79 | + form.appendChild(inputvar4); | |
80 | + | |
71 | 81 | document.body.appendChild(form); |
72 | 82 | form.submit(); |
73 | 83 | } | ... | ... |
PFE06/src/main/resources/templates/session.html
... | ... | @@ -95,12 +95,17 @@ |
95 | 95 | </tbody> |
96 | 96 | </table> |
97 | 97 | <div class="form-group"> |
98 | - <input type="text" class="form-control" id="majName" placeholder="Nom de la maj" name="maj"> | |
98 | + <input type="text" class="form-control" id="majName" placeholder="Nom de la maj" name="maj" style="margin-top:20px;"> | |
99 | 99 | </div> |
100 | 100 | <div class="form-group"> |
101 | 101 | <input type="date" class="form-control" id="majDate" placeholder="Date de la mise à jour" name="date"> |
102 | 102 | </div> |
103 | - <!-- Ajouter une liste qui montre les differents fichiers disponibles --> | |
103 | + | |
104 | + <select multiple class="form-control" style="margin-bottom:20px;" id="file_choice"> | |
105 | + <option value="">--</option> | |
106 | + <option th:each="file : ${customerFiles}" th:value="${file}" th:utext="${file}"/> | |
107 | + </select> | |
108 | + | |
104 | 109 | <button id="save_maj" type="submit" class="btn btn-primary">Sauvegarder la mise à jour</button> |
105 | 110 | <button id="run_maj" type="submit" class="btn btn-primary">Lancer la mise à jour</button> |
106 | 111 | ... | ... |