[69] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
[165] | 2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
[69] | 3 | |
---|
[85] | 4 | class TaskDetailedController extends BaseController { |
---|
[66] | 5 | |
---|
[185] | 6 | def personService |
---|
[140] | 7 | def dateUtilService |
---|
[180] | 8 | def taskService |
---|
[143] | 9 | def taskSearchService |
---|
[140] | 10 | def filterService |
---|
[165] | 11 | def exportService |
---|
[139] | 12 | |
---|
[181] | 13 | // these actions only accept POST requests |
---|
| 14 | static allowedMethods = [save:'POST', update:'POST', restore:'POST', trash:'POST', approve:'POST', renegeApproval:'POST', complete:'POST', reopen:'POST'] |
---|
[66] | 15 | |
---|
[140] | 16 | def index = { redirect(action:search,params:params) } |
---|
| 17 | |
---|
[66] | 18 | def list = { |
---|
[143] | 19 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
[124] | 20 | [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ] |
---|
[66] | 21 | } |
---|
[143] | 22 | |
---|
[139] | 23 | def search = { |
---|
[144] | 24 | // println params |
---|
[143] | 25 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
| 26 | |
---|
[155] | 27 | // Quick Search: |
---|
[143] | 28 | if(!params.filter) |
---|
[139] | 29 | { |
---|
[144] | 30 | def taskInstanceList = [] |
---|
[185] | 31 | def personInstance = personService.currentUser() |
---|
[143] | 32 | |
---|
[155] | 33 | if(params.quickSearch == "searchMyTodays") { |
---|
[144] | 34 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
| 35 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
| 36 | else { params.message = "No tasks found for today." } |
---|
| 37 | } |
---|
[155] | 38 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
[144] | 39 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
| 40 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
[185] | 41 | else { params.message = "No tasks found for the last week." } |
---|
[144] | 42 | } |
---|
[155] | 43 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
[144] | 44 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
| 45 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
[185] | 46 | else { params.message = "No tasks found for the last week." } |
---|
[144] | 47 | } |
---|
| 48 | else { |
---|
| 49 | //Default: |
---|
| 50 | taskInstanceList = taskSearchService.getTodays(params) |
---|
| 51 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
| 52 | else { params.message = "No tasks found for today." } |
---|
[155] | 53 | params.quickSearch = "searchTodays" |
---|
[144] | 54 | } |
---|
[155] | 55 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
[139] | 56 | } |
---|
[143] | 57 | // filterPane: |
---|
| 58 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
| 59 | taskInstanceTotal: filterService.count( params, Task ), |
---|
| 60 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
| 61 | params:params ] |
---|
[140] | 62 | } |
---|
[143] | 63 | |
---|
[155] | 64 | def searchCalendar = { |
---|
| 65 | // println params |
---|
| 66 | params.max = 30 |
---|
[140] | 67 | |
---|
[155] | 68 | // Quick Search: |
---|
| 69 | if(!params.filter) |
---|
[139] | 70 | { |
---|
[155] | 71 | def taskInstanceList = [] |
---|
[185] | 72 | def personInstance = personService.currentUser() |
---|
[155] | 73 | |
---|
| 74 | if(params.quickSearch == "searchMyTodays") { |
---|
| 75 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
| 76 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
| 77 | else { params.message = "No tasks found for today." } |
---|
| 78 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 79 | } |
---|
| 80 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
| 81 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
| 82 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
[185] | 83 | else { params.message = "No tasks found for the last week." } |
---|
[155] | 84 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 85 | } |
---|
| 86 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
| 87 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
| 88 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
[185] | 89 | else { params.message = "No tasks found for the last week." } |
---|
[155] | 90 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 91 | } |
---|
| 92 | else { |
---|
| 93 | //Default: |
---|
| 94 | taskInstanceList = taskSearchService.getTodays(params) |
---|
| 95 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
| 96 | else { params.message = "No tasks found for today." } |
---|
| 97 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 98 | params.quickSearch = "searchTodays" |
---|
| 99 | } |
---|
| 100 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
[139] | 101 | } |
---|
[155] | 102 | // filterPane: |
---|
| 103 | def taskInstanceTotal = filterService.count( params, Task ) |
---|
| 104 | if(taskInstanceTotal > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 105 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
| 106 | taskInstanceTotal: taskInstanceTotal, |
---|
| 107 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
| 108 | params:params ] |
---|
[139] | 109 | } |
---|
[140] | 110 | |
---|
[165] | 111 | def budget = { |
---|
| 112 | // println params |
---|
| 113 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
| 114 | |
---|
| 115 | // Quick Search: |
---|
| 116 | if(!params.filter) |
---|
| 117 | { |
---|
| 118 | def taskInstanceList = [] |
---|
[185] | 119 | def personInstance = personService.currentUser() |
---|
[165] | 120 | |
---|
| 121 | if(params.quickSearch == "budgetUnplanned") { |
---|
| 122 | taskInstanceList = taskSearchService.getBudgetUnplanned(params) |
---|
| 123 | if(taskInstanceList.totalCount > 0) { params.message = "Budget unplanned tasks in the last week." } |
---|
| 124 | else { params.message = "No tasks found." } |
---|
| 125 | } |
---|
| 126 | //else if(params.quickSearch == "budgetPlanned") { |
---|
| 127 | else { |
---|
| 128 | //Default: |
---|
| 129 | taskInstanceList = taskSearchService.getBudgetPlanned(params) |
---|
| 130 | if(taskInstanceList.totalCount > 0) { params.message = "Budget planned Tasks in the last week." } |
---|
| 131 | else { params.message = "No tasks found.." } |
---|
| 132 | } |
---|
| 133 | // export plugin: |
---|
| 134 | if(params?.format && params.format != "html") { |
---|
| 135 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
| 136 | response.setHeader("Content-disposition", "attachment; filename=tasks.${params.extension}") |
---|
| 137 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskStatus", "taskType"] |
---|
| 138 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
| 139 | "leadPerson": "Lead Person", "taskStatus": "Task Status", "taskType": "Task Type"] |
---|
| 140 | Map formatters = [:] |
---|
| 141 | String title = "${params.quickSearch} tasks in the last week." |
---|
| 142 | Map parameters = [title: title] |
---|
| 143 | |
---|
| 144 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
| 145 | } |
---|
| 146 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
| 147 | } |
---|
| 148 | // filterPane: |
---|
| 149 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
| 150 | taskInstanceTotal: filterService.count( params, Task ), |
---|
| 151 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
| 152 | params:params ] |
---|
| 153 | } |
---|
| 154 | |
---|
[66] | 155 | def show = { |
---|
[147] | 156 | |
---|
[139] | 157 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 158 | if(params._action_Show) |
---|
| 159 | { params.action='show' } |
---|
| 160 | |
---|
[66] | 161 | def taskInstance = Task.get( params.id ) |
---|
| 162 | |
---|
| 163 | if(!taskInstance) { |
---|
| 164 | flash.message = "Task not found with id ${params.id}" |
---|
[139] | 165 | redirect(action:search) |
---|
[66] | 166 | } |
---|
[133] | 167 | else { |
---|
[179] | 168 | params.max = 10 |
---|
| 169 | params.order = "desc" |
---|
| 170 | params.sort = "id" |
---|
[134] | 171 | |
---|
[179] | 172 | def entryWorkDoneList = Entry.withCriteria { |
---|
| 173 | def entryType = EntryType.findByName("WorkDone") |
---|
| 174 | eq("entryType", entryType) |
---|
| 175 | eq("task", taskInstance) |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | def entryFaultList = Entry.withCriteria { |
---|
| 179 | def entryType = EntryType.findByName("Fault") |
---|
| 180 | eq("entryType", entryType) |
---|
| 181 | eq("task", taskInstance) |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | def subTaskInstanceList = Task.findAllByParentTask(taskInstance, params) |
---|
| 185 | def subTaskInstanceTotal = Task.countByParentTask(taskInstance) |
---|
[134] | 186 | def showTaskTab = new String("true") |
---|
| 187 | |
---|
[175] | 188 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
| 189 | |
---|
[180] | 190 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
| 191 | |
---|
[133] | 192 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
| 193 | def taskProcedureExits = new Boolean("true") |
---|
| 194 | if(!taskProcedureInstance) { |
---|
| 195 | taskProcedureExits = false |
---|
| 196 | } |
---|
[175] | 197 | |
---|
| 198 | params.order = "asc" |
---|
| 199 | params.sort = "procedureStepNumber" |
---|
| 200 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
| 201 | |
---|
[134] | 202 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
| 203 | def taskRecurringScheduleExits= new Boolean("true") |
---|
[175] | 204 | if(!taskRecurringScheduleInstance) { |
---|
[134] | 205 | taskRecurringScheduleExits = false |
---|
| 206 | } |
---|
[179] | 207 | |
---|
[137] | 208 | return [ taskInstance: taskInstance, |
---|
[179] | 209 | entryWorkDoneList: entryWorkDoneList, |
---|
| 210 | entryFaultList: entryFaultList, |
---|
[133] | 211 | taskProcedureInstance: taskProcedureInstance, |
---|
| 212 | taskProcedureExits: taskProcedureExits, |
---|
[134] | 213 | showTaskTab: showTaskTab, |
---|
[179] | 214 | subTaskInstanceList: subTaskInstanceList, |
---|
| 215 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
| 216 | subTaskInstanceMax: params.max, |
---|
| 217 | maintenanceActionList: maintenanceActionList, |
---|
| 218 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
| 219 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
[180] | 220 | inventoryMovementList: inventoryMovementList, |
---|
| 221 | taskModificationList: taskModificationList] |
---|
[131] | 222 | } |
---|
[66] | 223 | } |
---|
| 224 | |
---|
[181] | 225 | def restore = { |
---|
| 226 | |
---|
| 227 | if(!Task.exists(params.id)) { |
---|
| 228 | flash.message = "Task not found with id ${params.id}" |
---|
| 229 | redirect(action:'search') |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | def result = taskService.restore(params) |
---|
| 233 | |
---|
| 234 | if(!result.error) { |
---|
| 235 | flash.message = "Task ${params.id} has been restored." |
---|
| 236 | redirect(action:show,id:result.taskInstance.id) |
---|
| 237 | } |
---|
| 238 | else { |
---|
| 239 | if(result.taskInstance) { |
---|
| 240 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
[96] | 241 | } |
---|
[181] | 242 | else { |
---|
| 243 | flash.message = "Task could not be updated." |
---|
| 244 | redirect(action:'search') |
---|
[96] | 245 | } |
---|
[66] | 246 | } |
---|
[181] | 247 | |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | def trash = { |
---|
| 251 | |
---|
| 252 | if(!Task.exists(params.id)) { |
---|
| 253 | flash.message = "Task not found with id ${params.id}." |
---|
| 254 | redirect(action:'search') |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | def result = taskService.trash(params) |
---|
| 258 | |
---|
| 259 | if(!result.error) { |
---|
| 260 | flash.message = "Task ${params.id} has been moved to trash." |
---|
| 261 | redirect(action:'search') |
---|
| 262 | } |
---|
[66] | 263 | else { |
---|
[181] | 264 | if(result.taskInstance) { |
---|
| 265 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 266 | } |
---|
| 267 | else { |
---|
| 268 | flash.message = "Task could not be updated." |
---|
| 269 | redirect(action:'search') |
---|
| 270 | } |
---|
[66] | 271 | } |
---|
[181] | 272 | |
---|
[66] | 273 | } |
---|
| 274 | |
---|
[181] | 275 | def approve = { |
---|
| 276 | |
---|
| 277 | if(!Task.exists(params.id)) { |
---|
| 278 | flash.message = "Task not found with id ${params.id}." |
---|
| 279 | redirect(action:'search') |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | def result = taskService.approve(params) |
---|
| 283 | |
---|
| 284 | if(!result.error) { |
---|
| 285 | flash.message = "Task ${params.id} has been approved." |
---|
| 286 | redirect(action:show,id:result.taskInstance.id) |
---|
| 287 | } |
---|
| 288 | else { |
---|
| 289 | if(result.taskInstance) { |
---|
| 290 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 291 | } |
---|
| 292 | else { |
---|
| 293 | flash.message = "Task could not be updated." |
---|
| 294 | redirect(action:'search') |
---|
| 295 | } |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | def renegeApproval = { |
---|
| 301 | |
---|
| 302 | if(!Task.exists(params.id)) { |
---|
| 303 | flash.message = "Task not found with id ${params.id}." |
---|
| 304 | redirect(action:'search') |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | def result = taskService.renegeApproval(params) |
---|
| 308 | |
---|
| 309 | if(!result.error) { |
---|
| 310 | flash.message = "Task ${params.id} has had approval removed." |
---|
| 311 | redirect(action:show,id:result.taskInstance.id) |
---|
| 312 | } |
---|
| 313 | else { |
---|
| 314 | if(result.taskInstance) { |
---|
| 315 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 316 | } |
---|
| 317 | else { |
---|
| 318 | flash.message = "Task could not be updated." |
---|
| 319 | redirect(action:'search') |
---|
| 320 | } |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | def complete = { |
---|
| 326 | |
---|
| 327 | if(!Task.exists(params.id)) { |
---|
| 328 | flash.message = "Task not found with id ${params.id}." |
---|
| 329 | redirect(action:'search') |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | def result = taskService.complete(params) |
---|
| 333 | |
---|
| 334 | if(!result.error) { |
---|
| 335 | flash.message = "Task ${params.id} has been completed." |
---|
| 336 | redirect(action:show,id:result.taskInstance.id) |
---|
| 337 | } |
---|
| 338 | else { |
---|
| 339 | if(result.taskInstance) { |
---|
| 340 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 341 | } |
---|
| 342 | else { |
---|
| 343 | flash.message = "Task could not be updated." |
---|
| 344 | redirect(action:'search') |
---|
| 345 | } |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | } |
---|
| 349 | |
---|
| 350 | def reopen = { |
---|
| 351 | |
---|
| 352 | if(!Task.exists(params.id)) { |
---|
| 353 | flash.message = "Task not found with id ${params.id}." |
---|
| 354 | redirect(action:'search') |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | def result = taskService.reopen(params) |
---|
| 358 | |
---|
| 359 | if(!result.error) { |
---|
| 360 | flash.message = "Task ${params.id} has been reopened." |
---|
| 361 | redirect(action:show,id:result.taskInstance.id) |
---|
| 362 | } |
---|
| 363 | else { |
---|
| 364 | if(result.taskInstance) { |
---|
| 365 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 366 | } |
---|
| 367 | else { |
---|
| 368 | flash.message = "Task could not be updated." |
---|
| 369 | redirect(action:'search') |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | } |
---|
| 374 | |
---|
[66] | 375 | def edit = { |
---|
[147] | 376 | |
---|
[139] | 377 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 378 | if(params._action_Edit) |
---|
| 379 | { params.action='edit' } |
---|
[169] | 380 | |
---|
[66] | 381 | def taskInstance = Task.get( params.id ) |
---|
| 382 | |
---|
| 383 | if(!taskInstance) { |
---|
| 384 | flash.message = "Task not found with id ${params.id}" |
---|
[139] | 385 | redirect(action:search) |
---|
[66] | 386 | } |
---|
| 387 | else { |
---|
[181] | 388 | if(taskInstance.trash) { |
---|
| 389 | flash.message = "You may not edit items in the trash." |
---|
| 390 | redirect(action:show,id:taskInstance.id) |
---|
| 391 | } |
---|
[84] | 392 | def criteria = taskInstance.createCriteria() |
---|
[169] | 393 | def possibleParentList = criteria { |
---|
[84] | 394 | and { |
---|
| 395 | notEqual('id', taskInstance.id) |
---|
[169] | 396 | taskInstance.subTasks.each() { notEqual('id', it.id) } |
---|
[84] | 397 | } |
---|
| 398 | } |
---|
[169] | 399 | return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
[84] | 400 | } |
---|
| 401 | } |
---|
| 402 | |
---|
[66] | 403 | def update = { |
---|
[179] | 404 | |
---|
[180] | 405 | if(!Task.exists(params.id)) { |
---|
| 406 | flash.message = "Task not found with id ${params.id}" |
---|
| 407 | redirect(action:'search') |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | def result = taskService.update(params) |
---|
| 411 | |
---|
| 412 | if(!result.error) { |
---|
[66] | 413 | flash.message = "Task ${params.id} updated" |
---|
[180] | 414 | redirect(action:show,id:result.taskInstance.id) |
---|
| 415 | } |
---|
| 416 | else { |
---|
| 417 | if(result.taskInstance) { |
---|
| 418 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
[66] | 419 | } |
---|
| 420 | else { |
---|
[180] | 421 | flash.message = "Task could not be updated." |
---|
| 422 | redirect(action:'search') |
---|
[66] | 423 | } |
---|
| 424 | } |
---|
[180] | 425 | |
---|
[66] | 426 | } |
---|
| 427 | |
---|
[180] | 428 | // def update = { |
---|
| 429 | // def taskInstance = Task.get( params.id ) |
---|
| 430 | // if(taskInstance) { |
---|
| 431 | // if(params.version) { |
---|
| 432 | // def version = params.version.toLong() |
---|
| 433 | // if(taskInstance.version > version) { |
---|
| 434 | // |
---|
| 435 | // taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.") |
---|
| 436 | // render(view:'edit',model:[taskInstance:taskInstance]) |
---|
| 437 | // return |
---|
| 438 | // } |
---|
| 439 | // } |
---|
| 440 | // taskInstance.properties = params |
---|
| 441 | // if(!taskInstance.hasErrors() && taskInstance.save(flush: true)) { |
---|
| 442 | // flash.message = "Task ${params.id} updated" |
---|
| 443 | // redirect(action:show,id:taskInstance.id) |
---|
| 444 | // } |
---|
| 445 | // else { |
---|
| 446 | // render(view:'edit',model:[taskInstance:taskInstance]) |
---|
| 447 | // } |
---|
| 448 | // } |
---|
| 449 | // else { |
---|
| 450 | // flash.message = "Task not found with id ${params.id}" |
---|
| 451 | // redirect(action:edit,id:params.id) |
---|
| 452 | // } |
---|
| 453 | // } |
---|
| 454 | |
---|
[66] | 455 | def create = { |
---|
| 456 | def taskInstance = new Task() |
---|
[181] | 457 | // Default leadPerson to current user. |
---|
[185] | 458 | taskInstance.leadPerson = personService.currentUser() |
---|
[66] | 459 | taskInstance.properties = params |
---|
| 460 | return ['taskInstance':taskInstance] |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | def save = { |
---|
[180] | 464 | def result = taskService.create(params) |
---|
| 465 | |
---|
| 466 | if(!result.error) { |
---|
| 467 | flash.message = "Task ${result.taskInstance.id} created." |
---|
| 468 | redirect(action: show,id: result.taskInstance.id) |
---|
[66] | 469 | } |
---|
| 470 | else { |
---|
[180] | 471 | if(result.taskInstance) { |
---|
| 472 | render(view:'create',model:[taskInstance:result.taskInstance]) |
---|
| 473 | } |
---|
| 474 | else { |
---|
| 475 | flash.message = "Could not create task." |
---|
| 476 | redirect(action:"search") |
---|
| 477 | } |
---|
| 478 | |
---|
[66] | 479 | } |
---|
| 480 | } |
---|
[179] | 481 | |
---|
| 482 | def listSubTasks = { |
---|
| 483 | def parentTaskInstance = Task.get(params.id) |
---|
| 484 | |
---|
[134] | 485 | if(!parentTaskInstance) { |
---|
| 486 | flash.message = "Task not found with id ${params.id}" |
---|
[139] | 487 | redirect(action:search) |
---|
[133] | 488 | } |
---|
| 489 | else { |
---|
[179] | 490 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
| 491 | def subTaskInstanceList = Task.findAllByParentTask(parentTaskInstance, params) |
---|
| 492 | def subTaskInstanceTotal = Task.countByParentTask(parentTaskInstance) |
---|
| 493 | |
---|
[134] | 494 | [ taskInstanceList: subTaskInstanceList, |
---|
[179] | 495 | taskInstanceTotal: subTaskInstanceTotal, |
---|
| 496 | parentTaskInstance: parentTaskInstance] |
---|
| 497 | } |
---|
| 498 | } |
---|
| 499 | |
---|
[66] | 500 | } |
---|