Ignore:
Timestamp:
Feb 28, 2010, 7:13:47 PM (14 years ago)
Author:
gav
Message:

Add attentionFlag to Task domain along with views and logic to suite.
Add entry type 'cause', refactor as required.
Refactor task types.
Move createBreakin to createImmediateCallout.

File:
1 edited

Legend:

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

    r395 r418  
    1414
    1515    // these actions only accept POST requests
    16     static allowedMethods = [save:'POST', update:'POST', restore:'POST', trash:'POST', approve:'POST', renegeApproval:'POST', complete:'POST', reopen:'POST']
     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']
    1719
    1820    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
    1921    def index = { redirect(action: 'search', params: params) }
    20 
    21     @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
    22     def list = {
    23         params.max = Math.min( params.max ? params.max.toInteger() : 10,  100 )
    24         [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ]
    25     }
    2622
    2723    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
     
    115111        filterParams.max = params.max
    116112        filterParams.offset = params.offset?.toInteger() ?: 0
    117         filterParams.sort = params.sort ?: "id"
     113        filterParams.sort = params.sort ?: "attentionFlag"
    118114        filterParams.order = params.order ?: "desc"
    119115
     
    253249            params.sort = "id"
    254250
    255             def entryWorkDoneList = Entry.withCriteria {
    256                                                                 eq("entryType", EntryType.get(2))
    257                                                                 eq("task", taskInstance)
    258                                                         }
    259 
    260251            def entryFaultList = Entry.withCriteria {
    261252                                                                eq("entryType", EntryType.get(1))
     
    263254                                                        }
    264255
     256            def entryCauseList = Entry.withCriteria {
     257                                                                eq("entryType", EntryType.get(2))
     258                                                                eq("task", taskInstance)
     259                                                        }
     260
     261            def entryWorkDoneList = Entry.withCriteria {
     262                                                                eq("entryType", EntryType.get(3))
     263                                                                eq("task", taskInstance)
     264                                                        }
     265
    265266            def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params)
    266267            def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false)
     
    290291
    291292            return [ taskInstance: taskInstance,
     293                            entryFaultList: entryFaultList,
     294                            entryCauseList: entryCauseList,
    292295                            entryWorkDoneList: entryWorkDoneList,
    293                             entryFaultList: entryFaultList,
    294296                            taskProcedureInstance: taskProcedureInstance,
    295297                            taskProcedureExits: taskProcedureExits,
     
    308310    }
    309311
     312    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
    310313    def restore = {
    311314
    312         if(!Task.exists(params.id)) {
    313             flash.message = "Task not found with id ${params.id}"
    314             redirect(action: 'search')
    315         }
    316 
    317315        def result = taskService.restore(params)
    318316
    319317        if(!result.error) {
    320318                flash.message = "Task ${params.id} has been restored."
    321                 redirect(action: 'show', id: result.taskInstance.id)
    322         }
    323         else {
    324             if(result.taskInstance) {
    325                 render(view:'edit',model:[taskInstance:result.taskInstance])
    326             }
    327             else {
    328                 flash.message = "Task could not be updated."
    329                 redirect(action: 'search')
    330             }
    331         }
    332 
    333     }
    334 
     319                redirect(action: show, id: params.id)
     320                return
     321        }
     322
     323        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     324
     325        if(result.taskInstance)
     326            redirect(action: show, id: params.id)
     327        else
     328            redirect(action: 'search')
     329
     330    }
     331
     332    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
    335333    def trash = {
    336 
    337         if(!Task.exists(params.id)) {
    338             flash.message = "Task not found with id ${params.id}."
    339             redirect(action: 'search')
    340         }
    341334
    342335        def result = taskService.trash(params)
     
    345338                flash.message = "Task ${params.id} has been moved to trash."
    346339                redirect(action: 'search')
    347         }
    348         else {
    349             if(result.taskInstance) {
    350                 render(view:'edit',model:[taskInstance:result.taskInstance])
    351             }
    352             else {
    353                 flash.message = "Task could not be updated."
    354                 redirect(action: 'search')
    355             }
    356         }
    357 
    358     }
    359 
     340                return
     341        }
     342
     343        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     344
     345        if(result.taskInstance)
     346            redirect(action: show, id: params.id)
     347        else
     348            redirect(action: 'search')
     349
     350    }
     351
     352    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager'])
    360353    def approve = {
    361354
    362         if(!Task.exists(params.id)) {
    363             flash.message = "Task not found with id ${params.id}."
    364             redirect(action: 'search')
    365         }
    366 
    367355        def result = taskService.approve(params)
    368356
    369357        if(!result.error) {
    370358                flash.message = "Task ${params.id} has been approved."
    371                 redirect(action: 'show', id: result.taskInstance.id)
    372         }
    373         else {
    374             if(result.taskInstance) {
    375                 render(view:'edit',model:[taskInstance:result.taskInstance])
    376             }
    377             else {
    378                 flash.message = "Task could not be updated."
    379                 redirect(action: 'search')
    380             }
    381         }
    382 
    383     }
    384 
     359                redirect(action: show, id: params.id)
     360                return
     361        }
     362
     363        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     364
     365        if(result.taskInstance)
     366            redirect(action: show, id: params.id)
     367        else
     368            redirect(action: 'search')
     369
     370    }
     371
     372    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
    385373    def renegeApproval = {
    386374
    387         if(!Task.exists(params.id)) {
    388             flash.message = "Task not found with id ${params.id}."
    389             redirect(action: 'search')
    390         }
    391 
    392375        def result = taskService.renegeApproval(params)
    393376
    394377        if(!result.error) {
    395378                flash.message = "Task ${params.id} has had approval removed."
    396                 redirect(action: 'show', id: result.taskInstance.id)
    397         }
    398         else {
    399             if(result.taskInstance) {
    400                 render(view:'edit',model:[taskInstance:result.taskInstance])
    401             }
    402             else {
    403                 flash.message = "Task could not be updated."
    404                 redirect(action: 'search')
    405             }
    406         }
     379                redirect(action: show, id: params.id)
     380                return
     381        }
     382
     383        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     384
     385        if(result.taskInstance)
     386            redirect(action: show, id: params.id)
     387        else
     388            redirect(action: 'search')
    407389
    408390    }
     
    411393    def complete = {
    412394
    413         if(!Task.exists(params.id)) {
    414             flash.message = "Task not found with id ${params.id}."
    415             redirect(action: 'search')
    416         }
    417 
    418395        def result = taskService.complete(params)
    419396
    420397        if(!result.error) {
    421398                flash.message = "Task ${params.id} has been completed."
    422                 redirect(action: 'show', id: result.taskInstance.id)
    423         }
    424         else {
    425             if(result.taskInstance) {
    426                 render(view:'edit',model:[taskInstance:result.taskInstance])
    427             }
    428             else {
    429                 flash.message = "Task could not be updated."
    430                 redirect(action: 'search')
    431             }
    432         }
     399                redirect(action: show, id: params.id)
     400                return
     401        }
     402
     403        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     404
     405        if(result.taskInstance)
     406            redirect(action: show, id: params.id)
     407        else
     408            redirect(action: 'search')
     409
     410    }
     411
     412    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
     413    def setAttentionFlag = {
     414
     415        def result = taskService.setAttentionFlag(params)
     416
     417        if(!result.error) {
     418                flash.message = "Task ${params.id} has been flagged for attention."
     419                redirect(action: show, id: params.id)
     420                return
     421        }
     422
     423        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     424
     425        if(result.taskInstance)
     426            redirect(action: show, id: params.id)
     427        else
     428            redirect(action: 'search')
     429
     430    }
     431
     432    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
     433    def clearAttentionFlag = {
     434
     435        def result = taskService.clearAttentionFlag(params)
     436
     437        if(!result.error) {
     438                flash.message = "Task ${params.id} attention flag cleared."
     439                redirect(action: show, id: params.id)
     440                return
     441        }
     442
     443        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     444
     445        if(result.taskInstance)
     446            redirect(action: show, id: params.id)
     447        else
     448            redirect(action: 'search')
    433449
    434450    }
     
    437453    def reopen = {
    438454
    439         if(!Task.exists(params.id)) {
    440             flash.message = "Task not found with id ${params.id}."
    441             redirect(action: 'search')
    442         }
    443 
    444455        def result = taskService.reopen(params)
    445456
    446457        if(!result.error) {
    447458                flash.message = "Task ${params.id} has been reopened."
    448                 redirect(action: 'show', id: result.taskInstance.id)
    449         }
    450         else {
    451             if(result.taskInstance) {
    452                 render(view:'edit',model:[taskInstance:result.taskInstance])
    453             }
    454             else {
    455                 flash.message = "Task could not be updated."
    456                 redirect(action: 'search')
    457             }
    458         }
     459                redirect(action: show, id: params.id)
     460                return
     461        }
     462
     463        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     464
     465        if(result.taskInstance)
     466            redirect(action: show, id: params.id)
     467        else
     468            redirect(action: 'search')
    459469
    460470    }
     
    488498    def update = {
    489499
    490         if(!Task.exists(params.id)) {
    491             flash.message = "Task not found with id ${params.id}"
    492             redirect(action: 'search')
    493         }
    494 
    495500        def result = taskService.update(params)
    496501
    497502        if(!result.error) {
    498503                flash.message = "Task ${params.id} updated"
    499                 redirect(action: 'show', id: result.taskInstance.id)
    500         }
    501         else {
    502             render(view:'edit',model:[taskInstance:result.taskInstance.attach()])
    503         }
     504                redirect(action: show, id: params.id)
     505                return
     506        }
     507
     508        if(result.error.code == "task.modifications.failedToSave")
     509            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     510
     511        render(view:'edit',model:[taskInstance:result.taskInstance.attach()])
    504512
    505513    }
     
    526534            flash.message = "Task ${result.taskInstance.id} created."
    527535            redirect(action: 'show', id: result.taskInstance.id)
    528         }
    529         else {
    530             if(result.taskInstance) {
    531                 render(view:'create', model:[taskInstance:result.taskInstance])
    532             }
    533             else {
    534                 flash.message = "Could not create task."
    535                 redirect(action: 'search')
    536             }
    537 
    538         }
     536            return
     537        }
     538
     539        if(result.error.code == "task.modifications.failedToSave")
     540            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     541
     542        render(view:'create', model:[taskInstance:result.taskInstance])
    539543    }
    540544
     
    571575            else {
    572576                if(result.taskInstance.errors.hasFieldErrors("parentTask")) {
    573                     flash.message = g.message(code:"task.operationNotPermittedOnTaskInTrash")
     577                    flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash")
    574578                    redirect(action: 'show', id:  parentTaskInstance.id)
    575579                }
     
    587591
    588592    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
    589     def createBreakin = {
     593    def createImmediateCallout = {
    590594        def taskInstance = new Task()
    591595
    592596        def entryFaultInstance = new Entry(entryType: EntryType.get(1))  // Fault.
    593         def entryWorkDoneInstance = new Entry(entryType: EntryType.get(2))  // Work Done.
     597        def entryCauseInstance = new Entry(entryType: EntryType.get(2))  // Cause.
     598        def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3))  // Work Done.
    594599
    595600        return ['taskInstance': taskInstance,
    596601                        'entryFaultInstance': entryFaultInstance,
     602                        'entryCauseInstance': entryCauseInstance,
    597603                        'entryWorkDoneInstance': entryWorkDoneInstance]
    598604    }
    599605
    600606    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
    601     def saveBreakin = {
    602         def result = taskService.saveBreakin(params)
     607    def saveImmediateCallout = {
     608        def result = taskService.saveImmediateCallout(params)
    603609
    604610        if(!result.error) {
     
    611617            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
    612618
    613         render(view:'createBreakin',
     619        render(view:'createImmediateCallout',
    614620                    model: ['taskInstance': result.taskInstance,
    615621                                'entryFaultInstance': result.entryFaultInstance,
     622                                'entryCauseInstance': result.entryCauseInstance,
    616623                                'entryWorkDoneInstance': result.entryWorkDoneInstance])
    617624
Note: See TracChangeset for help on using the changeset viewer.