Ignore:
Timestamp:
Nov 4, 2009, 2:47:47 PM (15 years ago)
Author:
gav
Message:

Add support for taskModification audit/change log, the create and update modifications are complete.
Moved create and update of tasks to taskService.
Small Assset domain class adjustment to prevent blank asset name.
Removed "static scope = 'request'" from services since I don't believe it is required and it limits where the service may be used.

File:
1 edited

Legend:

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

    r179 r180  
    66    def authenticateService
    77    def dateUtilService
     8    def taskService
    89    def taskSearchService
    910    def filterService
     
    186187
    187188            def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0])
     189
     190            def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0])
    188191
    189192            def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id)
     
    215218                            taskRecurringScheduleInstance: taskRecurringScheduleInstance,
    216219                            taskRecurringScheduleExits: taskRecurringScheduleExits,
    217                             inventoryMovementList: inventoryMovementList]
     220                            inventoryMovementList: inventoryMovementList,
     221                            taskModificationList: taskModificationList]
    218222        }
    219223    }
     
    263267
    264268    def update = {
    265         def taskInstance = Task.get( params.id )
    266         if(taskInstance) {
    267             if(params.version) {
    268                 def version = params.version.toLong()
    269                 if(taskInstance.version > version) {
    270 
    271                     taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
    272                     render(view:'edit',model:[taskInstance:taskInstance])
    273                     return
    274                 }
    275             }
    276             taskInstance.properties = params
    277             if(!taskInstance.hasErrors() && taskInstance.save(flush: true)) {
     269
     270        if(!Task.exists(params.id)) {
     271            flash.message = "Task not found with id ${params.id}"
     272            redirect(action:'search')
     273        }
     274
     275        def result = taskService.update(params)
     276
     277        if(!result.error) {
    278278                flash.message = "Task ${params.id} updated"
    279                 redirect(action:show,id:taskInstance.id)
    280             }
    281             else {
    282                 render(view:'edit',model:[taskInstance:taskInstance])
    283             }
    284         }
    285         else {
    286             flash.message = "Task not found with id ${params.id}"
    287             redirect(action:edit,id:params.id)
    288         }
    289     }
     279                redirect(action:show,id:result.taskInstance.id)
     280        }
     281        else {
     282            if(result.taskInstance) {
     283                render(view:'edit',model:[taskInstance:result.taskInstance])
     284            }
     285            else {
     286                flash.message = "Task could not be updated."
     287                redirect(action:'search')
     288            }
     289        }
     290
     291    }
     292
     293//     def update = {
     294//         def taskInstance = Task.get( params.id )
     295//         if(taskInstance) {
     296//             if(params.version) {
     297//                 def version = params.version.toLong()
     298//                 if(taskInstance.version > version) {
     299//
     300//                     taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
     301//                     render(view:'edit',model:[taskInstance:taskInstance])
     302//                     return
     303//                 }
     304//             }
     305//             taskInstance.properties = params
     306//             if(!taskInstance.hasErrors() && taskInstance.save(flush: true)) {
     307//                 flash.message = "Task ${params.id} updated"
     308//                 redirect(action:show,id:taskInstance.id)
     309//             }
     310//             else {
     311//                 render(view:'edit',model:[taskInstance:taskInstance])
     312//             }
     313//         }
     314//         else {
     315//             flash.message = "Task not found with id ${params.id}"
     316//             redirect(action:edit,id:params.id)
     317//         }
     318//     }
    290319
    291320    def create = {
     
    296325
    297326    def save = {
    298         def taskInstance = new Task(params)
    299         if(!taskInstance.hasErrors() && taskInstance.save(flush: true)) {
    300             flash.message = "Task ${taskInstance.id} created"
    301             redirect(action:show,id:taskInstance.id)
    302         }
    303         else {
    304             render(view:'create',model:[taskInstance:taskInstance])
     327        def result = taskService.create(params)
     328
     329        if(!result.error) {
     330            flash.message = "Task ${result.taskInstance.id} created."
     331            redirect(action: show,id: result.taskInstance.id)
     332        }
     333        else {
     334            if(result.taskInstance) {
     335                render(view:'create',model:[taskInstance:result.taskInstance])
     336            }
     337            else {
     338                flash.message = "Could not create task."
     339                redirect(action:"search")
     340            }
     341
    305342        }
    306343    }
Note: See TracChangeset for help on using the changeset viewer.