source: trunk/grails-app/controllers/TaskProcedureDetailedController.groovy @ 880

Last change on this file since 880 was 813, checked in by gav, 14 years ago

Remove inadvertantly commited action on TaskProcedure controller.

File size: 6.7 KB
RevLine 
[133]1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
[298]3@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager'])
[133]4class TaskProcedureDetailedController extends BaseController {
[147]5
[155]6    def filterService
[798]7    def assetService
8    def taskProcedureService
[155]9
[133]10    def index = { redirect(action:list,params:params) }
11
12    // the delete, save and update actions only accept POST requests
13    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
14
[298]15    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[133]16    def list = {
17        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
[147]18
19        if(!params.filter)
20        { return [taskProcedureInstanceList: TaskProcedure.list(params), taskProcedureInstanceTotal: TaskProcedure.count()] }
21
22        // filterPane:
23        return[ taskProcedureInstanceList: filterService.filter( params, TaskProcedure ),
24            taskProcedureInstanceTotal: filterService.count( params, TaskProcedure ),
25            filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params),
26            params:params ]
[133]27    }
[147]28
[298]29    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[134]30    def search = {
31        redirect(action:list)
32    }
[133]33
[298]34    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
[133]35    def show = {
[147]36
37        // In the case of an actionSubmit button, rewrite action name from 'index'.
38        if(params._action_Show)
[375]39            params.action='show'
[147]40
[133]41        def taskProcedureInstance = TaskProcedure.get( params.id )
42
43        if(!taskProcedureInstance) {
[798]44            flash.errorMessage = "TaskProcedure not found with id ${params.id}"
[809]45            redirect(action:'list')
[798]46            return
[133]47        }
[798]48
[809]49        def taskProcedureRevision
50        if(params.revision?.toInteger())
51             taskProcedureRevision = taskProcedureInstance.getRevision( params.revision )
52        else
53             taskProcedureRevision = taskProcedureInstance.latestRevision
[133]54
[809]55        if(!taskProcedureRevision) {
56            flash.errorMessage = "TaskProcedure ${params.id} revision ${params.revision} not found"
57            redirect(action:'list')
58            return
[133]59        }
[809]60
61        return [taskProcedureRevision: taskProcedureRevision]
62
[133]63    }
64
65    def edit = {
[147]66
67        // In the case of an actionSubmit button, rewrite action name from 'index'.
[809]68        //if(params._action_Edit)
[375]69            params.action='edit'
[147]70
[133]71        def taskProcedureInstance = TaskProcedure.get( params.id )
72
73        if(!taskProcedureInstance) {
[798]74            flash.errorMessage = "TaskProcedure not found with id ${params.id}"
[133]75            redirect(action:list)
76        }
77        else {
[798]78            def assemblies = assetService.getAssemblies(taskProcedureInstance.linkedTask.primaryAsset)
79            return [ taskProcedureInstance : taskProcedureInstance,
80                            assemblies: assemblies ]
[133]81        }
82    }
83
84    def update = {
[798]85        def result = taskProcedureService.update(params)
[147]86
[798]87        if(!result.error) {
88            flash.message = g.message(code: "default.update.success", args: ["TaskProcedure", params.id])
[809]89            redirect(action:'show', id:result.taskProcedureInstance.id)
[798]90            return
[133]91        }
[798]92
93        if(result.error.code == "default.not.found") {
94            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
[365]95            redirect(action:list)
[798]96            return
[133]97        }
[798]98
99        if(result.error.code == "default.optimistic.locking.failure") {
100            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
[809]101            redirect(action:'show', id:result.taskProcedureInstance.id)
[798]102            return
103        }
104
105        def assemblies = assetService.getAssemblies(result.taskProcedureInstance.linkedTask.primaryAsset)
106        render(view:'edit', model:[taskProcedureInstance: result.taskProcedureInstance,
107                                                assemblies: assemblies])
[133]108    }
109
110    def create = {
[147]111
[798]112        if(!params.taskInstance?.id) {
113            flash.errorMessage = "Please select or create a task, then go to the Procedure tab."
[155]114            redirect(controller:"taskDetailed", action:"search")
[798]115            return
[147]116        }
[798]117
118        params.linkedTask = Task.get(params.taskInstance.id)
119
120        // Task already has a taskProcedure.
[809]121        if(params.linkedTask.taskProcedureRevision) {
[798]122            flash.errorMessage = g.message(code: 'default.optimistic.locking.failure')
123            redirect(controller:'taskDetailed',
124                            action:'show',
125                            id:params.linkedTask.id,
126                            params:[showTab:"showProcedureTab"])
127            return
128        }
129
130        // Task does not have a primaryAsset.
131        if(!params.linkedTask?.primaryAsset) {
132            flash.errorMessage = "Please set a Primary Asset first, then go to the Procedure tab."
133            redirect(controller:"taskDetailed", action:"show", id:params.linkedTask?.id)
134            return
135        }
136
137        def taskProcedureInstance = new TaskProcedure()
138        taskProcedureInstance.properties = params
139
140        // Populate a couple of maintenanceActions for the first assembly.
141        def assemblies = assetService.getAssemblies(params.linkedTask.primaryAsset)
142        if(assemblies) {
143            def assembly = assemblies[0]
144            def ma = taskProcedureInstance.maintenanceActionLazyList.get(0)
145            ma.assetSubItem = assembly
146            ma.procedureStepNumber = 10
147            ma = taskProcedureInstance.maintenanceActionLazyList.get(1)
148            ma.assetSubItem = assembly
149            ma.procedureStepNumber = 20
150        }
151
152        return ['taskProcedureInstance':taskProcedureInstance, 'assemblies': assemblies]
[133]153    }
154
155    def save = {
[798]156        def result = taskProcedureService.save(params)
[147]157
[798]158        if(!result.error) {
159            flash.message = g.message(code: "default.create.success", args: ["TaskProcedure", result.taskProcedureInstance.id])
[809]160            redirect(action:'show', id:result.taskProcedureInstance.id)
[798]161            return
[133]162        }
[798]163
[809]164        // Task already has a taskProcedure.
[798]165        if(result.error.code == "default.optimistic.locking.failure") {
166            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
167            redirect(controller:'taskDetailed',
168                            action:'show',
[809]169                            id:params.linkedTask.id,
[798]170                            params:[showTab:"showProcedureTab"])
171            return
[133]172        }
[798]173
174        def assemblies = assetService.getAssemblies(result.taskProcedureInstance.linkedTask.primaryAsset)
175        render(view:'create', model:[taskProcedureInstance: result.taskProcedureInstance,
176                                                    assemblies: assemblies])
[133]177    }
[798]178
[133]179}
Note: See TracBrowser for help on using the repository browser.