1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
3 | |
---|
4 | class TaskDetailedController extends BaseController { |
---|
5 | |
---|
6 | def authenticateService |
---|
7 | def dateUtilService |
---|
8 | def taskService |
---|
9 | def taskSearchService |
---|
10 | def filterService |
---|
11 | def exportService |
---|
12 | |
---|
13 | // these actions only accept POST requests |
---|
14 | static allowedMethods = [save:'POST', update:'POST', restore:'POST', trash:'POST', approve:'POST', renegeApproval:'POST', complete:'POST', reopen:'POST'] |
---|
15 | |
---|
16 | def index = { redirect(action:search,params:params) } |
---|
17 | |
---|
18 | def list = { |
---|
19 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
20 | [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ] |
---|
21 | } |
---|
22 | |
---|
23 | def search = { |
---|
24 | // println params |
---|
25 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
26 | |
---|
27 | // Quick Search: |
---|
28 | if(!params.filter) |
---|
29 | { |
---|
30 | def taskInstanceList = [] |
---|
31 | def personInstance = Person.get(authenticateService.userDomain().id) |
---|
32 | |
---|
33 | if(params.quickSearch == "searchMyTodays") { |
---|
34 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
35 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
36 | else { params.message = "No tasks found for today." } |
---|
37 | } |
---|
38 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
39 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
40 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
41 | else { params.message = "No tasks found for today." } |
---|
42 | } |
---|
43 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
44 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
45 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
46 | else { params.message = "No tasks found for today." } |
---|
47 | } |
---|
48 | else { |
---|
49 | //Default: |
---|
50 | taskInstanceList = taskSearchService.getTodays(params) |
---|
51 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
52 | else { params.message = "No tasks found for today." } |
---|
53 | params.quickSearch = "searchTodays" |
---|
54 | } |
---|
55 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
56 | } |
---|
57 | // filterPane: |
---|
58 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
59 | taskInstanceTotal: filterService.count( params, Task ), |
---|
60 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
61 | params:params ] |
---|
62 | } |
---|
63 | |
---|
64 | def searchCalendar = { |
---|
65 | // println params |
---|
66 | params.max = 30 |
---|
67 | |
---|
68 | // Quick Search: |
---|
69 | if(!params.filter) |
---|
70 | { |
---|
71 | def taskInstanceList = [] |
---|
72 | def personInstance = Person.get(authenticateService.userDomain().id) |
---|
73 | |
---|
74 | if(params.quickSearch == "searchMyTodays") { |
---|
75 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
76 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
77 | else { params.message = "No tasks found for today." } |
---|
78 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
79 | } |
---|
80 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
81 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
82 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
83 | else { params.message = "No tasks found for today." } |
---|
84 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
85 | } |
---|
86 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
87 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
88 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
89 | else { params.message = "No tasks found for today." } |
---|
90 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
91 | } |
---|
92 | else { |
---|
93 | //Default: |
---|
94 | taskInstanceList = taskSearchService.getTodays(params) |
---|
95 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
96 | else { params.message = "No tasks found for today." } |
---|
97 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
98 | params.quickSearch = "searchTodays" |
---|
99 | } |
---|
100 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
101 | } |
---|
102 | // filterPane: |
---|
103 | def taskInstanceTotal = filterService.count( params, Task ) |
---|
104 | if(taskInstanceTotal > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
105 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
106 | taskInstanceTotal: taskInstanceTotal, |
---|
107 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
108 | params:params ] |
---|
109 | } |
---|
110 | |
---|
111 | def budget = { |
---|
112 | // println params |
---|
113 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
114 | |
---|
115 | // Quick Search: |
---|
116 | if(!params.filter) |
---|
117 | { |
---|
118 | def taskInstanceList = [] |
---|
119 | def personInstance = Person.get(authenticateService.userDomain().id) |
---|
120 | |
---|
121 | if(params.quickSearch == "budgetUnplanned") { |
---|
122 | taskInstanceList = taskSearchService.getBudgetUnplanned(params) |
---|
123 | if(taskInstanceList.totalCount > 0) { params.message = "Budget unplanned tasks in the last week." } |
---|
124 | else { params.message = "No tasks found." } |
---|
125 | } |
---|
126 | //else if(params.quickSearch == "budgetPlanned") { |
---|
127 | else { |
---|
128 | //Default: |
---|
129 | taskInstanceList = taskSearchService.getBudgetPlanned(params) |
---|
130 | if(taskInstanceList.totalCount > 0) { params.message = "Budget planned Tasks in the last week." } |
---|
131 | else { params.message = "No tasks found.." } |
---|
132 | } |
---|
133 | // export plugin: |
---|
134 | if(params?.format && params.format != "html") { |
---|
135 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
136 | response.setHeader("Content-disposition", "attachment; filename=tasks.${params.extension}") |
---|
137 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskStatus", "taskType"] |
---|
138 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
139 | "leadPerson": "Lead Person", "taskStatus": "Task Status", "taskType": "Task Type"] |
---|
140 | Map formatters = [:] |
---|
141 | String title = "${params.quickSearch} tasks in the last week." |
---|
142 | Map parameters = [title: title] |
---|
143 | |
---|
144 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
145 | } |
---|
146 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
147 | } |
---|
148 | // filterPane: |
---|
149 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
150 | taskInstanceTotal: filterService.count( params, Task ), |
---|
151 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
152 | params:params ] |
---|
153 | } |
---|
154 | |
---|
155 | def show = { |
---|
156 | |
---|
157 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
158 | if(params._action_Show) |
---|
159 | { params.action='show' } |
---|
160 | |
---|
161 | def taskInstance = Task.get( params.id ) |
---|
162 | |
---|
163 | if(!taskInstance) { |
---|
164 | flash.message = "Task not found with id ${params.id}" |
---|
165 | redirect(action:search) |
---|
166 | } |
---|
167 | else { |
---|
168 | params.max = 10 |
---|
169 | params.order = "desc" |
---|
170 | params.sort = "id" |
---|
171 | |
---|
172 | def entryWorkDoneList = Entry.withCriteria { |
---|
173 | def entryType = EntryType.findByName("WorkDone") |
---|
174 | eq("entryType", entryType) |
---|
175 | eq("task", taskInstance) |
---|
176 | } |
---|
177 | |
---|
178 | def entryFaultList = Entry.withCriteria { |
---|
179 | def entryType = EntryType.findByName("Fault") |
---|
180 | eq("entryType", entryType) |
---|
181 | eq("task", taskInstance) |
---|
182 | } |
---|
183 | |
---|
184 | def subTaskInstanceList = Task.findAllByParentTask(taskInstance, params) |
---|
185 | def subTaskInstanceTotal = Task.countByParentTask(taskInstance) |
---|
186 | def showTaskTab = new String("true") |
---|
187 | |
---|
188 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
189 | |
---|
190 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
191 | |
---|
192 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
193 | def taskProcedureExits = new Boolean("true") |
---|
194 | if(!taskProcedureInstance) { |
---|
195 | taskProcedureExits = false |
---|
196 | } |
---|
197 | |
---|
198 | params.order = "asc" |
---|
199 | params.sort = "procedureStepNumber" |
---|
200 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
201 | |
---|
202 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
203 | def taskRecurringScheduleExits= new Boolean("true") |
---|
204 | if(!taskRecurringScheduleInstance) { |
---|
205 | taskRecurringScheduleExits = false |
---|
206 | } |
---|
207 | |
---|
208 | return [ taskInstance: taskInstance, |
---|
209 | entryWorkDoneList: entryWorkDoneList, |
---|
210 | entryFaultList: entryFaultList, |
---|
211 | taskProcedureInstance: taskProcedureInstance, |
---|
212 | taskProcedureExits: taskProcedureExits, |
---|
213 | showTaskTab: showTaskTab, |
---|
214 | subTaskInstanceList: subTaskInstanceList, |
---|
215 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
216 | subTaskInstanceMax: params.max, |
---|
217 | maintenanceActionList: maintenanceActionList, |
---|
218 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
219 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
220 | inventoryMovementList: inventoryMovementList, |
---|
221 | taskModificationList: taskModificationList] |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | def restore = { |
---|
226 | |
---|
227 | if(!Task.exists(params.id)) { |
---|
228 | flash.message = "Task not found with id ${params.id}" |
---|
229 | redirect(action:'search') |
---|
230 | } |
---|
231 | |
---|
232 | def result = taskService.restore(params) |
---|
233 | |
---|
234 | if(!result.error) { |
---|
235 | flash.message = "Task ${params.id} has been restored." |
---|
236 | redirect(action:show,id:result.taskInstance.id) |
---|
237 | } |
---|
238 | else { |
---|
239 | if(result.taskInstance) { |
---|
240 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
241 | } |
---|
242 | else { |
---|
243 | flash.message = "Task could not be updated." |
---|
244 | redirect(action:'search') |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | } |
---|
249 | |
---|
250 | def trash = { |
---|
251 | |
---|
252 | if(!Task.exists(params.id)) { |
---|
253 | flash.message = "Task not found with id ${params.id}." |
---|
254 | redirect(action:'search') |
---|
255 | } |
---|
256 | |
---|
257 | def result = taskService.trash(params) |
---|
258 | |
---|
259 | if(!result.error) { |
---|
260 | flash.message = "Task ${params.id} has been moved to trash." |
---|
261 | redirect(action:'search') |
---|
262 | } |
---|
263 | else { |
---|
264 | if(result.taskInstance) { |
---|
265 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
266 | } |
---|
267 | else { |
---|
268 | flash.message = "Task could not be updated." |
---|
269 | redirect(action:'search') |
---|
270 | } |
---|
271 | } |
---|
272 | |
---|
273 | } |
---|
274 | |
---|
275 | def approve = { |
---|
276 | |
---|
277 | if(!Task.exists(params.id)) { |
---|
278 | flash.message = "Task not found with id ${params.id}." |
---|
279 | redirect(action:'search') |
---|
280 | } |
---|
281 | |
---|
282 | def result = taskService.approve(params) |
---|
283 | |
---|
284 | if(!result.error) { |
---|
285 | flash.message = "Task ${params.id} has been approved." |
---|
286 | redirect(action:show,id:result.taskInstance.id) |
---|
287 | } |
---|
288 | else { |
---|
289 | if(result.taskInstance) { |
---|
290 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
291 | } |
---|
292 | else { |
---|
293 | flash.message = "Task could not be updated." |
---|
294 | redirect(action:'search') |
---|
295 | } |
---|
296 | } |
---|
297 | |
---|
298 | } |
---|
299 | |
---|
300 | def renegeApproval = { |
---|
301 | |
---|
302 | if(!Task.exists(params.id)) { |
---|
303 | flash.message = "Task not found with id ${params.id}." |
---|
304 | redirect(action:'search') |
---|
305 | } |
---|
306 | |
---|
307 | def result = taskService.renegeApproval(params) |
---|
308 | |
---|
309 | if(!result.error) { |
---|
310 | flash.message = "Task ${params.id} has had approval removed." |
---|
311 | redirect(action:show,id:result.taskInstance.id) |
---|
312 | } |
---|
313 | else { |
---|
314 | if(result.taskInstance) { |
---|
315 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
316 | } |
---|
317 | else { |
---|
318 | flash.message = "Task could not be updated." |
---|
319 | redirect(action:'search') |
---|
320 | } |
---|
321 | } |
---|
322 | |
---|
323 | } |
---|
324 | |
---|
325 | def complete = { |
---|
326 | |
---|
327 | if(!Task.exists(params.id)) { |
---|
328 | flash.message = "Task not found with id ${params.id}." |
---|
329 | redirect(action:'search') |
---|
330 | } |
---|
331 | |
---|
332 | def result = taskService.complete(params) |
---|
333 | |
---|
334 | if(!result.error) { |
---|
335 | flash.message = "Task ${params.id} has been completed." |
---|
336 | redirect(action:show,id:result.taskInstance.id) |
---|
337 | } |
---|
338 | else { |
---|
339 | if(result.taskInstance) { |
---|
340 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
341 | } |
---|
342 | else { |
---|
343 | flash.message = "Task could not be updated." |
---|
344 | redirect(action:'search') |
---|
345 | } |
---|
346 | } |
---|
347 | |
---|
348 | } |
---|
349 | |
---|
350 | def reopen = { |
---|
351 | |
---|
352 | if(!Task.exists(params.id)) { |
---|
353 | flash.message = "Task not found with id ${params.id}." |
---|
354 | redirect(action:'search') |
---|
355 | } |
---|
356 | |
---|
357 | def result = taskService.reopen(params) |
---|
358 | |
---|
359 | if(!result.error) { |
---|
360 | flash.message = "Task ${params.id} has been reopened." |
---|
361 | redirect(action:show,id:result.taskInstance.id) |
---|
362 | } |
---|
363 | else { |
---|
364 | if(result.taskInstance) { |
---|
365 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
366 | } |
---|
367 | else { |
---|
368 | flash.message = "Task could not be updated." |
---|
369 | redirect(action:'search') |
---|
370 | } |
---|
371 | } |
---|
372 | |
---|
373 | } |
---|
374 | |
---|
375 | def edit = { |
---|
376 | |
---|
377 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
378 | if(params._action_Edit) |
---|
379 | { params.action='edit' } |
---|
380 | |
---|
381 | def taskInstance = Task.get( params.id ) |
---|
382 | |
---|
383 | if(!taskInstance) { |
---|
384 | flash.message = "Task not found with id ${params.id}" |
---|
385 | redirect(action:search) |
---|
386 | } |
---|
387 | else { |
---|
388 | if(taskInstance.trash) { |
---|
389 | flash.message = "You may not edit items in the trash." |
---|
390 | redirect(action:show,id:taskInstance.id) |
---|
391 | } |
---|
392 | def criteria = taskInstance.createCriteria() |
---|
393 | def possibleParentList = criteria { |
---|
394 | and { |
---|
395 | notEqual('id', taskInstance.id) |
---|
396 | taskInstance.subTasks.each() { notEqual('id', it.id) } |
---|
397 | } |
---|
398 | } |
---|
399 | return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
400 | } |
---|
401 | } |
---|
402 | |
---|
403 | def update = { |
---|
404 | |
---|
405 | if(!Task.exists(params.id)) { |
---|
406 | flash.message = "Task not found with id ${params.id}" |
---|
407 | redirect(action:'search') |
---|
408 | } |
---|
409 | |
---|
410 | def result = taskService.update(params) |
---|
411 | |
---|
412 | if(!result.error) { |
---|
413 | flash.message = "Task ${params.id} updated" |
---|
414 | redirect(action:show,id:result.taskInstance.id) |
---|
415 | } |
---|
416 | else { |
---|
417 | if(result.taskInstance) { |
---|
418 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
419 | } |
---|
420 | else { |
---|
421 | flash.message = "Task could not be updated." |
---|
422 | redirect(action:'search') |
---|
423 | } |
---|
424 | } |
---|
425 | |
---|
426 | } |
---|
427 | |
---|
428 | // def update = { |
---|
429 | // def taskInstance = Task.get( params.id ) |
---|
430 | // if(taskInstance) { |
---|
431 | // if(params.version) { |
---|
432 | // def version = params.version.toLong() |
---|
433 | // if(taskInstance.version > version) { |
---|
434 | // |
---|
435 | // taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.") |
---|
436 | // render(view:'edit',model:[taskInstance:taskInstance]) |
---|
437 | // return |
---|
438 | // } |
---|
439 | // } |
---|
440 | // taskInstance.properties = params |
---|
441 | // if(!taskInstance.hasErrors() && taskInstance.save(flush: true)) { |
---|
442 | // flash.message = "Task ${params.id} updated" |
---|
443 | // redirect(action:show,id:taskInstance.id) |
---|
444 | // } |
---|
445 | // else { |
---|
446 | // render(view:'edit',model:[taskInstance:taskInstance]) |
---|
447 | // } |
---|
448 | // } |
---|
449 | // else { |
---|
450 | // flash.message = "Task not found with id ${params.id}" |
---|
451 | // redirect(action:edit,id:params.id) |
---|
452 | // } |
---|
453 | // } |
---|
454 | |
---|
455 | def create = { |
---|
456 | def taskInstance = new Task() |
---|
457 | // Default leadPerson to current user. |
---|
458 | taskInstance.leadPerson = Person.get(authenticateService.userDomain().id) |
---|
459 | taskInstance.properties = params |
---|
460 | return ['taskInstance':taskInstance] |
---|
461 | } |
---|
462 | |
---|
463 | def save = { |
---|
464 | def result = taskService.create(params) |
---|
465 | |
---|
466 | if(!result.error) { |
---|
467 | flash.message = "Task ${result.taskInstance.id} created." |
---|
468 | redirect(action: show,id: result.taskInstance.id) |
---|
469 | } |
---|
470 | else { |
---|
471 | if(result.taskInstance) { |
---|
472 | render(view:'create',model:[taskInstance:result.taskInstance]) |
---|
473 | } |
---|
474 | else { |
---|
475 | flash.message = "Could not create task." |
---|
476 | redirect(action:"search") |
---|
477 | } |
---|
478 | |
---|
479 | } |
---|
480 | } |
---|
481 | |
---|
482 | def listSubTasks = { |
---|
483 | def parentTaskInstance = Task.get(params.id) |
---|
484 | |
---|
485 | if(!parentTaskInstance) { |
---|
486 | flash.message = "Task not found with id ${params.id}" |
---|
487 | redirect(action:search) |
---|
488 | } |
---|
489 | else { |
---|
490 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
491 | def subTaskInstanceList = Task.findAllByParentTask(parentTaskInstance, params) |
---|
492 | def subTaskInstanceTotal = Task.countByParentTask(parentTaskInstance) |
---|
493 | |
---|
494 | [ taskInstanceList: subTaskInstanceList, |
---|
495 | taskInstanceTotal: subTaskInstanceTotal, |
---|
496 | parentTaskInstance: parentTaskInstance] |
---|
497 | } |
---|
498 | } |
---|
499 | |
---|
500 | } |
---|