source: branches/features/grailsUpgrade/grails-app/controllers/TaskProcedureDetailedController.groovy @ 885

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

Remove inadvertantly commited action on TaskProcedure controller.

File size: 6.7 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager'])
4class TaskProcedureDetailedController extends BaseController {
5
6    def filterService
7    def assetService
8    def taskProcedureService
9
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
15    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
16    def list = {
17        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
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 ]
27    }
28
29    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
30    def search = {
31        redirect(action:list)
32    }
33
34    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
35    def show = {
36
37        // In the case of an actionSubmit button, rewrite action name from 'index'.
38        if(params._action_Show)
39            params.action='show'
40
41        def taskProcedureInstance = TaskProcedure.get( params.id )
42
43        if(!taskProcedureInstance) {
44            flash.errorMessage = "TaskProcedure not found with id ${params.id}"
45            redirect(action:'list')
46            return
47        }
48
49        def taskProcedureRevision
50        if(params.revision?.toInteger())
51             taskProcedureRevision = taskProcedureInstance.getRevision( params.revision )
52        else
53             taskProcedureRevision = taskProcedureInstance.latestRevision
54
55        if(!taskProcedureRevision) {
56            flash.errorMessage = "TaskProcedure ${params.id} revision ${params.revision} not found"
57            redirect(action:'list')
58            return
59        }
60
61        return [taskProcedureRevision: taskProcedureRevision]
62
63    }
64
65    def edit = {
66
67        // In the case of an actionSubmit button, rewrite action name from 'index'.
68        //if(params._action_Edit)
69            params.action='edit'
70
71        def taskProcedureInstance = TaskProcedure.get( params.id )
72
73        if(!taskProcedureInstance) {
74            flash.errorMessage = "TaskProcedure not found with id ${params.id}"
75            redirect(action:list)
76        }
77        else {
78            def assemblies = assetService.getAssemblies(taskProcedureInstance.linkedTask.primaryAsset)
79            return [ taskProcedureInstance : taskProcedureInstance,
80                            assemblies: assemblies ]
81        }
82    }
83
84    def update = {
85        def result = taskProcedureService.update(params)
86
87        if(!result.error) {
88            flash.message = g.message(code: "default.update.success", args: ["TaskProcedure", params.id])
89            redirect(action:'show', id:result.taskProcedureInstance.id)
90            return
91        }
92
93        if(result.error.code == "default.not.found") {
94            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
95            redirect(action:list)
96            return
97        }
98
99        if(result.error.code == "default.optimistic.locking.failure") {
100            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
101            redirect(action:'show', id:result.taskProcedureInstance.id)
102            return
103        }
104
105        def assemblies = assetService.getAssemblies(result.taskProcedureInstance.linkedTask.primaryAsset)
106        render(view:'edit', model:[taskProcedureInstance: result.taskProcedureInstance,
107                                                assemblies: assemblies])
108    }
109
110    def create = {
111
112        if(!params.taskInstance?.id) {
113            flash.errorMessage = "Please select or create a task, then go to the Procedure tab."
114            redirect(controller:"taskDetailed", action:"search")
115            return
116        }
117
118        params.linkedTask = Task.get(params.taskInstance.id)
119
120        // Task already has a taskProcedure.
121        if(params.linkedTask.taskProcedureRevision) {
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]
153    }
154
155    def save = {
156        def result = taskProcedureService.save(params)
157
158        if(!result.error) {
159            flash.message = g.message(code: "default.create.success", args: ["TaskProcedure", result.taskProcedureInstance.id])
160            redirect(action:'show', id:result.taskProcedureInstance.id)
161            return
162        }
163
164        // Task already has a taskProcedure.
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',
169                            id:params.linkedTask.id,
170                            params:[showTab:"showProcedureTab"])
171            return
172        }
173
174        def assemblies = assetService.getAssemblies(result.taskProcedureInstance.linkedTask.primaryAsset)
175        render(view:'create', model:[taskProcedureInstance: result.taskProcedureInstance,
176                                                    assemblies: assemblies])
177    }
178
179}
Note: See TracBrowser for help on using the repository browser.