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 taskSearchService |
---|
9 | def filterService |
---|
10 | def exportService |
---|
11 | |
---|
12 | // the delete, save and update actions only accept POST requests |
---|
13 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
14 | |
---|
15 | def index = { redirect(action:search,params:params) } |
---|
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 search = { |
---|
23 | // println params |
---|
24 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
25 | |
---|
26 | // Quick Search: |
---|
27 | if(!params.filter) |
---|
28 | { |
---|
29 | def taskInstanceList = [] |
---|
30 | def personInstance = Person.get(authenticateService.userDomain().id) |
---|
31 | |
---|
32 | if(params.quickSearch == "searchMyTodays") { |
---|
33 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
34 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
35 | else { params.message = "No tasks found for today." } |
---|
36 | } |
---|
37 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
38 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
39 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
40 | else { params.message = "No tasks found for today." } |
---|
41 | } |
---|
42 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
43 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
44 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
45 | else { params.message = "No tasks found for today." } |
---|
46 | } |
---|
47 | else { |
---|
48 | //Default: |
---|
49 | taskInstanceList = taskSearchService.getTodays(params) |
---|
50 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
51 | else { params.message = "No tasks found for today." } |
---|
52 | params.quickSearch = "searchTodays" |
---|
53 | } |
---|
54 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
55 | } |
---|
56 | // filterPane: |
---|
57 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
58 | taskInstanceTotal: filterService.count( params, Task ), |
---|
59 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
60 | params:params ] |
---|
61 | } |
---|
62 | |
---|
63 | def searchCalendar = { |
---|
64 | // println params |
---|
65 | params.max = 30 |
---|
66 | |
---|
67 | // Quick Search: |
---|
68 | if(!params.filter) |
---|
69 | { |
---|
70 | def taskInstanceList = [] |
---|
71 | def personInstance = Person.get(authenticateService.userDomain().id) |
---|
72 | |
---|
73 | if(params.quickSearch == "searchMyTodays") { |
---|
74 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
75 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
76 | else { params.message = "No tasks found for today." } |
---|
77 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
78 | } |
---|
79 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
80 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
81 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
82 | else { params.message = "No tasks found for today." } |
---|
83 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
84 | } |
---|
85 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
86 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
87 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
88 | else { params.message = "No tasks found for today." } |
---|
89 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
90 | } |
---|
91 | else { |
---|
92 | //Default: |
---|
93 | taskInstanceList = taskSearchService.getTodays(params) |
---|
94 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
95 | else { params.message = "No tasks found for today." } |
---|
96 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
97 | params.quickSearch = "searchTodays" |
---|
98 | } |
---|
99 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
100 | } |
---|
101 | // filterPane: |
---|
102 | def taskInstanceTotal = filterService.count( params, Task ) |
---|
103 | if(taskInstanceTotal > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
104 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
105 | taskInstanceTotal: taskInstanceTotal, |
---|
106 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
107 | params:params ] |
---|
108 | } |
---|
109 | |
---|
110 | def budget = { |
---|
111 | // println params |
---|
112 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
113 | |
---|
114 | // Quick Search: |
---|
115 | if(!params.filter) |
---|
116 | { |
---|
117 | def taskInstanceList = [] |
---|
118 | def personInstance = Person.get(authenticateService.userDomain().id) |
---|
119 | |
---|
120 | if(params.quickSearch == "budgetUnplanned") { |
---|
121 | taskInstanceList = taskSearchService.getBudgetUnplanned(params) |
---|
122 | if(taskInstanceList.totalCount > 0) { params.message = "Budget unplanned tasks in the last week." } |
---|
123 | else { params.message = "No tasks found." } |
---|
124 | } |
---|
125 | //else if(params.quickSearch == "budgetPlanned") { |
---|
126 | else { |
---|
127 | //Default: |
---|
128 | taskInstanceList = taskSearchService.getBudgetPlanned(params) |
---|
129 | if(taskInstanceList.totalCount > 0) { params.message = "Budget planned Tasks in the last week." } |
---|
130 | else { params.message = "No tasks found.." } |
---|
131 | } |
---|
132 | // export plugin: |
---|
133 | if(params?.format && params.format != "html") { |
---|
134 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
135 | response.setHeader("Content-disposition", "attachment; filename=tasks.${params.extension}") |
---|
136 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskStatus", "taskType"] |
---|
137 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
138 | "leadPerson": "Lead Person", "taskStatus": "Task Status", "taskType": "Task Type"] |
---|
139 | Map formatters = [:] |
---|
140 | String title = "${params.quickSearch} tasks in the last week." |
---|
141 | Map parameters = [title: title] |
---|
142 | |
---|
143 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
144 | } |
---|
145 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
146 | } |
---|
147 | // filterPane: |
---|
148 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
149 | taskInstanceTotal: filterService.count( params, Task ), |
---|
150 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
151 | params:params ] |
---|
152 | } |
---|
153 | |
---|
154 | def show = { |
---|
155 | |
---|
156 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
157 | if(params._action_Show) |
---|
158 | { params.action='show' } |
---|
159 | |
---|
160 | def taskInstance = Task.get( params.id ) |
---|
161 | |
---|
162 | if(!taskInstance) { |
---|
163 | flash.message = "Task not found with id ${params.id}" |
---|
164 | redirect(action:search) |
---|
165 | } |
---|
166 | else { |
---|
167 | params.max = 10 |
---|
168 | params.order = "desc" |
---|
169 | params.sort = "id" |
---|
170 | |
---|
171 | def entryWorkDoneList = Entry.withCriteria { |
---|
172 | def entryType = EntryType.findByName("WorkDone") |
---|
173 | eq("entryType", entryType) |
---|
174 | eq("task", taskInstance) |
---|
175 | } |
---|
176 | |
---|
177 | def entryFaultList = Entry.withCriteria { |
---|
178 | def entryType = EntryType.findByName("Fault") |
---|
179 | eq("entryType", entryType) |
---|
180 | eq("task", taskInstance) |
---|
181 | } |
---|
182 | |
---|
183 | def subTaskInstanceList = Task.findAllByParentTask(taskInstance, params) |
---|
184 | def subTaskInstanceTotal = Task.countByParentTask(taskInstance) |
---|
185 | def showTaskTab = new String("true") |
---|
186 | |
---|
187 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
188 | def taskProcedureExits = new Boolean("true") |
---|
189 | if(!taskProcedureInstance) { |
---|
190 | taskProcedureExits = false |
---|
191 | } |
---|
192 | // else { |
---|
193 | params.order = "asc" |
---|
194 | params.sort = "procedureStepNumber" |
---|
195 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
196 | // } |
---|
197 | |
---|
198 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
199 | def taskRecurringScheduleExits= new Boolean("true") |
---|
200 | if(!taskRecurringScheduleInstance) { |
---|
201 | taskRecurringScheduleExits = false |
---|
202 | } |
---|
203 | |
---|
204 | return [ taskInstance: taskInstance, |
---|
205 | entryWorkDoneList: entryWorkDoneList, |
---|
206 | entryFaultList: entryFaultList, |
---|
207 | taskProcedureInstance: taskProcedureInstance, |
---|
208 | taskProcedureExits: taskProcedureExits, |
---|
209 | showTaskTab: showTaskTab, |
---|
210 | subTaskInstanceList: subTaskInstanceList, |
---|
211 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
212 | subTaskInstanceMax: params.max, |
---|
213 | maintenanceActionList: maintenanceActionList, |
---|
214 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
215 | taskRecurringScheduleExits: taskRecurringScheduleExits] |
---|
216 | } |
---|
217 | } |
---|
218 | |
---|
219 | def delete = { |
---|
220 | def taskInstance = Task.get( params.id ) |
---|
221 | if(taskInstance) { |
---|
222 | try { |
---|
223 | taskInstance.isActive = false |
---|
224 | flash.message = "Task ${params.id} has been set to inactive." |
---|
225 | redirect(action:search) |
---|
226 | } |
---|
227 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
228 | flash.message = "Task ${params.id} could not be deleted" |
---|
229 | redirect(action:show,id:params.id) |
---|
230 | } |
---|
231 | } |
---|
232 | else { |
---|
233 | flash.message = "Task not found with id ${params.id}" |
---|
234 | redirect(action:search) |
---|
235 | } |
---|
236 | } |
---|
237 | |
---|
238 | def edit = { |
---|
239 | |
---|
240 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
241 | if(params._action_Edit) |
---|
242 | { params.action='edit' } |
---|
243 | |
---|
244 | def taskInstance = Task.get( params.id ) |
---|
245 | |
---|
246 | if(!taskInstance) { |
---|
247 | flash.message = "Task not found with id ${params.id}" |
---|
248 | redirect(action:search) |
---|
249 | } |
---|
250 | else { |
---|
251 | def criteria = taskInstance.createCriteria() |
---|
252 | def possibleParentList = criteria { |
---|
253 | and { |
---|
254 | notEqual('id', taskInstance.id) |
---|
255 | taskInstance.subTasks.each() { notEqual('id', it.id) } |
---|
256 | } |
---|
257 | } |
---|
258 | return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | def update = { |
---|
263 | def taskInstance = Task.get( params.id ) |
---|
264 | if(taskInstance) { |
---|
265 | if(params.version) { |
---|
266 | def version = params.version.toLong() |
---|
267 | if(taskInstance.version > version) { |
---|
268 | |
---|
269 | taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.") |
---|
270 | render(view:'edit',model:[taskInstance:taskInstance]) |
---|
271 | return |
---|
272 | } |
---|
273 | } |
---|
274 | taskInstance.properties = params |
---|
275 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
276 | flash.message = "Task ${params.id} updated" |
---|
277 | redirect(action:show,id:taskInstance.id) |
---|
278 | } |
---|
279 | else { |
---|
280 | render(view:'edit',model:[taskInstance:taskInstance]) |
---|
281 | } |
---|
282 | } |
---|
283 | else { |
---|
284 | flash.message = "Task not found with id ${params.id}" |
---|
285 | redirect(action:edit,id:params.id) |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | def create = { |
---|
290 | def taskInstance = new Task() |
---|
291 | taskInstance.properties = params |
---|
292 | return ['taskInstance':taskInstance] |
---|
293 | } |
---|
294 | |
---|
295 | def save = { |
---|
296 | def taskInstance = new Task(params) |
---|
297 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
---|
298 | flash.message = "Task ${taskInstance.id} created" |
---|
299 | redirect(action:show,id:taskInstance.id) |
---|
300 | } |
---|
301 | else { |
---|
302 | render(view:'create',model:[taskInstance:taskInstance]) |
---|
303 | } |
---|
304 | } |
---|
305 | |
---|
306 | def listSubTasks = { |
---|
307 | def parentTaskInstance = Task.get(params.id) |
---|
308 | |
---|
309 | if(!parentTaskInstance) { |
---|
310 | flash.message = "Task not found with id ${params.id}" |
---|
311 | redirect(action:search) |
---|
312 | } |
---|
313 | else { |
---|
314 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
315 | def subTaskInstanceList = Task.findAllByParentTask(parentTaskInstance, params) |
---|
316 | def subTaskInstanceTotal = Task.countByParentTask(parentTaskInstance) |
---|
317 | |
---|
318 | [ taskInstanceList: subTaskInstanceList, |
---|
319 | taskInstanceTotal: subTaskInstanceTotal, |
---|
320 | parentTaskInstance: parentTaskInstance] |
---|
321 | } |
---|
322 | } |
---|
323 | |
---|
324 | } |
---|