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