1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
3 | import com.zeddware.grails.plugins.filterpane.FilterUtils |
---|
4 | |
---|
5 | class TaskDetailedController extends BaseController { |
---|
6 | |
---|
7 | def personService |
---|
8 | def taskService |
---|
9 | def taskSearchService |
---|
10 | def filterService |
---|
11 | def exportService |
---|
12 | def dateUtilService |
---|
13 | |
---|
14 | // these actions only accept POST requests |
---|
15 | static allowedMethods = [save:'POST', update:'POST', restore:'POST', trash:'POST', approve:'POST', renegeApproval:'POST', complete:'POST', reopen:'POST'] |
---|
16 | |
---|
17 | def index = { redirect(action: 'search', params: params) } |
---|
18 | |
---|
19 | def list = { |
---|
20 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
21 | [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ] |
---|
22 | } |
---|
23 | |
---|
24 | def setTaskSearchParamsMax = { |
---|
25 | def max = 1000 |
---|
26 | if(params.newMax.isInteger()) { |
---|
27 | def i = params.newMax.toInteger() |
---|
28 | if(i > 0 && i <= max) |
---|
29 | session.taskSearchParamsMax = params.newMax |
---|
30 | if(i > max) |
---|
31 | session.taskSearchParamsMax = max |
---|
32 | } |
---|
33 | forward(action: 'search', params: params) |
---|
34 | } |
---|
35 | |
---|
36 | def search = { |
---|
37 | |
---|
38 | if(session.taskSearchParamsMax) |
---|
39 | params.max = session.taskSearchParamsMax |
---|
40 | |
---|
41 | // TaskSearchService protects itself but filterPane does not. |
---|
42 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 1000 ) |
---|
43 | |
---|
44 | def taskInstanceList = [] |
---|
45 | def taskInstanceTotal |
---|
46 | def filterParams = [:] |
---|
47 | def personInstance = personService.currentUser |
---|
48 | |
---|
49 | // Quick Search: |
---|
50 | if(!FilterUtils.isFilterApplied(params)) { |
---|
51 | |
---|
52 | if(params.quickSearch == "searchMyTodays") { |
---|
53 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
54 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
55 | else { params.message = "No tasks found for today." } |
---|
56 | } |
---|
57 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
58 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
59 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
60 | else { params.message = "No tasks found for the last week." } |
---|
61 | } |
---|
62 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
63 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
64 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
65 | else { params.message = "No tasks found for the last week." } |
---|
66 | } |
---|
67 | else { |
---|
68 | //Default: |
---|
69 | taskInstanceList = taskSearchService.getTodays(params) |
---|
70 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
71 | else { params.message = "No tasks found for today." } |
---|
72 | params.quickSearch = "searchTodays" |
---|
73 | } |
---|
74 | |
---|
75 | taskInstanceTotal = taskInstanceList.totalCount |
---|
76 | filterParams.quickSearch = params.quickSearch |
---|
77 | } |
---|
78 | else { |
---|
79 | // filterPane: |
---|
80 | taskInstanceList = filterService.filter( params, Task ) |
---|
81 | taskInstanceTotal = filterService.count( params, Task ) |
---|
82 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
83 | } |
---|
84 | |
---|
85 | // export plugin: |
---|
86 | if(params?.format && params.format != "html") { |
---|
87 | |
---|
88 | def dateFmt = { date -> |
---|
89 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
90 | } |
---|
91 | |
---|
92 | String title |
---|
93 | if(params.quickSearch) |
---|
94 | title = "${params.quickSearch} tasks." |
---|
95 | else |
---|
96 | title = "Filtered tasks." |
---|
97 | |
---|
98 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
99 | response.setHeader("Content-disposition", "attachment; filename=tasks.${params.extension}") |
---|
100 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskStatus"] |
---|
101 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
102 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", "taskStatus": "Task Status"] |
---|
103 | Map formatters = [ targetStartDate: dateFmt] |
---|
104 | Map parameters = [title: title, separator: ","] |
---|
105 | |
---|
106 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
107 | } |
---|
108 | |
---|
109 | // Add some basic params to filterParams. |
---|
110 | filterParams.max = params.max |
---|
111 | filterParams.offset = params.offset?.toInteger() ?: 0 |
---|
112 | filterParams.sort = params.sort ?: "id" |
---|
113 | filterParams.order = params.order ?: "desc" |
---|
114 | |
---|
115 | return[ taskInstanceList: taskInstanceList, |
---|
116 | taskInstanceTotal: taskInstanceTotal, |
---|
117 | filterParams: filterParams ] |
---|
118 | |
---|
119 | } // end search() |
---|
120 | |
---|
121 | def searchCalendar = { |
---|
122 | params.max = 30 |
---|
123 | |
---|
124 | // Quick Search: |
---|
125 | if(!FilterUtils.isFilterApplied(params)) { |
---|
126 | def taskInstanceList = [] |
---|
127 | def personInstance = personService.currentUser |
---|
128 | |
---|
129 | if(params.quickSearch == "searchMyTodays") { |
---|
130 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
131 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
132 | else { params.message = "No tasks found for today." } |
---|
133 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
134 | } |
---|
135 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
136 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
137 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
138 | else { params.message = "No tasks found for the last week." } |
---|
139 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
140 | } |
---|
141 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
142 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
143 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
144 | else { params.message = "No tasks found for the last week." } |
---|
145 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
146 | } |
---|
147 | else { |
---|
148 | //Default: |
---|
149 | taskInstanceList = taskSearchService.getTodays(params) |
---|
150 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
151 | else { params.message = "No tasks found for today." } |
---|
152 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
153 | params.quickSearch = "searchTodays" |
---|
154 | } |
---|
155 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
156 | } |
---|
157 | // filterPane: |
---|
158 | def taskInstanceTotal = filterService.count( params, Task ) |
---|
159 | if(taskInstanceTotal > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
160 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
161 | taskInstanceTotal: taskInstanceTotal, |
---|
162 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
163 | params:params ] |
---|
164 | } |
---|
165 | |
---|
166 | def budget = { |
---|
167 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
168 | |
---|
169 | // Quick Search: |
---|
170 | if(!FilterUtils.isFilterApplied(params)) { |
---|
171 | def taskInstanceList = [] |
---|
172 | def personInstance = personService.currentUser |
---|
173 | |
---|
174 | if(params.quickSearch == "budgetUnplanned") { |
---|
175 | taskInstanceList = taskSearchService.getBudgetUnplanned(params) |
---|
176 | if(taskInstanceList.totalCount > 0) { params.message = "Budget unplanned tasks in the last week." } |
---|
177 | else { params.message = "No tasks found." } |
---|
178 | } |
---|
179 | //else if(params.quickSearch == "budgetPlanned") { |
---|
180 | else { |
---|
181 | //Default: |
---|
182 | taskInstanceList = taskSearchService.getBudgetPlanned(params) |
---|
183 | if(taskInstanceList.totalCount > 0) { params.message = "Budget planned Tasks in the last week." } |
---|
184 | else { params.message = "No tasks found.." } |
---|
185 | } |
---|
186 | // export plugin: |
---|
187 | if(params?.format && params.format != "html") { |
---|
188 | |
---|
189 | def dateFmt = { date -> |
---|
190 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
191 | } |
---|
192 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
193 | response.setHeader("Content-disposition", "attachment; filename=tasks.${params.extension}") |
---|
194 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskStatus", "taskType"] |
---|
195 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
196 | "leadPerson": "Lead Person", "taskStatus": "Task Status", "taskType": "Task Type"] |
---|
197 | Map formatters = [ targetStartDate: dateFmt] |
---|
198 | String title = "${params.quickSearch} tasks in the last week." |
---|
199 | Map parameters = [title: title, separator: ","] |
---|
200 | |
---|
201 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
202 | } |
---|
203 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
204 | } |
---|
205 | // filterPane: |
---|
206 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
207 | taskInstanceTotal: filterService.count( params, Task ), |
---|
208 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
209 | params:params ] |
---|
210 | } |
---|
211 | |
---|
212 | def show = { |
---|
213 | |
---|
214 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
215 | if(params._action_Show) |
---|
216 | { params.action='show' } |
---|
217 | |
---|
218 | def showTab = [:] |
---|
219 | switch (params.showTab) { |
---|
220 | case "showProcedureTab": |
---|
221 | showTab.procedure = new String("true") |
---|
222 | break |
---|
223 | case "showRecurrenceTab": |
---|
224 | showTab.recurrence = new String("true") |
---|
225 | break |
---|
226 | case "showInventoryTab": |
---|
227 | showTab.inventory = new String("true") |
---|
228 | break |
---|
229 | case "showSubTasksTab": |
---|
230 | showTab.subTasks = new String("true") |
---|
231 | break |
---|
232 | default: |
---|
233 | showTab.task = new String("true") |
---|
234 | } |
---|
235 | |
---|
236 | def taskInstance = Task.get( params.id ) |
---|
237 | |
---|
238 | if(!taskInstance) { |
---|
239 | flash.message = "Task not found with id ${params.id}" |
---|
240 | redirect(action: 'search') |
---|
241 | } |
---|
242 | else { |
---|
243 | params.max = 10 |
---|
244 | params.order = "desc" |
---|
245 | params.sort = "id" |
---|
246 | |
---|
247 | def entryWorkDoneList = Entry.withCriteria { |
---|
248 | eq("entryType", EntryType.get(2)) |
---|
249 | eq("task", taskInstance) |
---|
250 | } |
---|
251 | |
---|
252 | def entryFaultList = Entry.withCriteria { |
---|
253 | eq("entryType", EntryType.get(1)) |
---|
254 | eq("task", taskInstance) |
---|
255 | } |
---|
256 | |
---|
257 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
---|
258 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
---|
259 | |
---|
260 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
261 | |
---|
262 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
263 | |
---|
264 | def assignedGroupList = taskInstance.assignedGroups.sort { p1, p2 -> p1.personGroup.name.compareToIgnoreCase(p2.personGroup.name) } |
---|
265 | def assignedPersonList = taskInstance.assignedPersons.sort { p1, p2 -> p1.person.firstName.compareToIgnoreCase(p2.person.firstName) } |
---|
266 | |
---|
267 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
268 | def taskProcedureExits = new Boolean("true") |
---|
269 | if(!taskProcedureInstance) { |
---|
270 | taskProcedureExits = false |
---|
271 | } |
---|
272 | |
---|
273 | params.order = "asc" |
---|
274 | params.sort = "procedureStepNumber" |
---|
275 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
276 | |
---|
277 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
278 | def taskRecurringScheduleExits= new Boolean("true") |
---|
279 | if(!taskRecurringScheduleInstance) { |
---|
280 | taskRecurringScheduleExits = false |
---|
281 | } |
---|
282 | |
---|
283 | return [ taskInstance: taskInstance, |
---|
284 | entryWorkDoneList: entryWorkDoneList, |
---|
285 | entryFaultList: entryFaultList, |
---|
286 | taskProcedureInstance: taskProcedureInstance, |
---|
287 | taskProcedureExits: taskProcedureExits, |
---|
288 | showTab: showTab, |
---|
289 | subTaskInstanceList: subTaskInstanceList, |
---|
290 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
291 | subTaskInstanceMax: params.max, |
---|
292 | maintenanceActionList: maintenanceActionList, |
---|
293 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
294 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
295 | inventoryMovementList: inventoryMovementList, |
---|
296 | taskModificationList: taskModificationList, |
---|
297 | assignedGroupList: assignedGroupList, |
---|
298 | assignedPersonList: assignedPersonList] |
---|
299 | } |
---|
300 | } |
---|
301 | |
---|
302 | def restore = { |
---|
303 | |
---|
304 | if(!Task.exists(params.id)) { |
---|
305 | flash.message = "Task not found with id ${params.id}" |
---|
306 | redirect(action: 'search') |
---|
307 | } |
---|
308 | |
---|
309 | def result = taskService.restore(params) |
---|
310 | |
---|
311 | if(!result.error) { |
---|
312 | flash.message = "Task ${params.id} has been restored." |
---|
313 | redirect(action: 'show', id: result.taskInstance.id) |
---|
314 | } |
---|
315 | else { |
---|
316 | if(result.taskInstance) { |
---|
317 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
318 | } |
---|
319 | else { |
---|
320 | flash.message = "Task could not be updated." |
---|
321 | redirect(action: 'search') |
---|
322 | } |
---|
323 | } |
---|
324 | |
---|
325 | } |
---|
326 | |
---|
327 | def trash = { |
---|
328 | |
---|
329 | if(!Task.exists(params.id)) { |
---|
330 | flash.message = "Task not found with id ${params.id}." |
---|
331 | redirect(action: 'search') |
---|
332 | } |
---|
333 | |
---|
334 | def result = taskService.trash(params) |
---|
335 | |
---|
336 | if(!result.error) { |
---|
337 | flash.message = "Task ${params.id} has been moved to trash." |
---|
338 | redirect(action: 'search') |
---|
339 | } |
---|
340 | else { |
---|
341 | if(result.taskInstance) { |
---|
342 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
343 | } |
---|
344 | else { |
---|
345 | flash.message = "Task could not be updated." |
---|
346 | redirect(action: 'search') |
---|
347 | } |
---|
348 | } |
---|
349 | |
---|
350 | } |
---|
351 | |
---|
352 | def approve = { |
---|
353 | |
---|
354 | if(!Task.exists(params.id)) { |
---|
355 | flash.message = "Task not found with id ${params.id}." |
---|
356 | redirect(action: 'search') |
---|
357 | } |
---|
358 | |
---|
359 | def result = taskService.approve(params) |
---|
360 | |
---|
361 | if(!result.error) { |
---|
362 | flash.message = "Task ${params.id} has been approved." |
---|
363 | redirect(action: 'show', id: result.taskInstance.id) |
---|
364 | } |
---|
365 | else { |
---|
366 | if(result.taskInstance) { |
---|
367 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
368 | } |
---|
369 | else { |
---|
370 | flash.message = "Task could not be updated." |
---|
371 | redirect(action: 'search') |
---|
372 | } |
---|
373 | } |
---|
374 | |
---|
375 | } |
---|
376 | |
---|
377 | def renegeApproval = { |
---|
378 | |
---|
379 | if(!Task.exists(params.id)) { |
---|
380 | flash.message = "Task not found with id ${params.id}." |
---|
381 | redirect(action: 'search') |
---|
382 | } |
---|
383 | |
---|
384 | def result = taskService.renegeApproval(params) |
---|
385 | |
---|
386 | if(!result.error) { |
---|
387 | flash.message = "Task ${params.id} has had approval removed." |
---|
388 | redirect(action: 'show', id: result.taskInstance.id) |
---|
389 | } |
---|
390 | else { |
---|
391 | if(result.taskInstance) { |
---|
392 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
393 | } |
---|
394 | else { |
---|
395 | flash.message = "Task could not be updated." |
---|
396 | redirect(action: 'search') |
---|
397 | } |
---|
398 | } |
---|
399 | |
---|
400 | } |
---|
401 | |
---|
402 | def complete = { |
---|
403 | |
---|
404 | if(!Task.exists(params.id)) { |
---|
405 | flash.message = "Task not found with id ${params.id}." |
---|
406 | redirect(action: 'search') |
---|
407 | } |
---|
408 | |
---|
409 | def result = taskService.complete(params) |
---|
410 | |
---|
411 | if(!result.error) { |
---|
412 | flash.message = "Task ${params.id} has been completed." |
---|
413 | redirect(action: 'show', id: result.taskInstance.id) |
---|
414 | } |
---|
415 | else { |
---|
416 | if(result.taskInstance) { |
---|
417 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
418 | } |
---|
419 | else { |
---|
420 | flash.message = "Task could not be updated." |
---|
421 | redirect(action: 'search') |
---|
422 | } |
---|
423 | } |
---|
424 | |
---|
425 | } |
---|
426 | |
---|
427 | def reopen = { |
---|
428 | |
---|
429 | if(!Task.exists(params.id)) { |
---|
430 | flash.message = "Task not found with id ${params.id}." |
---|
431 | redirect(action: 'search') |
---|
432 | } |
---|
433 | |
---|
434 | def result = taskService.reopen(params) |
---|
435 | |
---|
436 | if(!result.error) { |
---|
437 | flash.message = "Task ${params.id} has been reopened." |
---|
438 | redirect(action: 'show', id: result.taskInstance.id) |
---|
439 | } |
---|
440 | else { |
---|
441 | if(result.taskInstance) { |
---|
442 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
443 | } |
---|
444 | else { |
---|
445 | flash.message = "Task could not be updated." |
---|
446 | redirect(action: 'search') |
---|
447 | } |
---|
448 | } |
---|
449 | |
---|
450 | } |
---|
451 | |
---|
452 | def edit = { |
---|
453 | |
---|
454 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
455 | if(params._action_Edit) |
---|
456 | { params.action='edit' } |
---|
457 | |
---|
458 | def taskInstance = Task.get( params.id ) |
---|
459 | |
---|
460 | if(!taskInstance) { |
---|
461 | flash.message = "Task not found with id ${params.id}" |
---|
462 | redirect(action: 'search') |
---|
463 | } |
---|
464 | else { |
---|
465 | if(taskInstance.trash) { |
---|
466 | flash.message = "You may not edit tasks that are in the trash." |
---|
467 | redirect(action: 'show', id: taskInstance.id) |
---|
468 | return |
---|
469 | } |
---|
470 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
471 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
472 | return [ taskInstance : taskInstance ] |
---|
473 | } |
---|
474 | } |
---|
475 | |
---|
476 | def update = { |
---|
477 | |
---|
478 | if(!Task.exists(params.id)) { |
---|
479 | flash.message = "Task not found with id ${params.id}" |
---|
480 | redirect(action: 'search') |
---|
481 | } |
---|
482 | |
---|
483 | def result = taskService.update(params) |
---|
484 | |
---|
485 | if(!result.error) { |
---|
486 | flash.message = "Task ${params.id} updated" |
---|
487 | redirect(action: 'show', id: result.taskInstance.id) |
---|
488 | } |
---|
489 | else { |
---|
490 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
---|
491 | } |
---|
492 | |
---|
493 | } |
---|
494 | |
---|
495 | def create = { |
---|
496 | def taskInstance = new Task() |
---|
497 | |
---|
498 | // Set the targetStartDate if specified, used by searchCalendar view. |
---|
499 | if(params.year && params.month && params.day) |
---|
500 | taskInstance.targetStartDate = dateUtilService.makeDate(params.year, params.month, params.day) |
---|
501 | |
---|
502 | // Default leadPerson to current user, unless supplied in params. |
---|
503 | taskInstance.leadPerson = personService.currentUser |
---|
504 | taskInstance.properties = params |
---|
505 | return ['taskInstance': taskInstance] |
---|
506 | } |
---|
507 | |
---|
508 | def save = { |
---|
509 | def result = taskService.create(params) |
---|
510 | |
---|
511 | if(!result.error) { |
---|
512 | flash.message = "Task ${result.taskInstance.id} created." |
---|
513 | redirect(action: 'show', id: result.taskInstance.id) |
---|
514 | } |
---|
515 | else { |
---|
516 | if(result.taskInstance) { |
---|
517 | render(view:'create', model:[taskInstance:result.taskInstance]) |
---|
518 | } |
---|
519 | else { |
---|
520 | flash.message = "Could not create task." |
---|
521 | redirect(action: 'search') |
---|
522 | } |
---|
523 | |
---|
524 | } |
---|
525 | } |
---|
526 | |
---|
527 | def listSubTasks = { |
---|
528 | def parentTaskInstance = Task.get(params.id) |
---|
529 | |
---|
530 | if(!parentTaskInstance) { |
---|
531 | flash.message = "Task not found with id ${params.id}" |
---|
532 | redirect(action: 'search') |
---|
533 | } |
---|
534 | else { |
---|
535 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
536 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
537 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
538 | |
---|
539 | [ taskInstanceList: subTaskInstanceList, |
---|
540 | taskInstanceTotal: subTaskInstanceTotal, |
---|
541 | parentTaskInstance: parentTaskInstance] |
---|
542 | } |
---|
543 | } |
---|
544 | |
---|
545 | def createSubTask = { |
---|
546 | def parentTaskInstance = Task.get(params.id) |
---|
547 | |
---|
548 | if(parentTaskInstance) { |
---|
549 | |
---|
550 | def result = taskService.createSubTask(parentTaskInstance) |
---|
551 | if(!result.error) { |
---|
552 | flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements." |
---|
553 | redirect(action: 'edit', id: result.taskInstance.id) |
---|
554 | } |
---|
555 | else { |
---|
556 | if(result.taskInstance.errors.hasFieldErrors("parentTask")) { |
---|
557 | flash.message = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
558 | redirect(action: 'show', id: parentTaskInstance.id) |
---|
559 | } |
---|
560 | else { |
---|
561 | render(view: 'create', model:[taskInstance: result.taskInstance]) |
---|
562 | } |
---|
563 | } |
---|
564 | } |
---|
565 | |
---|
566 | else { |
---|
567 | flash.message = "Task not found with id ${params.id}" |
---|
568 | redirect(action: 'search') |
---|
569 | } |
---|
570 | } |
---|
571 | |
---|
572 | } // end of class. |
---|