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 | import org.springframework.web.servlet.support.RequestContextUtils as RCU |
---|
5 | |
---|
6 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
7 | class TaskDetailedController extends BaseController { |
---|
8 | |
---|
9 | def authService |
---|
10 | def taskService |
---|
11 | def taskSearchService |
---|
12 | def filterService |
---|
13 | def exportService |
---|
14 | def dateUtilService |
---|
15 | |
---|
16 | // these actions only accept POST requests |
---|
17 | static allowedMethods = [save:'POST',update:'POST',restore:'POST', trash:'POST', |
---|
18 | approve:'POST', renegeApproval:'POST', complete:'POST', |
---|
19 | reopen:'POST', setAttentionFlag:'POST', clearAttentionFlag:'POST'] |
---|
20 | |
---|
21 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
22 | def index = { redirect(action: 'search', params: params) } |
---|
23 | |
---|
24 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
25 | def setSearchParamsMax = { |
---|
26 | def max = 1000 |
---|
27 | if(params.newMax.isInteger()) { |
---|
28 | def i = params.newMax.toInteger() |
---|
29 | if(i > 0 && i <= max) |
---|
30 | session.taskSearchParamsMax = params.newMax |
---|
31 | if(i > max) |
---|
32 | session.taskSearchParamsMax = max |
---|
33 | } |
---|
34 | forward(action: 'search', params: params) |
---|
35 | } |
---|
36 | |
---|
37 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
38 | def setSearchCalendarParamsMax = { |
---|
39 | def max = 1000 |
---|
40 | if(params.newMax.isInteger()) { |
---|
41 | def i = params.newMax.toInteger() |
---|
42 | if(i > 0 && i <= max) |
---|
43 | session.taskSearchCalendarParamsMax = params.newMax |
---|
44 | if(i > max) |
---|
45 | session.taskSearchCalendarParamsMax = max |
---|
46 | } |
---|
47 | forward(action: 'searchCalendar', params: params) |
---|
48 | } |
---|
49 | |
---|
50 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
51 | def search = { |
---|
52 | |
---|
53 | if(session.taskSearchParamsMax) |
---|
54 | params.max = session.taskSearchParamsMax |
---|
55 | |
---|
56 | // Protect filterPane. |
---|
57 | params.max = Math.min( params.max ? params.max.toInteger() : 20, 1000 ) |
---|
58 | |
---|
59 | def taskInstanceList = [] |
---|
60 | def taskInstanceTotal |
---|
61 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
62 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
63 | |
---|
64 | // Restore search unless a new search is being requested. |
---|
65 | if(!params.quickSearch && !filterParams) { |
---|
66 | if(session.taskSearchQuickSearch) |
---|
67 | params.quickSearch = session.taskSearchQuickSearch |
---|
68 | else if(session.taskSearchFilterParams) { |
---|
69 | session.taskSearchFilterParams.each() { params[it.key] = it.value } |
---|
70 | params.filter = session.taskSearchFilter |
---|
71 | isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | if(isFilterApplied) { |
---|
76 | // filterPane: |
---|
77 | taskInstanceList = filterService.filter( params, Task ) |
---|
78 | taskInstanceTotal = filterService.count( params, Task ) |
---|
79 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
80 | // Remember search. |
---|
81 | session.taskSearchFilterParams = new LinkedHashMap(filterParams) |
---|
82 | session.taskSearchFilter = new LinkedHashMap(params.filter) |
---|
83 | session.taskSearchQuickSearch = null |
---|
84 | } |
---|
85 | else { |
---|
86 | // Quick Search: |
---|
87 | if(!params.quickSearch) params.quickSearch = "myTodays" |
---|
88 | def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request)) |
---|
89 | taskInstanceList = result.taskInstanceList |
---|
90 | taskInstanceTotal = result.taskInstanceList.totalCount |
---|
91 | params.message = result.message |
---|
92 | filterParams.quickSearch = result.quickSearch |
---|
93 | // Remember search. |
---|
94 | session.taskSearchFilterParams = null |
---|
95 | session.taskSearchFilter = null |
---|
96 | session.taskSearchQuickSearch = result.quickSearch |
---|
97 | } |
---|
98 | |
---|
99 | // export plugin: |
---|
100 | if(params?.format && params.format != "html") { |
---|
101 | |
---|
102 | def dateFmt = { date -> |
---|
103 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
104 | } |
---|
105 | |
---|
106 | String title |
---|
107 | if(params.quickSearch) |
---|
108 | title = params.message |
---|
109 | else |
---|
110 | title = "Filtered tasks." |
---|
111 | |
---|
112 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
113 | response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}") |
---|
114 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskType", "taskStatus"] |
---|
115 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
116 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", |
---|
117 | "taskType": "Task Type", "taskStatus": "Task Status"] |
---|
118 | Map formatters = [ targetStartDate: dateFmt] |
---|
119 | Map parameters = [title: title, separator: ","] |
---|
120 | |
---|
121 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
122 | } |
---|
123 | |
---|
124 | // Add some basic params to filterParams. |
---|
125 | filterParams.max = params.max |
---|
126 | filterParams.offset = params.offset?.toInteger() ?: 0 |
---|
127 | filterParams.sort = params.sort ?: "attentionFlag" |
---|
128 | filterParams.order = params.order ?: "desc" |
---|
129 | |
---|
130 | return[ taskInstanceList: taskInstanceList, |
---|
131 | taskInstanceTotal: taskInstanceTotal, |
---|
132 | filterParams: filterParams, |
---|
133 | params: params ] |
---|
134 | |
---|
135 | } // search |
---|
136 | |
---|
137 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
138 | def searchCalendar = { |
---|
139 | |
---|
140 | // No pagination for calendar. |
---|
141 | params.offset = 0 |
---|
142 | |
---|
143 | // Restore params.max |
---|
144 | if(session.taskSearchCalendarParamsMax) |
---|
145 | params.max = session.taskSearchCalendarParamsMax |
---|
146 | |
---|
147 | // Protect filterPane. |
---|
148 | params.max = Math.min( params.max ? params.max.toInteger() : 100, 1000 ) |
---|
149 | |
---|
150 | def taskInstanceList = [] |
---|
151 | def taskInstanceTotal |
---|
152 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
153 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
154 | |
---|
155 | // Restore search unless a new search is being requested. |
---|
156 | if(!params.quickSearch && !filterParams) { |
---|
157 | if(session.taskSearchCalendarQuickSearch) |
---|
158 | params.quickSearch = session.taskSearchCalendarQuickSearch |
---|
159 | else if(session.taskSearchCalendarFilterParams) { |
---|
160 | session.taskSearchCalendarFilterParams.each() { params[it.key] = it.value } |
---|
161 | params.filter = session.taskSearchCalendarFilter |
---|
162 | isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | // The date the calendar will use to determine the month to show. |
---|
167 | // Use session, if not specified in params, otherwise use today. |
---|
168 | def showDate = new Date() |
---|
169 | if(params.showMonth) { |
---|
170 | if(params.showYear) |
---|
171 | showDate = dateUtilService.makeDate(params.showYear, params.showMonth) |
---|
172 | else |
---|
173 | showDate = dateUtilService.makeDate(dateUtilService.getYearFromDate(showDate), params.showMonth) |
---|
174 | // Remember the showDate. |
---|
175 | session.taskSearchCalendarShowDate = showDate |
---|
176 | } |
---|
177 | else if(session.taskSearchCalendarShowDate) |
---|
178 | showDate = session.taskSearchCalendarShowDate |
---|
179 | |
---|
180 | // Get the dates for the calendar month controls. |
---|
181 | def calendarMonthControls = getCalendarMonthControls(showDate) |
---|
182 | |
---|
183 | if(isFilterApplied) { |
---|
184 | // filterPane: |
---|
185 | taskInstanceList = filterService.filter( params, Task ) |
---|
186 | taskInstanceTotal = filterService.count( params, Task ) |
---|
187 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
188 | // Remember search. |
---|
189 | session.taskSearchCalendarFilterParams = new LinkedHashMap(filterParams) |
---|
190 | session.taskSearchCalendarFilter = new LinkedHashMap(params.filter) |
---|
191 | session.taskSearchCalendarQuickSearch = null |
---|
192 | } |
---|
193 | else { |
---|
194 | // Quick Search: |
---|
195 | def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request)) |
---|
196 | taskInstanceList = result.taskInstanceList |
---|
197 | taskInstanceTotal = result.taskInstanceList.totalCount |
---|
198 | params.message = result.message |
---|
199 | filterParams.quickSearch = result.quickSearch |
---|
200 | // Remember search. |
---|
201 | session.taskSearchCalendarFilterParams = null |
---|
202 | session.taskSearchCalendarFilter = null |
---|
203 | session.taskSearchCalendarQuickSearch = result.quickSearch |
---|
204 | } |
---|
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 | |
---|
213 | String title |
---|
214 | if(params.quickSearch) |
---|
215 | title = params.message |
---|
216 | else |
---|
217 | title = "Filtered tasks." |
---|
218 | |
---|
219 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
220 | response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}") |
---|
221 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskType", "taskStatus"] |
---|
222 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
223 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", |
---|
224 | "taskType": "Task Type", "taskStatus": "Task Status"] |
---|
225 | Map formatters = [ targetStartDate: dateFmt] |
---|
226 | Map parameters = [title: title, separator: ","] |
---|
227 | |
---|
228 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
229 | } |
---|
230 | |
---|
231 | if(taskInstanceTotal > params.max) |
---|
232 | params.errorMessage = g.message(code:"task.search.calendar.text.too.many.results", args:[params.max]) |
---|
233 | |
---|
234 | // Add some basic params to filterParams. |
---|
235 | filterParams.max = params.max |
---|
236 | filterParams.offset = params.offset?.toInteger() ?: 0 |
---|
237 | |
---|
238 | return[taskInstanceList: taskInstanceList, |
---|
239 | taskInstanceTotal: taskInstanceTotal, |
---|
240 | filterParams: filterParams, |
---|
241 | params: params, |
---|
242 | showDate: showDate, |
---|
243 | today: calendarMonthControls.today, |
---|
244 | previousMonth: calendarMonthControls.previousMonth, |
---|
245 | nextMonth: calendarMonthControls.nextMonth, |
---|
246 | previousYear: calendarMonthControls.previousYear, |
---|
247 | nextYear: calendarMonthControls.nextYear] |
---|
248 | |
---|
249 | } // searchCalendar |
---|
250 | |
---|
251 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
252 | def show = { |
---|
253 | |
---|
254 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
255 | if(params._action_Show) |
---|
256 | params.action='show' |
---|
257 | |
---|
258 | // Used by navigation. |
---|
259 | if(params.id == 'nav') { |
---|
260 | params.id = session.currentTaskId ?: null |
---|
261 | redirect(action: show, id: params.id) |
---|
262 | return |
---|
263 | } |
---|
264 | |
---|
265 | def showTab = [:] |
---|
266 | switch (params.showTab) { |
---|
267 | case "showProcedureTab": |
---|
268 | showTab.procedure = new String("true") |
---|
269 | break |
---|
270 | case "showRecurrenceTab": |
---|
271 | showTab.recurrence = new String("true") |
---|
272 | break |
---|
273 | case "showInventoryTab": |
---|
274 | showTab.inventory = new String("true") |
---|
275 | break |
---|
276 | case "showSubTasksTab": |
---|
277 | showTab.subTasks = new String("true") |
---|
278 | break |
---|
279 | default: |
---|
280 | showTab.task = new String("true") |
---|
281 | } |
---|
282 | |
---|
283 | def taskInstance = Task.get( params.id ) |
---|
284 | |
---|
285 | if(!taskInstance) { |
---|
286 | flash.message = "Task not found with id ${params.id}" |
---|
287 | redirect(action: 'search') |
---|
288 | } |
---|
289 | else { |
---|
290 | // Remember the current task id for use with navigation. |
---|
291 | session.currentTaskId = params.id |
---|
292 | |
---|
293 | params.max = 10 |
---|
294 | params.order = "desc" |
---|
295 | params.sort = "id" |
---|
296 | |
---|
297 | def entryFaultList = Entry.withCriteria { |
---|
298 | eq("entryType", EntryType.get(1)) |
---|
299 | eq("task", taskInstance) |
---|
300 | } |
---|
301 | |
---|
302 | def entryCauseList = Entry.withCriteria { |
---|
303 | eq("entryType", EntryType.get(2)) |
---|
304 | eq("task", taskInstance) |
---|
305 | } |
---|
306 | |
---|
307 | def entryWorkDoneList = Entry.withCriteria { |
---|
308 | eq("entryType", EntryType.get(3)) |
---|
309 | eq("task", taskInstance) |
---|
310 | } |
---|
311 | |
---|
312 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
---|
313 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
---|
314 | |
---|
315 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
316 | |
---|
317 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
318 | |
---|
319 | def assignedGroupList = taskInstance.assignedGroups.sort { p1, p2 -> p1.personGroup.name.compareToIgnoreCase(p2.personGroup.name) } |
---|
320 | def assignedPersonList = taskInstance.assignedPersons.sort { p1, p2 -> p1.person.firstName.compareToIgnoreCase(p2.person.firstName) } |
---|
321 | |
---|
322 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
323 | def taskProcedureExits = new Boolean("true") |
---|
324 | if(!taskProcedureInstance) { |
---|
325 | taskProcedureExits = false |
---|
326 | } |
---|
327 | |
---|
328 | params.order = "asc" |
---|
329 | params.sort = "procedureStepNumber" |
---|
330 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
331 | |
---|
332 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
333 | def taskRecurringScheduleExits= new Boolean("true") |
---|
334 | if(!taskRecurringScheduleInstance) { |
---|
335 | taskRecurringScheduleExits = false |
---|
336 | } |
---|
337 | |
---|
338 | return [ taskInstance: taskInstance, |
---|
339 | entryFaultList: entryFaultList, |
---|
340 | entryCauseList: entryCauseList, |
---|
341 | entryWorkDoneList: entryWorkDoneList, |
---|
342 | taskProcedureInstance: taskProcedureInstance, |
---|
343 | taskProcedureExits: taskProcedureExits, |
---|
344 | showTab: showTab, |
---|
345 | subTaskInstanceList: subTaskInstanceList, |
---|
346 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
347 | subTaskInstanceMax: params.max, |
---|
348 | maintenanceActionList: maintenanceActionList, |
---|
349 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
350 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
351 | inventoryMovementList: inventoryMovementList, |
---|
352 | taskModificationList: taskModificationList, |
---|
353 | assignedGroupList: assignedGroupList, |
---|
354 | assignedPersonList: assignedPersonList] |
---|
355 | } |
---|
356 | } |
---|
357 | |
---|
358 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
359 | def restore = { |
---|
360 | |
---|
361 | def result = taskService.restore(params) |
---|
362 | |
---|
363 | if(!result.error) { |
---|
364 | flash.message = "Task ${params.id} has been restored." |
---|
365 | redirect(action: show, id: params.id) |
---|
366 | return |
---|
367 | } |
---|
368 | |
---|
369 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
370 | |
---|
371 | if(result.taskInstance) |
---|
372 | redirect(action: show, id: params.id) |
---|
373 | else |
---|
374 | redirect(action: 'search') |
---|
375 | |
---|
376 | } |
---|
377 | |
---|
378 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
379 | def trash = { |
---|
380 | |
---|
381 | def result = taskService.trash(params) |
---|
382 | |
---|
383 | if(!result.error) { |
---|
384 | flash.message = "Task ${params.id} has been moved to trash." |
---|
385 | redirect(action: 'search') |
---|
386 | return |
---|
387 | } |
---|
388 | |
---|
389 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
390 | |
---|
391 | if(result.taskInstance) |
---|
392 | redirect(action: show, id: params.id) |
---|
393 | else |
---|
394 | redirect(action: 'search') |
---|
395 | |
---|
396 | } |
---|
397 | |
---|
398 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
399 | def approve = { |
---|
400 | |
---|
401 | def result = taskService.approve(params) |
---|
402 | |
---|
403 | if(!result.error) { |
---|
404 | flash.message = "Task ${params.id} has been approved." |
---|
405 | redirect(action: show, id: params.id) |
---|
406 | return |
---|
407 | } |
---|
408 | |
---|
409 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
410 | |
---|
411 | if(result.taskInstance) |
---|
412 | redirect(action: show, id: params.id) |
---|
413 | else |
---|
414 | redirect(action: 'search') |
---|
415 | |
---|
416 | } |
---|
417 | |
---|
418 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
419 | def renegeApproval = { |
---|
420 | |
---|
421 | def result = taskService.renegeApproval(params) |
---|
422 | |
---|
423 | if(!result.error) { |
---|
424 | flash.message = "Task ${params.id} has had approval removed." |
---|
425 | redirect(action: show, id: params.id) |
---|
426 | return |
---|
427 | } |
---|
428 | |
---|
429 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
430 | |
---|
431 | if(result.taskInstance) |
---|
432 | redirect(action: show, id: params.id) |
---|
433 | else |
---|
434 | redirect(action: 'search') |
---|
435 | |
---|
436 | } |
---|
437 | |
---|
438 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
439 | def complete = { |
---|
440 | |
---|
441 | def result = taskService.complete(params) |
---|
442 | |
---|
443 | if(!result.error) { |
---|
444 | flash.message = "Task ${params.id} has been completed." |
---|
445 | redirect(action: show, id: params.id) |
---|
446 | return |
---|
447 | } |
---|
448 | |
---|
449 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
450 | |
---|
451 | if(result.taskInstance) |
---|
452 | redirect(action: show, id: params.id) |
---|
453 | else |
---|
454 | redirect(action: 'search') |
---|
455 | |
---|
456 | } |
---|
457 | |
---|
458 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
459 | def setAttentionFlag = { |
---|
460 | |
---|
461 | def result = taskService.setAttentionFlag(params) |
---|
462 | |
---|
463 | if(!result.error) { |
---|
464 | flash.message = "Task ${params.id} has been flagged for attention." |
---|
465 | redirect(action: show, id: params.id) |
---|
466 | return |
---|
467 | } |
---|
468 | |
---|
469 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
470 | |
---|
471 | if(result.taskInstance) |
---|
472 | redirect(action: show, id: params.id) |
---|
473 | else |
---|
474 | redirect(action: 'search') |
---|
475 | |
---|
476 | } |
---|
477 | |
---|
478 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
479 | def clearAttentionFlag = { |
---|
480 | |
---|
481 | def result = taskService.clearAttentionFlag(params) |
---|
482 | |
---|
483 | if(!result.error) { |
---|
484 | flash.message = "Task ${params.id} attention flag cleared." |
---|
485 | redirect(action: show, id: params.id) |
---|
486 | return |
---|
487 | } |
---|
488 | |
---|
489 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
490 | |
---|
491 | if(result.taskInstance) |
---|
492 | redirect(action: show, id: params.id) |
---|
493 | else |
---|
494 | redirect(action: 'search') |
---|
495 | |
---|
496 | } |
---|
497 | |
---|
498 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
499 | def reopen = { |
---|
500 | |
---|
501 | def result = taskService.reopen(params) |
---|
502 | |
---|
503 | if(!result.error) { |
---|
504 | flash.message = "Task ${params.id} has been reopened." |
---|
505 | redirect(action: show, id: params.id) |
---|
506 | return |
---|
507 | } |
---|
508 | |
---|
509 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
510 | |
---|
511 | if(result.taskInstance) |
---|
512 | redirect(action: show, id: params.id) |
---|
513 | else |
---|
514 | redirect(action: 'search') |
---|
515 | |
---|
516 | } |
---|
517 | |
---|
518 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
519 | def edit = { |
---|
520 | |
---|
521 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
522 | if(params._action_Edit) |
---|
523 | params.action='edit' |
---|
524 | |
---|
525 | // Used by navigation. |
---|
526 | if(params.id == 'nav') { |
---|
527 | params.id = session.currentTaskId ?: null |
---|
528 | redirect(action: edit, id: params.id) |
---|
529 | return |
---|
530 | } |
---|
531 | |
---|
532 | def taskInstance = Task.get( params.id ) |
---|
533 | |
---|
534 | if(!taskInstance) { |
---|
535 | flash.message = "Task not found with id ${params.id}" |
---|
536 | redirect(action: 'search') |
---|
537 | } |
---|
538 | else { |
---|
539 | // Remember the current task id for use with navigation. |
---|
540 | session.currentTaskId = params.id |
---|
541 | |
---|
542 | if(taskInstance.trash) { |
---|
543 | flash.message = "You may not edit tasks that are in the trash." |
---|
544 | redirect(action: 'show', id: taskInstance.id) |
---|
545 | return |
---|
546 | } |
---|
547 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
548 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
549 | return [ taskInstance : taskInstance ] |
---|
550 | } |
---|
551 | } |
---|
552 | |
---|
553 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
554 | def update = { |
---|
555 | |
---|
556 | def result = taskService.update(params) |
---|
557 | |
---|
558 | if(!result.error) { |
---|
559 | flash.message = "Task ${params.id} updated" |
---|
560 | redirect(action: show, id: params.id) |
---|
561 | return |
---|
562 | } |
---|
563 | |
---|
564 | if(result.error.code == "task.modifications.failedToSave") |
---|
565 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
566 | |
---|
567 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
---|
568 | |
---|
569 | } |
---|
570 | |
---|
571 | /** |
---|
572 | * The create action is used to create scheduled types of tasks. |
---|
573 | */ |
---|
574 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
575 | def create = { |
---|
576 | def taskInstance = new Task() |
---|
577 | |
---|
578 | // Set the targetStartDate if specified, used by searchCalendar view. |
---|
579 | if(params.year && params.month && params.day) { |
---|
580 | def date = dateUtilService.makeDate(params.year, params.month, params.day) |
---|
581 | taskInstance.targetStartDate = date |
---|
582 | taskInstance.targetCompletionDate = date |
---|
583 | } |
---|
584 | |
---|
585 | // Default leadPerson to current user, unless supplied in params. |
---|
586 | taskInstance.leadPerson = authService.currentUser |
---|
587 | taskInstance.properties = params |
---|
588 | |
---|
589 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
590 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
591 | taskInstance.taskPriority = scheduledTaskPriorities.default |
---|
592 | return ['taskInstance': taskInstance, |
---|
593 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
594 | 'scheduledTaskPriorities': scheduledTaskPriorities.list] |
---|
595 | } |
---|
596 | |
---|
597 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
598 | def save = { |
---|
599 | def result = taskService.save(params) |
---|
600 | |
---|
601 | if(!result.error) { |
---|
602 | flash.message = "Task ${result.taskInstance.id} created." |
---|
603 | redirect(action: 'show', id: result.taskInstance.id) |
---|
604 | return |
---|
605 | } |
---|
606 | |
---|
607 | if(result.error.code == "task.modifications.failedToSave") |
---|
608 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
609 | |
---|
610 | |
---|
611 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
612 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
613 | render(view:'create', model:[taskInstance:result.taskInstance, |
---|
614 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
615 | 'scheduledTaskPriorities': scheduledTaskPriorities.list]) |
---|
616 | } |
---|
617 | |
---|
618 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
619 | def listSubTasks = { |
---|
620 | def parentTaskInstance = Task.get(params.id) |
---|
621 | |
---|
622 | if(!parentTaskInstance) { |
---|
623 | flash.message = "Task not found with id ${params.id}" |
---|
624 | redirect(action: 'search') |
---|
625 | } |
---|
626 | else { |
---|
627 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
628 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
629 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
630 | |
---|
631 | [ taskInstanceList: subTaskInstanceList, |
---|
632 | taskInstanceTotal: subTaskInstanceTotal, |
---|
633 | parentTaskInstance: parentTaskInstance] |
---|
634 | } |
---|
635 | } |
---|
636 | |
---|
637 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
638 | def createSubTask = { |
---|
639 | def parentTaskInstance = Task.get(params.id) |
---|
640 | |
---|
641 | if(parentTaskInstance) { |
---|
642 | |
---|
643 | def result = taskService.createSubTask(parentTaskInstance) |
---|
644 | if(!result.error) { |
---|
645 | flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements." |
---|
646 | redirect(action: 'edit', id: result.taskInstance.id) |
---|
647 | } |
---|
648 | else { |
---|
649 | if(result.taskInstance.errors.hasFieldErrors("parentTask")) { |
---|
650 | flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
651 | redirect(action: 'show', id: parentTaskInstance.id) |
---|
652 | } |
---|
653 | else { |
---|
654 | render(view: 'create', model:[taskInstance: result.taskInstance]) |
---|
655 | } |
---|
656 | } |
---|
657 | } |
---|
658 | |
---|
659 | else { |
---|
660 | flash.message = "Task not found with id ${params.id}" |
---|
661 | redirect(action: 'search') |
---|
662 | } |
---|
663 | } |
---|
664 | |
---|
665 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
666 | def createUnscheduled = { |
---|
667 | def taskInstance = new Task() |
---|
668 | |
---|
669 | // Default leadPerson to current user, unless supplied in params. |
---|
670 | taskInstance.leadPerson = authService.currentUser |
---|
671 | taskInstance.properties = params |
---|
672 | |
---|
673 | // Always for Unscheduled task. |
---|
674 | taskInstance.taskType = TaskType.get(2) // Unscheduled Breakin. |
---|
675 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
676 | taskInstance.taskPriority = unscheduledTaskPriorities.default |
---|
677 | |
---|
678 | return ['taskInstance': taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list] |
---|
679 | } |
---|
680 | |
---|
681 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
682 | def saveUnscheduled = { |
---|
683 | def result = taskService.saveUnscheduled(params) |
---|
684 | |
---|
685 | if(!result.error) { |
---|
686 | flash.message = "Task ${result.taskInstance.id} created." |
---|
687 | redirect(action: 'show', id: result.taskInstance.id) |
---|
688 | return |
---|
689 | } |
---|
690 | |
---|
691 | if(result.error.code == "task.modifications.failedToSave") |
---|
692 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
693 | |
---|
694 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
695 | |
---|
696 | render(view:'createUnscheduled', |
---|
697 | model: ['taskInstance': result.taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list]) |
---|
698 | } |
---|
699 | |
---|
700 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
701 | def createImmediateCallout = { |
---|
702 | def taskInstance = new Task() |
---|
703 | |
---|
704 | def entryFaultInstance = new Entry(entryType: EntryType.get(1)) // Fault. |
---|
705 | def entryCauseInstance = new Entry(entryType: EntryType.get(2)) // Cause. |
---|
706 | def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3)) // Work Done. |
---|
707 | |
---|
708 | return ['taskInstance': taskInstance, |
---|
709 | 'entryFaultInstance': entryFaultInstance, |
---|
710 | 'entryCauseInstance': entryCauseInstance, |
---|
711 | 'entryWorkDoneInstance': entryWorkDoneInstance] |
---|
712 | } |
---|
713 | |
---|
714 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
715 | def saveImmediateCallout = { |
---|
716 | def result = taskService.saveImmediateCallout(params) |
---|
717 | |
---|
718 | if(!result.error) { |
---|
719 | flash.message = "Task ${result.taskInstance.id} created." |
---|
720 | redirect(action: 'show', id: result.taskInstance.id) |
---|
721 | return |
---|
722 | } |
---|
723 | |
---|
724 | if(result.error.code == "task.modifications.failedToSave") |
---|
725 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
726 | |
---|
727 | render(view:'createImmediateCallout', |
---|
728 | model: ['taskInstance': result.taskInstance, |
---|
729 | 'entryFaultInstance': result.entryFaultInstance, |
---|
730 | 'entryCauseInstance': result.entryCauseInstance, |
---|
731 | 'entryWorkDoneInstance': result.entryWorkDoneInstance]) |
---|
732 | |
---|
733 | } |
---|
734 | |
---|
735 | /** |
---|
736 | * Get some integers for use by the month control links. |
---|
737 | */ |
---|
738 | private getCalendarMonthControls(Date showDate) { |
---|
739 | def result = [:] |
---|
740 | result.today = [:] |
---|
741 | result.today.date = new Date() |
---|
742 | result.today.month = dateUtilService.getMonthFromDate(result.today.date) |
---|
743 | result.today.year = dateUtilService.getYearFromDate(result.today.date) |
---|
744 | result.nextMonth = [:] |
---|
745 | result.nextMonth.date = dateUtilService.getNextMonth(showDate) |
---|
746 | result.nextMonth.month = dateUtilService.getMonthFromDate(result.nextMonth.date) |
---|
747 | result.nextMonth.year = dateUtilService.getYearFromDate(result.nextMonth.date) |
---|
748 | result.previousMonth = [:] |
---|
749 | result.previousMonth.date = dateUtilService.getPreviousMonth(showDate) |
---|
750 | result.previousMonth.month = dateUtilService.getMonthFromDate(result.previousMonth.date) |
---|
751 | result.previousMonth.year = dateUtilService.getYearFromDate(result.previousMonth.date) |
---|
752 | result.nextYear = [:] |
---|
753 | result.nextYear.date = dateUtilService.getNextYear(showDate) |
---|
754 | result.nextYear.month = dateUtilService.getMonthFromDate(result.nextYear.date) |
---|
755 | result.nextYear.year = dateUtilService.getYearFromDate(result.nextYear.date) |
---|
756 | result.previousYear = [:] |
---|
757 | result.previousYear.date = dateUtilService.getPreviousYear(showDate) |
---|
758 | result.previousYear.month = dateUtilService.getMonthFromDate(result.previousYear.date) |
---|
759 | result.previousYear.year = dateUtilService.getYearFromDate(result.previousYear.date) |
---|
760 | return result |
---|
761 | } |
---|
762 | |
---|
763 | } // end of class. |
---|