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

Last change on this file since 928 was 913, checked in by gav, 14 years ago

Svn merge -r875:r911 branches/features/grailsUpgrade/ into trunk/.

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