[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 |
---|
[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}" |
---|
| 45 | redirect(controller:'taskDetailed', action:'search') |
---|
| 46 | return |
---|
[133] | 47 | } |
---|
[798] | 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) { |
---|
[798] | 58 | def taskInstance = taskProcedureInstance.linkedTask |
---|
[133] | 59 | try { |
---|
[798] | 60 | taskProcedureInstance.tasks.each { |
---|
| 61 | it.taskProcedure = null |
---|
| 62 | } |
---|
[365] | 63 | taskProcedureInstance.delete(flush:true) |
---|
[133] | 64 | flash.message = "TaskProcedure ${params.id} deleted" |
---|
[798] | 65 | redirect(controller:'taskDetailed', |
---|
| 66 | action:'show', |
---|
| 67 | id:taskInstance.id, |
---|
| 68 | params:[showTab:"showProcedureTab"]) |
---|
[133] | 69 | } |
---|
| 70 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
[798] | 71 | flash.errorMessage = "TaskProcedure ${params.id} could not be deleted" |
---|
| 72 | redirect(controller:'taskDetailed', |
---|
| 73 | action:'show', |
---|
| 74 | id:taskInstance.id, |
---|
| 75 | params:[showTab:"showProcedureTab"]) |
---|
[133] | 76 | } |
---|
| 77 | } |
---|
| 78 | else { |
---|
[798] | 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) { |
---|
[798] | 93 | flash.errorMessage = "TaskProcedure not found with id ${params.id}" |
---|
[133] | 94 | redirect(action:list) |
---|
| 95 | } |
---|
| 96 | else { |
---|
[798] | 97 | def assemblies = assetService.getAssemblies(taskProcedureInstance.linkedTask.primaryAsset) |
---|
| 98 | return [ taskProcedureInstance : taskProcedureInstance, |
---|
| 99 | assemblies: assemblies ] |
---|
[133] | 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | def update = { |
---|
[798] | 104 | def result = taskProcedureService.update(params) |
---|
[147] | 105 | |
---|
[798] | 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 |
---|
[133] | 113 | } |
---|
[798] | 114 | |
---|
| 115 | if(result.error.code == "default.not.found") { |
---|
| 116 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
[365] | 117 | redirect(action:list) |
---|
[798] | 118 | return |
---|
[133] | 119 | } |
---|
[798] | 120 | |
---|
| 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 | |
---|
| 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 | |
---|
[798] | 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") |
---|
[798] | 140 | return |
---|
[147] | 141 | } |
---|
[798] | 142 | |
---|
| 143 | params.linkedTask = Task.get(params.taskInstance.id) |
---|
| 144 | |
---|
| 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. |
---|
| 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 |
---|
| 164 | |
---|
| 165 | // Populate a couple of maintenanceActions for the first assembly. |
---|
| 166 | def assemblies = assetService.getAssemblies(params.linkedTask.primaryAsset) |
---|
| 167 | if(assemblies) { |
---|
| 168 | def assembly = assemblies[0] |
---|
| 169 | def ma = taskProcedureInstance.maintenanceActionLazyList.get(0) |
---|
| 170 | ma.assetSubItem = assembly |
---|
| 171 | ma.procedureStepNumber = 10 |
---|
| 172 | ma = taskProcedureInstance.maintenanceActionLazyList.get(1) |
---|
| 173 | ma.assetSubItem = assembly |
---|
| 174 | ma.procedureStepNumber = 20 |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | return ['taskProcedureInstance':taskProcedureInstance, 'assemblies': assemblies] |
---|
[133] | 178 | } |
---|
| 179 | |
---|
| 180 | def save = { |
---|
[798] | 181 | def result = taskProcedureService.save(params) |
---|
[147] | 182 | |
---|
[798] | 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 |
---|
[133] | 190 | } |
---|
[798] | 191 | |
---|
| 192 | if(result.error.code == "default.optimistic.locking.failure") { |
---|
| 193 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 194 | redirect(controller:'taskDetailed', |
---|
| 195 | action:'show', |
---|
| 196 | id:result.taskProcedureInstance.linkedTask.id, |
---|
| 197 | params:[showTab:"showProcedureTab"]) |
---|
| 198 | return |
---|
[133] | 199 | } |
---|
[798] | 200 | |
---|
| 201 | def assemblies = assetService.getAssemblies(result.taskProcedureInstance.linkedTask.primaryAsset) |
---|
| 202 | render(view:'create', model:[taskProcedureInstance: result.taskProcedureInstance, |
---|
| 203 | assemblies: assemblies]) |
---|
[133] | 204 | } |
---|
[798] | 205 | |
---|
[133] | 206 | } |
---|