Revize e9236d13
Přidáno uživatelem Jan Čarnogurský před více než 4 roky(ů)
src/main/java/vldc/aswi/web/controller/AssemblyController.java | ||
---|---|---|
87 | 87 |
/** Title text for new assembly form. */ |
88 | 88 |
private String assemblyNewTitleText = "Vytvoření nové sestavy"; |
89 | 89 |
|
90 |
/** Name of thymeleaf parameter, which will contain error text from validator. */ |
|
91 |
private String assemblyErrorName = "errorText"; |
|
92 |
|
|
93 | 90 |
/** |
94 | 91 |
* Bind assembly validator. |
95 | 92 |
* @param binder Binder. |
... | ... | |
167 | 164 |
@RequestParam(required=false, value="generateTable") String generateTable, |
168 | 165 |
@RequestParam(required=false, value="exportXls") String exportXls, |
169 | 166 |
@RequestParam(required=false, value="exportPdf") String exportPdf, |
170 |
@RequestParam(required=false, value="saveConfiguration") String saveConfiguration) |
|
167 |
@RequestParam(required=false, value="saveConfiguration") String saveConfiguration, |
|
168 |
RedirectAttributes redirectAttributes) |
|
171 | 169 |
{ |
172 | 170 |
|
173 | 171 |
ModelAndView modelAndView = new ModelAndView(); |
... | ... | |
210 | 208 |
|
211 | 209 |
initializeFields(configuration); |
212 | 210 |
|
211 |
redirectAttributes.addFlashAttribute(assemblySuccessName, "Šablona byla úspěšně uložena"); |
|
212 |
|
|
213 | 213 |
modelAndView.setViewName("redirect:/configuration?configurationID=" + configuration.getId()); |
214 | 214 |
} |
215 | 215 |
|
... | ... | |
237 | 237 |
* @return ModelAndView for index. |
238 | 238 |
*/ |
239 | 239 |
@GetMapping("/assembly_delete") |
240 |
public ModelAndView assemblyDeleteGet(@RequestParam("assemblyID") String id) { |
|
240 |
public ModelAndView assemblyDeleteGet(@RequestParam("assemblyID") String id, RedirectAttributes redirectAttributes) {
|
|
241 | 241 |
ModelAndView modelAndView = new ModelAndView("redirect:/"); |
242 | 242 |
|
243 | 243 |
Long assemblyId = Utils.tryParseLong(id); |
244 | 244 |
|
245 | 245 |
if (assemblyId == null) { |
246 |
// TODO: print error in index.
|
|
246 |
redirectAttributes.addFlashAttribute(assemblyErrorName, "Sestavu se nepodařilo odstranit.");
|
|
247 | 247 |
} |
248 | 248 |
boolean success = this.assemblyManager.deleteAssembly(assemblyId); |
249 |
// TODO: check success. |
|
249 |
|
|
250 |
if (success) |
|
251 |
{ |
|
252 |
redirectAttributes.addFlashAttribute(assemblySuccessName, "Sestava byla úspěšně odstraněna"); |
|
253 |
} |
|
254 |
else |
|
255 |
{ |
|
256 |
redirectAttributes.addFlashAttribute(assemblyErrorName, "Sestavu se nepodařilo odstranit"); |
|
257 |
} |
|
250 | 258 |
|
251 | 259 |
return modelAndView; |
252 | 260 |
} |
... | ... | |
311 | 319 |
|
312 | 320 |
modelMap.addAttribute("assembly", updatedAssembly); |
313 | 321 |
modelMap.addAttribute(assemblyTitleName, assemblyEditTitleText + " " + updatedAssembly.getName()); |
322 |
modelMap.addAttribute(assemblySuccessName, "Úspěšně uloženo"); |
|
314 | 323 |
} |
315 | 324 |
|
316 | 325 |
modelMap.addAttribute("allRoles", this.roleManager.getRoles()); |
... | ... | |
371 | 380 |
this.parameterManager.addParameters(assemblyId, assembly.getParameters()); |
372 | 381 |
|
373 | 382 |
modelAndView.setViewName("redirect:/assembly_edit?assemblyID=" + assemblyId); |
383 |
modelMap.addAttribute(assemblySuccessName, "Sestava byla úspěšně vytvořena"); |
|
374 | 384 |
} |
375 | 385 |
|
376 | 386 |
modelMap.addAttribute("allRoles", this.roleManager.getRoles()); |
src/main/java/vldc/aswi/web/controller/BasicController.java | ||
---|---|---|
8 | 8 |
@Controller |
9 | 9 |
public class BasicController { |
10 | 10 |
|
11 |
/** Name of thymeleaf parameter, which will contain error text from validator. */ |
|
12 |
protected String assemblyErrorName = "errorText"; |
|
13 |
|
|
14 |
/** Name of thymeleaf parameter, which will contain success text from validator. */ |
|
15 |
protected String assemblySuccessName = "successText"; |
|
16 |
|
|
11 | 17 |
/** |
12 | 18 |
* Return message containings all errors from validator. |
13 | 19 |
* @param result Validator results. |
src/main/java/vldc/aswi/web/controller/ConfigurationController.java | ||
---|---|---|
9 | 9 |
import org.springframework.validation.BindingResult; |
10 | 10 |
import org.springframework.web.bind.annotation.*; |
11 | 11 |
import org.springframework.web.servlet.ModelAndView; |
12 |
import org.springframework.web.servlet.mvc.support.RedirectAttributes; |
|
12 | 13 |
import vldc.aswi.domain.Assembly; |
13 | 14 |
import vldc.aswi.domain.Configuration; |
14 | 15 |
import vldc.aswi.domain.Location; |
... | ... | |
55 | 56 |
* @return modelAndView of page to be shown |
56 | 57 |
*/ |
57 | 58 |
@GetMapping("/configuration") |
58 |
public ModelAndView configurationGet(@RequestParam("configurationID") String id) { |
|
59 |
public ModelAndView configurationGet(@RequestParam("configurationID") String id, |
|
60 |
@ModelAttribute("successText") String successMsg, |
|
61 |
@ModelAttribute("errorText") String errorMsg) { |
|
59 | 62 |
ModelAndView modelAndView = new ModelAndView("assembly"); |
60 | 63 |
|
61 | 64 |
ModelMap modelMap = modelAndView.getModelMap(); |
... | ... | |
84 | 87 |
modelMap.addAttribute("comparator", comparator); |
85 | 88 |
modelMap.addAttribute("formAction", "/configuration?configurationID=" + configuration.getId()); |
86 | 89 |
|
90 |
modelMap.addAttribute(assemblySuccessName, successMsg); |
|
91 |
modelMap.addAttribute(assemblyErrorName, errorMsg); |
|
92 |
|
|
87 | 93 |
return modelAndView; |
88 | 94 |
} |
89 | 95 |
|
... | ... | |
101 | 107 |
@RequestParam(required=false, value="generateTable") String generateTable, |
102 | 108 |
@RequestParam(required=false, value="exportXls") String exportXls, |
103 | 109 |
@RequestParam(required=false, value="exportPdf") String exportPdf, |
104 |
@RequestParam(required=false, value="saveConfiguration") String saveConfiguration) |
|
110 |
@RequestParam(required=false, value="saveConfiguration") String saveConfiguration, |
|
111 |
RedirectAttributes redirectAttributes |
|
112 |
) |
|
105 | 113 |
{ |
106 | 114 |
ModelAndView modelAndView = new ModelAndView(); |
115 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
107 | 116 |
|
108 | 117 |
if (bindingResult.hasErrors()) { |
109 | 118 |
// TODO: 04.05.2020 Error message |
... | ... | |
116 | 125 |
{ |
117 | 126 |
prepareForTable(newConfiguration); |
118 | 127 |
System.out.println("Generuj tabulku"); |
119 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
120 | 128 |
modelMap.addAttribute("configurationID", id); |
121 | 129 |
modelMap.addAttribute("contingencyTableRows", this.sqlQueryManager.getContingencyTableRow(newConfiguration)); |
122 | 130 |
Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder()); |
... | ... | |
141 | 149 |
|
142 | 150 |
initializeFields(configuration); |
143 | 151 |
|
152 |
redirectAttributes.addFlashAttribute(assemblySuccessName, "Šablona byla úspěšně uložena"); |
|
144 | 153 |
modelAndView.setViewName("redirect:/configuration?configurationID=" + configuration.getId()); |
154 |
|
|
145 | 155 |
} |
146 | 156 |
|
147 | 157 |
return modelAndView; |
... | ... | |
153 | 163 |
* @return ModelAndView for index. |
154 | 164 |
*/ |
155 | 165 |
@GetMapping("/configuration_delete") |
156 |
public ModelAndView configurationDeleteGet(@RequestParam("configurationID") String id) { |
|
166 |
public ModelAndView configurationDeleteGet(@RequestParam("configurationID") String id, RedirectAttributes redirectAttributes) {
|
|
157 | 167 |
ModelAndView modelAndView = new ModelAndView("redirect:/"); |
158 | 168 |
|
159 | 169 |
Long configurationId = Utils.tryParseLong(id); |
160 | 170 |
|
161 | 171 |
if (configurationId == null) { |
162 |
// TODO: print error in index.
|
|
172 |
redirectAttributes.addFlashAttribute(assemblyErrorName, "Sestavu se nepodařilo odstranit");
|
|
163 | 173 |
} |
164 | 174 |
|
165 | 175 |
boolean success = this.configurationManager.deleteConfiguration(configurationId); |
166 |
// TODO: check success. |
|
176 |
|
|
177 |
if (success) |
|
178 |
{ |
|
179 |
redirectAttributes.addFlashAttribute(assemblySuccessName, "Sestava byla úspěšně odstraněna"); |
|
180 |
} |
|
181 |
else |
|
182 |
{ |
|
183 |
redirectAttributes.addFlashAttribute(assemblyErrorName, "Sestavu se nepodařilo odstranit"); |
|
184 |
} |
|
167 | 185 |
|
168 | 186 |
return modelAndView; |
169 | 187 |
} |
src/main/java/vldc/aswi/web/controller/IndexController.java | ||
---|---|---|
58 | 58 |
* @return modelAndView with index page |
59 | 59 |
*/ |
60 | 60 |
@GetMapping("/") |
61 |
public ModelAndView index() { |
|
61 |
public ModelAndView index(@ModelAttribute("successText") String successMsg, @ModelAttribute("errorText") String errorMsg) {
|
|
62 | 62 |
ModelAndView modelAndView = new ModelAndView("index"); |
63 | 63 |
|
64 | 64 |
ModelMap modelMap = modelAndView.getModelMap(); |
... | ... | |
83 | 83 |
modelMap.addAttribute("attributes", createAttributesString(assemblies)); |
84 | 84 |
modelMap.addAttribute("configurations", configurationManager.getConfigurations()); |
85 | 85 |
|
86 |
modelMap.addAttribute(assemblySuccessName, successMsg); |
|
87 |
modelMap.addAttribute(assemblyErrorName, errorMsg); |
|
88 |
|
|
89 |
|
|
86 | 90 |
return modelAndView; |
87 | 91 |
} |
88 | 92 |
|
src/main/webapp/WEB-INF/templates/layouts/layout.html | ||
---|---|---|
28 | 28 |
|
29 | 29 |
</head> |
30 | 30 |
<body> |
31 |
<div th:if="${errorText}" >
|
|
31 |
<div th:if="${!#strings.isEmpty(errorText)}" >
|
|
32 | 32 |
<div class="alert alert-danger"> |
33 | 33 |
<span th:text="${errorText}"></span> |
34 | 34 |
</div> |
35 | 35 |
</div> |
36 |
<div th:if="${successText}" >
|
|
36 |
<div th:if="${!#strings.isEmpty(successText)}" >
|
|
37 | 37 |
<div class="alert alert-success"> |
38 | 38 |
<span th:text="${successText}"></span> |
39 | 39 |
</div> |
Také k dispozici: Unified diff
re #8150 - added success/error messages