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