Skip to content

Commit c54fd5c

Browse files
committed
URL PATH of Actions - Controller Methods Refactoring
1 parent ba68499 commit c54fd5c

File tree

11 files changed

+200
-188
lines changed

11 files changed

+200
-188
lines changed

src/main/java/org/woehlke/simpleworklist/task/TaskController.java

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -33,71 +33,6 @@ public TaskController(TaskMoveService taskMoveService) {
3333
this.taskMoveService = taskMoveService;
3434
}
3535

36-
@RequestMapping(path = "/add", method = RequestMethod.GET)
37-
public final String addNewTaskToInboxGet(
38-
@ModelAttribute("userSession") UserSessionBean userSession,
39-
Locale locale, Model model
40-
) {
41-
UserAccount userAccount = userAccountLoginSuccessService.retrieveCurrentUser();
42-
Task task = new Task();
43-
task.setTaskState(TaskState.INBOX);
44-
task.setTaskEnergy(TaskEnergy.NONE);
45-
task.setTaskTime(TaskTime.NONE);
46-
Boolean mustChooseContext = false;
47-
if(userSession.getContextId() == 0L){
48-
mustChooseContext = true;
49-
task.setContext(userAccount.getDefaultContext());
50-
} else {
51-
Context context = contextService.findByIdAndUserAccount(userSession.getContextId(), userAccount);
52-
task.setContext(context);
53-
}
54-
Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(TaskState.INBOX,locale);
55-
model.addAttribute("breadcrumb", breadcrumb);
56-
model.addAttribute("mustChooseArea", mustChooseContext);
57-
model.addAttribute("breadcrumb", breadcrumb);
58-
model.addAttribute("task", task);
59-
return "task/addToInbox";
60-
}
61-
62-
@RequestMapping(path = "/add", method = RequestMethod.POST)
63-
public final String addNewTaskToInboxPost(
64-
@ModelAttribute("userSession") UserSessionBean userSession,
65-
@Valid Task task,
66-
BindingResult result,
67-
Locale locale,
68-
Model model
69-
) {
70-
Context context = super.getContext(userSession);
71-
if (result.hasErrors()) {
72-
for (ObjectError e : result.getAllErrors()) {
73-
log.info(e.toString());
74-
}
75-
Boolean mustChooseArea = false;
76-
task.setContext(context);
77-
Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(TaskState.INBOX,locale);
78-
model.addAttribute("mustChooseArea", mustChooseArea);
79-
model.addAttribute("breadcrumb", breadcrumb);
80-
model.addAttribute("task", task);
81-
return "task/addToProject";
82-
} else {
83-
task.setProject(null);
84-
if(task.getDueDate()==null){
85-
task.setTaskState(TaskState.INBOX);
86-
} else {
87-
task.setTaskState(TaskState.SCHEDULED);
88-
}
89-
task.setFocus(false);
90-
task.setContext(context);
91-
long maxOrderIdProject = taskMoveService.getMaxOrderIdProject(task.getProject(),context);
92-
task.setOrderIdProject(++maxOrderIdProject);
93-
long maxOrderIdTaskState = taskMoveService.getMaxOrderIdTaskState(task.getTaskState(),task.getContext());
94-
task.setOrderIdTaskState(++maxOrderIdTaskState);
95-
task = taskService.saveAndFlush(task);
96-
log.info(task.toString());
97-
return "redirect:/taskstate/" + task.getTaskState().name().toLowerCase();
98-
}
99-
}
100-
10136
@RequestMapping(path = "/{taskId}/edit", method = RequestMethod.GET)
10237
public final String editTaskGet(
10338
@PathVariable("taskId") Task task,

src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateMoveController.java

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@
33
import lombok.extern.slf4j.Slf4j;
44
import org.springframework.stereotype.Controller;
55
import org.springframework.ui.Model;
6+
import org.springframework.validation.BindingResult;
7+
import org.springframework.validation.ObjectError;
68
import org.springframework.web.bind.annotation.*;
9+
import org.woehlke.simpleworklist.breadcrumb.Breadcrumb;
710
import org.woehlke.simpleworklist.common.AbstractController;
811
import org.woehlke.simpleworklist.context.Context;
912
import org.woehlke.simpleworklist.project.Project;
1013
import org.woehlke.simpleworklist.task.Task;
1114
import org.woehlke.simpleworklist.task.TaskControllerService;
15+
import org.woehlke.simpleworklist.task.TaskEnergy;
16+
import org.woehlke.simpleworklist.task.TaskTime;
1217
import org.woehlke.simpleworklist.user.UserSessionBean;
1318

1419
import org.springframework.beans.factory.annotation.Autowired;
20+
import org.woehlke.simpleworklist.user.account.UserAccount;
21+
22+
import javax.validation.Valid;
23+
import java.util.Locale;
1524

1625
/**
1726
* Created by tw on 21.02.16.
@@ -33,6 +42,73 @@ public TaskStateMoveController(
3342
this.taskControllerService = taskControllerService;
3443
}
3544

45+
@RequestMapping(path = "/add", method = RequestMethod.GET)
46+
public final String addNewTaskToInboxGet(
47+
@ModelAttribute("userSession") UserSessionBean userSession,
48+
Locale locale, Model model
49+
) {
50+
log.info("addNewTaskToInboxGet");
51+
UserAccount userAccount = userAccountLoginSuccessService.retrieveCurrentUser();
52+
Task task = new Task();
53+
task.setTaskState(TaskState.INBOX);
54+
task.setTaskEnergy(TaskEnergy.NONE);
55+
task.setTaskTime(TaskTime.NONE);
56+
Boolean mustChooseContext = false;
57+
if(userSession.getContextId() == 0L){
58+
mustChooseContext = true;
59+
task.setContext(userAccount.getDefaultContext());
60+
} else {
61+
Context context = contextService.findByIdAndUserAccount(userSession.getContextId(), userAccount);
62+
task.setContext(context);
63+
}
64+
Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(TaskState.INBOX,locale);
65+
model.addAttribute("breadcrumb", breadcrumb);
66+
model.addAttribute("mustChooseArea", mustChooseContext);
67+
model.addAttribute("breadcrumb", breadcrumb);
68+
model.addAttribute("task", task);
69+
return "taskstate/task/add";
70+
}
71+
72+
@RequestMapping(path = "/add", method = RequestMethod.POST)
73+
public final String addNewTaskToInboxPost(
74+
@ModelAttribute("userSession") UserSessionBean userSession,
75+
@Valid Task task,
76+
BindingResult result,
77+
Locale locale,
78+
Model model
79+
) {
80+
log.info("addNewTaskToInboxPost");
81+
Context context = super.getContext(userSession);
82+
if (result.hasErrors()) {
83+
for (ObjectError e : result.getAllErrors()) {
84+
log.info(e.toString());
85+
}
86+
Boolean mustChooseArea = false;
87+
task.setContext(context);
88+
Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(TaskState.INBOX,locale);
89+
model.addAttribute("mustChooseArea", mustChooseArea);
90+
model.addAttribute("breadcrumb", breadcrumb);
91+
model.addAttribute("task", task);
92+
return "taskstate/task/add";
93+
} else {
94+
task.setProject(null);
95+
if(task.getDueDate()==null){
96+
task.setTaskState(TaskState.INBOX);
97+
} else {
98+
task.setTaskState(TaskState.SCHEDULED);
99+
}
100+
task.setFocus(false);
101+
task.setContext(context);
102+
long maxOrderIdProject = taskMoveService.getMaxOrderIdProject(task.getProject(),context);
103+
task.setOrderIdProject(++maxOrderIdProject);
104+
long maxOrderIdTaskState = taskMoveService.getMaxOrderIdTaskState(task.getTaskState(),task.getContext());
105+
task.setOrderIdTaskState(++maxOrderIdTaskState);
106+
task = taskService.saveAndFlush(task);
107+
log.info(task.toString());
108+
return "redirect:/taskstate/" + task.getTaskState().name().toLowerCase();
109+
}
110+
}
111+
36112
@RequestMapping(path = "/{sourceTaskId}/changeorderto/{destinationTaskId}", method = RequestMethod.GET)
37113
public String changeTaskOrderId(
38114
@PathVariable("sourceTaskId") Task sourceTask,
@@ -52,8 +128,10 @@ public String changeTaskOrderId(
52128
}
53129

54130
@RequestMapping(path = "/{taskId}/move/to/project/{projectId}", method = RequestMethod.GET)
55-
public final String moveTaskToAnotherProject(@PathVariable("taskId") Task task,
56-
@PathVariable long projectId) {
131+
public final String moveTaskToAnotherProject(
132+
@PathVariable("taskId") Task task,
133+
@PathVariable long projectId
134+
) {
57135
if(projectId == 0) {
58136
task = taskMoveService.moveTaskToRootProject(task);
59137
} else {
@@ -91,7 +169,7 @@ public final String moveTaskToWaiting(@PathVariable("taskId") Task task) {
91169
return "redirect:/taskstate/waiting";
92170
}
93171

94-
@RequestMapping(path = "/{taskId}/move/to/taskstate//someday", method = RequestMethod.GET)
172+
@RequestMapping(path = "/{taskId}/move/to/taskstate/someday", method = RequestMethod.GET)
95173
public final String moveTaskToSomeday(@PathVariable("taskId") Task task) {
96174
log.info("dragged and dropped "+task.getId()+" to someday");
97175
task = taskMoveService.moveTaskToSomeday(task);
@@ -112,14 +190,14 @@ public final String moveTaskToCompleted(@PathVariable("taskId") Task task) {
112190
return "redirect:/taskstate/completed";
113191
}
114192

115-
@RequestMapping(path = "/{taskId}/move/to/taskstate/trash", method = RequestMethod.GET)
193+
@RequestMapping(path = "/{taskId}/move/to/trash", method = RequestMethod.GET)
116194
public final String moveTaskToTrash(@PathVariable("taskId") Task task) {
117195
log.info("dragged and dropped "+task.getId()+" to trash");
118196
task = taskMoveService.moveTaskToTrash(task);
119197
return "redirect:/taskstate/trash";
120198
}
121199

122-
@RequestMapping(path = "/completed/move/to/taskstate/trash", method = RequestMethod.GET)
200+
@RequestMapping(path = "/completed/move/to/trash", method = RequestMethod.GET)
123201
public final String deleteallCompleted(
124202
@ModelAttribute("userSession") UserSessionBean userSession
125203
) {

src/main/resources/application.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,26 @@ org:
5858
- "/webjars"
5959
webSecurity:
6060
loginProcessingUrl: "/j_spring_security_check"
61-
logoutUrl: "/logout"
61+
logoutUrl: "/user/logout"
6262
cookieNamesToClear:
6363
- "JSESSIONID"
6464
invalidateHttpSession: true
6565
defaultSuccessUrl: "/"
66-
failureForwardUrl: "/login?login_error=1"
66+
failureForwardUrl: "/user/login?login_error=1"
6767
usernameParameter: "j_username"
6868
passwordParameter: "j_password"
69-
loginPage: "/login"
69+
loginPage: "/user/login"
7070
antPatternsPublic:
7171
- "/webjars/**"
7272
- "/css/**"
7373
- "/img/**"
7474
- "/js/**"
7575
- "/favicon.ico"
76-
- "/test*/**"
77-
- "/login*"
78-
- "/register*"
79-
- "/confirm*/**"
80-
- "/resetPassword*"
81-
- "/passwordResetConfirm*/**"
76+
- "/user/login*"
77+
- "/user/register*"
78+
- "/user/register/confirm/**"
79+
- "/user/resetPassword*"
80+
- "/user/resetPassword/confirm/**"
8281
- "/error*"
8382
strengthBCryptPasswordEncoder: 10
8483
---

src/main/resources/templates/project/add.html renamed to src/main/resources/templates/project/id/add/project.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h1>
1919

2020
<div th:fragment="mytwcontent">
2121
<div>
22-
<form id="formId" th:action="@{/project/{id}/add/new/project(id=${thisProject.id})}" th:object="${project}" method="post">
22+
<form id="formId" th:action="@{/project/{id}/add/project(id=${thisProject.id})}" th:object="${project}" method="post">
2323
<div class="form-group">
2424
<label th:for="${#ids.next('name')}" class="control-label">Name</label>
2525
<input type="text" th:field="*{name}" class="form-control" />
Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
<!DOCTYPE html>
2-
<html th:lang="${#locale.language}"
3-
xmlns="http://www.w3.org/1999/xhtml"
4-
xmlns:th="http://www.thymeleaf.org"
5-
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
6-
xmlns:sd="http://www.thymeleaf.org/spring-data">
7-
<head th:replace="layout/page :: tw-page-head(headtitle=~{::title},links=~{},refreshMessages=false)">
8-
<title th:text="'SimpleWorklist | ' + #{project.show.h1}">Title</title>
9-
</head>
10-
<body th:replace="layout/page :: tw-page-body(twcontent=~{::mytwcontent},twtitle=~{::mytwtitle},scripts=~{})">
11-
12-
<div th:fragment="mytwtitle">
13-
<div id="tw-content-title">
14-
<h1>
15-
<i class="fas fa-folder-open"></i>
16-
<span th:text="#{project.show.h1}">Project</span>
17-
<small th:if="${thisProject.id gt 0}">
18-
<span th:text="${thisProject.name}"></span>
19-
</small>
20-
</h1>
21-
<div id="tw-content-title-actionbuttons">
22-
<a class="btn btn-sm btn-primary" data-toggle="collapse" href="#collapseDescription" role="button" aria-expanded="false" aria-controls="collapseExample">
23-
<div th:text="#{project.show.description}">Project Description</div>
24-
</a>
25-
<a class="btn btn-sm btn-secondary" role="button" th:href="@{/project/{thisProjectId}/edit(thisProjectId=${thisProject.id})}" href="#">
26-
<i class="fas fa-edit"></i>
27-
<span th:text="#{project.show.edit}">Edit Project</span>
28-
</a>
29-
<a class="btn btn-sm btn-secondary" role="button" th:href="@{/project/{thisProjectId}/delete(thisProjectId=${thisProject.id})}" href="#">
30-
<i class="fas fa-trash-alt"></i>
31-
<span th:text="#{project.show.delete}">Delete Project</span>
32-
</a>
33-
<a class="btn btn-sm btn-secondary" role="button" th:href="@{/project/{pid}/add/new/project(pid=${thisProject.id})}">
34-
<i class="fas fa-plus-square"></i>
35-
<span th:text="#{layout.page.addProject}">Add a Project</span>
36-
</a>
37-
<a class="btn btn-sm btn-secondary" role="button" th:href="@{/task/addtoproject/{thisProjectId}(thisProjectId=${thisProject.id})}" href="#">
38-
<i class="fas fa-plus-square"></i>
39-
<span th:text="#{project.show.addTask}">Add a Task</span>
40-
</a>
41-
</div>
42-
<div class="collapse" id="collapseDescription">
43-
<div class="card card-body" th:text="${thisProject.description}"></div>
44-
</div>
45-
</div>
46-
</div>
47-
48-
<div th:fragment="mytwcontent">
49-
<!-- Document Window -->
50-
<div th:replace="layout/tasks :: tw-tasks-message(message=${message})">
51-
</div>
52-
<div th:if="${taskPage.getTotalElements() gt 0}">
53-
<!-- TODO: #34 -->
54-
<div th:replace="layout/tasks :: tw-tasks-table(taskPage=${taskPage},myTaskState='PROJECT')">
55-
</div>
56-
</div>
57-
<div th:if="${taskPage.getTotalElements() eq 0}">
58-
<p><span th:text="#{project.show.nothingToDo}">There is nothing to do in this project.</span></p>
59-
</div>
60-
</div>
61-
62-
</body>
63-
</html>
1+
<!DOCTYPE html>
2+
<html th:lang="${#locale.language}"
3+
xmlns="http://www.w3.org/1999/xhtml"
4+
xmlns:th="http://www.thymeleaf.org"
5+
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
6+
xmlns:sd="http://www.thymeleaf.org/spring-data">
7+
<head th:replace="layout/page :: tw-page-head(headtitle=~{::title},links=~{},refreshMessages=false)">
8+
<title th:text="'SimpleWorklist | ' + #{project.show.h1}">Title</title>
9+
</head>
10+
<body th:replace="layout/page :: tw-page-body(twcontent=~{::mytwcontent},twtitle=~{::mytwtitle},scripts=~{})">
11+
12+
<div th:fragment="mytwtitle">
13+
<div id="tw-content-title">
14+
<h1>
15+
<i class="fas fa-folder-open"></i>
16+
<span th:text="#{project.show.h1}">Project</span>
17+
<small th:if="${thisProject.id gt 0}">
18+
<span th:text="${thisProject.name}"></span>
19+
</small>
20+
</h1>
21+
<div id="tw-content-title-actionbuttons">
22+
<a class="btn btn-sm btn-primary" data-toggle="collapse" href="#collapseDescription" role="button" aria-expanded="false" aria-controls="collapseExample">
23+
<div th:text="#{project.show.description}">Project Description</div>
24+
</a>
25+
<a class="btn btn-sm btn-secondary" role="button" th:href="@{/project/{thisProjectId}/edit(thisProjectId=${thisProject.id})}" href="#">
26+
<i class="fas fa-edit"></i>
27+
<span th:text="#{project.show.edit}">Edit Project</span>
28+
</a>
29+
<a class="btn btn-sm btn-secondary" role="button" th:href="@{/project/{thisProjectId}/delete(thisProjectId=${thisProject.id})}" href="#">
30+
<i class="fas fa-trash-alt"></i>
31+
<span th:text="#{project.show.delete}">Delete Project</span>
32+
</a>
33+
<a class="btn btn-sm btn-secondary" role="button" th:href="@{/project/{thisProjectId}/add/project(thisProjectId=${thisProject.id})}">
34+
<i class="fas fa-plus-square"></i>
35+
<span th:text="#{layout.page.addProject}">Add a Project</span>
36+
</a>
37+
<a class="btn btn-sm btn-secondary" role="button" th:href="@{/project/{thisProjectId}/add/task(thisProjectId=${thisProject.id})}" href="#">
38+
<i class="fas fa-plus-square"></i>
39+
<span th:text="#{project.show.addTask}">Add a Task</span>
40+
</a>
41+
</div>
42+
<div class="collapse" id="collapseDescription">
43+
<div class="card card-body" th:text="${thisProject.description}"></div>
44+
</div>
45+
</div>
46+
</div>
47+
48+
<div th:fragment="mytwcontent">
49+
<!-- Document Window -->
50+
<div th:replace="layout/tasks :: tw-tasks-message(message=${message})">
51+
</div>
52+
<div th:if="${taskPage.getTotalElements() gt 0}">
53+
<!-- TODO: #34 -->
54+
<div th:replace="layout/tasks :: tw-tasks-table(taskPage=${taskPage},myTaskState='PROJECT')">
55+
</div>
56+
</div>
57+
<div th:if="${taskPage.getTotalElements() eq 0}">
58+
<p><span th:text="#{project.show.nothingToDo}">There is nothing to do in this project.</span></p>
59+
</div>
60+
</div>
61+
62+
</body>
63+
</html>

0 commit comments

Comments
 (0)