[133] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
[298] | 3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[133] | 4 | class TaskProcedureDetailedController extends BaseController { |
---|
[147] | 5 | |
---|
[155] | 6 | def filterService |
---|
[776] | 7 | def assetService |
---|
[774] | 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) { |
---|
[770] | 44 | flash.errorMessage = "TaskProcedure not found with id ${params.id}" |
---|
| 45 | redirect(controller:'taskDetailed', action:'search') |
---|
| 46 | return |
---|
[133] | 47 | } |
---|
[770] | 48 | |
---|
| 49 | redirect(controller:'taskDetailed', |
---|
| 50 | action:'show', |
---|
| 51 | id:taskProcedureInstance.linkedTask?.id, |
---|
| 52 | params:[showTab:"showProcedureTab"]) |
---|
[133] | 53 | } |
---|
| 54 | |
---|
| 55 | def delete = { |
---|
| 56 | def taskProcedureInstance = TaskProcedure.get( params.id ) |
---|
| 57 | if(taskProcedureInstance) { |
---|
[770] | 58 | def taskInstance = taskProcedureInstance.linkedTask |
---|
[133] | 59 | try { |
---|
[758] | 60 | taskProcedureInstance.tasks.each { |
---|
| 61 | it.taskProcedure = null |
---|
| 62 | } |
---|
[365] | 63 | taskProcedureInstance.delete(flush:true) |
---|
[133] | 64 | flash.message = "TaskProcedure ${params.id} deleted" |
---|
[770] | 65 | redirect(controller:'taskDetailed', |
---|
| 66 | action:'show', |
---|
| 67 | id:taskInstance.id, |
---|
| 68 | params:[showTab:"showProcedureTab"]) |
---|
[133] | 69 | } |
---|
| 70 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
[775] | 71 | flash.errorMessage = "TaskProcedure ${params.id} could not be deleted" |
---|
[770] | 72 | redirect(controller:'taskDetailed', |
---|
| 73 | action:'show', |
---|
| 74 | id:taskInstance.id, |
---|
| 75 | params:[showTab:"showProcedureTab"]) |
---|
[133] | 76 | } |
---|
| 77 | } |
---|
| 78 | else { |
---|
[775] | 79 | flash.errorMessage = "TaskProcedure not found with id ${params.id}" |
---|
[133] | 80 | redirect(action:list) |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | def edit = { |
---|
[147] | 85 | |
---|
| 86 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 87 | if(params._action_Edit) |
---|
[375] | 88 | params.action='edit' |
---|
[147] | 89 | |
---|
[133] | 90 | def taskProcedureInstance = TaskProcedure.get( params.id ) |
---|
| 91 | |
---|
| 92 | if(!taskProcedureInstance) { |
---|
[775] | 93 | flash.errorMessage = "TaskProcedure not found with id ${params.id}" |
---|
[133] | 94 | redirect(action:list) |
---|
| 95 | } |
---|
| 96 | else { |
---|
[776] | 97 | def assemblies = assetService.getAssemblies(taskProcedureInstance.linkedTask.primaryAsset) |
---|
| 98 | return [ taskProcedureInstance : taskProcedureInstance, |
---|
| 99 | assemblies: assemblies ] |
---|
[133] | 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | def update = { |
---|
[774] | 104 | def result = taskProcedureService.update(params) |
---|
[147] | 105 | |
---|
[774] | 106 | if(!result.error) { |
---|
| 107 | flash.message = g.message(code: "default.update.success", args: ["TaskProcedure", params.id]) |
---|
| 108 | redirect(controller:'taskDetailed', |
---|
| 109 | action:'show', |
---|
| 110 | id:result.taskProcedureInstance.linkedTask.id, |
---|
| 111 | params:[showTab:"showProcedureTab"]) |
---|
| 112 | return |
---|
| 113 | } |
---|
[760] | 114 | |
---|
[774] | 115 | if(result.error.code == "default.not.found") { |
---|
[775] | 116 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
[365] | 117 | redirect(action:list) |
---|
[774] | 118 | return |
---|
[133] | 119 | } |
---|
[774] | 120 | |
---|
[775] | 121 | if(result.error.code == "default.optimistic.locking.failure") { |
---|
| 122 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 123 | redirect(controller:'taskDetailed', |
---|
| 124 | action:'show', |
---|
| 125 | id:result.taskProcedureInstance.linkedTask.id, |
---|
| 126 | params:[showTab:"showProcedureTab"]) |
---|
| 127 | return |
---|
| 128 | } |
---|
| 129 | |
---|
[776] | 130 | def assemblies = assetService.getAssemblies(result.taskProcedureInstance.linkedTask.primaryAsset) |
---|
| 131 | render(view:'edit', model:[taskProcedureInstance: result.taskProcedureInstance, |
---|
| 132 | assemblies: assemblies]) |
---|
[133] | 133 | } |
---|
| 134 | |
---|
| 135 | def create = { |
---|
[147] | 136 | |
---|
[770] | 137 | if(!params.taskInstance?.id) { |
---|
| 138 | flash.errorMessage = "Please select or create a task, then go to the Procedure tab." |
---|
[155] | 139 | redirect(controller:"taskDetailed", action:"search") |
---|
[770] | 140 | return |
---|
[147] | 141 | } |
---|
[770] | 142 | |
---|
| 143 | params.linkedTask = Task.get(params.taskInstance.id) |
---|
| 144 | |
---|
[775] | 145 | // Task already has a taskProcedure. |
---|
| 146 | if(params.linkedTask.taskProcedure) { |
---|
| 147 | flash.errorMessage = g.message(code: 'default.optimistic.locking.failure') |
---|
| 148 | redirect(controller:'taskDetailed', |
---|
| 149 | action:'show', |
---|
| 150 | id:params.linkedTask.id, |
---|
| 151 | params:[showTab:"showProcedureTab"]) |
---|
| 152 | return |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | // Task does not have a primaryAsset. |
---|
[770] | 156 | if(!params.linkedTask?.primaryAsset) { |
---|
| 157 | flash.errorMessage = "Please set a Primary Asset first, then go to the Procedure tab." |
---|
| 158 | redirect(controller:"taskDetailed", action:"show", id:params.linkedTask?.id) |
---|
| 159 | return |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | def taskProcedureInstance = new TaskProcedure() |
---|
| 163 | taskProcedureInstance.properties = params |
---|
[776] | 164 | |
---|
[789] | 165 | // Populate a couple of maintenanceActions for the first assembly. |
---|
[776] | 166 | def assemblies = assetService.getAssemblies(params.linkedTask.primaryAsset) |
---|
[789] | 167 | if(assemblies) { |
---|
| 168 | def assembly = assemblies[0] |
---|
| 169 | def ma = taskProcedureInstance.maintenanceActionLazyList.get(0) |
---|
[776] | 170 | ma.assetSubItem = assembly |
---|
[789] | 171 | ma.procedureStepNumber = 10 |
---|
| 172 | ma = taskProcedureInstance.maintenanceActionLazyList.get(1) |
---|
| 173 | ma.assetSubItem = assembly |
---|
| 174 | ma.procedureStepNumber = 20 |
---|
[776] | 175 | } |
---|
| 176 | |
---|
| 177 | return ['taskProcedureInstance':taskProcedureInstance, 'assemblies': assemblies] |
---|
[133] | 178 | } |
---|
| 179 | |
---|
| 180 | def save = { |
---|
[775] | 181 | def result = taskProcedureService.save(params) |
---|
[147] | 182 | |
---|
[775] | 183 | if(!result.error) { |
---|
| 184 | flash.message = g.message(code: "default.create.success", args: ["TaskProcedure", result.taskProcedureInstance.id]) |
---|
| 185 | redirect(controller:'taskDetailed', |
---|
| 186 | action:'show', |
---|
| 187 | id:result.taskProcedureInstance.linkedTask.id, |
---|
| 188 | params:[showTab:"showProcedureTab"]) |
---|
| 189 | return |
---|
[770] | 190 | } |
---|
| 191 | |
---|
[775] | 192 | if(result.error.code == "default.optimistic.locking.failure") { |
---|
| 193 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
[770] | 194 | redirect(controller:'taskDetailed', |
---|
| 195 | action:'show', |
---|
[775] | 196 | id:result.taskProcedureInstance.linkedTask.id, |
---|
[770] | 197 | params:[showTab:"showProcedureTab"]) |
---|
[775] | 198 | return |
---|
[133] | 199 | } |
---|
[775] | 200 | |
---|
[776] | 201 | def assemblies = assetService.getAssemblies(result.taskProcedureInstance.linkedTask.primaryAsset) |
---|
| 202 | render(view:'create', model:[taskProcedureInstance: result.taskProcedureInstance, |
---|
| 203 | assemblies: assemblies]) |
---|
[133] | 204 | } |
---|
[770] | 205 | |
---|
[133] | 206 | } |
---|