From c4bbb1a9d973bf024b9c731cad601363dd37703c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Eudes=20Lima?= Date: Mon, 23 Nov 2020 10:04:54 -0300 Subject: [PATCH 1/2] feat: update modal of delete project --- .../dct/apf/controller/ProjectController.java | 27 ++++++- .../resources/templates/project/list.html | 74 +++++++------------ 2 files changed, 49 insertions(+), 52 deletions(-) diff --git a/src/main/java/br/ufrn/dct/apf/controller/ProjectController.java b/src/main/java/br/ufrn/dct/apf/controller/ProjectController.java index 24ec3e2..a17fe8e 100644 --- a/src/main/java/br/ufrn/dct/apf/controller/ProjectController.java +++ b/src/main/java/br/ufrn/dct/apf/controller/ProjectController.java @@ -15,6 +15,7 @@ import javax.validation.Valid; import java.util.ArrayList; import java.util.List; +import static java.util.Objects.isNull; @Controller public class ProjectController extends AbstractController { @@ -65,10 +66,28 @@ public ModelAndView edit(@PathVariable("id") Long id) { } @GetMapping("/project/delete/{id}") - public ModelAndView delete(@PathVariable("id") Long id) { - projectService.delete(id); + public ModelAndView deleteView(@PathVariable("id") Long id) { + ModelAndView mv = new ModelAndView("project/list"); - return findAll(); + User current = getCurrentUser(); + List projects = projectService.findByUserId(current.getId()); + Project project = projectService.findOne(id); + + mv.addObject("projects", projects); + mv.addObject("project", project); + mv.addObject("showModalDelete", true); + + return mv; + } + + @PostMapping("/project/delete/{id}") + public String delete(@PathVariable("id") Long id) { + // @TODO validar permissões + if (!isNull(projectService.findOne(id))) { + projectService.delete(id); + } + + return "redirect:/project"; } @PostMapping("/project/save") @@ -123,7 +142,7 @@ public ProjectSuggestionWrapper autocompleteSuggestions(@RequestParam("searchstr } // truncate the list to the first n, max 20 elements - int n = suggestions.size() > 20 ? 20 : suggestions.size(); + int n = Math.min(suggestions.size(), 20); List sulb = new ArrayList<>(suggestions.subList(0, n)); ProjectSuggestionWrapper sw = new ProjectSuggestionWrapper(); diff --git a/src/main/resources/templates/project/list.html b/src/main/resources/templates/project/list.html index 53edabc..39f612d 100644 --- a/src/main/resources/templates/project/list.html +++ b/src/main/resources/templates/project/list.html @@ -18,27 +18,34 @@
- -
+