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 | // Search urls: |
---|
25 | if(!params.filter) |
---|
26 | { |
---|
27 | def taskInstanceList = [] |
---|
28 | def personInstance = Person.get(authenticateService.userDomain().id) |
---|
29 | |
---|
30 | if(params.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.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.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 | } |
---|
51 | |
---|
52 | return[ taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount] |
---|
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 advancedSearch = { |
---|
62 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
63 | |
---|
64 | if(!params._action_advancedSearch) |
---|
65 | { |
---|
66 | // Default: |
---|
67 | def taskInstanceActivesList = Task.findAllByIsActive(true, params) |
---|
68 | def taskInstanceActivesTotal = Task.countByIsActive(true) |
---|
69 | return [taskInstanceList: taskInstanceActivesList, taskInstanceTotal: taskInstanceActivesTotal] |
---|
70 | } |
---|
71 | render( view:'advancedSearch', |
---|
72 | model:[ taskInstanceList: filterService.filter( params, Task ), |
---|
73 | taskInstanceTotal: filterService.count( params, Task ), |
---|
74 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
75 | params:params ] ) |
---|
76 | } |
---|
77 | |
---|
78 | // def searchTodays = { |
---|
79 | // def taskInstanceList = taskSearchService.getTodays(params) |
---|
80 | // |
---|
81 | // if(taskInstanceList.totalCount > 0) |
---|
82 | // { |
---|
83 | // flash.message = "Today's tasks" |
---|
84 | // } |
---|
85 | // else { flash.message = "No tasks found for today" } |
---|
86 | // |
---|
87 | // render( view:'search', |
---|
88 | // model:[ taskInstanceList: taskInstanceList, |
---|
89 | // taskInstanceTotal: taskInstanceList.totalCount]) |
---|
90 | // } |
---|
91 | |
---|
92 | // def searchMyTodays = { |
---|
93 | // params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
94 | // |
---|
95 | // def taskInstanceList = Task.createCriteria().list() { |
---|
96 | // eq("leadPerson", Person.get(authenticateService.userDomain().id)) |
---|
97 | // ge("targetStartDate", dateUtilService.getToday()) |
---|
98 | // eq("isActive", true) |
---|
99 | // } |
---|
100 | // |
---|
101 | // def taskInstanceTotal = Task.createCriteria().count() { |
---|
102 | // eq("leadPerson", Person.get(authenticateService.userDomain().id)) |
---|
103 | // ge("targetStartDate", dateUtilService.getToday()) |
---|
104 | // eq("isActive", true) |
---|
105 | // } |
---|
106 | // |
---|
107 | // if(taskInstanceTotal > 0) |
---|
108 | // { |
---|
109 | // flash.message = "Today's tasks" |
---|
110 | // } |
---|
111 | // else { flash.message = "No tasks found for today" } |
---|
112 | // |
---|
113 | // render( view:'search', |
---|
114 | // model:[ taskInstanceList: taskInstanceList, |
---|
115 | // taskInstanceTotal: taskInstanceTotal]) |
---|
116 | // } |
---|
117 | |
---|
118 | def searchInTheLastWeek = { |
---|
119 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
120 | |
---|
121 | def taskInstanceList = Task.createCriteria().list() { |
---|
122 | ge("targetStartDate", dateUtilService.getToday()-7) |
---|
123 | eq("isActive", true) |
---|
124 | } |
---|
125 | |
---|
126 | def taskInstanceTotal = Task.createCriteria().count() { |
---|
127 | ge("targetStartDate", dateUtilService.getToday()-7) |
---|
128 | eq("isActive", true) |
---|
129 | } |
---|
130 | |
---|
131 | if(taskInstanceTotal > 0) |
---|
132 | { |
---|
133 | flash.message = "Tasks with target start date in the last week." |
---|
134 | } |
---|
135 | |
---|
136 | else {flash.message = "No tasks found with target start date in the last week." } |
---|
137 | |
---|
138 | render( view:'search', |
---|
139 | model:[ taskInstanceList: taskInstanceList, |
---|
140 | taskInstanceTotal: taskInstanceTotal]) |
---|
141 | } |
---|
142 | |
---|
143 | def searchMyInTheLastWeek = { |
---|
144 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
145 | |
---|
146 | def taskInstanceList = Task.createCriteria().list() { |
---|
147 | eq("leadPerson", Person.get(authenticateService.userDomain().id)) |
---|
148 | ge("targetStartDate", dateUtilService.getToday()-7) |
---|
149 | eq("isActive", true) |
---|
150 | } |
---|
151 | |
---|
152 | def taskInstanceTotal = Task.createCriteria().count() { |
---|
153 | eq("leadPerson", Person.get(authenticateService.userDomain().id)) |
---|
154 | ge("targetStartDate", dateUtilService.getToday()-7) |
---|
155 | eq("isActive", true) |
---|
156 | } |
---|
157 | |
---|
158 | if(taskInstanceTotal > 0) |
---|
159 | { |
---|
160 | flash.message = "Tasks with target start date in the last week." |
---|
161 | } |
---|
162 | else { flash.message = "No tasks found with target start date in the last week." } |
---|
163 | |
---|
164 | render( view:'search', |
---|
165 | model:[ taskInstanceList: taskInstanceList, |
---|
166 | taskInstanceTotal: taskInstanceTotal]) |
---|
167 | } |
---|
168 | |
---|
169 | // def search = { |
---|
170 | // params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
171 | // |
---|
172 | // if(!params.order) { |
---|
173 | // params.sort = "id" |
---|
174 | // params.order = "desc" |
---|
175 | // } |
---|
176 | // |
---|
177 | // if(params.search == "ShowAll") |
---|
178 | // { |
---|
179 | // def taskInstanceActivesList = Task.findAllByIsActive(true, params) |
---|
180 | // def taskInstanceActivesTotal = Task.countByIsActive(true) |
---|
181 | // return [taskInstanceList: taskInstanceActivesList, taskInstanceTotal: taskInstanceActivesTotal] |
---|
182 | // } |
---|
183 | // if(params.search == "ShowDeleted") |
---|
184 | // { |
---|
185 | // def taskInstanceActivesList = Task.findAllByIsActive(false, params) |
---|
186 | // def taskInstanceActivesTotal = Task.countByIsActive(false) |
---|
187 | // return [taskInstanceList: taskInstanceActivesList, taskInstanceTotal: taskInstanceActivesTotal] |
---|
188 | // } |
---|
189 | // // Default: |
---|
190 | // def taskInstanceActivesList = Task.findAllByIsActive(true, params) |
---|
191 | // def taskInstanceActivesTotal = Task.countByIsActive(true) |
---|
192 | // [taskInstanceList: taskInstanceActivesList, taskInstanceTotal: taskInstanceActivesTotal] |
---|
193 | // } |
---|
194 | |
---|
195 | def searchShowAll = { |
---|
196 | redirect(action:'search', params:[search:"ShowAll"]) |
---|
197 | } |
---|
198 | |
---|
199 | def searchShowDeleted = { |
---|
200 | redirect(action:'search', params:[search:"ShowDeleted"]) |
---|
201 | } |
---|
202 | |
---|
203 | def show = { |
---|
204 | |
---|
205 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
206 | if(params._action_Show) |
---|
207 | { params.action='show' } |
---|
208 | |
---|
209 | def taskInstance = Task.get( params.id ) |
---|
210 | |
---|
211 | if(!taskInstance) { |
---|
212 | flash.message = "Task not found with id ${params.id}" |
---|
213 | redirect(action:search) |
---|
214 | } |
---|
215 | else { |
---|
216 | params.max = 10 |
---|
217 | params.order = "desc" |
---|
218 | params.sort = "id" |
---|
219 | |
---|
220 | def entryWorkDoneList = Entry.withCriteria { |
---|
221 | def entryType = EntryType.findByName("WorkDone") |
---|
222 | eq("entryType", entryType) |
---|
223 | eq("task", taskInstance) |
---|
224 | } |
---|
225 | |
---|
226 | def entryFaultList = Entry.withCriteria { |
---|
227 | def entryType = EntryType.findByName("Fault") |
---|
228 | eq("entryType", entryType) |
---|
229 | eq("task", taskInstance) |
---|
230 | } |
---|
231 | |
---|
232 | def subTaskInstanceList = Task.findAllByParentTask(taskInstance, params) |
---|
233 | def subTaskInstanceTotal = Task.countByParentTask(taskInstance) |
---|
234 | def showTaskTab = new String("true") |
---|
235 | |
---|
236 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
237 | def taskProcedureExits = new Boolean("true") |
---|
238 | if(!taskProcedureInstance) { |
---|
239 | taskProcedureExits = false |
---|
240 | } |
---|
241 | // else { |
---|
242 | params.order = "asc" |
---|
243 | params.sort = "procedureStepNumber" |
---|
244 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
245 | // } |
---|
246 | |
---|
247 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
248 | def taskRecurringScheduleExits= new Boolean("true") |
---|
249 | if(!taskRecurringScheduleInstance) { |
---|
250 | taskRecurringScheduleExits = false |
---|
251 | } |
---|
252 | |
---|
253 | return [ taskInstance: taskInstance, |
---|
254 | entryWorkDoneList: entryWorkDoneList, |
---|
255 | entryFaultList: entryFaultList, |
---|
256 | taskProcedureInstance: taskProcedureInstance, |
---|
257 | taskProcedureExits: taskProcedureExits, |
---|
258 | showTaskTab: showTaskTab, |
---|
259 | subTaskInstanceList: subTaskInstanceList, |
---|
260 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
261 | subTaskInstanceMax: params.max, |
---|
262 | maintenanceActionList: maintenanceActionList, |
---|
263 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
264 | taskRecurringScheduleExits: taskRecurringScheduleExits] |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | def delete = { |
---|
269 | def taskInstance = Task.get( params.id ) |
---|
270 | if(taskInstance) { |
---|
271 | try { |
---|
272 | taskInstance.isActive = false |
---|
273 | flash.message = "Task ${params.id} has been set to inactive." |
---|
274 | redirect(action:search) |
---|
275 | } |
---|
276 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
277 | flash.message = "Task ${params.id} could not be deleted" |
---|
278 | redirect(action:show,id:params.id) |
---|
279 | } |
---|
280 | } |
---|
281 | else { |
---|
282 | flash.message = "Task not found with id ${params.id}" |
---|
283 | redirect(action:search) |
---|
284 | } |
---|
285 | } |
---|
286 | |
---|
287 | def edit = { |
---|
288 | |
---|
289 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
290 | if(params._action_Edit) |
---|
291 | { params.action='edit' } |
---|
292 | |
---|
293 | def taskInstance = Task.get( params.id ) |
---|
294 | |
---|
295 | if(!taskInstance) { |
---|
296 | flash.message = "Task not found with id ${params.id}" |
---|
297 | redirect(action:search) |
---|
298 | } |
---|
299 | else { |
---|
300 | def criteria = taskInstance.createCriteria() |
---|
301 | def result = criteria { |
---|
302 | and { |
---|
303 | notEqual('id', taskInstance.id) |
---|
304 | } |
---|
305 | } |
---|
306 | return [ taskInstance : taskInstance, possibleParentList: result ] |
---|
307 | } |
---|
308 | } |
---|
309 | |
---|
310 | def update = { |
---|
311 | def taskInstance = Task.get( params.id ) |
---|
312 | if(taskInstance) { |
---|
313 | if(params.version) { |
---|
314 | def version = params.version.toLong() |
---|
315 | if(taskInstance.version > version) { |
---|
316 | |
---|
317 | taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.") |
---|
318 | render(view:'edit',model:[taskInstance:taskInstance]) |
---|
319 | return |
---|
320 | } |
---|
321 | } |
---|
322 | taskInstance.properties = params |
---|
323 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
324 | flash.message = "Task ${params.id} updated" |
---|
325 | redirect(action:show,id:taskInstance.id) |
---|
326 | } |
---|
327 | else { |
---|
328 | render(view:'edit',model:[taskInstance:taskInstance]) |
---|
329 | } |
---|
330 | } |
---|
331 | else { |
---|
332 | flash.message = "Task not found with id ${params.id}" |
---|
333 | redirect(action:edit,id:params.id) |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | def create = { |
---|
338 | def taskInstance = new Task() |
---|
339 | taskInstance.properties = params |
---|
340 | return ['taskInstance':taskInstance] |
---|
341 | } |
---|
342 | |
---|
343 | def save = { |
---|
344 | def taskInstance = new Task(params) |
---|
345 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
346 | flash.message = "Task ${taskInstance.id} created" |
---|
347 | redirect(action:show,id:taskInstance.id) |
---|
348 | } |
---|
349 | else { |
---|
350 | render(view:'create',model:[taskInstance:taskInstance]) |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | def listSubTasks = { |
---|
355 | def parentTaskInstance = Task.get(params.id) |
---|
356 | |
---|
357 | if(!parentTaskInstance) { |
---|
358 | flash.message = "Task not found with id ${params.id}" |
---|
359 | redirect(action:search) |
---|
360 | } |
---|
361 | else { |
---|
362 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
363 | def subTaskInstanceList = Task.findAllByParentTask(parentTaskInstance, params) |
---|
364 | def subTaskInstanceTotal = Task.countByParentTask(parentTaskInstance) |
---|
365 | |
---|
366 | [ taskInstanceList: subTaskInstanceList, |
---|
367 | taskInstanceTotal: subTaskInstanceTotal, |
---|
368 | parentTaskInstance: parentTaskInstance] |
---|
369 | } |
---|
370 | } |
---|
371 | |
---|
372 | } |
---|