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/add.html b/src/main/resources/templates/project/add.html index d5c8184..9da802a 100644 --- a/src/main/resources/templates/project/add.html +++ b/src/main/resources/templates/project/add.html @@ -42,7 +42,7 @@ -
+
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 @@
-