@@ -93,6 +93,7 @@ public final String addNewTaskToInboxPost(
93
93
log .info ("addNewTaskToInboxPost" );
94
94
Context context = super .getContext (userSession );
95
95
model .addAttribute ("dataPage" , true );
96
+ model .addAttribute ("addProjectToTask" , false );
96
97
if (result .hasErrors ()) {
97
98
for (ObjectError e : result .getAllErrors ()) {
98
99
log .info (e .toString ());
@@ -113,26 +114,44 @@ public final String addNewTaskToInboxPost(
113
114
}
114
115
}
115
116
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
+
116
142
@ RequestMapping (path = "/{taskId}/edit" , method = RequestMethod .GET )
117
143
public final String editTaskGet (
118
144
@ NotNull @ PathVariable ("taskId" ) Task task ,
119
145
@ NotNull @ ModelAttribute ("userSession" ) UserSessionBean userSession ,
120
146
Locale locale , Model model
121
147
) {
122
148
log .info ("editTaskGet" );
149
+ addProjectFromTaskToModel ( task , model );
123
150
UserAccount userAccount = userAccountLoginSuccessService .retrieveCurrentUser ();
124
151
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
- }
132
152
Context thisContext = task .getContext ();
133
- Breadcrumb breadcrumb = breadcrumbService .getBreadcrumbForTaskstate (task .getTaskState (), locale ,userSession );
153
+ Breadcrumb breadcrumb = breadcrumbService .getBreadcrumbForTaskstate (task .getTaskState (), locale , userSession );
134
154
model .addAttribute ("breadcrumb" , breadcrumb );
135
- model .addAttribute ("thisProject" , thisProject );
136
155
model .addAttribute ("thisContext" , thisContext );
137
156
model .addAttribute ("task" , task );
138
157
model .addAttribute ("contexts" , contexts );
@@ -153,6 +172,7 @@ public final String editTaskPost(
153
172
) {
154
173
log .info ("editTaskPost" );
155
174
model .addAttribute ("dataPage" , true );
175
+ model .addAttribute ("addProjectToTask" , true );
156
176
if (task .getTaskState ()==TaskState .SCHEDULED && task .getDueDate ()==null ){
157
177
String objectName ="task" ;
158
178
String field ="dueDate" ;
@@ -173,27 +193,33 @@ public final String editTaskPost(
173
193
task = persistentTask ;
174
194
UserAccount userAccount = userAccountLoginSuccessService .retrieveCurrentUser ();
175
195
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 );
183
197
Context thisContext = task .getContext ();
184
198
Breadcrumb breadcrumb = breadcrumbService .getBreadcrumbForShowOneProject (thisProject ,locale ,userSession );
185
199
model .addAttribute ("breadcrumb" , breadcrumb );
186
- model .addAttribute ("thisProject" , thisProject );
187
200
model .addAttribute ("thisContext" , thisContext );
188
201
model .addAttribute ("task" , task );
189
202
model .addAttribute ("contexts" , contexts );
190
203
model .addAttribute ("userSession" , userSession );
191
- model .addAttribute ("addProjectToTask" , true );
192
204
return "taskstate/task/edit" ;
193
205
} else {
194
206
task .unsetFocus ();
195
- task .setRootProject ();
196
207
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
+ }
197
223
persistentTask .merge (task );
198
224
task = taskService .updatedViaTaskstate (persistentTask );
199
225
model .addAttribute ("userSession" , userSession );
0 commit comments