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