| 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
|---|
| 2 | |
|---|
| 3 | class TaskDetailedController extends BaseController { |
|---|
| 4 | |
|---|
| 5 | def index = { redirect(action:list,params:params) } |
|---|
| 6 | |
|---|
| 7 | // the delete, save and update actions only accept POST requests |
|---|
| 8 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
|---|
| 9 | |
|---|
| 10 | // def list = { |
|---|
| 11 | // params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
|---|
| 12 | // def taskInstanceActives = Task.findAllByIsActive( true ).list( params ) |
|---|
| 13 | // // def taskInstanceList = taskInstanceActives.list( params ) |
|---|
| 14 | // return [ taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceActives.count() ] |
|---|
| 15 | // } |
|---|
| 16 | |
|---|
| 17 | def list = { |
|---|
| 18 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
|---|
| 19 | [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ] |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | def show = { |
|---|
| 23 | def taskInstance = Task.get( params.id ) |
|---|
| 24 | |
|---|
| 25 | if(!taskInstance) { |
|---|
| 26 | flash.message = "Task not found with id ${params.id}" |
|---|
| 27 | redirect(action:list) |
|---|
| 28 | } |
|---|
| 29 | else { |
|---|
| 30 | params.max = 10 |
|---|
| 31 | params.order = "desc" |
|---|
| 32 | params.sort = "id" |
|---|
| 33 | |
|---|
| 34 | def subTaskInstanceList = Task.findAllByParentTask(taskInstance, params) |
|---|
| 35 | def subTaskInstanceTotal = Task.countByParentTask(taskInstance) |
|---|
| 36 | def showTaskTab = new String("true") |
|---|
| 37 | |
|---|
| 38 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
|---|
| 39 | def taskProcedureExits = new Boolean("true") |
|---|
| 40 | if(!taskProcedureInstance) { |
|---|
| 41 | taskProcedureExits = false |
|---|
| 42 | } |
|---|
| 43 | // else { |
|---|
| 44 | params.order = "asc" |
|---|
| 45 | params.sort = "procedureStepNumber" |
|---|
| 46 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
|---|
| 47 | // } |
|---|
| 48 | |
|---|
| 49 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
|---|
| 50 | def taskRecurringScheduleExits= new Boolean("true") |
|---|
| 51 | if(!taskRecurringScheduleInstance) { |
|---|
| 52 | taskRecurringScheduleExits = false |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | return [ taskInstance : taskInstance, |
|---|
| 56 | taskProcedureInstance: taskProcedureInstance, |
|---|
| 57 | taskProcedureExits: taskProcedureExits, |
|---|
| 58 | showTaskTab: showTaskTab, |
|---|
| 59 | subTaskInstanceList: subTaskInstanceList, |
|---|
| 60 | subTaskInstanceTotal: subTaskInstanceTotal, |
|---|
| 61 | subTaskInstanceMax: params.max, |
|---|
| 62 | maintenanceActionList: maintenanceActionList, |
|---|
| 63 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
|---|
| 64 | taskRecurringScheduleExits: taskRecurringScheduleExits] |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | def delete = { |
|---|
| 69 | def taskInstance = Task.get( params.id ) |
|---|
| 70 | if(taskInstance) { |
|---|
| 71 | try { |
|---|
| 72 | taskInstance.isActive = false |
|---|
| 73 | flash.message = "Task ${params.id} has been set to inactive." |
|---|
| 74 | redirect(action:list) |
|---|
| 75 | } |
|---|
| 76 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
|---|
| 77 | flash.message = "Task ${params.id} could not be deleted" |
|---|
| 78 | redirect(action:show,id:params.id) |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | else { |
|---|
| 82 | flash.message = "Task not found with id ${params.id}" |
|---|
| 83 | redirect(action:list) |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | def edit = { |
|---|
| 88 | def taskInstance = Task.get( params.id ) |
|---|
| 89 | |
|---|
| 90 | if(!taskInstance) { |
|---|
| 91 | flash.message = "Task not found with id ${params.id}" |
|---|
| 92 | redirect(action:list) |
|---|
| 93 | } |
|---|
| 94 | else { |
|---|
| 95 | def criteria = taskInstance.createCriteria() |
|---|
| 96 | def results = criteria { |
|---|
| 97 | and { |
|---|
| 98 | notEqual('id', taskInstance.id) |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | return [ taskInstance : taskInstance, possibleParentList: results ] |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | def update = { |
|---|
| 106 | def taskInstance = Task.get( params.id ) |
|---|
| 107 | if(taskInstance) { |
|---|
| 108 | if(params.version) { |
|---|
| 109 | def version = params.version.toLong() |
|---|
| 110 | if(taskInstance.version > version) { |
|---|
| 111 | |
|---|
| 112 | taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.") |
|---|
| 113 | render(view:'edit',model:[taskInstance:taskInstance]) |
|---|
| 114 | return |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | taskInstance.properties = params |
|---|
| 118 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
|---|
| 119 | flash.message = "Task ${params.id} updated" |
|---|
| 120 | redirect(action:show,id:taskInstance.id) |
|---|
| 121 | } |
|---|
| 122 | else { |
|---|
| 123 | render(view:'edit',model:[taskInstance:taskInstance]) |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | else { |
|---|
| 127 | flash.message = "Task not found with id ${params.id}" |
|---|
| 128 | redirect(action:edit,id:params.id) |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | def create = { |
|---|
| 133 | def taskInstance = new Task() |
|---|
| 134 | taskInstance.properties = params |
|---|
| 135 | return ['taskInstance':taskInstance] |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | def save = { |
|---|
| 139 | def taskInstance = new Task(params) |
|---|
| 140 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
|---|
| 141 | flash.message = "Task ${taskInstance.id} created" |
|---|
| 142 | redirect(action:show,id:taskInstance.id) |
|---|
| 143 | } |
|---|
| 144 | else { |
|---|
| 145 | render(view:'create',model:[taskInstance:taskInstance]) |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | def listSubTasks = { |
|---|
| 150 | def parentTaskInstance = Task.get(params.id) |
|---|
| 151 | |
|---|
| 152 | if(!parentTaskInstance) { |
|---|
| 153 | flash.message = "Task not found with id ${params.id}" |
|---|
| 154 | redirect(action:list) |
|---|
| 155 | } |
|---|
| 156 | else { |
|---|
| 157 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
|---|
| 158 | def subTaskInstanceList = Task.findAllByParentTask(parentTaskInstance, params) |
|---|
| 159 | def subTaskInstanceTotal = Task.countByParentTask(parentTaskInstance) |
|---|
| 160 | |
|---|
| 161 | [ taskInstanceList: subTaskInstanceList, |
|---|
| 162 | taskInstanceTotal: subTaskInstanceTotal, |
|---|
| 163 | parentTaskInstance: parentTaskInstance] |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | } |
|---|