Commit 4ca22bac80ec4f3abc76c23e633fb5c0d84aa460
1 parent
cb678ccc
Bouton "Lancer la mise à jour" fonctionnel
Lors de l'appui sur ce bouton, un fichier yaml est créé dans le répertoire "toflash" contenant les informations de la mise à jour. Ces fichiers seront traités par un programme annexe.
Showing
7 changed files
with
195 additions
and
83 deletions
Show diff stats
... | ... | @@ -0,0 +1,13 @@ |
1 | +nodes: | |
2 | + - name: AT-001 | |
3 | + ip: '85.10.201.246' | |
4 | + arch: ARM | |
5 | + - name: AT-002 | |
6 | + ip: '85.10.201.247' | |
7 | + arch: ARM | |
8 | + - name: AT-003 | |
9 | + ip: '85.10.201.248' | |
10 | + arch: ARM | |
11 | + - name: ATTTT-008 | |
12 | + ip: '85.10.201.249' | |
13 | + arch: ARM | |
0 | 14 | \ No newline at end of file | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/MainController.java
... | ... | @@ -213,7 +213,6 @@ public class MainController { |
213 | 213 | node.setName(element.getName()); |
214 | 214 | node.setArch(element.getArch()); |
215 | 215 | node.setIp(element.getIp()); |
216 | - node.setNode_id((int)(nodeRepository.count() + 1)); | |
217 | 216 | nodeRepository.save(node); |
218 | 217 | } |
219 | 218 | } |
... | ... | @@ -250,7 +249,6 @@ public class MainController { |
250 | 249 | maj_c.setDate(date); |
251 | 250 | maj_c.setNodes(nodes); |
252 | 251 | maj_c.setFile(file); |
253 | - maj_c.setMaj_id((int)(majRepository.count() + 1)); | |
254 | 252 | |
255 | 253 | majRepository.save(maj_c); // ajouter la mise a jour dans la table |
256 | 254 | HashSet<Maj> majs = new HashSet<Maj>(Arrays.asList(maj_c)); |
... | ... | @@ -260,4 +258,53 @@ public class MainController { |
260 | 258 | |
261 | 259 | return "redirect:/session"; |
262 | 260 | } |
261 | + | |
262 | + @PostMapping(path="/runmaj") | |
263 | + public String runMaj(@RequestParam String name, @RequestParam String date, @RequestParam String nodes, @RequestParam String file){ | |
264 | + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | |
265 | + Customer customer = customerRepository.findByEmail(auth.getName()); | |
266 | + | |
267 | + Maj maj_c = new Maj(); | |
268 | + maj_c.setMaj(name); | |
269 | + maj_c.setDate(date); | |
270 | + maj_c.setNodes(nodes); | |
271 | + maj_c.setFile(file); | |
272 | + | |
273 | + Map<String, Object> data = new HashMap<String, Object>(); | |
274 | + data.put("name", maj_c.getMaj()); | |
275 | + data.put("date", maj_c.getDate()); | |
276 | + data.put("file", maj_c.getFile()); | |
277 | + data.put("nodes", maj_c.getNodes().split(";")); | |
278 | + Yaml yaml = new Yaml(); | |
279 | + FileWriter writer = null; | |
280 | + try { | |
281 | + writer = new FileWriter("toflash/" + customer.getEmail().split("@")[0] + "_" + maj_c.getMaj() + ".yaml"); | |
282 | + } catch (IOException e) { | |
283 | + e.printStackTrace(); | |
284 | + } | |
285 | + yaml.dump(data, writer); | |
286 | + | |
287 | + return "redirect:/session"; | |
288 | + } | |
289 | + | |
290 | + @PostMapping(path="/startsavedmaj") | |
291 | + @ResponseStatus(value = HttpStatus.OK) | |
292 | + public void startSavedMaj(@RequestParam String majname){ | |
293 | + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | |
294 | + Customer customer = customerRepository.findByEmail(auth.getName()); | |
295 | + Maj maj = majRepository.findByMaj(majname); | |
296 | + Map<String, Object> data = new HashMap<String, Object>(); | |
297 | + data.put("name", maj.getMaj()); | |
298 | + data.put("date", maj.getDate()); | |
299 | + data.put("file", maj.getFile()); | |
300 | + data.put("nodes", maj.getNodes().split(";")); | |
301 | + Yaml yaml = new Yaml(); | |
302 | + FileWriter writer = null; | |
303 | + try { | |
304 | + writer = new FileWriter("toflash/" + customer.getEmail().split("@")[0] + "_" + maj.getMaj() + ".yaml"); | |
305 | + } catch (IOException e) { | |
306 | + e.printStackTrace(); | |
307 | + } | |
308 | + yaml.dump(data, writer); | |
309 | + } | |
263 | 310 | } |
264 | 311 | \ No newline at end of file | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/MajRepository.java
PFE06/src/main/resources/static/js/session.js
1 | 1 | $(document).ready(function() { |
2 | 2 | |
3 | - /********** Configuration file ***********/ | |
4 | - | |
5 | - var configName = document.getElementById("config_name"); | |
6 | - var configSend = document.getElementById("config_send"); | |
7 | - var file = document.getElementById("configInputFile"); | |
8 | - var readyToSend = false; | |
9 | - var formData = new FormData(); | |
3 | + /********** Start saved maj ************/ | |
10 | 4 | |
11 | - file.addEventListener('change', function() { | |
12 | - delete formData; | |
13 | - formData = new FormData(); | |
14 | - configName.innerHTML = this.files[0].name; | |
15 | - formData.append("file", this.files[0]); | |
16 | - readyToSend = true; | |
17 | - }, false) | |
5 | + var startMaj = document.getElementById("start_maj"); | |
18 | 6 | |
19 | - configSend.addEventListener('click', function() { | |
7 | + startMaj.addEventListener('click', function() { | |
20 | 8 | var modalContent = document.getElementById("modal-content"); |
21 | 9 | var modalTitle = document.getElementById("modal-title"); |
22 | - if(readyToSend) { | |
10 | + var majNameSelect = document.getElementById("maj_name").value; | |
11 | + if(majNameSelect !== "" && majNameSelect !== "--") { | |
23 | 12 | var request = new XMLHttpRequest(); |
24 | - request.open("POST", "/config"); | |
13 | + request.open("POST", "/startsavedmaj"); | |
14 | + var formData = new FormData(); | |
15 | + formData.append("majname", majNameSelect); | |
25 | 16 | |
26 | 17 | request.onreadystatechange = function() { |
27 | 18 | if(this.readyState === XMLHttpRequest.DONE && this.status === 200) { |
28 | 19 | var modalButton = document.getElementById("modal-button"); |
29 | - modalButton.addEventListener('click', function(e) { | |
20 | + modalButton.addEventListener('click', function() { | |
30 | 21 | location.reload(); |
31 | 22 | }) |
32 | - modalContent.innerHTML = "Upload terminé !"; | |
33 | 23 | modalTitle.innerHTML = "Félicitations"; |
24 | + modalContent.innerHTML = "La mise à jour a bien été paramétrée"; | |
34 | 25 | $("#warningFilesNumber").modal(); |
35 | 26 | } |
36 | 27 | } |
37 | - | |
38 | 28 | request.send(formData); |
39 | 29 | } |
40 | 30 | else { |
41 | - modalContent.innerHTML = "Veuillez sélectionner un fichier !"; | |
42 | - $("#warningFilesNumber").modal() | |
31 | + modalTitle.innerHTML = "Attention !"; | |
32 | + modalContent.innerHTML = "Veuillez choisir le nom d'une mise à jour"; | |
33 | + $("#warningFilesNumber").modal(); | |
43 | 34 | } |
44 | - | |
45 | 35 | }) |
46 | 36 | |
37 | + | |
38 | + /********** Configuration file ***********/ | |
39 | + | |
40 | + var configName = document.getElementById("config_name"); | |
41 | + var configSend = document.getElementById("config_send"); | |
42 | + var file = document.getElementById("configInputFile"); | |
43 | + var readyToSend = false; | |
44 | + var formData = new FormData(); | |
45 | + | |
46 | + if(file != null) { | |
47 | + file.addEventListener('change', function () { | |
48 | + delete formData; | |
49 | + formData = new FormData(); | |
50 | + configName.innerHTML = this.files[0].name; | |
51 | + formData.append("file", this.files[0]); | |
52 | + readyToSend = true; | |
53 | + }, false) | |
54 | + | |
55 | + configSend.addEventListener('click', function () { | |
56 | + var modalContent = document.getElementById("modal-content"); | |
57 | + var modalTitle = document.getElementById("modal-title"); | |
58 | + if (readyToSend) { | |
59 | + var request = new XMLHttpRequest(); | |
60 | + request.open("POST", "/config"); | |
61 | + | |
62 | + request.onreadystatechange = function () { | |
63 | + if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { | |
64 | + var modalButton = document.getElementById("modal-button"); | |
65 | + modalButton.addEventListener('click', function (e) { | |
66 | + location.reload(); | |
67 | + }) | |
68 | + modalContent.innerHTML = "Upload terminé !"; | |
69 | + modalTitle.innerHTML = "Félicitations"; | |
70 | + $("#warningFilesNumber").modal(); | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + request.send(formData); | |
75 | + } | |
76 | + else { | |
77 | + modalContent.innerHTML = "Veuillez sélectionner un fichier !"; | |
78 | + $("#warningFilesNumber").modal() | |
79 | + } | |
80 | + | |
81 | + }) | |
82 | + } | |
83 | + | |
47 | 84 | /********** Tableau **********/ |
48 | 85 | |
49 | 86 | var tableNodes = $('#nodes-table').DataTable( { |
... | ... | @@ -65,67 +102,73 @@ $(document).ready(function() { |
65 | 102 | nodeSet.delete(rowData[0]); |
66 | 103 | } ); |
67 | 104 | |
68 | - document.getElementById("save_maj").addEventListener('click', function() { | |
69 | - | |
70 | - var form = document.createElement('form'); | |
71 | - form.setAttribute('action', 'savemaj'); | |
72 | - form.setAttribute('method', 'post'); | |
105 | + var sendInfoMaj = function(action) { | |
106 | + console.log(action); | |
107 | + var form = document.createElement('form'); | |
108 | + form.setAttribute('action', action); | |
109 | + form.setAttribute('method', 'post'); | |
73 | 110 | |
74 | - var modalContent = document.getElementById("modal-content"); | |
75 | - var majName = document.getElementById("majName").value; | |
76 | - var majDate = document.getElementById("majDate").value; | |
77 | - var majFile = document.getElementById("file_choice").value; | |
111 | + var modalContent = document.getElementById("modal-content"); | |
112 | + var majName = document.getElementById("majName").value; | |
113 | + var majDate = document.getElementById("majDate").value; | |
114 | + var majFile = document.getElementById("file_choice").value; | |
78 | 115 | |
79 | - if(nodeSet.size == 0) { | |
80 | - $("#warningFilesNumber").modal(); | |
81 | - } | |
116 | + if(nodeSet.size == 0) { | |
117 | + $("#warningFilesNumber").modal(); | |
118 | + } | |
82 | 119 | |
83 | - else if(majName == "") { | |
84 | - modalContent.innerHTML = "Veuillez choisir un nom pour la mise à jour"; | |
85 | - $("#warningFilesNumber").modal(); | |
86 | - } | |
120 | + else if(majName === "") { | |
121 | + modalContent.innerHTML = "Veuillez choisir un nom pour la mise à jour"; | |
122 | + $("#warningFilesNumber").modal(); | |
123 | + } | |
87 | 124 | |
88 | - else if(majDate == "") { | |
89 | - modalContent.innerHTML = "Veuillez choisir une date pour la mise à jour" | |
90 | - $("#warningFilesNumber").modal(); | |
91 | - } | |
125 | + else if(majDate === "") { | |
126 | + modalContent.innerHTML = "Veuillez choisir une date pour la mise à jour" | |
127 | + $("#warningFilesNumber").modal(); | |
128 | + } | |
92 | 129 | |
93 | - else if(majFile == "" || majFile == "--") { | |
94 | - modalContent.innerHTML = "Veuillez choisir un fichier pour la mise à jour" | |
95 | - $("#warningFilesNumber").modal(); | |
96 | - } | |
130 | + else if(majFile === "" || majFile === "--") { | |
131 | + modalContent.innerHTML = "Veuillez choisir un fichier pour la mise à jour" | |
132 | + $("#warningFilesNumber").modal(); | |
133 | + } | |
97 | 134 | |
98 | - else { | |
99 | - var nodes = Array.from(nodeSet); | |
100 | - | |
101 | - var inputvar1 = document.createElement('input'); | |
102 | - inputvar1.setAttribute('type', 'hidden'); | |
103 | - inputvar1.setAttribute('name', 'name'); | |
104 | - inputvar1.setAttribute('value', majName); | |
105 | - form.appendChild(inputvar1); | |
106 | - | |
107 | - var inputvar2 = document.createElement('input'); | |
108 | - inputvar2.setAttribute('type', 'hidden'); | |
109 | - inputvar2.setAttribute('name', 'date'); | |
110 | - inputvar2.setAttribute('value', majDate); | |
111 | - form.appendChild(inputvar2); | |
112 | - | |
113 | - var inputvar3 = document.createElement('input'); | |
114 | - inputvar3.setAttribute('type', 'hidden'); | |
115 | - inputvar3.setAttribute('name', 'nodes'); | |
116 | - inputvar3.setAttribute('value', nodes.join(";")); | |
117 | - form.appendChild(inputvar3); | |
118 | - | |
119 | - var inputvar4 = document.createElement('input'); | |
120 | - inputvar4.setAttribute('type', 'hidden'); | |
121 | - inputvar4.setAttribute('name', 'file'); | |
122 | - inputvar4.setAttribute('value', majFile); | |
123 | - form.appendChild(inputvar4); | |
124 | - | |
125 | - document.body.appendChild(form); | |
126 | - form.submit(); | |
127 | - } | |
135 | + else { | |
136 | + var nodes = Array.from(nodeSet); | |
137 | + | |
138 | + var inputvar1 = document.createElement('input'); | |
139 | + inputvar1.setAttribute('type', 'hidden'); | |
140 | + inputvar1.setAttribute('name', 'name'); | |
141 | + inputvar1.setAttribute('value', majName); | |
142 | + form.appendChild(inputvar1); | |
143 | + | |
144 | + var inputvar2 = document.createElement('input'); | |
145 | + inputvar2.setAttribute('type', 'hidden'); | |
146 | + inputvar2.setAttribute('name', 'date'); | |
147 | + inputvar2.setAttribute('value', majDate); | |
148 | + form.appendChild(inputvar2); | |
149 | + | |
150 | + var inputvar3 = document.createElement('input'); | |
151 | + inputvar3.setAttribute('type', 'hidden'); | |
152 | + inputvar3.setAttribute('name', 'nodes'); | |
153 | + inputvar3.setAttribute('value', nodes.join(";")); | |
154 | + form.appendChild(inputvar3); | |
155 | + | |
156 | + var inputvar4 = document.createElement('input'); | |
157 | + inputvar4.setAttribute('type', 'hidden'); | |
158 | + inputvar4.setAttribute('name', 'file'); | |
159 | + inputvar4.setAttribute('value', majFile); | |
160 | + form.appendChild(inputvar4); | |
161 | + | |
162 | + document.body.appendChild(form); | |
163 | + form.submit(); | |
164 | + } | |
165 | + } | |
128 | 166 | |
167 | + document.getElementById("save_maj").addEventListener('click', function() { | |
168 | + sendInfoMaj('savemaj'); | |
169 | + }); | |
170 | + document.getElementById("run_maj").addEventListener('click', function() { | |
171 | + sendInfoMaj('runmaj'); | |
129 | 172 | }); |
130 | 173 | |
131 | 174 | } ); | ... | ... |
PFE06/src/main/resources/templates/session.html
... | ... | @@ -76,9 +76,9 @@ nodes: |
76 | 76 | |
77 | 77 | <h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;">Relancer une mise à jour</h1> |
78 | 78 | <div class="form-group"> |
79 | - <select multiple class="form-control"> | |
80 | - <option value="">--</option> | |
81 | - <option th:each="maj : ${customerMaj}" th:value="${maj.getMaj_id()}" th:utext="${maj.getMaj()}"/> | |
79 | + <select multiple id="maj_name" class="form-control"> | |
80 | + <option value="--">--</option> | |
81 | + <option th:each="maj : ${customerMaj}" th:value="${maj.getMaj()}" th:utext="${maj.getMaj()}"/> | |
82 | 82 | </select> |
83 | 83 | <button id="start_maj" type="submit" class="btn btn-primary" style="margin-top:20px;">Lancer la mise à jour</button> |
84 | 84 | </div> |
... | ... | @@ -107,7 +107,7 @@ nodes: |
107 | 107 | <input type="date" class="form-control" id="majDate" placeholder="Date de la mise à jour" name="date"> |
108 | 108 | </div> |
109 | 109 | <select multiple class="form-control" style="margin-bottom:20px;" id="file_choice"> |
110 | - <option value="">--</option> | |
110 | + <option value="--">--</option> | |
111 | 111 | <option th:each="file : ${customerFiles}" th:value="${file}" th:utext="${file}"/> |
112 | 112 | </select> |
113 | 113 | <button id="save_maj" type="submit" class="btn btn-primary">Sauvegarder la mise à jour</button> | ... | ... |