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