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 | // def taskProcedureInstance = TaskProcedure.get(taskInstance?.taskProcedure?.id) |
---|
31 | // return [ taskInstance : taskInstance, taskProcedureInstance: taskProcedureInstance] |
---|
32 | // |
---|
33 | // } |
---|
34 | // } |
---|
35 | |
---|
36 | def show = { |
---|
37 | def taskInstance = Task.get( params.id ) |
---|
38 | |
---|
39 | if(!taskInstance) { |
---|
40 | flash.message = "Task not found with id ${params.id}" |
---|
41 | redirect(action:list) |
---|
42 | } |
---|
43 | else { |
---|
44 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
45 | def taskProcedureExits = new Boolean("true") |
---|
46 | def showTaskTab = new String("true") |
---|
47 | |
---|
48 | if(!taskProcedureInstance) { |
---|
49 | taskProcedureExits = false |
---|
50 | } |
---|
51 | return [ taskInstance : taskInstance, |
---|
52 | taskProcedureInstance: taskProcedureInstance, |
---|
53 | taskProcedureExits: taskProcedureExits, |
---|
54 | showTaskTab: showTaskTab] |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | def delete = { |
---|
59 | def taskInstance = Task.get( params.id ) |
---|
60 | if(taskInstance) { |
---|
61 | try { |
---|
62 | taskInstance.isActive = false |
---|
63 | flash.message = "Task ${params.id} has been set to inactive." |
---|
64 | redirect(action:list) |
---|
65 | } |
---|
66 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
67 | flash.message = "Task ${params.id} could not be deleted" |
---|
68 | redirect(action:show,id:params.id) |
---|
69 | } |
---|
70 | } |
---|
71 | else { |
---|
72 | flash.message = "Task not found with id ${params.id}" |
---|
73 | redirect(action:list) |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | def edit = { |
---|
78 | def taskInstance = Task.get( params.id ) |
---|
79 | |
---|
80 | if(!taskInstance) { |
---|
81 | flash.message = "Task not found with id ${params.id}" |
---|
82 | redirect(action:list) |
---|
83 | } |
---|
84 | else { |
---|
85 | def criteria = taskInstance.createCriteria() |
---|
86 | def results = criteria { |
---|
87 | and { |
---|
88 | notEqual('id', taskInstance.id) |
---|
89 | } |
---|
90 | } |
---|
91 | return [ taskInstance : taskInstance, possibleParentList: results ] |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | def update = { |
---|
96 | def taskInstance = Task.get( params.id ) |
---|
97 | if(taskInstance) { |
---|
98 | if(params.version) { |
---|
99 | def version = params.version.toLong() |
---|
100 | if(taskInstance.version > version) { |
---|
101 | |
---|
102 | taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.") |
---|
103 | render(view:'edit',model:[taskInstance:taskInstance]) |
---|
104 | return |
---|
105 | } |
---|
106 | } |
---|
107 | taskInstance.properties = params |
---|
108 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
109 | flash.message = "Task ${params.id} updated" |
---|
110 | redirect(action:show,id:taskInstance.id) |
---|
111 | } |
---|
112 | else { |
---|
113 | render(view:'edit',model:[taskInstance:taskInstance]) |
---|
114 | } |
---|
115 | } |
---|
116 | else { |
---|
117 | flash.message = "Task not found with id ${params.id}" |
---|
118 | redirect(action:edit,id:params.id) |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | def create = { |
---|
123 | def taskInstance = new Task() |
---|
124 | taskInstance.properties = params |
---|
125 | return ['taskInstance':taskInstance] |
---|
126 | } |
---|
127 | |
---|
128 | def save = { |
---|
129 | def taskInstance = new Task(params) |
---|
130 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
131 | flash.message = "Task ${taskInstance.id} created" |
---|
132 | redirect(action:show,id:taskInstance.id) |
---|
133 | } |
---|
134 | else { |
---|
135 | render(view:'create',model:[taskInstance:taskInstance]) |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | //Generate a new TaskProcedure for a taskInstance. |
---|
140 | def generateProcedure = { |
---|
141 | def taskProcedureInstance = new TaskProcedure() |
---|
142 | taskProcedureInstance.properties = params |
---|
143 | |
---|
144 | def taskInstance = Task.get(params.taskInstance.id) |
---|
145 | def taskProcedureExits = new Boolean("true") |
---|
146 | def showProcedureTab = new String("true") |
---|
147 | |
---|
148 | if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save()) { |
---|
149 | taskProcedureInstance.addToTasks(taskInstance) |
---|
150 | flash.message = "Procedure created, you can now add steps to the procedure" |
---|
151 | // redirect(action:show, id:params.taskInstance.id) |
---|
152 | } |
---|
153 | else { |
---|
154 | taskProcedureExits = false |
---|
155 | } |
---|
156 | |
---|
157 | render(view:'show',model:[ taskInstance : taskInstance, |
---|
158 | taskProcedureInstance: taskProcedureInstance, |
---|
159 | taskProcedureExits: taskProcedureExits, |
---|
160 | showProcedureTab: showProcedureTab]) |
---|
161 | } |
---|
162 | |
---|
163 | def findProcedure = { |
---|
164 | redirect(controller:"taskProcedureDetailed", action:"list", id:params.taskInstance.id) |
---|
165 | } |
---|
166 | |
---|
167 | } |
---|