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 | // Used by navigation. |
---|
223 | if(params.id == 'nav') { |
---|
224 | params.id = session.currentTaskId ?: null |
---|
225 | redirect(action: show, id: params.id) |
---|
226 | return |
---|
227 | } |
---|
228 | |
---|
229 | def showTab = [:] |
---|
230 | switch (params.showTab) { |
---|
231 | case "showProcedureTab": |
---|
232 | showTab.procedure = new String("true") |
---|
233 | break |
---|
234 | case "showRecurrenceTab": |
---|
235 | showTab.recurrence = new String("true") |
---|
236 | break |
---|
237 | case "showInventoryTab": |
---|
238 | showTab.inventory = new String("true") |
---|
239 | break |
---|
240 | case "showSubTasksTab": |
---|
241 | showTab.subTasks = new String("true") |
---|
242 | break |
---|
243 | default: |
---|
244 | showTab.task = new String("true") |
---|
245 | } |
---|
246 | |
---|
247 | def taskInstance = Task.get( params.id ) |
---|
248 | |
---|
249 | if(!taskInstance) { |
---|
250 | flash.message = "Task not found with id ${params.id}" |
---|
251 | redirect(action: 'search') |
---|
252 | } |
---|
253 | else { |
---|
254 | // Remember the current task id for use with navigation. |
---|
255 | session.currentTaskId = params.id |
---|
256 | |
---|
257 | params.max = 10 |
---|
258 | params.order = "desc" |
---|
259 | params.sort = "id" |
---|
260 | |
---|
261 | def entryFaultList = Entry.withCriteria { |
---|
262 | eq("entryType", EntryType.get(1)) |
---|
263 | eq("task", taskInstance) |
---|
264 | } |
---|
265 | |
---|
266 | def entryCauseList = Entry.withCriteria { |
---|
267 | eq("entryType", EntryType.get(2)) |
---|
268 | eq("task", taskInstance) |
---|
269 | } |
---|
270 | |
---|
271 | def entryWorkDoneList = Entry.withCriteria { |
---|
272 | eq("entryType", EntryType.get(3)) |
---|
273 | eq("task", taskInstance) |
---|
274 | } |
---|
275 | |
---|
276 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
---|
277 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
---|
278 | |
---|
279 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
280 | |
---|
281 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
282 | |
---|
283 | def assignedGroupList = taskInstance.assignedGroups.sort { p1, p2 -> p1.personGroup.name.compareToIgnoreCase(p2.personGroup.name) } |
---|
284 | def assignedPersonList = taskInstance.assignedPersons.sort { p1, p2 -> p1.person.firstName.compareToIgnoreCase(p2.person.firstName) } |
---|
285 | |
---|
286 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
287 | def taskProcedureExits = new Boolean("true") |
---|
288 | if(!taskProcedureInstance) { |
---|
289 | taskProcedureExits = false |
---|
290 | } |
---|
291 | |
---|
292 | params.order = "asc" |
---|
293 | params.sort = "procedureStepNumber" |
---|
294 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
295 | |
---|
296 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
297 | def taskRecurringScheduleExits= new Boolean("true") |
---|
298 | if(!taskRecurringScheduleInstance) { |
---|
299 | taskRecurringScheduleExits = false |
---|
300 | } |
---|
301 | |
---|
302 | return [ taskInstance: taskInstance, |
---|
303 | entryFaultList: entryFaultList, |
---|
304 | entryCauseList: entryCauseList, |
---|
305 | entryWorkDoneList: entryWorkDoneList, |
---|
306 | taskProcedureInstance: taskProcedureInstance, |
---|
307 | taskProcedureExits: taskProcedureExits, |
---|
308 | showTab: showTab, |
---|
309 | subTaskInstanceList: subTaskInstanceList, |
---|
310 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
311 | subTaskInstanceMax: params.max, |
---|
312 | maintenanceActionList: maintenanceActionList, |
---|
313 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
314 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
315 | inventoryMovementList: inventoryMovementList, |
---|
316 | taskModificationList: taskModificationList, |
---|
317 | assignedGroupList: assignedGroupList, |
---|
318 | assignedPersonList: assignedPersonList] |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
323 | def restore = { |
---|
324 | |
---|
325 | def result = taskService.restore(params) |
---|
326 | |
---|
327 | if(!result.error) { |
---|
328 | flash.message = "Task ${params.id} has been restored." |
---|
329 | redirect(action: show, id: params.id) |
---|
330 | return |
---|
331 | } |
---|
332 | |
---|
333 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
334 | |
---|
335 | if(result.taskInstance) |
---|
336 | redirect(action: show, id: params.id) |
---|
337 | else |
---|
338 | redirect(action: 'search') |
---|
339 | |
---|
340 | } |
---|
341 | |
---|
342 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
343 | def trash = { |
---|
344 | |
---|
345 | def result = taskService.trash(params) |
---|
346 | |
---|
347 | if(!result.error) { |
---|
348 | flash.message = "Task ${params.id} has been moved to trash." |
---|
349 | redirect(action: 'search') |
---|
350 | return |
---|
351 | } |
---|
352 | |
---|
353 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
354 | |
---|
355 | if(result.taskInstance) |
---|
356 | redirect(action: show, id: params.id) |
---|
357 | else |
---|
358 | redirect(action: 'search') |
---|
359 | |
---|
360 | } |
---|
361 | |
---|
362 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
363 | def approve = { |
---|
364 | |
---|
365 | def result = taskService.approve(params) |
---|
366 | |
---|
367 | if(!result.error) { |
---|
368 | flash.message = "Task ${params.id} has been approved." |
---|
369 | redirect(action: show, id: params.id) |
---|
370 | return |
---|
371 | } |
---|
372 | |
---|
373 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
374 | |
---|
375 | if(result.taskInstance) |
---|
376 | redirect(action: show, id: params.id) |
---|
377 | else |
---|
378 | redirect(action: 'search') |
---|
379 | |
---|
380 | } |
---|
381 | |
---|
382 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
383 | def renegeApproval = { |
---|
384 | |
---|
385 | def result = taskService.renegeApproval(params) |
---|
386 | |
---|
387 | if(!result.error) { |
---|
388 | flash.message = "Task ${params.id} has had approval removed." |
---|
389 | redirect(action: show, id: params.id) |
---|
390 | return |
---|
391 | } |
---|
392 | |
---|
393 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
394 | |
---|
395 | if(result.taskInstance) |
---|
396 | redirect(action: show, id: params.id) |
---|
397 | else |
---|
398 | redirect(action: 'search') |
---|
399 | |
---|
400 | } |
---|
401 | |
---|
402 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
403 | def complete = { |
---|
404 | |
---|
405 | def result = taskService.complete(params) |
---|
406 | |
---|
407 | if(!result.error) { |
---|
408 | flash.message = "Task ${params.id} has been completed." |
---|
409 | redirect(action: show, id: params.id) |
---|
410 | return |
---|
411 | } |
---|
412 | |
---|
413 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
414 | |
---|
415 | if(result.taskInstance) |
---|
416 | redirect(action: show, id: params.id) |
---|
417 | else |
---|
418 | redirect(action: 'search') |
---|
419 | |
---|
420 | } |
---|
421 | |
---|
422 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
423 | def setAttentionFlag = { |
---|
424 | |
---|
425 | def result = taskService.setAttentionFlag(params) |
---|
426 | |
---|
427 | if(!result.error) { |
---|
428 | flash.message = "Task ${params.id} has been flagged for attention." |
---|
429 | redirect(action: show, id: params.id) |
---|
430 | return |
---|
431 | } |
---|
432 | |
---|
433 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
434 | |
---|
435 | if(result.taskInstance) |
---|
436 | redirect(action: show, id: params.id) |
---|
437 | else |
---|
438 | redirect(action: 'search') |
---|
439 | |
---|
440 | } |
---|
441 | |
---|
442 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
443 | def clearAttentionFlag = { |
---|
444 | |
---|
445 | def result = taskService.clearAttentionFlag(params) |
---|
446 | |
---|
447 | if(!result.error) { |
---|
448 | flash.message = "Task ${params.id} attention flag cleared." |
---|
449 | redirect(action: show, id: params.id) |
---|
450 | return |
---|
451 | } |
---|
452 | |
---|
453 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
454 | |
---|
455 | if(result.taskInstance) |
---|
456 | redirect(action: show, id: params.id) |
---|
457 | else |
---|
458 | redirect(action: 'search') |
---|
459 | |
---|
460 | } |
---|
461 | |
---|
462 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
463 | def reopen = { |
---|
464 | |
---|
465 | def result = taskService.reopen(params) |
---|
466 | |
---|
467 | if(!result.error) { |
---|
468 | flash.message = "Task ${params.id} has been reopened." |
---|
469 | redirect(action: show, id: params.id) |
---|
470 | return |
---|
471 | } |
---|
472 | |
---|
473 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
474 | |
---|
475 | if(result.taskInstance) |
---|
476 | redirect(action: show, id: params.id) |
---|
477 | else |
---|
478 | redirect(action: 'search') |
---|
479 | |
---|
480 | } |
---|
481 | |
---|
482 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
483 | def edit = { |
---|
484 | |
---|
485 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
486 | if(params._action_Edit) |
---|
487 | params.action='edit' |
---|
488 | |
---|
489 | // Used by navigation. |
---|
490 | if(params.id == 'nav') { |
---|
491 | params.id = session.currentTaskId ?: null |
---|
492 | redirect(action: edit, id: params.id) |
---|
493 | return |
---|
494 | } |
---|
495 | |
---|
496 | def taskInstance = Task.get( params.id ) |
---|
497 | |
---|
498 | if(!taskInstance) { |
---|
499 | flash.message = "Task not found with id ${params.id}" |
---|
500 | redirect(action: 'search') |
---|
501 | } |
---|
502 | else { |
---|
503 | // Remember the current task id for use with navigation. |
---|
504 | session.currentTaskId = params.id |
---|
505 | |
---|
506 | if(taskInstance.trash) { |
---|
507 | flash.message = "You may not edit tasks that are in the trash." |
---|
508 | redirect(action: 'show', id: taskInstance.id) |
---|
509 | return |
---|
510 | } |
---|
511 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
512 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
513 | return [ taskInstance : taskInstance ] |
---|
514 | } |
---|
515 | } |
---|
516 | |
---|
517 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
518 | def update = { |
---|
519 | |
---|
520 | def result = taskService.update(params) |
---|
521 | |
---|
522 | if(!result.error) { |
---|
523 | flash.message = "Task ${params.id} updated" |
---|
524 | redirect(action: show, id: params.id) |
---|
525 | return |
---|
526 | } |
---|
527 | |
---|
528 | if(result.error.code == "task.modifications.failedToSave") |
---|
529 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
530 | |
---|
531 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
---|
532 | |
---|
533 | } |
---|
534 | |
---|
535 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
536 | def create = { |
---|
537 | def taskInstance = new Task() |
---|
538 | |
---|
539 | // Set the targetStartDate if specified, used by searchCalendar view. |
---|
540 | if(params.year && params.month && params.day) |
---|
541 | taskInstance.targetStartDate = dateUtilService.makeDate(params.year, params.month, params.day) |
---|
542 | |
---|
543 | // Default leadPerson to current user, unless supplied in params. |
---|
544 | taskInstance.leadPerson = authService.currentUser |
---|
545 | taskInstance.properties = params |
---|
546 | |
---|
547 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
548 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
549 | taskInstance.taskPriority = scheduledTaskPriorities.default |
---|
550 | return ['taskInstance': taskInstance, |
---|
551 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
552 | 'scheduledTaskPriorities': scheduledTaskPriorities.list] |
---|
553 | } |
---|
554 | |
---|
555 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
556 | def save = { |
---|
557 | def result = taskService.save(params) |
---|
558 | |
---|
559 | if(!result.error) { |
---|
560 | flash.message = "Task ${result.taskInstance.id} created." |
---|
561 | redirect(action: 'show', id: result.taskInstance.id) |
---|
562 | return |
---|
563 | } |
---|
564 | |
---|
565 | if(result.error.code == "task.modifications.failedToSave") |
---|
566 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
567 | |
---|
568 | |
---|
569 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
570 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
571 | render(view:'create', model:[taskInstance:result.taskInstance, |
---|
572 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
573 | 'scheduledTaskPriorities': scheduledTaskPriorities.list]) |
---|
574 | } |
---|
575 | |
---|
576 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
577 | def listSubTasks = { |
---|
578 | def parentTaskInstance = Task.get(params.id) |
---|
579 | |
---|
580 | if(!parentTaskInstance) { |
---|
581 | flash.message = "Task not found with id ${params.id}" |
---|
582 | redirect(action: 'search') |
---|
583 | } |
---|
584 | else { |
---|
585 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
586 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
587 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
588 | |
---|
589 | [ taskInstanceList: subTaskInstanceList, |
---|
590 | taskInstanceTotal: subTaskInstanceTotal, |
---|
591 | parentTaskInstance: parentTaskInstance] |
---|
592 | } |
---|
593 | } |
---|
594 | |
---|
595 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
596 | def createSubTask = { |
---|
597 | def parentTaskInstance = Task.get(params.id) |
---|
598 | |
---|
599 | if(parentTaskInstance) { |
---|
600 | |
---|
601 | def result = taskService.createSubTask(parentTaskInstance) |
---|
602 | if(!result.error) { |
---|
603 | flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements." |
---|
604 | redirect(action: 'edit', id: result.taskInstance.id) |
---|
605 | } |
---|
606 | else { |
---|
607 | if(result.taskInstance.errors.hasFieldErrors("parentTask")) { |
---|
608 | flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
609 | redirect(action: 'show', id: parentTaskInstance.id) |
---|
610 | } |
---|
611 | else { |
---|
612 | render(view: 'create', model:[taskInstance: result.taskInstance]) |
---|
613 | } |
---|
614 | } |
---|
615 | } |
---|
616 | |
---|
617 | else { |
---|
618 | flash.message = "Task not found with id ${params.id}" |
---|
619 | redirect(action: 'search') |
---|
620 | } |
---|
621 | } |
---|
622 | |
---|
623 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
624 | def createUnscheduled = { |
---|
625 | def taskInstance = new Task() |
---|
626 | |
---|
627 | // Default leadPerson to current user, unless supplied in params. |
---|
628 | taskInstance.leadPerson = authService.currentUser |
---|
629 | taskInstance.properties = params |
---|
630 | |
---|
631 | // Always for Unscheduled task. |
---|
632 | taskInstance.taskType = TaskType.get(2) // Unscheduled Breakin. |
---|
633 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
634 | taskInstance.taskPriority = unscheduledTaskPriorities.default |
---|
635 | |
---|
636 | return ['taskInstance': taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list] |
---|
637 | } |
---|
638 | |
---|
639 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
640 | def saveUnscheduled = { |
---|
641 | def result = taskService.saveUnscheduled(params) |
---|
642 | |
---|
643 | if(!result.error) { |
---|
644 | flash.message = "Task ${result.taskInstance.id} created." |
---|
645 | redirect(action: 'show', id: result.taskInstance.id) |
---|
646 | return |
---|
647 | } |
---|
648 | |
---|
649 | if(result.error.code == "task.modifications.failedToSave") |
---|
650 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
651 | |
---|
652 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
653 | |
---|
654 | render(view:'createUnscheduled', |
---|
655 | model: ['taskInstance': result.taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list]) |
---|
656 | } |
---|
657 | |
---|
658 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
659 | def createImmediateCallout = { |
---|
660 | def taskInstance = new Task() |
---|
661 | |
---|
662 | def entryFaultInstance = new Entry(entryType: EntryType.get(1)) // Fault. |
---|
663 | def entryCauseInstance = new Entry(entryType: EntryType.get(2)) // Cause. |
---|
664 | def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3)) // Work Done. |
---|
665 | |
---|
666 | return ['taskInstance': taskInstance, |
---|
667 | 'entryFaultInstance': entryFaultInstance, |
---|
668 | 'entryCauseInstance': entryCauseInstance, |
---|
669 | 'entryWorkDoneInstance': entryWorkDoneInstance] |
---|
670 | } |
---|
671 | |
---|
672 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
673 | def saveImmediateCallout = { |
---|
674 | def result = taskService.saveImmediateCallout(params) |
---|
675 | |
---|
676 | if(!result.error) { |
---|
677 | flash.message = "Task ${result.taskInstance.id} created." |
---|
678 | redirect(action: 'show', id: result.taskInstance.id) |
---|
679 | return |
---|
680 | } |
---|
681 | |
---|
682 | if(result.error.code == "task.modifications.failedToSave") |
---|
683 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
684 | |
---|
685 | render(view:'createImmediateCallout', |
---|
686 | model: ['taskInstance': result.taskInstance, |
---|
687 | 'entryFaultInstance': result.entryFaultInstance, |
---|
688 | 'entryCauseInstance': result.entryCauseInstance, |
---|
689 | 'entryWorkDoneInstance': result.entryWorkDoneInstance]) |
---|
690 | |
---|
691 | } |
---|
692 | |
---|
693 | } // end of class. |
---|