Skip to content

Commit 5eb9cb5

Browse files
committed
work
1 parent 8f7b066 commit 5eb9cb5

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

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

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public final String addNewTaskToInboxPost(
9393
log.info("addNewTaskToInboxPost");
9494
Context context = super.getContext(userSession);
9595
model.addAttribute("dataPage", true);
96+
model.addAttribute("addProjectToTask", false);
9697
if (result.hasErrors()) {
9798
for (ObjectError e : result.getAllErrors()) {
9899
log.info(e.toString());
@@ -113,26 +114,44 @@ public final String addNewTaskToInboxPost(
113114
}
114115
}
115116

117+
/**
118+
* @param task
119+
* @param model
120+
* @return Project thisProject
121+
*/
122+
private Project addProjectFromTaskToModel(Task task, Model model){
123+
Project lastProject;
124+
Project thisProject;
125+
if (task.getProject() == null) {
126+
thisProject = new Project();
127+
thisProject.setId(0L);
128+
} else {
129+
thisProject = task.getProject();
130+
}
131+
if (task.getProject() == null) {
132+
lastProject = new Project();
133+
lastProject.setId(0L);
134+
} else {
135+
lastProject = task.getLastProject();
136+
}
137+
model.addAttribute("thisProject", thisProject);
138+
model.addAttribute("lastProject", lastProject);
139+
return thisProject;
140+
}
141+
116142
@RequestMapping(path = "/{taskId}/edit", method = RequestMethod.GET)
117143
public final String editTaskGet(
118144
@NotNull @PathVariable("taskId") Task task,
119145
@NotNull @ModelAttribute("userSession") UserSessionBean userSession,
120146
Locale locale, Model model
121147
) {
122148
log.info("editTaskGet");
149+
addProjectFromTaskToModel( task, model );
123150
UserAccount userAccount = userAccountLoginSuccessService.retrieveCurrentUser();
124151
List<Context> contexts = contextService.getAllForUser(userAccount);
125-
Project thisProject;
126-
if (task.getProject() == null) {
127-
thisProject = new Project();
128-
thisProject.setId(0L);
129-
} else {
130-
thisProject = task.getProject();
131-
}
132152
Context thisContext = task.getContext();
133-
Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(task.getTaskState(), locale,userSession);
153+
Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(task.getTaskState(), locale, userSession);
134154
model.addAttribute("breadcrumb", breadcrumb);
135-
model.addAttribute("thisProject", thisProject);
136155
model.addAttribute("thisContext", thisContext);
137156
model.addAttribute("task", task);
138157
model.addAttribute("contexts", contexts);
@@ -153,6 +172,7 @@ public final String editTaskPost(
153172
) {
154173
log.info("editTaskPost");
155174
model.addAttribute("dataPage", true);
175+
model.addAttribute("addProjectToTask", true);
156176
if(task.getTaskState()==TaskState.SCHEDULED && task.getDueDate()==null){
157177
String objectName="task";
158178
String field="dueDate";
@@ -173,27 +193,33 @@ public final String editTaskPost(
173193
task = persistentTask;
174194
UserAccount userAccount = userAccountLoginSuccessService.retrieveCurrentUser();
175195
List<Context> contexts = contextService.getAllForUser(userAccount);
176-
Project thisProject;
177-
if (task.getContext() == null) {
178-
thisProject = new Project();
179-
thisProject.setId(0L);
180-
} else {
181-
thisProject = task.getProject();
182-
}
196+
Project thisProject = addProjectFromTaskToModel( task, model );
183197
Context thisContext = task.getContext();
184198
Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(thisProject,locale,userSession);
185199
model.addAttribute("breadcrumb", breadcrumb);
186-
model.addAttribute("thisProject", thisProject);
187200
model.addAttribute("thisContext", thisContext);
188201
model.addAttribute("task", task);
189202
model.addAttribute("contexts", contexts);
190203
model.addAttribute("userSession", userSession);
191-
model.addAttribute("addProjectToTask", true);
192204
return "taskstate/task/edit";
193205
} else {
194206
task.unsetFocus();
195-
task.setRootProject();
196207
Task persistentTask = taskService.findOne(task.getId());
208+
if(task.getProject() != null){
209+
Long pidt = task.getProject().getId();
210+
if (persistentTask.getProject() != null) {
211+
Long pidp = persistentTask.getProject().getId();
212+
if(pidt != null && pidt != 0L) {
213+
Project newProject = projectService.findByProjectId(pidt);
214+
persistentTask.setProject(newProject);
215+
if (pidp != null && pidp != 0L) {
216+
if (!newProject.equals(persistentTask.getProject())) {
217+
persistentTask.setLastProject(persistentTask.getProject());
218+
}
219+
}
220+
}
221+
}
222+
}
197223
persistentTask.merge(task);
198224
task = taskService.updatedViaTaskstate(persistentTask);
199225
model.addAttribute("userSession", userSession);

src/main/java/org/woehlke/java/simpleworklist/domain/project/Project.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.Serializable;
44
import java.util.ArrayList;
55
import java.util.List;
6+
import java.util.Objects;
67
import java.util.UUID;
78

89
import javax.persistence.*;
@@ -36,7 +37,6 @@
3637
)
3738
@Getter
3839
@Setter
39-
@EqualsAndHashCode(callSuper = true, exclude = {"children","parent"})
4040
@ToString(callSuper = true, exclude = {"children","parent","description"})
4141
public class Project extends AuditModel implements Serializable, ComparableById<Project> {
4242

@@ -166,5 +166,7 @@ public Project addOtherProjectToChildren(Project otherProject) {
166166
public String out(){
167167
return "Project: "+name+" ("+id+")";
168168
}
169+
170+
169171
}
170172

0 commit comments

Comments
 (0)