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