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