source: trunk/grails-app/controllers/TaskDetailedController.groovy @ 922

Last change on this file since 922 was 922, checked in by gav, 13 years ago

Fix Java-1.5.0 NPE on WorkLoad? view.

File size: 40.7 KB
RevLine 
[69]1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
[165]2import org.codehaus.groovy.grails.commons.ConfigurationHolder
[209]3import com.zeddware.grails.plugins.filterpane.FilterUtils
[476]4import org.springframework.web.servlet.support.RequestContextUtils as RCU
[69]5
[298]6@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager'])
[85]7class TaskDetailedController extends BaseController {
[66]8
[291]9    def authService
[180]10    def taskService
[143]11    def taskSearchService
[585]12    def taskReportService
[140]13    def filterService
[165]14    def exportService
[214]15    def dateUtilService
[139]16
[181]17    // these actions only accept POST requests
[418]18    static allowedMethods = [save:'POST',update:'POST',restore:'POST', trash:'POST',
19                                                approve:'POST', renegeApproval:'POST', complete:'POST',
20                                                reopen:'POST', setAttentionFlag:'POST', clearAttentionFlag:'POST']
[66]21
[298]22    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[196]23    def index = { redirect(action: 'search', params: params) }
[140]24
[298]25    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[326]26    def setSearchParamsMax = {
[262]27        def max = 1000
[615]28        if(params.newMax?.isInteger()) {
[260]29            def i = params.newMax.toInteger()
[262]30            if(i > 0 && i <= max)
31                session.taskSearchParamsMax = params.newMax
32            if(i > max)
33                session.taskSearchParamsMax = max
34        }
[260]35        forward(action: 'search', params: params)
36    }
37
[298]38    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[476]39    def setSearchCalendarParamsMax = {
40        def max = 1000
[615]41        if(params.newMax?.isInteger()) {
[476]42            def i = params.newMax.toInteger()
43            if(i > 0 && i <= max)
44                session.taskSearchCalendarParamsMax = params.newMax
45            if(i > max)
46                session.taskSearchCalendarParamsMax = max
47        }
48        forward(action: 'searchCalendar', params: params)
49    }
50
[483]51    /**
52    * Search for tasks.
53    */
[476]54    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[139]55    def search = {
[143]56
[260]57        if(session.taskSearchParamsMax)
58            params.max = session.taskSearchParamsMax
59
[468]60        // Protect filterPane.
[525]61        params.max = Math.min( params.max ? params.max.toInteger() : 100,  1000 )
[260]62
[713]63        // View main data.
[260]64        def taskInstanceList = []
65        def taskInstanceTotal
[476]66        def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params)
67        def isFilterApplied = FilterUtils.isFilterApplied(params)
[260]68
[476]69        // Restore search unless a new search is being requested.
70        if(!params.quickSearch && !filterParams) {
[713]71            if(session.taskSearchFilterParams) {
[476]72                session.taskSearchFilterParams.each() { params[it.key] = it.value }
73                params.filter = session.taskSearchFilter
74                isFilterApplied = FilterUtils.isFilterApplied(params)
[144]75            }
[476]76        }
[713]77        if(!params.quickSearch) {
78            if(session.taskSearchQuickSearch) {
79                params.quickSearch = session.taskSearchQuickSearch
80                params.person = Person.get(session.taskQuickSearchPersonId.toLong())
81                params.startDate = session.taskQuickSearchStartDate
82                params.endDate = session.taskQuickSearchEndDate
83                params.includeCompleted = session.taskQuickSearchIncludeCompleted
84            }
85        }
[260]86
[486]87        // Remember sort if supplied, otherwise try to restore.
88        if(params.sort && params.order) {
[582]89            // Reset to defaultSort if requested.
90            if(params.sort == 'defaultSort') {
91                params.sort = null
92                params.order = null
93                session.removeAttribute("taskSearchSort")
94                session.removeAttribute("taskSearchOrder")
95            }
96            else {
97                session.taskSearchSort = params.sort
98                session.taskSearchOrder = params.order
99            }
[486]100        }
101        else if(session.taskSearchSort && session.taskSearchOrder) {
102            params.sort = session.taskSearchSort
103            params.order = session.taskSearchOrder
104        }
105
[476]106        if(isFilterApplied) {
[260]107            // filterPane:
[582]108            params.sort = params.sort ?: "id"
109            params.order = params.order ?: "desc"
[513]110            if(params.sort == "attentionFlag") // See ticket #64 in Trac.
111                params.sort = "id"
[516]112            // Prevent tasks in the trash being returned unless explicitly requested.
113            if(!params.filter.op.trash) {
114                params.filter.op.trash = "Equal"
115                params.filter.trash = "false"
116            }
117            // Call filterService.
[260]118            taskInstanceList = filterService.filter( params, Task )
119            taskInstanceTotal = filterService.count( params, Task )
120            filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params)
[476]121            // Remember search.
122            session.taskSearchFilterParams = new LinkedHashMap(filterParams)
123            session.taskSearchFilter = new LinkedHashMap(params.filter)
[260]124        }
[476]125        else {
126            // Quick Search:
127            def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request))
128            taskInstanceList = result.taskInstanceList
129            taskInstanceTotal = result.taskInstanceList.totalCount
130            params.message = result.message
[713]131            params.quickSearch = result.quickSearch
132            params.person = result.person
133            params.startDate = result.startDate
134            params.endDate = result.endDate
135            params.includeCompleted = result.includeCompleted
[476]136            // Remember search.
[488]137            session.removeAttribute("taskSearchFilterParams")
138            session.removeAttribute("taskSearchFilter")
[476]139            session.taskSearchQuickSearch = result.quickSearch
[713]140            session.taskQuickSearchPersonId = result.person.id
141            session.taskQuickSearchStartDate = result.startDate
142            session.taskQuickSearchEndDate = result.endDate
143            session.taskQuickSearchIncludeCompleted = result.includeCompleted
[476]144        }
[143]145
[260]146        // export plugin:
147        if(params?.format && params.format != "html") {
148
[913]149            def dateFmt = { domain, value ->
150                formatDate(format: "EEE, dd-MMM-yyyy", date: value)
[260]151            }
152
153            String title
154            if(params.quickSearch)
[476]155                title = params.message
[260]156            else
157                title = "Filtered tasks."
158
159            response.contentType = ConfigurationHolder.config.grails.mime.types[params.format]
[390]160            response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}")
[871]161            List fields = ["id", "targetStartDate", "primaryAsset", "description", "taskPriority", "taskType", "taskStatus"]
162            Map labels = ["id": "Task #", "targetStartDate": "Target Start Date", "primaryAsset": "Asset",
163                                    "description": "Description", "taskPriority": "Task Priority",
[475]164                                    "taskType": "Task Type", "taskStatus": "Task Status"]
[260]165            Map formatters = [ targetStartDate: dateFmt]
166            Map parameters = [title: title, separator: ","]
167
168            exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters)
169        }
170
171        // Add some basic params to filterParams.
172        filterParams.max = params.max
173        filterParams.offset = params.offset?.toInteger() ?: 0
[582]174        filterParams.sort = params.sort ?: "id"
[260]175        filterParams.order = params.order ?: "desc"
176
[552]177        // Get some associatedProperty values for filterpane.
178        def associatedPropertyValues = [:]
179        def associatedPropertyMax = 10000
[840]180        def taskPriorityNameQuery = 'select distinct tp.name from TaskPriority tp where tp.isActive = ? order by tp.name'
181        associatedPropertyValues.taskPriorityList = TaskPriority.executeQuery(taskPriorityNameQuery, [true], [max:associatedPropertyMax])
[552]182        def lastNameQuery = 'select distinct p.lastName from Person p where p.isActive = ? order by p.lastName'
183        associatedPropertyValues.lastNameList = Person.executeQuery(lastNameQuery, [true], [max:associatedPropertyMax])
184        def firstNameQuery = 'select distinct p.firstName from Person p where p.isActive = ? order by p.firstName'
185        associatedPropertyValues.firstNameList = Person.executeQuery(firstNameQuery, [true], [max:associatedPropertyMax])
[840]186        def taskGroupNameQuery = 'select distinct tg.name from TaskGroup tg where tg.isActive = ? order by tg.name'
187        associatedPropertyValues.taskGroupList = TaskGroup.executeQuery(taskGroupNameQuery, [true], [max:associatedPropertyMax])
188        def assetNameQuery = 'select distinct a.name from Asset a where a.isActive = ? order by a.name'
189        associatedPropertyValues.assetList = Asset.executeQuery(assetNameQuery, [true], [max:associatedPropertyMax])
[838]190        def highestSeverityCodeQuery = 'select distinct cs.code from ConditionSeverity cs where cs.isActive = ? order by cs.code'
191        associatedPropertyValues.highestSeverityList = ConditionSeverity.executeQuery(highestSeverityCodeQuery, [true], [max:associatedPropertyMax])
[840]192        def taskStatusNameQuery = 'select a.name from TaskStatus a where a.isActive = ? order by a.id'
193        associatedPropertyValues.taskStatusList = TaskStatus.executeQuery(taskStatusNameQuery, [true], [max:associatedPropertyMax])
194        def taskTypeNameQuery = 'select a.name from TaskType a where a.isActive = ? order by a.name'
195        associatedPropertyValues.taskTypeList = TaskType.executeQuery(taskTypeNameQuery, [true], [max:associatedPropertyMax])
[552]196        def startOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), -10))
197        def endOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), 10))
198        associatedPropertyValues.yearRange = startOfYearRange..endOfYearRange
199
[260]200        return[ taskInstanceList: taskInstanceList,
[476]201                        taskInstanceTotal: taskInstanceTotal,
202                        filterParams: filterParams,
[552]203                        params: params,
[713]204                        associatedPropertyValues: associatedPropertyValues,
205                        quickSearchSelection: taskSearchService.quickSearchSelection]
[260]206
[476]207    } // search
[260]208
[298]209    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[155]210    def searchCalendar = {
[140]211
[476]212        // No pagination for calendar.
213        params.offset = 0
[474]214
[476]215        // Restore params.max
216        if(session.taskSearchCalendarParamsMax)
217            params.max = session.taskSearchCalendarParamsMax
218
[474]219        // Protect filterPane.
[476]220        params.max = Math.min( params.max ? params.max.toInteger() : 100,  1000 )
[474]221
[585]222        def displayList = []
[476]223        def taskInstanceList = []
224        def taskInstanceTotal
225        def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params)
226        def isFilterApplied = FilterUtils.isFilterApplied(params)
[474]227
[476]228        // Restore search unless a new search is being requested.
229        if(!params.quickSearch && !filterParams) {
[713]230            if(session.taskSearchCalendarFilterParams) {
[476]231                session.taskSearchCalendarFilterParams.each() { params[it.key] = it.value }
232                params.filter = session.taskSearchCalendarFilter
233                isFilterApplied = FilterUtils.isFilterApplied(params)
234            }
235        }
[713]236        if(!params.quickSearch) {
237            if(session.taskSearchCalendarQuickSearch) {
238                params.quickSearch = session.taskSearchCalendarQuickSearch
239                params.person = Person.get(session.taskCalendarQuickSearchPersonId.toLong())
240                params.startDate = session.taskCalendarQuickSearchStartDate
241                params.endDate = session.taskCalendarQuickSearchEndDate
242                params.includeCompleted = session.taskCalendarQuickSearchIncludeCompleted
243            }
244        }
[474]245
[476]246        // The date the calendar will use to determine the month to show.
247        // Use session, if not specified in params, otherwise use today.
248        def showDate = new Date()
249        if(params.showMonth) {
250            if(params.showYear)
251                showDate = dateUtilService.makeDate(params.showYear, params.showMonth)
252            else
253                showDate = dateUtilService.makeDate(dateUtilService.getYearFromDate(showDate), params.showMonth)
254            // Remember the showDate.
255            session.taskSearchCalendarShowDate = showDate
256        }
257        else if(session.taskSearchCalendarShowDate)
258            showDate = session.taskSearchCalendarShowDate
[155]259
[476]260        // Get the dates for the calendar month controls.
261        def calendarMonthControls = getCalendarMonthControls(showDate)
262
263        if(isFilterApplied) {
264            // filterPane:
[589]265            params.sort = params.sort ?: "id"
266            params.order = params.order ?: "desc"
[516]267            if(params.sort == "attentionFlag") // See ticket #64 in Trac.
268                params.sort = "id"
269            // Prevent tasks in the trash being returned unless explicitly requested.
270            if(!params.filter.op.trash) {
271                params.filter.op.trash = "Equal"
272                params.filter.trash = "false"
273            }
274            // Call filterService.
[476]275            taskInstanceList = filterService.filter( params, Task )
276            taskInstanceTotal = filterService.count( params, Task )
277            filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params)
278            // Remember search.
279            session.taskSearchCalendarFilterParams = new LinkedHashMap(filterParams)
280            session.taskSearchCalendarFilter = new LinkedHashMap(params.filter)
[139]281        }
[476]282        else {
283            // Quick Search:
284            def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request))
285            taskInstanceList = result.taskInstanceList
286            taskInstanceTotal = result.taskInstanceList.totalCount
287            params.message = result.message
[713]288            params.quickSearch = result.quickSearch
289            params.person = result.person
290            params.startDate = result.startDate
291            params.endDate = result.endDate
292            params.includeCompleted = result.includeCompleted
[476]293            // Remember search.
[488]294            session.removeAttribute("taskSearchCalendarFilterParams")
295            session.removeAttribute("taskSearchCalendarFilter")
[476]296            session.taskSearchCalendarQuickSearch = result.quickSearch
[713]297            session.taskCalendarQuickSearchPersonId = result.person.id
298            session.taskCalendarQuickSearchStartDate = result.startDate
299            session.taskCalendarQuickSearchEndDate = result.endDate
300            session.taskCalendarQuickSearchIncludeCompleted = result.includeCompleted
[476]301        }
[140]302
[588]303//         displayList = taskReportService.getWorkLoadSummary(
304//                                     [taskInstanceList: taskInstanceList], RCU.getLocale(request)
305//                                 ).displayList
[585]306
[476]307        // export plugin:
308        if(params?.format && params.format != "html") {
[165]309
[913]310            def dateFmt = { domain, value ->
311                formatDate(format: "EEE, dd-MMM-yyyy", date: value)
[165]312            }
[260]313
[476]314            String title
315            if(params.quickSearch)
316                title = params.message
317            else
318                title = "Filtered tasks."
[165]319
[476]320            response.contentType = ConfigurationHolder.config.grails.mime.types[params.format]
321            response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}")
[871]322            List fields = ["id", "targetStartDate", "primaryAsset", "description", "taskPriority", "taskType", "taskStatus"]
323            Map labels = ["id": "Task #", "targetStartDate": "Target Start Date", "primaryAsset": "Asset",
324                                    "description": "Description", "taskPriority": "Task Priority",
[476]325                                    "taskType": "Task Type", "taskStatus": "Task Status"]
326            Map formatters = [ targetStartDate: dateFmt]
327            Map parameters = [title: title, separator: ","]
328
329            exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters)
[165]330        }
331
[588]332        if(taskInstanceTotal > params.max)
333            params.errorMessage = g.message(code:"task.search.calendar.text.too.many.results", args:[params.max])
[476]334
335        // Add some basic params to filterParams.
336        filterParams.max = params.max
337        filterParams.offset = params.offset?.toInteger() ?: 0
[589]338        filterParams.sort = params.sort ?: "id"
339        filterParams.order = params.order ?: "desc"
[476]340
[589]341        // Get some associatedProperty values for filterpane.
342        def associatedPropertyValues = [:]
343        def associatedPropertyMax = 10000
[840]344        def taskPriorityNameQuery = 'select distinct tp.name from TaskPriority tp where tp.isActive = ? order by tp.name'
345        associatedPropertyValues.taskPriorityList = TaskPriority.executeQuery(taskPriorityNameQuery, [true], [max:associatedPropertyMax])
[589]346        def lastNameQuery = 'select distinct p.lastName from Person p where p.isActive = ? order by p.lastName'
347        associatedPropertyValues.lastNameList = Person.executeQuery(lastNameQuery, [true], [max:associatedPropertyMax])
348        def firstNameQuery = 'select distinct p.firstName from Person p where p.isActive = ? order by p.firstName'
349        associatedPropertyValues.firstNameList = Person.executeQuery(firstNameQuery, [true], [max:associatedPropertyMax])
[840]350        def taskGroupNameQuery = 'select distinct tg.name from TaskGroup tg where tg.isActive = ? order by tg.name'
351        associatedPropertyValues.taskGroupList = TaskGroup.executeQuery(taskGroupNameQuery, [true], [max:associatedPropertyMax])
352        def assetNameQuery = 'select distinct a.name from Asset a where a.isActive = ? order by a.name'
353        associatedPropertyValues.assetList = Asset.executeQuery(assetNameQuery, [true], [max:associatedPropertyMax])
[838]354        def highestSeverityCodeQuery = 'select distinct cs.code from ConditionSeverity cs where cs.isActive = ? order by cs.code'
355        associatedPropertyValues.highestSeverityList = ConditionSeverity.executeQuery(highestSeverityCodeQuery, [true], [max:associatedPropertyMax])
[840]356        def taskStatusNameQuery = 'select a.name from TaskStatus a where a.isActive = ? order by a.id'
357        associatedPropertyValues.taskStatusList = TaskStatus.executeQuery(taskStatusNameQuery, [true], [max:associatedPropertyMax])
358        def taskTypeNameQuery = 'select a.name from TaskType a where a.isActive = ? order by a.name'
359        associatedPropertyValues.taskTypeList = TaskType.executeQuery(taskTypeNameQuery, [true], [max:associatedPropertyMax])
[589]360        def startOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), -10))
361        def endOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), 10))
362        associatedPropertyValues.yearRange = startOfYearRange..endOfYearRange
363
[588]364        return[taskInstanceList: taskInstanceList,
[476]365                        taskInstanceTotal: taskInstanceTotal,
366                        filterParams: filterParams,
367                        params: params,
[589]368                        associatedPropertyValues: associatedPropertyValues,
[476]369                        showDate: showDate,
370                        today: calendarMonthControls.today,
371                        previousMonth: calendarMonthControls.previousMonth,
372                        nextMonth: calendarMonthControls.nextMonth,
373                        previousYear: calendarMonthControls.previousYear,
[713]374                        nextYear: calendarMonthControls.nextYear,
375                        quickSearchSelection: taskSearchService.quickSearchSelection]
[476]376
377    } // searchCalendar
378
[298]379    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[66]380    def show = {
[147]381
[139]382        // In the case of an actionSubmit button, rewrite action name from 'index'.
383        if(params._action_Show)
[375]384            params.action='show'
[139]385
[433]386        // Used by navigation.
387        if(params.id == 'nav') {
388            params.id = session.currentTaskId ?: null
389            redirect(action: show, id: params.id)
390            return
391        }
392
[225]393        def showTab = [:]
394        switch (params.showTab) {
395            case "showProcedureTab":
396                showTab.procedure =  new String("true")
397                break
398            case "showRecurrenceTab":
399                showTab.recurrence =  new String("true")
400                break
401            case "showInventoryTab":
402                showTab.inventory = new String("true")
403                break
404            case "showSubTasksTab":
405                showTab.subTasks = new String("true")
406                break
407            default:
408                showTab.task = new String("true")
409        }
410
[66]411        def taskInstance = Task.get( params.id )
412
413        if(!taskInstance) {
414            flash.message = "Task not found with id ${params.id}"
[196]415            redirect(action: 'search')
[66]416        }
[133]417        else {
[433]418            // Remember the current task id for use with navigation.
419            session.currentTaskId = params.id
420
[179]421            params.max = 10
422            params.order = "desc"
423            params.sort = "id"
[134]424
[418]425            def entryFaultList = Entry.withCriteria {
426                                                                eq("entryType", EntryType.get(1))
427                                                                eq("task", taskInstance)
428                                                        }
429
430            def entryCauseList = Entry.withCriteria {
[190]431                                                                eq("entryType", EntryType.get(2))
[179]432                                                                eq("task", taskInstance)
433                                                        }
434
[418]435            def entryWorkDoneList = Entry.withCriteria {
436                                                                eq("entryType", EntryType.get(3))
[179]437                                                                eq("task", taskInstance)
438                                                        }
439
[833]440            def entryPMList = Entry.withCriteria {
441                                                                eq("entryType", EntryType.get(6))
442                                                                eq("task", taskInstance)
443                                                        }
444
[196]445            def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params)
446            def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false)
[134]447
[175]448            def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0])
449
[180]450            def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0])
451
[253]452            def assignedGroupList = taskInstance.assignedGroups.sort { p1, p2 -> p1.personGroup.name.compareToIgnoreCase(p2.personGroup.name) }
453            def assignedPersonList = taskInstance.assignedPersons.sort { p1, p2 -> p1.person.firstName.compareToIgnoreCase(p2.person.firstName) }
454
[809]455            def taskProcedureRevision = TaskProcedureRevision.get(taskInstance.taskProcedureRevision?.id)
[133]456            def taskProcedureExits = new Boolean("true")
[809]457            if(!taskProcedureRevision) {
[133]458                taskProcedureExits = false
459            }
[175]460
[134]461            def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id)
462            def taskRecurringScheduleExits= new Boolean("true")
[175]463            if(!taskRecurringScheduleInstance) {
[134]464                taskRecurringScheduleExits = false
465            }
[179]466
[137]467            return [ taskInstance: taskInstance,
[418]468                            entryFaultList: entryFaultList,
469                            entryCauseList: entryCauseList,
[179]470                            entryWorkDoneList: entryWorkDoneList,
[833]471                            entryPMList: entryPMList,
[809]472                            taskProcedureRevision: taskProcedureRevision,
[133]473                            taskProcedureExits: taskProcedureExits,
[225]474                            showTab: showTab,
[179]475                            subTaskInstanceList: subTaskInstanceList,
476                            subTaskInstanceTotal: subTaskInstanceTotal,
477                            subTaskInstanceMax: params.max,
478                            taskRecurringScheduleInstance: taskRecurringScheduleInstance,
479                            taskRecurringScheduleExits: taskRecurringScheduleExits,
[180]480                            inventoryMovementList: inventoryMovementList,
[253]481                            taskModificationList: taskModificationList,
482                            assignedGroupList: assignedGroupList,
483                            assignedPersonList: assignedPersonList]
[131]484        }
[66]485    }
486
[418]487    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[181]488    def restore = {
489
490        def result = taskService.restore(params)
491
492        if(!result.error) {
493                flash.message = "Task ${params.id} has been restored."
[418]494                redirect(action: show, id: params.id)
495                return
[181]496        }
497
[418]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
[181]505    }
506
[418]507    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[181]508    def trash = {
509
510        def result = taskService.trash(params)
511
512        if(!result.error) {
513                flash.message = "Task ${params.id} has been moved to trash."
[196]514                redirect(action: 'search')
[418]515                return
[181]516        }
517
[418]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
[66]525    }
526
[418]527    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager'])
[181]528    def approve = {
529
530        def result = taskService.approve(params)
531
532        if(!result.error) {
533                flash.message = "Task ${params.id} has been approved."
[418]534                redirect(action: show, id: params.id)
535                return
[181]536        }
537
[418]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
[181]545    }
546
[465]547    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager'])
[181]548    def renegeApproval = {
549
550        def result = taskService.renegeApproval(params)
551
552        if(!result.error) {
553                flash.message = "Task ${params.id} has had approval removed."
[418]554                redirect(action: show, id: params.id)
555                return
[181]556        }
557
[418]558        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
559
560        if(result.taskInstance)
561            redirect(action: show, id: params.id)
562        else
563            redirect(action: 'search')
564
[181]565    }
566
[298]567    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[181]568    def complete = {
569
570        def result = taskService.complete(params)
571
572        if(!result.error) {
573                flash.message = "Task ${params.id} has been completed."
[418]574                redirect(action: show, id: params.id)
575                return
[181]576        }
[418]577
578        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
579
580        if(result.taskInstance)
581            redirect(action: show, id: params.id)
582        else
583            redirect(action: 'search')
584
585    }
586
587    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
588    def setAttentionFlag = {
589
590        def result = taskService.setAttentionFlag(params)
591
592        if(!result.error) {
593                flash.message = "Task ${params.id} has been flagged for attention."
594                redirect(action: show, id: params.id)
595                return
[181]596        }
597
[418]598        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
599
600        if(result.taskInstance)
601            redirect(action: show, id: params.id)
602        else
603            redirect(action: 'search')
604
[181]605    }
606
[298]607    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[418]608    def clearAttentionFlag = {
[181]609
[418]610        def result = taskService.clearAttentionFlag(params)
611
612        if(!result.error) {
613                flash.message = "Task ${params.id} attention flag cleared."
614                redirect(action: show, id: params.id)
615                return
[181]616        }
617
[418]618        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
619
620        if(result.taskInstance)
621            redirect(action: show, id: params.id)
622        else
623            redirect(action: 'search')
624
625    }
626
627    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
628    def reopen = {
629
[181]630        def result = taskService.reopen(params)
631
632        if(!result.error) {
633                flash.message = "Task ${params.id} has been reopened."
[418]634                redirect(action: show, id: params.id)
635                return
[181]636        }
637
[418]638        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
639
640        if(result.taskInstance)
641            redirect(action: show, id: params.id)
642        else
643            redirect(action: 'search')
644
[181]645    }
646
[298]647    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[66]648    def edit = {
[147]649
[139]650        // In the case of an actionSubmit button, rewrite action name from 'index'.
651        if(params._action_Edit)
[375]652            params.action='edit'
[169]653
[433]654        // Used by navigation.
655        if(params.id == 'nav') {
656            params.id = session.currentTaskId ?: null
657            redirect(action: edit, id: params.id)
658            return
659        }
660
[66]661        def taskInstance = Task.get( params.id )
662
663        if(!taskInstance) {
664            flash.message = "Task not found with id ${params.id}"
[196]665            redirect(action: 'search')
[66]666        }
667        else {
[433]668            // Remember the current task id for use with navigation.
669            session.currentTaskId = params.id
670
[181]671            if(taskInstance.trash) {
[196]672                flash.message = "You may not edit tasks that are in the trash."
673                redirect(action: 'show', id: taskInstance.id)
674                return
[181]675            }
[246]676//             def possibleParentList = taskService.possibleParentList(taskInstance)
677//             return [ taskInstance : taskInstance, possibleParentList: possibleParentList ]
678            return [ taskInstance : taskInstance ]
[84]679        }
680    }
681
[298]682    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[66]683    def update = {
[179]684
[180]685        def result = taskService.update(params)
686
687        if(!result.error) {
[66]688                flash.message = "Task ${params.id} updated"
[418]689                redirect(action: show, id: params.id)
690                return
[180]691        }
692
[418]693        if(result.error.code == "task.modifications.failedToSave")
694            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
695
696        render(view:'edit',model:[taskInstance:result.taskInstance.attach()])
697
[66]698    }
699
[473]700    /**
701    * The create action is used to create scheduled types of tasks.
702    */
703    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager'])
[66]704    def create = {
705        def taskInstance = new Task()
[214]706
707        // Set the targetStartDate if specified, used by searchCalendar view.
[476]708        if(params.year && params.month && params.day) {
709            def date = dateUtilService.makeDate(params.year, params.month, params.day)
710            taskInstance.targetStartDate = date
711            taskInstance.targetCompletionDate = date
712        }
[214]713
[196]714        // Default leadPerson to current user, unless supplied in params.
[291]715        taskInstance.leadPerson = authService.currentUser
[487]716
717        // Apply params, overiding anything above.
[66]718        taskInstance.properties = params
[433]719
720        def scheduledTaskTypes = taskService.scheduledTaskTypes
721        def scheduledTaskPriorities = taskService.scheduledTaskPriorities
722        taskInstance.taskPriority = scheduledTaskPriorities.default
723        return ['taskInstance': taskInstance,
724                    'scheduledTaskTypes': scheduledTaskTypes,
725                    'scheduledTaskPriorities': scheduledTaskPriorities.list]
[66]726    }
727
[298]728    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[66]729    def save = {
[394]730        def result = taskService.save(params)
[180]731
732        if(!result.error) {
733            flash.message = "Task ${result.taskInstance.id} created."
[196]734            redirect(action: 'show', id: result.taskInstance.id)
[418]735            return
[66]736        }
[180]737
[418]738        if(result.error.code == "task.modifications.failedToSave")
739            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
740
[433]741
742        def scheduledTaskTypes = taskService.scheduledTaskTypes
743        def scheduledTaskPriorities = taskService.scheduledTaskPriorities
744        render(view:'create', model:[taskInstance:result.taskInstance,
745                                                    'scheduledTaskTypes': scheduledTaskTypes,
746                                                    'scheduledTaskPriorities': scheduledTaskPriorities.list])
[66]747    }
[179]748
[298]749    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[179]750    def listSubTasks = {
751        def parentTaskInstance = Task.get(params.id)
752
[134]753        if(!parentTaskInstance) {
754            flash.message = "Task not found with id ${params.id}"
[196]755            redirect(action: 'search')
[133]756        }
757        else {
[630]758        params.max = Math.min( params.max ? params.max.toInteger() : 200,  200)
[869]759        def filterParams = [:]
[196]760        def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params)
761        def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false)
[179]762
[134]763        [ taskInstanceList: subTaskInstanceList,
[179]764            taskInstanceTotal:  subTaskInstanceTotal,
[869]765            parentTaskInstance: parentTaskInstance,
766            filterParams: filterParams]
[179]767        }
768    }
769
[298]770    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[196]771    def createSubTask = {
772        def parentTaskInstance = Task.get(params.id)
773
774        if(parentTaskInstance) {
775
776            def result = taskService.createSubTask(parentTaskInstance)
777            if(!result.error) {
778                flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements."
779                redirect(action: 'edit', id: result.taskInstance.id)
780            }
781            else {
782                if(result.taskInstance.errors.hasFieldErrors("parentTask")) {
[418]783                    flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash")
[196]784                    redirect(action: 'show', id:  parentTaskInstance.id)
785                }
786                else {
787                    render(view: 'create', model:[taskInstance: result.taskInstance])
788                }
789            }
790        }
791
792        else {
793            flash.message = "Task not found with id ${params.id}"
794            redirect(action: 'search')
795        }
796    }
797
[395]798    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[433]799    def createUnscheduled = {
800        def taskInstance = new Task()
801
802        // Default leadPerson to current user, unless supplied in params.
803        taskInstance.leadPerson = authService.currentUser
804        taskInstance.properties = params
805
806        // Always for Unscheduled task.
807        taskInstance.taskType = TaskType.get(2) // Unscheduled Breakin.
808        def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities
809        taskInstance.taskPriority = unscheduledTaskPriorities.default
810
811        return ['taskInstance': taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list]
812    }
813
814    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
815    def saveUnscheduled = {
816        def result = taskService.saveUnscheduled(params)
817
818        if(!result.error) {
819            flash.message = "Task ${result.taskInstance.id} created."
820            redirect(action: 'show', id: result.taskInstance.id)
821            return
822        }
823
824        if(result.error.code == "task.modifications.failedToSave")
825            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
826
827        def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities
828
829        render(view:'createUnscheduled',
830                    model: ['taskInstance': result.taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list])
831    }
832
833    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[418]834    def createImmediateCallout = {
[395]835        def taskInstance = new Task()
836
837        def entryFaultInstance = new Entry(entryType: EntryType.get(1))  // Fault.
[418]838        def entryCauseInstance = new Entry(entryType: EntryType.get(2))  // Cause.
839        def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3))  // Work Done.
[395]840
841        return ['taskInstance': taskInstance,
842                        'entryFaultInstance': entryFaultInstance,
[418]843                        'entryCauseInstance': entryCauseInstance,
[395]844                        'entryWorkDoneInstance': entryWorkDoneInstance]
845    }
846
847    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[418]848    def saveImmediateCallout = {
849        def result = taskService.saveImmediateCallout(params)
[395]850
851        if(!result.error) {
852            flash.message = "Task ${result.taskInstance.id} created."
853            redirect(action: 'show', id: result.taskInstance.id)
854            return
855        }
856
857        if(result.error.code == "task.modifications.failedToSave")
858            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
859
[418]860        render(view:'createImmediateCallout',
[395]861                    model: ['taskInstance': result.taskInstance,
862                                'entryFaultInstance': result.entryFaultInstance,
[418]863                                'entryCauseInstance': result.entryCauseInstance,
[395]864                                'entryWorkDoneInstance': result.entryWorkDoneInstance])
865
866    }
867
[476]868    /**
[490]869    * Render a users total work done hours.
870    */
871    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
872    def workDone = {
873        def result = taskSearchService.getWorkDone(params, RCU.getLocale(request))
874
875        params.message = result.message
876
877        return[entries: result.entries,
878                    totalEntries : result.totalEntries,
879                    startOfDay: result.startOfDay,
880                    person: result.person,
881                    totalHours: result.totalHours,
882                    totalMinutes: result.totalMinutes]
883    } // workDone
884
885    /**
[701]886    * Render work load hours.
887    */
888    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
889    def workLoad= {
[922]890        def filterParams = [:]
[701]891        def result = taskSearchService.getWorkLoad(params, RCU.getLocale(request))
892
893        params.message = result.message
894        params.errorMessage = result.errorMessage
895
896        return[tasks: result.tasks,
897                    startDate: result.startDate,
898                    endDate: result.endDate,
899                    taskGroups: result.taskGroups,
900                    taskStatusList: result.taskStatusList,
901                    workLoadGroups: result.workLoadGroups,
902                    totalHours: result.totalHours,
[922]903                    totalMinutes: result.totalMinutes,
904                    filterParams: filterParams]
[701]905    } // workLoad
906
907    /**
[476]908    * Get some integers for use by the month control links.
909    */
910    private getCalendarMonthControls(Date showDate) {
911        def result = [:]
912        result.today = [:]
913        result.today.date = new Date()
914        result.today.month = dateUtilService.getMonthFromDate(result.today.date)
915        result.today.year = dateUtilService.getYearFromDate(result.today.date)
916        result.nextMonth = [:]
[553]917        result.nextMonth.date = dateUtilService.plusMonth(showDate)
[476]918        result.nextMonth.month = dateUtilService.getMonthFromDate(result.nextMonth.date)
919        result.nextMonth.year = dateUtilService.getYearFromDate(result.nextMonth.date)
920        result.previousMonth =  [:]
[553]921        result.previousMonth.date = dateUtilService.plusMonth(showDate, -1)
[476]922        result.previousMonth.month = dateUtilService.getMonthFromDate(result.previousMonth.date)
923        result.previousMonth.year = dateUtilService.getYearFromDate(result.previousMonth.date)
924        result.nextYear = [:]
[552]925        result.nextYear.date = dateUtilService.plusYear(showDate)
[476]926        result.nextYear.month = dateUtilService.getMonthFromDate(result.nextYear.date)
927        result.nextYear.year = dateUtilService.getYearFromDate(result.nextYear.date)
928        result.previousYear = [:]
[552]929        result.previousYear.date = dateUtilService.plusYear(showDate, -1)
[476]930        result.previousYear.month = dateUtilService.getMonthFromDate(result.previousYear.date)
931        result.previousYear.year = dateUtilService.getYearFromDate(result.previousYear.date)
932        return result
933    }
934
[196]935} // end of class.
Note: See TracBrowser for help on using the repository browser.