[69] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
[165] | 2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
[209] | 3 | import com.zeddware.grails.plugins.filterpane.FilterUtils |
---|
[476] | 4 | import org.springframework.web.servlet.support.RequestContextUtils as RCU |
---|
[69] | 5 | |
---|
[298] | 6 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[85] | 7 | class TaskDetailedController extends BaseController { |
---|
[66] | 8 | |
---|
[291] | 9 | def authService |
---|
[180] | 10 | def taskService |
---|
[143] | 11 | def taskSearchService |
---|
[140] | 12 | def filterService |
---|
[165] | 13 | def exportService |
---|
[214] | 14 | def dateUtilService |
---|
[139] | 15 | |
---|
[181] | 16 | // these actions only accept POST requests |
---|
[418] | 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'] |
---|
[66] | 20 | |
---|
[298] | 21 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[196] | 22 | def index = { redirect(action: 'search', params: params) } |
---|
[140] | 23 | |
---|
[298] | 24 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[326] | 25 | def setSearchParamsMax = { |
---|
[262] | 26 | def max = 1000 |
---|
| 27 | if(params.newMax.isInteger()) { |
---|
[260] | 28 | def i = params.newMax.toInteger() |
---|
[262] | 29 | if(i > 0 && i <= max) |
---|
| 30 | session.taskSearchParamsMax = params.newMax |
---|
| 31 | if(i > max) |
---|
| 32 | session.taskSearchParamsMax = max |
---|
| 33 | } |
---|
[260] | 34 | forward(action: 'search', params: params) |
---|
| 35 | } |
---|
| 36 | |
---|
[298] | 37 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[476] | 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 | |
---|
[483] | 50 | /** |
---|
| 51 | * Search for tasks. |
---|
| 52 | */ |
---|
[476] | 53 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[139] | 54 | def search = { |
---|
[143] | 55 | |
---|
[260] | 56 | if(session.taskSearchParamsMax) |
---|
| 57 | params.max = session.taskSearchParamsMax |
---|
| 58 | |
---|
[468] | 59 | // Protect filterPane. |
---|
[476] | 60 | params.max = Math.min( params.max ? params.max.toInteger() : 20, 1000 ) |
---|
[260] | 61 | |
---|
| 62 | def taskInstanceList = [] |
---|
| 63 | def taskInstanceTotal |
---|
[476] | 64 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
| 65 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
[260] | 66 | |
---|
[476] | 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) |
---|
[144] | 75 | } |
---|
[476] | 76 | } |
---|
[260] | 77 | |
---|
[486] | 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 | |
---|
[476] | 88 | if(isFilterApplied) { |
---|
[260] | 89 | // filterPane: |
---|
| 90 | taskInstanceList = filterService.filter( params, Task ) |
---|
| 91 | taskInstanceTotal = filterService.count( params, Task ) |
---|
| 92 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
[476] | 93 | // Remember search. |
---|
| 94 | session.taskSearchFilterParams = new LinkedHashMap(filterParams) |
---|
| 95 | session.taskSearchFilter = new LinkedHashMap(params.filter) |
---|
[488] | 96 | session.removeAttribute("taskSearchQuickSearch") |
---|
[260] | 97 | } |
---|
[476] | 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. |
---|
[488] | 107 | session.removeAttribute("taskSearchFilterParams") |
---|
| 108 | session.removeAttribute("taskSearchFilter") |
---|
[476] | 109 | session.taskSearchQuickSearch = result.quickSearch |
---|
| 110 | } |
---|
[143] | 111 | |
---|
[260] | 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) |
---|
[476] | 121 | title = params.message |
---|
[260] | 122 | else |
---|
| 123 | title = "Filtered tasks." |
---|
| 124 | |
---|
| 125 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
[390] | 126 | response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}") |
---|
[475] | 127 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskType", "taskStatus"] |
---|
[260] | 128 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
[475] | 129 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", |
---|
| 130 | "taskType": "Task Type", "taskStatus": "Task Status"] |
---|
[260] | 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 |
---|
[418] | 140 | filterParams.sort = params.sort ?: "attentionFlag" |
---|
[260] | 141 | filterParams.order = params.order ?: "desc" |
---|
| 142 | |
---|
| 143 | return[ taskInstanceList: taskInstanceList, |
---|
[476] | 144 | taskInstanceTotal: taskInstanceTotal, |
---|
| 145 | filterParams: filterParams, |
---|
| 146 | params: params ] |
---|
[260] | 147 | |
---|
[476] | 148 | } // search |
---|
[260] | 149 | |
---|
[298] | 150 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[155] | 151 | def searchCalendar = { |
---|
[140] | 152 | |
---|
[476] | 153 | // No pagination for calendar. |
---|
| 154 | params.offset = 0 |
---|
[474] | 155 | |
---|
[476] | 156 | // Restore params.max |
---|
| 157 | if(session.taskSearchCalendarParamsMax) |
---|
| 158 | params.max = session.taskSearchCalendarParamsMax |
---|
| 159 | |
---|
[474] | 160 | // Protect filterPane. |
---|
[476] | 161 | params.max = Math.min( params.max ? params.max.toInteger() : 100, 1000 ) |
---|
[474] | 162 | |
---|
[476] | 163 | def taskInstanceList = [] |
---|
| 164 | def taskInstanceTotal |
---|
| 165 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
| 166 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
[474] | 167 | |
---|
[476] | 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 | } |
---|
[474] | 178 | |
---|
[476] | 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 |
---|
[155] | 192 | |
---|
[476] | 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) |
---|
[488] | 204 | session.removeAttribute("taskSearchCalendarQuickSearch") |
---|
[139] | 205 | } |
---|
[476] | 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. |
---|
[488] | 214 | session.removeAttribute("taskSearchCalendarFilterParams") |
---|
| 215 | session.removeAttribute("taskSearchCalendarFilter") |
---|
[476] | 216 | session.taskSearchCalendarQuickSearch = result.quickSearch |
---|
| 217 | } |
---|
[140] | 218 | |
---|
[476] | 219 | // export plugin: |
---|
| 220 | if(params?.format && params.format != "html") { |
---|
[165] | 221 | |
---|
[476] | 222 | def dateFmt = { date -> |
---|
| 223 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
[165] | 224 | } |
---|
[260] | 225 | |
---|
[476] | 226 | String title |
---|
| 227 | if(params.quickSearch) |
---|
| 228 | title = params.message |
---|
| 229 | else |
---|
| 230 | title = "Filtered tasks." |
---|
[165] | 231 | |
---|
[476] | 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) |
---|
[165] | 242 | } |
---|
| 243 | |
---|
[476] | 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 | |
---|
[298] | 264 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 265 | def show = { |
---|
[147] | 266 | |
---|
[139] | 267 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 268 | if(params._action_Show) |
---|
[375] | 269 | params.action='show' |
---|
[139] | 270 | |
---|
[433] | 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 | |
---|
[225] | 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 | |
---|
[66] | 296 | def taskInstance = Task.get( params.id ) |
---|
| 297 | |
---|
| 298 | if(!taskInstance) { |
---|
| 299 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 300 | redirect(action: 'search') |
---|
[66] | 301 | } |
---|
[133] | 302 | else { |
---|
[433] | 303 | // Remember the current task id for use with navigation. |
---|
| 304 | session.currentTaskId = params.id |
---|
| 305 | |
---|
[179] | 306 | params.max = 10 |
---|
| 307 | params.order = "desc" |
---|
| 308 | params.sort = "id" |
---|
[134] | 309 | |
---|
[418] | 310 | def entryFaultList = Entry.withCriteria { |
---|
| 311 | eq("entryType", EntryType.get(1)) |
---|
| 312 | eq("task", taskInstance) |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | def entryCauseList = Entry.withCriteria { |
---|
[190] | 316 | eq("entryType", EntryType.get(2)) |
---|
[179] | 317 | eq("task", taskInstance) |
---|
| 318 | } |
---|
| 319 | |
---|
[418] | 320 | def entryWorkDoneList = Entry.withCriteria { |
---|
| 321 | eq("entryType", EntryType.get(3)) |
---|
[179] | 322 | eq("task", taskInstance) |
---|
| 323 | } |
---|
| 324 | |
---|
[196] | 325 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
---|
| 326 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
---|
[134] | 327 | |
---|
[175] | 328 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
| 329 | |
---|
[180] | 330 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
| 331 | |
---|
[253] | 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 | |
---|
[133] | 335 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
| 336 | def taskProcedureExits = new Boolean("true") |
---|
| 337 | if(!taskProcedureInstance) { |
---|
| 338 | taskProcedureExits = false |
---|
| 339 | } |
---|
[175] | 340 | |
---|
| 341 | params.order = "asc" |
---|
| 342 | params.sort = "procedureStepNumber" |
---|
| 343 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
| 344 | |
---|
[134] | 345 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
| 346 | def taskRecurringScheduleExits= new Boolean("true") |
---|
[175] | 347 | if(!taskRecurringScheduleInstance) { |
---|
[134] | 348 | taskRecurringScheduleExits = false |
---|
| 349 | } |
---|
[179] | 350 | |
---|
[137] | 351 | return [ taskInstance: taskInstance, |
---|
[418] | 352 | entryFaultList: entryFaultList, |
---|
| 353 | entryCauseList: entryCauseList, |
---|
[179] | 354 | entryWorkDoneList: entryWorkDoneList, |
---|
[133] | 355 | taskProcedureInstance: taskProcedureInstance, |
---|
| 356 | taskProcedureExits: taskProcedureExits, |
---|
[225] | 357 | showTab: showTab, |
---|
[179] | 358 | subTaskInstanceList: subTaskInstanceList, |
---|
| 359 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
| 360 | subTaskInstanceMax: params.max, |
---|
| 361 | maintenanceActionList: maintenanceActionList, |
---|
| 362 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
| 363 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
[180] | 364 | inventoryMovementList: inventoryMovementList, |
---|
[253] | 365 | taskModificationList: taskModificationList, |
---|
| 366 | assignedGroupList: assignedGroupList, |
---|
| 367 | assignedPersonList: assignedPersonList] |
---|
[131] | 368 | } |
---|
[66] | 369 | } |
---|
| 370 | |
---|
[418] | 371 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 372 | def restore = { |
---|
| 373 | |
---|
| 374 | def result = taskService.restore(params) |
---|
| 375 | |
---|
| 376 | if(!result.error) { |
---|
| 377 | flash.message = "Task ${params.id} has been restored." |
---|
[418] | 378 | redirect(action: show, id: params.id) |
---|
| 379 | return |
---|
[181] | 380 | } |
---|
| 381 | |
---|
[418] | 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 | |
---|
[181] | 389 | } |
---|
| 390 | |
---|
[418] | 391 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 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." |
---|
[196] | 398 | redirect(action: 'search') |
---|
[418] | 399 | return |
---|
[181] | 400 | } |
---|
| 401 | |
---|
[418] | 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 | |
---|
[66] | 409 | } |
---|
| 410 | |
---|
[418] | 411 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[181] | 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] | 418 | redirect(action: show, id: params.id) |
---|
| 419 | return |
---|
[181] | 420 | } |
---|
| 421 | |
---|
[418] | 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 | |
---|
[181] | 429 | } |
---|
| 430 | |
---|
[465] | 431 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[181] | 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." |
---|
[418] | 438 | redirect(action: show, id: params.id) |
---|
| 439 | return |
---|
[181] | 440 | } |
---|
| 441 | |
---|
[418] | 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 | |
---|
[181] | 449 | } |
---|
| 450 | |
---|
[298] | 451 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 452 | def complete = { |
---|
| 453 | |
---|
| 454 | def result = taskService.complete(params) |
---|
| 455 | |
---|
| 456 | if(!result.error) { |
---|
| 457 | flash.message = "Task ${params.id} has been completed." |
---|
[418] | 458 | redirect(action: show, id: params.id) |
---|
| 459 | return |
---|
[181] | 460 | } |
---|
[418] | 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 |
---|
[181] | 480 | } |
---|
| 481 | |
---|
[418] | 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 | |
---|
[181] | 489 | } |
---|
| 490 | |
---|
[298] | 491 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[418] | 492 | def clearAttentionFlag = { |
---|
[181] | 493 | |
---|
[418] | 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 |
---|
[181] | 500 | } |
---|
| 501 | |
---|
[418] | 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 | |
---|
[181] | 514 | def result = taskService.reopen(params) |
---|
| 515 | |
---|
| 516 | if(!result.error) { |
---|
| 517 | flash.message = "Task ${params.id} has been reopened." |
---|
[418] | 518 | redirect(action: show, id: params.id) |
---|
| 519 | return |
---|
[181] | 520 | } |
---|
| 521 | |
---|
[418] | 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 | |
---|
[181] | 529 | } |
---|
| 530 | |
---|
[298] | 531 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 532 | def edit = { |
---|
[147] | 533 | |
---|
[139] | 534 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 535 | if(params._action_Edit) |
---|
[375] | 536 | params.action='edit' |
---|
[169] | 537 | |
---|
[433] | 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 | |
---|
[66] | 545 | def taskInstance = Task.get( params.id ) |
---|
| 546 | |
---|
| 547 | if(!taskInstance) { |
---|
| 548 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 549 | redirect(action: 'search') |
---|
[66] | 550 | } |
---|
| 551 | else { |
---|
[433] | 552 | // Remember the current task id for use with navigation. |
---|
| 553 | session.currentTaskId = params.id |
---|
| 554 | |
---|
[181] | 555 | if(taskInstance.trash) { |
---|
[196] | 556 | flash.message = "You may not edit tasks that are in the trash." |
---|
| 557 | redirect(action: 'show', id: taskInstance.id) |
---|
| 558 | return |
---|
[181] | 559 | } |
---|
[246] | 560 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
| 561 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
| 562 | return [ taskInstance : taskInstance ] |
---|
[84] | 563 | } |
---|
| 564 | } |
---|
| 565 | |
---|
[298] | 566 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 567 | def update = { |
---|
[179] | 568 | |
---|
[180] | 569 | def result = taskService.update(params) |
---|
| 570 | |
---|
| 571 | if(!result.error) { |
---|
[66] | 572 | flash.message = "Task ${params.id} updated" |
---|
[418] | 573 | redirect(action: show, id: params.id) |
---|
| 574 | return |
---|
[180] | 575 | } |
---|
| 576 | |
---|
[418] | 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 | |
---|
[66] | 582 | } |
---|
| 583 | |
---|
[473] | 584 | /** |
---|
| 585 | * The create action is used to create scheduled types of tasks. |
---|
| 586 | */ |
---|
| 587 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[66] | 588 | def create = { |
---|
| 589 | def taskInstance = new Task() |
---|
[214] | 590 | |
---|
| 591 | // Set the targetStartDate if specified, used by searchCalendar view. |
---|
[476] | 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 | } |
---|
[214] | 597 | |
---|
[196] | 598 | // Default leadPerson to current user, unless supplied in params. |
---|
[291] | 599 | taskInstance.leadPerson = authService.currentUser |
---|
[487] | 600 | |
---|
| 601 | // Apply params, overiding anything above. |
---|
[66] | 602 | taskInstance.properties = params |
---|
[433] | 603 | |
---|
| 604 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
| 605 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
[487] | 606 | taskInstance.scheduled = true |
---|
[433] | 607 | taskInstance.taskPriority = scheduledTaskPriorities.default |
---|
| 608 | return ['taskInstance': taskInstance, |
---|
| 609 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
| 610 | 'scheduledTaskPriorities': scheduledTaskPriorities.list] |
---|
[66] | 611 | } |
---|
| 612 | |
---|
[298] | 613 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 614 | def save = { |
---|
[394] | 615 | def result = taskService.save(params) |
---|
[180] | 616 | |
---|
| 617 | if(!result.error) { |
---|
| 618 | flash.message = "Task ${result.taskInstance.id} created." |
---|
[196] | 619 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[418] | 620 | return |
---|
[66] | 621 | } |
---|
[180] | 622 | |
---|
[418] | 623 | if(result.error.code == "task.modifications.failedToSave") |
---|
| 624 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 625 | |
---|
[433] | 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]) |
---|
[66] | 632 | } |
---|
[179] | 633 | |
---|
[298] | 634 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[179] | 635 | def listSubTasks = { |
---|
| 636 | def parentTaskInstance = Task.get(params.id) |
---|
| 637 | |
---|
[134] | 638 | if(!parentTaskInstance) { |
---|
| 639 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 640 | redirect(action: 'search') |
---|
[133] | 641 | } |
---|
| 642 | else { |
---|
[179] | 643 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
[196] | 644 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
| 645 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
[179] | 646 | |
---|
[134] | 647 | [ taskInstanceList: subTaskInstanceList, |
---|
[179] | 648 | taskInstanceTotal: subTaskInstanceTotal, |
---|
| 649 | parentTaskInstance: parentTaskInstance] |
---|
| 650 | } |
---|
| 651 | } |
---|
| 652 | |
---|
[298] | 653 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[196] | 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")) { |
---|
[418] | 666 | flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
[196] | 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 | |
---|
[395] | 681 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[433] | 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']) |
---|
[418] | 717 | def createImmediateCallout = { |
---|
[395] | 718 | def taskInstance = new Task() |
---|
| 719 | |
---|
| 720 | def entryFaultInstance = new Entry(entryType: EntryType.get(1)) // Fault. |
---|
[418] | 721 | def entryCauseInstance = new Entry(entryType: EntryType.get(2)) // Cause. |
---|
| 722 | def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3)) // Work Done. |
---|
[395] | 723 | |
---|
| 724 | return ['taskInstance': taskInstance, |
---|
| 725 | 'entryFaultInstance': entryFaultInstance, |
---|
[418] | 726 | 'entryCauseInstance': entryCauseInstance, |
---|
[395] | 727 | 'entryWorkDoneInstance': entryWorkDoneInstance] |
---|
| 728 | } |
---|
| 729 | |
---|
| 730 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[418] | 731 | def saveImmediateCallout = { |
---|
| 732 | def result = taskService.saveImmediateCallout(params) |
---|
[395] | 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 | |
---|
[418] | 743 | render(view:'createImmediateCallout', |
---|
[395] | 744 | model: ['taskInstance': result.taskInstance, |
---|
| 745 | 'entryFaultInstance': result.entryFaultInstance, |
---|
[418] | 746 | 'entryCauseInstance': result.entryCauseInstance, |
---|
[395] | 747 | 'entryWorkDoneInstance': result.entryWorkDoneInstance]) |
---|
| 748 | |
---|
| 749 | } |
---|
| 750 | |
---|
[476] | 751 | /** |
---|
[490] | 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 | /** |
---|
[476] | 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 | |
---|
[196] | 796 | } // end of class. |
---|