Skip to content

Commit 8f7b066

Browse files
committed
work
1 parent 84640a6 commit 8f7b066

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

src/main/java/org/woehlke/java/simpleworklist/domain/ProjectIdController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public final String projectTaskAddGet(
8686
model.addAttribute("userSession", userSession);
8787
model.addAttribute("taskstateType",PROJECTS.getType());
8888
model.addAttribute("dataPage", true);
89+
model.addAttribute("addProjectToTask", false);
8990
return "project/id/task/add";
9091
}
9192

@@ -101,6 +102,7 @@ public final String projectTaskAddPost(
101102
UserAccount userAccount = context.getUserAccount();
102103
model.addAttribute("taskstateType",PROJECTS.getType());
103104
model.addAttribute("dataPage", true);
105+
model.addAttribute("addProjectToTask", false);
104106
if (result.hasErrors()) {
105107
for (ObjectError e : result.getAllErrors()) {
106108
log.info(e.toString());

src/main/java/org/woehlke/java/simpleworklist/domain/ProjectRootController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public final String projectRootTaskAddPost(
165165
log.info("/project/root/task/add (POST)");
166166
Context context = super.getContext(userSession);
167167
model.addAttribute("dataPage", true);
168+
model.addAttribute("addProjectToTask", false);
168169
model.addAttribute("taskstateType",PROJECTS.getType());
169170
if (result.hasErrors()) {
170171
for (ObjectError e : result.getAllErrors()) {
@@ -214,6 +215,7 @@ public final String editTaskGet(
214215
model.addAttribute("userSession", userSession);
215216
model.addAttribute("taskstateType",PROJECTS.getType());
216217
model.addAttribute("dataPage", true);
218+
model.addAttribute("addProjectToTask", true);
217219
return "project/root/task/edit";
218220
}
219221

@@ -229,6 +231,7 @@ public final String editTaskPost(
229231
log.info("editTaskPost");
230232
model.addAttribute("taskstateType",PROJECTS.getType());
231233
model.addAttribute("dataPage", true);
234+
model.addAttribute("addProjectToTask", true);
232235
if(task.getTaskState()==TaskState.SCHEDULED && task.getDueDate()==null){
233236
String objectName="task";
234237
String field="dueDate";

src/main/java/org/woehlke/java/simpleworklist/domain/TaskStateTaskController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public final String addNewTaskToInboxGet(
7878
model.addAttribute("task", task);
7979
model.addAttribute("userSession", userSession);
8080
model.addAttribute("dataPage", true);
81+
model.addAttribute("addProjectToTask", false);
8182
return "taskstate/task/add";
8283
}
8384

@@ -122,7 +123,7 @@ public final String editTaskGet(
122123
UserAccount userAccount = userAccountLoginSuccessService.retrieveCurrentUser();
123124
List<Context> contexts = contextService.getAllForUser(userAccount);
124125
Project thisProject;
125-
if (task.getContext() == null) {
126+
if (task.getProject() == null) {
126127
thisProject = new Project();
127128
thisProject.setId(0L);
128129
} else {
@@ -137,6 +138,7 @@ public final String editTaskGet(
137138
model.addAttribute("contexts", contexts);
138139
model.addAttribute("userSession", userSession);
139140
model.addAttribute("dataPage", true);
141+
model.addAttribute("addProjectToTask", true);
140142
return "taskstate/task/edit";
141143
}
142144

@@ -186,6 +188,7 @@ public final String editTaskPost(
186188
model.addAttribute("task", task);
187189
model.addAttribute("contexts", contexts);
188190
model.addAttribute("userSession", userSession);
191+
model.addAttribute("addProjectToTask", true);
189192
return "taskstate/task/edit";
190193
} else {
191194
task.unsetFocus();

src/main/java/org/woehlke/java/simpleworklist/domain/task/TaskServiceImpl.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@
99
import org.springframework.transaction.annotation.Transactional;
1010
import org.woehlke.java.simpleworklist.domain.context.Context;
1111
import org.woehlke.java.simpleworklist.domain.project.Project;
12+
import org.woehlke.java.simpleworklist.domain.project.ProjectRepository;
1213
import org.woehlke.java.simpleworklist.domain.taskworkflow.TaskState;
1314

1415
import javax.validation.constraints.Min;
1516
import javax.validation.constraints.NotNull;
16-
import java.util.ArrayList;
17-
import java.util.Date;
18-
import java.util.List;
19-
import java.util.UUID;
17+
import java.util.*;
2018

2119
@Slf4j
2220
@Service
2321
public class TaskServiceImpl implements TaskService {
2422

2523
private final TaskRepository taskRepository;
2624

25+
private final ProjectRepository projectRepository;
26+
2727
@Autowired
28-
public TaskServiceImpl(TaskRepository taskRepository ) {
28+
public TaskServiceImpl(TaskRepository taskRepository, ProjectRepository projectRepository) {
2929
this.taskRepository = taskRepository;
30+
this.projectRepository = projectRepository;
3031
}
3132

3233
@Override
@@ -89,6 +90,16 @@ public Task findOne(@Min(1L) long taskId) {
8990
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
9091
public Task updatedViaTaskstate(@NotNull Task task) {
9192
log.info("updatedViaTaskstate");
93+
if(task.getProject() != null){
94+
Long projectId = task.getProject().getId();
95+
Project project = projectRepository.getReferenceById(projectId);
96+
task.setProject(project);
97+
}
98+
if(task.getLastProject()!=null){
99+
Long projectId = task.getLastProject().getId();
100+
Project project = projectRepository.getReferenceById(projectId);
101+
task.setLastProject(project);
102+
}
92103
task = taskRepository.saveAndFlush(task);
93104
log.info("persisted: " + task.outTaskstate());
94105
return task;
@@ -120,6 +131,7 @@ public Task addToInbox(@NotNull Task task) {
120131
task.setRootProject();
121132
task.unsetFocus();
122133
task.setTaskState(TaskState.INBOX);
134+
task.setLastProject(null);
123135
long maxOrderIdProject = this.getMaxOrderIdProjectRoot(task.getContext());
124136
task.setOrderIdProject(++maxOrderIdProject);
125137
long maxOrderIdTaskState = this.getMaxOrderIdTaskState(task.getTaskState(),task.getContext());

src/main/resources/templates/layout/task.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
<div th:each="err : ${#fields.errors('taskEnergy')}">
107107
<div class="invalid-feedback" th:text="${err}">err</div>
108108
</div>
109-
</div>&nbsp;
109+
</div>nbsp;
110110
</div>
111111

112112
<div class="col-md">
@@ -129,9 +129,9 @@
129129
</div>
130130
</div>
131131
</div>
132-
133132
</div>
134-
<div class="row my-2">
133+
134+
<div class="row my-2" th:if="${addProjectToTask}">
135135
<div class="col-md">
136136
<label th:for="${#ids.next('project.id')}" class="control-label">
137137
<span th:utext="#{task.show.project}">Project</span>
@@ -141,7 +141,8 @@
141141
<i class="fa-solid fa-cloud"></i>
142142
</span>
143143
<select th:field="*{project.id}" class="form-control form-control-lg" aria-describedby="basic-addon7">
144-
<option th:each="projectOption : ${rootProjects}"
144+
<option value="0"></option>
145+
<option th:each="projectOption : ${allProjects}"
145146
th:value="${projectOption.id}"
146147
th:text="${projectOption.name}">Project
147148
</option>

0 commit comments

Comments
 (0)