1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | |
---|
3 | class TaskDetailedController extends BaseController { |
---|
4 | |
---|
5 | def authenticateService |
---|
6 | def dateUtilService |
---|
7 | def taskSearchService |
---|
8 | def filterService |
---|
9 | |
---|
10 | // the delete, save and update actions only accept POST requests |
---|
11 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
12 | |
---|
13 | def index = { redirect(action:search,params:params) } |
---|
14 | |
---|
15 | def list = { |
---|
16 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
17 | [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ] |
---|
18 | } |
---|
19 | |
---|
20 | def search = { |
---|
21 | // println params |
---|
22 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
23 | |
---|
24 | // Quick Search: |
---|
25 | if(!params.filter) |
---|
26 | { |
---|
27 | def taskInstanceList = [] |
---|
28 | def personInstance = Person.get(authenticateService.userDomain().id) |
---|
29 | |
---|
30 | if(params.quickSearch == "searchMyTodays") { |
---|
31 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
32 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
33 | else { params.message = "No tasks found for today." } |
---|
34 | } |
---|
35 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
36 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
37 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
38 | else { params.message = "No tasks found for today." } |
---|
39 | } |
---|
40 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
41 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
42 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
43 | else { params.message = "No tasks found for today." } |
---|
44 | } |
---|
45 | else { |
---|
46 | //Default: |
---|
47 | taskInstanceList = taskSearchService.getTodays(params) |
---|
48 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
49 | else { params.message = "No tasks found for today." } |
---|
50 | params.quickSearch = "searchTodays" |
---|
51 | } |
---|
52 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
53 | } |
---|
54 | // filterPane: |
---|
55 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
56 | taskInstanceTotal: filterService.count( params, Task ), |
---|
57 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
58 | params:params ] |
---|
59 | } |
---|
60 | |
---|
61 | def searchCalendar = { |
---|
62 | // println params |
---|
63 | params.max = 30 |
---|
64 | |
---|
65 | // Quick Search: |
---|
66 | if(!params.filter) |
---|
67 | { |
---|
68 | def taskInstanceList = [] |
---|
69 | def personInstance = Person.get(authenticateService.userDomain().id) |
---|
70 | |
---|
71 | if(params.quickSearch == "searchMyTodays") { |
---|
72 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
73 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
74 | else { params.message = "No tasks found for today." } |
---|
75 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
76 | } |
---|
77 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
78 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
79 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
80 | else { params.message = "No tasks found for today." } |
---|
81 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
82 | } |
---|
83 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
84 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
85 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
86 | else { params.message = "No tasks found for today." } |
---|
87 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
88 | } |
---|
89 | else { |
---|
90 | //Default: |
---|
91 | taskInstanceList = taskSearchService.getTodays(params) |
---|
92 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
93 | else { params.message = "No tasks found for today." } |
---|
94 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
95 | params.quickSearch = "searchTodays" |
---|
96 | } |
---|
97 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
98 | } |
---|
99 | // filterPane: |
---|
100 | def taskInstanceTotal = filterService.count( params, Task ) |
---|
101 | if(taskInstanceTotal > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
102 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
103 | taskInstanceTotal: taskInstanceTotal, |
---|
104 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
105 | params:params ] |
---|
106 | } |
---|
107 | |
---|
108 | def show = { |
---|
109 | |
---|
110 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
111 | if(params._action_Show) |
---|
112 | { params.action='show' } |
---|
113 | |
---|
114 | def taskInstance = Task.get( params.id ) |
---|
115 | |
---|
116 | if(!taskInstance) { |
---|
117 | flash.message = "Task not found with id ${params.id}" |
---|
118 | redirect(action:search) |
---|
119 | } |
---|
120 | else { |
---|
121 | params.max = 10 |
---|
122 | params.order = "desc" |
---|
123 | params.sort = "id" |
---|
124 | |
---|
125 | def entryWorkDoneList = Entry.withCriteria { |
---|
126 | def entryType = EntryType.findByName("WorkDone") |
---|
127 | eq("entryType", entryType) |
---|
128 | eq("task", taskInstance) |
---|
129 | } |
---|
130 | |
---|
131 | def entryFaultList = Entry.withCriteria { |
---|
132 | def entryType = EntryType.findByName("Fault") |
---|
133 | eq("entryType", entryType) |
---|
134 | eq("task", taskInstance) |
---|
135 | } |
---|
136 | |
---|
137 | def subTaskInstanceList = Task.findAllByParentTask(taskInstance, params) |
---|
138 | def subTaskInstanceTotal = Task.countByParentTask(taskInstance) |
---|
139 | def showTaskTab = new String("true") |
---|
140 | |
---|
141 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
142 | def taskProcedureExits = new Boolean("true") |
---|
143 | if(!taskProcedureInstance) { |
---|
144 | taskProcedureExits = false |
---|
145 | } |
---|
146 | // else { |
---|
147 | params.order = "asc" |
---|
148 | params.sort = "procedureStepNumber" |
---|
149 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
150 | // } |
---|
151 | |
---|
152 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
153 | def taskRecurringScheduleExits= new Boolean("true") |
---|
154 | if(!taskRecurringScheduleInstance) { |
---|
155 | taskRecurringScheduleExits = false |
---|
156 | } |
---|
157 | |
---|
158 | return [ taskInstance: taskInstance, |
---|
159 | entryWorkDoneList: entryWorkDoneList, |
---|
160 | entryFaultList: entryFaultList, |
---|
161 | taskProcedureInstance: taskProcedureInstance, |
---|
162 | taskProcedureExits: taskProcedureExits, |
---|
163 | showTaskTab: showTaskTab, |
---|
164 | subTaskInstanceList: subTaskInstanceList, |
---|
165 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
166 | subTaskInstanceMax: params.max, |
---|
167 | maintenanceActionList: maintenanceActionList, |
---|
168 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
169 | taskRecurringScheduleExits: taskRecurringScheduleExits] |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | def delete = { |
---|
174 | def taskInstance = Task.get( params.id ) |
---|
175 | if(taskInstance) { |
---|
176 | try { |
---|
177 | taskInstance.isActive = false |
---|
178 | flash.message = "Task ${params.id} has been set to inactive." |
---|
179 | redirect(action:search) |
---|
180 | } |
---|
181 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
182 | flash.message = "Task ${params.id} could not be deleted" |
---|
183 | redirect(action:show,id:params.id) |
---|
184 | } |
---|
185 | } |
---|
186 | else { |
---|
187 | flash.message = "Task not found with id ${params.id}" |
---|
188 | redirect(action:search) |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | def edit = { |
---|
193 | |
---|
194 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
195 | if(params._action_Edit) |
---|
196 | { params.action='edit' } |
---|
197 | |
---|
198 | def taskInstance = Task.get( params.id ) |
---|
199 | |
---|
200 | if(!taskInstance) { |
---|
201 | flash.message = "Task not found with id ${params.id}" |
---|
202 | redirect(action:search) |
---|
203 | } |
---|
204 | else { |
---|
205 | def criteria = taskInstance.createCriteria() |
---|
206 | def result = criteria { |
---|
207 | and { |
---|
208 | notEqual('id', taskInstance.id) |
---|
209 | } |
---|
210 | } |
---|
211 | return [ taskInstance : taskInstance, possibleParentList: result ] |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | def update = { |
---|
216 | def taskInstance = Task.get( params.id ) |
---|
217 | if(taskInstance) { |
---|
218 | if(params.version) { |
---|
219 | def version = params.version.toLong() |
---|
220 | if(taskInstance.version > version) { |
---|
221 | |
---|
222 | taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.") |
---|
223 | render(view:'edit',model:[taskInstance:taskInstance]) |
---|
224 | return |
---|
225 | } |
---|
226 | } |
---|
227 | taskInstance.properties = params |
---|
228 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
229 | flash.message = "Task ${params.id} updated" |
---|
230 | redirect(action:show,id:taskInstance.id) |
---|
231 | } |
---|
232 | else { |
---|
233 | render(view:'edit',model:[taskInstance:taskInstance]) |
---|
234 | } |
---|
235 | } |
---|
236 | else { |
---|
237 | flash.message = "Task not found with id ${params.id}" |
---|
238 | redirect(action:edit,id:params.id) |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | def create = { |
---|
243 | def taskInstance = new Task() |
---|
244 | taskInstance.properties = params |
---|
245 | return ['taskInstance':taskInstance] |
---|
246 | } |
---|
247 | |
---|
248 | def save = { |
---|
249 | def taskInstance = new Task(params) |
---|
250 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
251 | flash.message = "Task ${taskInstance.id} created" |
---|
252 | redirect(action:show,id:taskInstance.id) |
---|
253 | } |
---|
254 | else { |
---|
255 | render(view:'create',model:[taskInstance:taskInstance]) |
---|
256 | } |
---|
257 | } |
---|
258 | |
---|
259 | def listSubTasks = { |
---|
260 | def parentTaskInstance = Task.get(params.id) |
---|
261 | |
---|
262 | if(!parentTaskInstance) { |
---|
263 | flash.message = "Task not found with id ${params.id}" |
---|
264 | redirect(action:search) |
---|
265 | } |
---|
266 | else { |
---|
267 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
268 | def subTaskInstanceList = Task.findAllByParentTask(parentTaskInstance, params) |
---|
269 | def subTaskInstanceTotal = Task.countByParentTask(parentTaskInstance) |
---|
270 | |
---|
271 | [ taskInstanceList: subTaskInstanceList, |
---|
272 | taskInstanceTotal: subTaskInstanceTotal, |
---|
273 | parentTaskInstance: parentTaskInstance] |
---|
274 | } |
---|
275 | } |
---|
276 | |
---|
277 | } |
---|