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