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