Ignore:
Timestamp:
Nov 24, 2009, 7:57:30 AM (14 years ago)
Author:
gav
Message:

Exclude tasks in trash from subTask lists.
Add create subTask functionality.
Move possibleParentList() to TaskService.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/TaskDetailedController.groovy

    r190 r196  
    1414    static allowedMethods = [save:'POST', update:'POST', restore:'POST', trash:'POST', approve:'POST', renegeApproval:'POST', complete:'POST', reopen:'POST']
    1515
    16     def index = { redirect(action:search,params:params) }
     16    def index = { redirect(action: 'search', params: params) }
    1717
    1818    def list = {
     
    163163        if(!taskInstance) {
    164164            flash.message = "Task not found with id ${params.id}"
    165             redirect(action:search)
     165            redirect(action: 'search')
    166166        }
    167167        else {
     
    180180                                                        }
    181181
    182             def subTaskInstanceList = Task.findAllByParentTask(taskInstance, params)
    183             def subTaskInstanceTotal = Task.countByParentTask(taskInstance)
     182            def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params)
     183            def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false)
    184184            def showTaskTab = new String("true")
    185185
     
    225225        if(!Task.exists(params.id)) {
    226226            flash.message = "Task not found with id ${params.id}"
    227             redirect(action:'search')
     227            redirect(action: 'search')
    228228        }
    229229
     
    232232        if(!result.error) {
    233233                flash.message = "Task ${params.id} has been restored."
    234                 redirect(action:show,id:result.taskInstance.id)
    235         }
    236         else {
    237             if(result.taskInstance) {
    238                 render(view:'edit',model:[taskInstance:result.taskInstance])
    239             }
    240             else {
    241                 flash.message = "Task could not be updated."
    242                 redirect(action:'search')
     234                redirect(action: 'show', id: result.taskInstance.id)
     235        }
     236        else {
     237            if(result.taskInstance) {
     238                render(view:'edit',model:[taskInstance:result.taskInstance])
     239            }
     240            else {
     241                flash.message = "Task could not be updated."
     242                redirect(action: 'search')
    243243            }
    244244        }
     
    250250        if(!Task.exists(params.id)) {
    251251            flash.message = "Task not found with id ${params.id}."
    252             redirect(action:'search')
     252            redirect(action: 'search')
    253253        }
    254254
     
    257257        if(!result.error) {
    258258                flash.message = "Task ${params.id} has been moved to trash."
    259                 redirect(action:'search')
    260         }
    261         else {
    262             if(result.taskInstance) {
    263                 render(view:'edit',model:[taskInstance:result.taskInstance])
    264             }
    265             else {
    266                 flash.message = "Task could not be updated."
    267                 redirect(action:'search')
     259                redirect(action: 'search')
     260        }
     261        else {
     262            if(result.taskInstance) {
     263                render(view:'edit',model:[taskInstance:result.taskInstance])
     264            }
     265            else {
     266                flash.message = "Task could not be updated."
     267                redirect(action: 'search')
    268268            }
    269269        }
     
    275275        if(!Task.exists(params.id)) {
    276276            flash.message = "Task not found with id ${params.id}."
    277             redirect(action:'search')
     277            redirect(action: 'search')
    278278        }
    279279
     
    282282        if(!result.error) {
    283283                flash.message = "Task ${params.id} has been approved."
    284                 redirect(action:show,id:result.taskInstance.id)
    285         }
    286         else {
    287             if(result.taskInstance) {
    288                 render(view:'edit',model:[taskInstance:result.taskInstance])
    289             }
    290             else {
    291                 flash.message = "Task could not be updated."
    292                 redirect(action:'search')
     284                redirect(action: 'show', id: result.taskInstance.id)
     285        }
     286        else {
     287            if(result.taskInstance) {
     288                render(view:'edit',model:[taskInstance:result.taskInstance])
     289            }
     290            else {
     291                flash.message = "Task could not be updated."
     292                redirect(action: 'search')
    293293            }
    294294        }
     
    300300        if(!Task.exists(params.id)) {
    301301            flash.message = "Task not found with id ${params.id}."
    302             redirect(action:'search')
     302            redirect(action: 'search')
    303303        }
    304304
     
    307307        if(!result.error) {
    308308                flash.message = "Task ${params.id} has had approval removed."
    309                 redirect(action:show,id:result.taskInstance.id)
    310         }
    311         else {
    312             if(result.taskInstance) {
    313                 render(view:'edit',model:[taskInstance:result.taskInstance])
    314             }
    315             else {
    316                 flash.message = "Task could not be updated."
    317                 redirect(action:'search')
     309                redirect(action: 'show', id: result.taskInstance.id)
     310        }
     311        else {
     312            if(result.taskInstance) {
     313                render(view:'edit',model:[taskInstance:result.taskInstance])
     314            }
     315            else {
     316                flash.message = "Task could not be updated."
     317                redirect(action: 'search')
    318318            }
    319319        }
     
    325325        if(!Task.exists(params.id)) {
    326326            flash.message = "Task not found with id ${params.id}."
    327             redirect(action:'search')
     327            redirect(action: 'search')
    328328        }
    329329
     
    332332        if(!result.error) {
    333333                flash.message = "Task ${params.id} has been completed."
    334                 redirect(action:show,id:result.taskInstance.id)
    335         }
    336         else {
    337             if(result.taskInstance) {
    338                 render(view:'edit',model:[taskInstance:result.taskInstance])
    339             }
    340             else {
    341                 flash.message = "Task could not be updated."
    342                 redirect(action:'search')
     334                redirect(action: 'show', id: result.taskInstance.id)
     335        }
     336        else {
     337            if(result.taskInstance) {
     338                render(view:'edit',model:[taskInstance:result.taskInstance])
     339            }
     340            else {
     341                flash.message = "Task could not be updated."
     342                redirect(action: 'search')
    343343            }
    344344        }
     
    350350        if(!Task.exists(params.id)) {
    351351            flash.message = "Task not found with id ${params.id}."
    352             redirect(action:'search')
     352            redirect(action: 'search')
    353353        }
    354354
     
    357357        if(!result.error) {
    358358                flash.message = "Task ${params.id} has been reopened."
    359                 redirect(action:show,id:result.taskInstance.id)
    360         }
    361         else {
    362             if(result.taskInstance) {
    363                 render(view:'edit',model:[taskInstance:result.taskInstance])
    364             }
    365             else {
    366                 flash.message = "Task could not be updated."
    367                 redirect(action:'search')
     359                redirect(action: 'show', id: result.taskInstance.id)
     360        }
     361        else {
     362            if(result.taskInstance) {
     363                render(view:'edit',model:[taskInstance:result.taskInstance])
     364            }
     365            else {
     366                flash.message = "Task could not be updated."
     367                redirect(action: 'search')
    368368            }
    369369        }
     
    381381        if(!taskInstance) {
    382382            flash.message = "Task not found with id ${params.id}"
    383             redirect(action:search)
     383            redirect(action: 'search')
    384384        }
    385385        else {
    386386            if(taskInstance.trash) {
    387                 flash.message = "You may not edit items in the trash."
    388                 redirect(action:show,id:taskInstance.id)
    389             }
    390             def criteria = taskInstance.createCriteria()
    391             def possibleParentList = criteria {
    392                 and {
    393                     notEqual('id', taskInstance.id)
    394                     taskInstance.subTasks.each() { notEqual('id', it.id) }
    395                     }
    396             }
     387                flash.message = "You may not edit tasks that are in the trash."
     388                redirect(action: 'show', id: taskInstance.id)
     389                return
     390            }
     391            def possibleParentList = taskService.possibleParentList(taskInstance)
    397392            return [ taskInstance : taskInstance, possibleParentList: possibleParentList ]
    398393        }
     
    403398        if(!Task.exists(params.id)) {
    404399            flash.message = "Task not found with id ${params.id}"
    405             redirect(action:'search')
     400            redirect(action: 'search')
    406401        }
    407402
     
    410405        if(!result.error) {
    411406                flash.message = "Task ${params.id} updated"
    412                 redirect(action:show,id:result.taskInstance.id)
    413         }
    414         else {
    415             if(result.taskInstance) {
    416                 render(view:'edit',model:[taskInstance:result.taskInstance])
    417             }
    418             else {
    419                 flash.message = "Task could not be updated."
    420                 redirect(action:'search')
     407                redirect(action: 'show', id: result.taskInstance.id)
     408        }
     409        else {
     410            if(result.taskInstance) {
     411                render(view:'edit',model:[taskInstance:result.taskInstance])
     412            }
     413            else {
     414                flash.message = "Task could not be updated."
     415                redirect(action: 'search')
    421416            }
    422417        }
     
    453448    def create = {
    454449        def taskInstance = new Task()
    455         // Default leadPerson to current user.
     450        // Default leadPerson to current user, unless supplied in params.
    456451        taskInstance.leadPerson = personService.currentUser()
    457452        taskInstance.properties = params
    458         return ['taskInstance':taskInstance]
     453        return ['taskInstance': taskInstance]
    459454    }
    460455
     
    464459        if(!result.error) {
    465460            flash.message = "Task ${result.taskInstance.id} created."
    466             redirect(action: show,id: result.taskInstance.id)
    467         }
    468         else {
    469             if(result.taskInstance) {
    470                 render(view:'create',model:[taskInstance:result.taskInstance])
     461            redirect(action: 'show', id: result.taskInstance.id)
     462        }
     463        else {
     464            if(result.taskInstance) {
     465                render(view:'create', model:[taskInstance:result.taskInstance])
    471466            }
    472467            else {
    473468                flash.message = "Could not create task."
    474                 redirect(action:"search")
     469                redirect(action: 'search')
    475470            }
    476471
     
    483478        if(!parentTaskInstance) {
    484479            flash.message = "Task not found with id ${params.id}"
    485             redirect(action:search)
     480            redirect(action: 'search')
    486481        }
    487482        else {
    488483        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
    489         def subTaskInstanceList = Task.findAllByParentTask(parentTaskInstance, params)
    490         def subTaskInstanceTotal = Task.countByParentTask(parentTaskInstance)
     484        def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params)
     485        def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false)
    491486
    492487        [ taskInstanceList: subTaskInstanceList,
     
    496491    }
    497492
    498 }
     493    def createSubTask = {
     494        def parentTaskInstance = Task.get(params.id)
     495
     496        if(parentTaskInstance) {
     497
     498            def result = taskService.createSubTask(parentTaskInstance)
     499            if(!result.error) {
     500                flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements."
     501                redirect(action: 'edit', id: result.taskInstance.id)
     502            }
     503            else {
     504                if(result.taskInstance.errors.hasFieldErrors("parentTask")) {
     505                    flash.message = g.message(code:"task.operationNotPermittedOnTaskInTrash")
     506                    redirect(action: 'show', id:  parentTaskInstance.id)
     507                }
     508                else {
     509                    render(view: 'create', model:[taskInstance: result.taskInstance])
     510                }
     511            }
     512        }
     513
     514        else {
     515            flash.message = "Task not found with id ${params.id}"
     516            redirect(action: 'search')
     517        }
     518    }
     519
     520} // end of class.
Note: See TracChangeset for help on using the changeset viewer.