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 | // Protect filterPane. |
---|
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 | |
---|
125 | if(session.taskSearchParamsMax) |
---|
126 | params.max = session.taskSearchParamsMax |
---|
127 | |
---|
128 | // Protect filterPane. |
---|
129 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
130 | |
---|
131 | // Set the month to show. |
---|
132 | def showMonth = new Date() |
---|
133 | if(session.taskSearchCalendarShowMonth) |
---|
134 | showMonth = session.taskSearchCalendarShowMonth |
---|
135 | |
---|
136 | if(params.nextMonth) |
---|
137 | showMonth = dateUtilService.getNextMonth(showMonth) |
---|
138 | else if(params.previousMonth) |
---|
139 | showMonth = dateUtilService.getPreviousMonth(showMonth) |
---|
140 | session.taskSearchCalendarShowMonth = showMonth |
---|
141 | |
---|
142 | // Quick Search: |
---|
143 | if(!FilterUtils.isFilterApplied(params)) { |
---|
144 | def taskInstanceList = [] |
---|
145 | def personInstance = authService.currentUser |
---|
146 | |
---|
147 | if(params.quickSearch == "searchMyTodays") { |
---|
148 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
149 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
150 | else { params.message = "No tasks found for today." } |
---|
151 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
152 | } |
---|
153 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
154 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
155 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
156 | else { params.message = "No tasks found for the last week." } |
---|
157 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
158 | } |
---|
159 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
160 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
161 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
162 | else { params.message = "No tasks found for the last week." } |
---|
163 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
164 | } |
---|
165 | else { |
---|
166 | //Default: |
---|
167 | taskInstanceList = taskSearchService.getTodays(params) |
---|
168 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
169 | else { params.message = "No tasks found for today." } |
---|
170 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
171 | params.quickSearch = "searchTodays" |
---|
172 | } |
---|
173 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, showMonth: showMonth, filterParams: params] |
---|
174 | } |
---|
175 | // filterPane: |
---|
176 | def taskInstanceTotal = filterService.count( params, Task ) |
---|
177 | if(taskInstanceTotal > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
178 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
179 | taskInstanceTotal: taskInstanceTotal, |
---|
180 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
181 | showMonth: showMonth, |
---|
182 | params:params ] |
---|
183 | } |
---|
184 | |
---|
185 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
186 | def budget = { |
---|
187 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
188 | |
---|
189 | // Quick Search: |
---|
190 | if(!FilterUtils.isFilterApplied(params)) { |
---|
191 | def taskInstanceList = [] |
---|
192 | def personInstance = authService.currentUser |
---|
193 | |
---|
194 | if(params.quickSearch == "budgetUnplanned") { |
---|
195 | taskInstanceList = taskSearchService.getBudgetUnplanned(params) |
---|
196 | if(taskInstanceList.totalCount > 0) { params.message = "Budget unplanned tasks in the last week." } |
---|
197 | else { params.message = "No tasks found." } |
---|
198 | } |
---|
199 | //else if(params.quickSearch == "budgetPlanned") { |
---|
200 | else { |
---|
201 | //Default: |
---|
202 | taskInstanceList = taskSearchService.getBudgetPlanned(params) |
---|
203 | if(taskInstanceList.totalCount > 0) { params.message = "Budget planned Tasks in the last week." } |
---|
204 | else { params.message = "No tasks found.." } |
---|
205 | } |
---|
206 | // export plugin: |
---|
207 | if(params?.format && params.format != "html") { |
---|
208 | |
---|
209 | def dateFmt = { date -> |
---|
210 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
211 | } |
---|
212 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
213 | response.setHeader("Content-disposition", "attachment; filename=tasks.${params.extension}") |
---|
214 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskStatus", "taskType"] |
---|
215 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
216 | "leadPerson": "Lead Person", "taskStatus": "Task Status", "taskType": "Task Type"] |
---|
217 | Map formatters = [ targetStartDate: dateFmt] |
---|
218 | String title = "${params.quickSearch} tasks in the last week." |
---|
219 | Map parameters = [title: title, separator: ","] |
---|
220 | |
---|
221 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
222 | } |
---|
223 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
224 | } |
---|
225 | // filterPane: |
---|
226 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
227 | taskInstanceTotal: filterService.count( params, Task ), |
---|
228 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
229 | params:params ] |
---|
230 | } |
---|
231 | |
---|
232 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
233 | def show = { |
---|
234 | |
---|
235 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
236 | if(params._action_Show) |
---|
237 | params.action='show' |
---|
238 | |
---|
239 | // Used by navigation. |
---|
240 | if(params.id == 'nav') { |
---|
241 | params.id = session.currentTaskId ?: null |
---|
242 | redirect(action: show, id: params.id) |
---|
243 | return |
---|
244 | } |
---|
245 | |
---|
246 | def showTab = [:] |
---|
247 | switch (params.showTab) { |
---|
248 | case "showProcedureTab": |
---|
249 | showTab.procedure = new String("true") |
---|
250 | break |
---|
251 | case "showRecurrenceTab": |
---|
252 | showTab.recurrence = new String("true") |
---|
253 | break |
---|
254 | case "showInventoryTab": |
---|
255 | showTab.inventory = new String("true") |
---|
256 | break |
---|
257 | case "showSubTasksTab": |
---|
258 | showTab.subTasks = new String("true") |
---|
259 | break |
---|
260 | default: |
---|
261 | showTab.task = new String("true") |
---|
262 | } |
---|
263 | |
---|
264 | def taskInstance = Task.get( params.id ) |
---|
265 | |
---|
266 | if(!taskInstance) { |
---|
267 | flash.message = "Task not found with id ${params.id}" |
---|
268 | redirect(action: 'search') |
---|
269 | } |
---|
270 | else { |
---|
271 | // Remember the current task id for use with navigation. |
---|
272 | session.currentTaskId = params.id |
---|
273 | |
---|
274 | params.max = 10 |
---|
275 | params.order = "desc" |
---|
276 | params.sort = "id" |
---|
277 | |
---|
278 | def entryFaultList = Entry.withCriteria { |
---|
279 | eq("entryType", EntryType.get(1)) |
---|
280 | eq("task", taskInstance) |
---|
281 | } |
---|
282 | |
---|
283 | def entryCauseList = Entry.withCriteria { |
---|
284 | eq("entryType", EntryType.get(2)) |
---|
285 | eq("task", taskInstance) |
---|
286 | } |
---|
287 | |
---|
288 | def entryWorkDoneList = Entry.withCriteria { |
---|
289 | eq("entryType", EntryType.get(3)) |
---|
290 | eq("task", taskInstance) |
---|
291 | } |
---|
292 | |
---|
293 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
---|
294 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
---|
295 | |
---|
296 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
297 | |
---|
298 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
299 | |
---|
300 | def assignedGroupList = taskInstance.assignedGroups.sort { p1, p2 -> p1.personGroup.name.compareToIgnoreCase(p2.personGroup.name) } |
---|
301 | def assignedPersonList = taskInstance.assignedPersons.sort { p1, p2 -> p1.person.firstName.compareToIgnoreCase(p2.person.firstName) } |
---|
302 | |
---|
303 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
304 | def taskProcedureExits = new Boolean("true") |
---|
305 | if(!taskProcedureInstance) { |
---|
306 | taskProcedureExits = false |
---|
307 | } |
---|
308 | |
---|
309 | params.order = "asc" |
---|
310 | params.sort = "procedureStepNumber" |
---|
311 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
312 | |
---|
313 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
314 | def taskRecurringScheduleExits= new Boolean("true") |
---|
315 | if(!taskRecurringScheduleInstance) { |
---|
316 | taskRecurringScheduleExits = false |
---|
317 | } |
---|
318 | |
---|
319 | return [ taskInstance: taskInstance, |
---|
320 | entryFaultList: entryFaultList, |
---|
321 | entryCauseList: entryCauseList, |
---|
322 | entryWorkDoneList: entryWorkDoneList, |
---|
323 | taskProcedureInstance: taskProcedureInstance, |
---|
324 | taskProcedureExits: taskProcedureExits, |
---|
325 | showTab: showTab, |
---|
326 | subTaskInstanceList: subTaskInstanceList, |
---|
327 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
328 | subTaskInstanceMax: params.max, |
---|
329 | maintenanceActionList: maintenanceActionList, |
---|
330 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
331 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
332 | inventoryMovementList: inventoryMovementList, |
---|
333 | taskModificationList: taskModificationList, |
---|
334 | assignedGroupList: assignedGroupList, |
---|
335 | assignedPersonList: assignedPersonList] |
---|
336 | } |
---|
337 | } |
---|
338 | |
---|
339 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
340 | def restore = { |
---|
341 | |
---|
342 | def result = taskService.restore(params) |
---|
343 | |
---|
344 | if(!result.error) { |
---|
345 | flash.message = "Task ${params.id} has been restored." |
---|
346 | redirect(action: show, id: params.id) |
---|
347 | return |
---|
348 | } |
---|
349 | |
---|
350 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
351 | |
---|
352 | if(result.taskInstance) |
---|
353 | redirect(action: show, id: params.id) |
---|
354 | else |
---|
355 | redirect(action: 'search') |
---|
356 | |
---|
357 | } |
---|
358 | |
---|
359 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
360 | def trash = { |
---|
361 | |
---|
362 | def result = taskService.trash(params) |
---|
363 | |
---|
364 | if(!result.error) { |
---|
365 | flash.message = "Task ${params.id} has been moved to trash." |
---|
366 | redirect(action: 'search') |
---|
367 | return |
---|
368 | } |
---|
369 | |
---|
370 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
371 | |
---|
372 | if(result.taskInstance) |
---|
373 | redirect(action: show, id: params.id) |
---|
374 | else |
---|
375 | redirect(action: 'search') |
---|
376 | |
---|
377 | } |
---|
378 | |
---|
379 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
380 | def approve = { |
---|
381 | |
---|
382 | def result = taskService.approve(params) |
---|
383 | |
---|
384 | if(!result.error) { |
---|
385 | flash.message = "Task ${params.id} has been approved." |
---|
386 | redirect(action: show, id: params.id) |
---|
387 | return |
---|
388 | } |
---|
389 | |
---|
390 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
391 | |
---|
392 | if(result.taskInstance) |
---|
393 | redirect(action: show, id: params.id) |
---|
394 | else |
---|
395 | redirect(action: 'search') |
---|
396 | |
---|
397 | } |
---|
398 | |
---|
399 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
400 | def renegeApproval = { |
---|
401 | |
---|
402 | def result = taskService.renegeApproval(params) |
---|
403 | |
---|
404 | if(!result.error) { |
---|
405 | flash.message = "Task ${params.id} has had approval removed." |
---|
406 | redirect(action: show, id: params.id) |
---|
407 | return |
---|
408 | } |
---|
409 | |
---|
410 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
411 | |
---|
412 | if(result.taskInstance) |
---|
413 | redirect(action: show, id: params.id) |
---|
414 | else |
---|
415 | redirect(action: 'search') |
---|
416 | |
---|
417 | } |
---|
418 | |
---|
419 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
420 | def complete = { |
---|
421 | |
---|
422 | def result = taskService.complete(params) |
---|
423 | |
---|
424 | if(!result.error) { |
---|
425 | flash.message = "Task ${params.id} has been completed." |
---|
426 | redirect(action: show, id: params.id) |
---|
427 | return |
---|
428 | } |
---|
429 | |
---|
430 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
431 | |
---|
432 | if(result.taskInstance) |
---|
433 | redirect(action: show, id: params.id) |
---|
434 | else |
---|
435 | redirect(action: 'search') |
---|
436 | |
---|
437 | } |
---|
438 | |
---|
439 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
440 | def setAttentionFlag = { |
---|
441 | |
---|
442 | def result = taskService.setAttentionFlag(params) |
---|
443 | |
---|
444 | if(!result.error) { |
---|
445 | flash.message = "Task ${params.id} has been flagged for attention." |
---|
446 | redirect(action: show, id: params.id) |
---|
447 | return |
---|
448 | } |
---|
449 | |
---|
450 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
451 | |
---|
452 | if(result.taskInstance) |
---|
453 | redirect(action: show, id: params.id) |
---|
454 | else |
---|
455 | redirect(action: 'search') |
---|
456 | |
---|
457 | } |
---|
458 | |
---|
459 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
460 | def clearAttentionFlag = { |
---|
461 | |
---|
462 | def result = taskService.clearAttentionFlag(params) |
---|
463 | |
---|
464 | if(!result.error) { |
---|
465 | flash.message = "Task ${params.id} attention flag cleared." |
---|
466 | redirect(action: show, id: params.id) |
---|
467 | return |
---|
468 | } |
---|
469 | |
---|
470 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
471 | |
---|
472 | if(result.taskInstance) |
---|
473 | redirect(action: show, id: params.id) |
---|
474 | else |
---|
475 | redirect(action: 'search') |
---|
476 | |
---|
477 | } |
---|
478 | |
---|
479 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
480 | def reopen = { |
---|
481 | |
---|
482 | def result = taskService.reopen(params) |
---|
483 | |
---|
484 | if(!result.error) { |
---|
485 | flash.message = "Task ${params.id} has been reopened." |
---|
486 | redirect(action: show, id: params.id) |
---|
487 | return |
---|
488 | } |
---|
489 | |
---|
490 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
491 | |
---|
492 | if(result.taskInstance) |
---|
493 | redirect(action: show, id: params.id) |
---|
494 | else |
---|
495 | redirect(action: 'search') |
---|
496 | |
---|
497 | } |
---|
498 | |
---|
499 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
500 | def edit = { |
---|
501 | |
---|
502 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
503 | if(params._action_Edit) |
---|
504 | params.action='edit' |
---|
505 | |
---|
506 | // Used by navigation. |
---|
507 | if(params.id == 'nav') { |
---|
508 | params.id = session.currentTaskId ?: null |
---|
509 | redirect(action: edit, id: params.id) |
---|
510 | return |
---|
511 | } |
---|
512 | |
---|
513 | def taskInstance = Task.get( params.id ) |
---|
514 | |
---|
515 | if(!taskInstance) { |
---|
516 | flash.message = "Task not found with id ${params.id}" |
---|
517 | redirect(action: 'search') |
---|
518 | } |
---|
519 | else { |
---|
520 | // Remember the current task id for use with navigation. |
---|
521 | session.currentTaskId = params.id |
---|
522 | |
---|
523 | if(taskInstance.trash) { |
---|
524 | flash.message = "You may not edit tasks that are in the trash." |
---|
525 | redirect(action: 'show', id: taskInstance.id) |
---|
526 | return |
---|
527 | } |
---|
528 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
529 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
530 | return [ taskInstance : taskInstance ] |
---|
531 | } |
---|
532 | } |
---|
533 | |
---|
534 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
535 | def update = { |
---|
536 | |
---|
537 | def result = taskService.update(params) |
---|
538 | |
---|
539 | if(!result.error) { |
---|
540 | flash.message = "Task ${params.id} updated" |
---|
541 | redirect(action: show, id: params.id) |
---|
542 | return |
---|
543 | } |
---|
544 | |
---|
545 | if(result.error.code == "task.modifications.failedToSave") |
---|
546 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
547 | |
---|
548 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
---|
549 | |
---|
550 | } |
---|
551 | |
---|
552 | /** |
---|
553 | * The create action is used to create scheduled types of tasks. |
---|
554 | */ |
---|
555 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
556 | def create = { |
---|
557 | def taskInstance = new Task() |
---|
558 | |
---|
559 | // Set the targetStartDate if specified, used by searchCalendar view. |
---|
560 | if(params.year && params.month && params.day) |
---|
561 | taskInstance.targetStartDate = dateUtilService.makeDate(params.year, params.month, params.day) |
---|
562 | |
---|
563 | // Default leadPerson to current user, unless supplied in params. |
---|
564 | taskInstance.leadPerson = authService.currentUser |
---|
565 | taskInstance.properties = params |
---|
566 | |
---|
567 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
568 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
569 | taskInstance.taskPriority = scheduledTaskPriorities.default |
---|
570 | return ['taskInstance': taskInstance, |
---|
571 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
572 | 'scheduledTaskPriorities': scheduledTaskPriorities.list] |
---|
573 | } |
---|
574 | |
---|
575 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
576 | def save = { |
---|
577 | def result = taskService.save(params) |
---|
578 | |
---|
579 | if(!result.error) { |
---|
580 | flash.message = "Task ${result.taskInstance.id} created." |
---|
581 | redirect(action: 'show', id: result.taskInstance.id) |
---|
582 | return |
---|
583 | } |
---|
584 | |
---|
585 | if(result.error.code == "task.modifications.failedToSave") |
---|
586 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
587 | |
---|
588 | |
---|
589 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
590 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
591 | render(view:'create', model:[taskInstance:result.taskInstance, |
---|
592 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
593 | 'scheduledTaskPriorities': scheduledTaskPriorities.list]) |
---|
594 | } |
---|
595 | |
---|
596 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
597 | def listSubTasks = { |
---|
598 | def parentTaskInstance = Task.get(params.id) |
---|
599 | |
---|
600 | if(!parentTaskInstance) { |
---|
601 | flash.message = "Task not found with id ${params.id}" |
---|
602 | redirect(action: 'search') |
---|
603 | } |
---|
604 | else { |
---|
605 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
606 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
607 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
608 | |
---|
609 | [ taskInstanceList: subTaskInstanceList, |
---|
610 | taskInstanceTotal: subTaskInstanceTotal, |
---|
611 | parentTaskInstance: parentTaskInstance] |
---|
612 | } |
---|
613 | } |
---|
614 | |
---|
615 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
616 | def createSubTask = { |
---|
617 | def parentTaskInstance = Task.get(params.id) |
---|
618 | |
---|
619 | if(parentTaskInstance) { |
---|
620 | |
---|
621 | def result = taskService.createSubTask(parentTaskInstance) |
---|
622 | if(!result.error) { |
---|
623 | flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements." |
---|
624 | redirect(action: 'edit', id: result.taskInstance.id) |
---|
625 | } |
---|
626 | else { |
---|
627 | if(result.taskInstance.errors.hasFieldErrors("parentTask")) { |
---|
628 | flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
629 | redirect(action: 'show', id: parentTaskInstance.id) |
---|
630 | } |
---|
631 | else { |
---|
632 | render(view: 'create', model:[taskInstance: result.taskInstance]) |
---|
633 | } |
---|
634 | } |
---|
635 | } |
---|
636 | |
---|
637 | else { |
---|
638 | flash.message = "Task not found with id ${params.id}" |
---|
639 | redirect(action: 'search') |
---|
640 | } |
---|
641 | } |
---|
642 | |
---|
643 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
644 | def createUnscheduled = { |
---|
645 | def taskInstance = new Task() |
---|
646 | |
---|
647 | // Default leadPerson to current user, unless supplied in params. |
---|
648 | taskInstance.leadPerson = authService.currentUser |
---|
649 | taskInstance.properties = params |
---|
650 | |
---|
651 | // Always for Unscheduled task. |
---|
652 | taskInstance.taskType = TaskType.get(2) // Unscheduled Breakin. |
---|
653 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
654 | taskInstance.taskPriority = unscheduledTaskPriorities.default |
---|
655 | |
---|
656 | return ['taskInstance': taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list] |
---|
657 | } |
---|
658 | |
---|
659 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
660 | def saveUnscheduled = { |
---|
661 | def result = taskService.saveUnscheduled(params) |
---|
662 | |
---|
663 | if(!result.error) { |
---|
664 | flash.message = "Task ${result.taskInstance.id} created." |
---|
665 | redirect(action: 'show', id: result.taskInstance.id) |
---|
666 | return |
---|
667 | } |
---|
668 | |
---|
669 | if(result.error.code == "task.modifications.failedToSave") |
---|
670 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
671 | |
---|
672 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
673 | |
---|
674 | render(view:'createUnscheduled', |
---|
675 | model: ['taskInstance': result.taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list]) |
---|
676 | } |
---|
677 | |
---|
678 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
679 | def createImmediateCallout = { |
---|
680 | def taskInstance = new Task() |
---|
681 | |
---|
682 | def entryFaultInstance = new Entry(entryType: EntryType.get(1)) // Fault. |
---|
683 | def entryCauseInstance = new Entry(entryType: EntryType.get(2)) // Cause. |
---|
684 | def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3)) // Work Done. |
---|
685 | |
---|
686 | return ['taskInstance': taskInstance, |
---|
687 | 'entryFaultInstance': entryFaultInstance, |
---|
688 | 'entryCauseInstance': entryCauseInstance, |
---|
689 | 'entryWorkDoneInstance': entryWorkDoneInstance] |
---|
690 | } |
---|
691 | |
---|
692 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
693 | def saveImmediateCallout = { |
---|
694 | def result = taskService.saveImmediateCallout(params) |
---|
695 | |
---|
696 | if(!result.error) { |
---|
697 | flash.message = "Task ${result.taskInstance.id} created." |
---|
698 | redirect(action: 'show', id: result.taskInstance.id) |
---|
699 | return |
---|
700 | } |
---|
701 | |
---|
702 | if(result.error.code == "task.modifications.failedToSave") |
---|
703 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
704 | |
---|
705 | render(view:'createImmediateCallout', |
---|
706 | model: ['taskInstance': result.taskInstance, |
---|
707 | 'entryFaultInstance': result.entryFaultInstance, |
---|
708 | 'entryCauseInstance': result.entryCauseInstance, |
---|
709 | 'entryWorkDoneInstance': result.entryWorkDoneInstance]) |
---|
710 | |
---|
711 | } |
---|
712 | |
---|
713 | } // end of class. |
---|