1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
3 | import com.zeddware.grails.plugins.filterpane.FilterUtils |
---|
4 | import org.springframework.web.servlet.support.RequestContextUtils as RCU |
---|
5 | |
---|
6 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
7 | class TaskDetailedController extends BaseController { |
---|
8 | |
---|
9 | def authService |
---|
10 | def taskService |
---|
11 | def taskSearchService |
---|
12 | def taskReportService |
---|
13 | def filterService |
---|
14 | def exportService |
---|
15 | def dateUtilService |
---|
16 | |
---|
17 | // these actions only accept POST requests |
---|
18 | static allowedMethods = [save:'POST',update:'POST',restore:'POST', trash:'POST', |
---|
19 | approve:'POST', renegeApproval:'POST', complete:'POST', |
---|
20 | reopen:'POST', setAttentionFlag:'POST', clearAttentionFlag:'POST'] |
---|
21 | |
---|
22 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
23 | def index = { redirect(action: 'search', params: params) } |
---|
24 | |
---|
25 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
26 | def setSearchParamsMax = { |
---|
27 | def max = 1000 |
---|
28 | if(params.newMax?.isInteger()) { |
---|
29 | def i = params.newMax.toInteger() |
---|
30 | if(i > 0 && i <= max) |
---|
31 | session.taskSearchParamsMax = params.newMax |
---|
32 | if(i > max) |
---|
33 | session.taskSearchParamsMax = max |
---|
34 | } |
---|
35 | forward(action: 'search', params: params) |
---|
36 | } |
---|
37 | |
---|
38 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
39 | def setSearchCalendarParamsMax = { |
---|
40 | def max = 1000 |
---|
41 | if(params.newMax?.isInteger()) { |
---|
42 | def i = params.newMax.toInteger() |
---|
43 | if(i > 0 && i <= max) |
---|
44 | session.taskSearchCalendarParamsMax = params.newMax |
---|
45 | if(i > max) |
---|
46 | session.taskSearchCalendarParamsMax = max |
---|
47 | } |
---|
48 | forward(action: 'searchCalendar', params: params) |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * Search for tasks. |
---|
53 | */ |
---|
54 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
55 | def search = { |
---|
56 | |
---|
57 | if(session.taskSearchParamsMax) |
---|
58 | params.max = session.taskSearchParamsMax |
---|
59 | |
---|
60 | // Protect filterPane. |
---|
61 | params.max = Math.min( params.max ? params.max.toInteger() : 100, 1000 ) |
---|
62 | |
---|
63 | // View main data. |
---|
64 | def taskInstanceList = [] |
---|
65 | def taskInstanceTotal |
---|
66 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
67 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
68 | |
---|
69 | // Restore search unless a new search is being requested. |
---|
70 | if(!params.quickSearch && !filterParams) { |
---|
71 | if(session.taskSearchFilterParams) { |
---|
72 | session.taskSearchFilterParams.each() { params[it.key] = it.value } |
---|
73 | params.filter = session.taskSearchFilter |
---|
74 | isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
75 | } |
---|
76 | } |
---|
77 | if(!params.quickSearch) { |
---|
78 | if(session.taskSearchQuickSearch) { |
---|
79 | params.quickSearch = session.taskSearchQuickSearch |
---|
80 | params.person = Person.get(session.taskQuickSearchPersonId.toLong()) |
---|
81 | params.startDate = session.taskQuickSearchStartDate |
---|
82 | params.endDate = session.taskQuickSearchEndDate |
---|
83 | params.includeCompleted = session.taskQuickSearchIncludeCompleted |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | // Remember sort if supplied, otherwise try to restore. |
---|
88 | if(params.sort && params.order) { |
---|
89 | // Reset to defaultSort if requested. |
---|
90 | if(params.sort == 'defaultSort') { |
---|
91 | params.sort = null |
---|
92 | params.order = null |
---|
93 | session.removeAttribute("taskSearchSort") |
---|
94 | session.removeAttribute("taskSearchOrder") |
---|
95 | } |
---|
96 | else { |
---|
97 | session.taskSearchSort = params.sort |
---|
98 | session.taskSearchOrder = params.order |
---|
99 | } |
---|
100 | } |
---|
101 | else if(session.taskSearchSort && session.taskSearchOrder) { |
---|
102 | params.sort = session.taskSearchSort |
---|
103 | params.order = session.taskSearchOrder |
---|
104 | } |
---|
105 | |
---|
106 | if(isFilterApplied) { |
---|
107 | // filterPane: |
---|
108 | params.sort = params.sort ?: "id" |
---|
109 | params.order = params.order ?: "desc" |
---|
110 | if(params.sort == "attentionFlag") // See ticket #64 in Trac. |
---|
111 | params.sort = "id" |
---|
112 | // Prevent tasks in the trash being returned unless explicitly requested. |
---|
113 | if(!params.filter.op.trash) { |
---|
114 | params.filter.op.trash = "Equal" |
---|
115 | params.filter.trash = "false" |
---|
116 | } |
---|
117 | // Call filterService. |
---|
118 | taskInstanceList = filterService.filter( params, Task ) |
---|
119 | taskInstanceTotal = filterService.count( params, Task ) |
---|
120 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
121 | // Remember search. |
---|
122 | session.taskSearchFilterParams = new LinkedHashMap(filterParams) |
---|
123 | session.taskSearchFilter = new LinkedHashMap(params.filter) |
---|
124 | } |
---|
125 | else { |
---|
126 | // Quick Search: |
---|
127 | def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request)) |
---|
128 | taskInstanceList = result.taskInstanceList |
---|
129 | taskInstanceTotal = result.taskInstanceList.totalCount |
---|
130 | params.message = result.message |
---|
131 | params.quickSearch = result.quickSearch |
---|
132 | params.person = result.person |
---|
133 | params.startDate = result.startDate |
---|
134 | params.endDate = result.endDate |
---|
135 | params.includeCompleted = result.includeCompleted |
---|
136 | // Remember search. |
---|
137 | session.removeAttribute("taskSearchFilterParams") |
---|
138 | session.removeAttribute("taskSearchFilter") |
---|
139 | session.taskSearchQuickSearch = result.quickSearch |
---|
140 | session.taskQuickSearchPersonId = result.person.id |
---|
141 | session.taskQuickSearchStartDate = result.startDate |
---|
142 | session.taskQuickSearchEndDate = result.endDate |
---|
143 | session.taskQuickSearchIncludeCompleted = result.includeCompleted |
---|
144 | } |
---|
145 | |
---|
146 | // export plugin: |
---|
147 | if(params?.format && params.format != "html") { |
---|
148 | |
---|
149 | def dateFmt = { date -> |
---|
150 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
151 | } |
---|
152 | |
---|
153 | String title |
---|
154 | if(params.quickSearch) |
---|
155 | title = params.message |
---|
156 | else |
---|
157 | title = "Filtered tasks." |
---|
158 | |
---|
159 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
160 | response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}") |
---|
161 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskType", "taskStatus"] |
---|
162 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
163 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", |
---|
164 | "taskType": "Task Type", "taskStatus": "Task Status"] |
---|
165 | Map formatters = [ targetStartDate: dateFmt] |
---|
166 | Map parameters = [title: title, separator: ","] |
---|
167 | |
---|
168 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
169 | } |
---|
170 | |
---|
171 | // Add some basic params to filterParams. |
---|
172 | filterParams.max = params.max |
---|
173 | filterParams.offset = params.offset?.toInteger() ?: 0 |
---|
174 | filterParams.sort = params.sort ?: "id" |
---|
175 | filterParams.order = params.order ?: "desc" |
---|
176 | |
---|
177 | // Get some associatedProperty values for filterpane. |
---|
178 | def associatedPropertyValues = [:] |
---|
179 | def associatedPropertyMax = 10000 |
---|
180 | associatedPropertyValues.taskPriorityList = TaskPriority.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
181 | def lastNameQuery = 'select distinct p.lastName from Person p where p.isActive = ? order by p.lastName' |
---|
182 | associatedPropertyValues.lastNameList = Person.executeQuery(lastNameQuery, [true], [max:associatedPropertyMax]) |
---|
183 | def firstNameQuery = 'select distinct p.firstName from Person p where p.isActive = ? order by p.firstName' |
---|
184 | associatedPropertyValues.firstNameList = Person.executeQuery(firstNameQuery, [true], [max:associatedPropertyMax]) |
---|
185 | associatedPropertyValues.taskGroupList = TaskGroup.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
186 | associatedPropertyValues.assetList = Asset.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
187 | associatedPropertyValues.taskStatusList = TaskStatus.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
188 | associatedPropertyValues.taskTypeList = TaskType.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
189 | def startOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), -10)) |
---|
190 | def endOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), 10)) |
---|
191 | associatedPropertyValues.yearRange = startOfYearRange..endOfYearRange |
---|
192 | |
---|
193 | return[ taskInstanceList: taskInstanceList, |
---|
194 | taskInstanceTotal: taskInstanceTotal, |
---|
195 | filterParams: filterParams, |
---|
196 | params: params, |
---|
197 | associatedPropertyValues: associatedPropertyValues, |
---|
198 | quickSearchSelection: taskSearchService.quickSearchSelection] |
---|
199 | |
---|
200 | } // search |
---|
201 | |
---|
202 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
203 | def searchCalendar = { |
---|
204 | |
---|
205 | // No pagination for calendar. |
---|
206 | params.offset = 0 |
---|
207 | |
---|
208 | // Restore params.max |
---|
209 | if(session.taskSearchCalendarParamsMax) |
---|
210 | params.max = session.taskSearchCalendarParamsMax |
---|
211 | |
---|
212 | // Protect filterPane. |
---|
213 | params.max = Math.min( params.max ? params.max.toInteger() : 100, 1000 ) |
---|
214 | |
---|
215 | def displayList = [] |
---|
216 | def taskInstanceList = [] |
---|
217 | def taskInstanceTotal |
---|
218 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
219 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
220 | |
---|
221 | // Restore search unless a new search is being requested. |
---|
222 | if(!params.quickSearch && !filterParams) { |
---|
223 | if(session.taskSearchCalendarFilterParams) { |
---|
224 | session.taskSearchCalendarFilterParams.each() { params[it.key] = it.value } |
---|
225 | params.filter = session.taskSearchCalendarFilter |
---|
226 | isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
227 | } |
---|
228 | } |
---|
229 | if(!params.quickSearch) { |
---|
230 | if(session.taskSearchCalendarQuickSearch) { |
---|
231 | params.quickSearch = session.taskSearchCalendarQuickSearch |
---|
232 | params.person = Person.get(session.taskCalendarQuickSearchPersonId.toLong()) |
---|
233 | params.startDate = session.taskCalendarQuickSearchStartDate |
---|
234 | params.endDate = session.taskCalendarQuickSearchEndDate |
---|
235 | params.includeCompleted = session.taskCalendarQuickSearchIncludeCompleted |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | // The date the calendar will use to determine the month to show. |
---|
240 | // Use session, if not specified in params, otherwise use today. |
---|
241 | def showDate = new Date() |
---|
242 | if(params.showMonth) { |
---|
243 | if(params.showYear) |
---|
244 | showDate = dateUtilService.makeDate(params.showYear, params.showMonth) |
---|
245 | else |
---|
246 | showDate = dateUtilService.makeDate(dateUtilService.getYearFromDate(showDate), params.showMonth) |
---|
247 | // Remember the showDate. |
---|
248 | session.taskSearchCalendarShowDate = showDate |
---|
249 | } |
---|
250 | else if(session.taskSearchCalendarShowDate) |
---|
251 | showDate = session.taskSearchCalendarShowDate |
---|
252 | |
---|
253 | // Get the dates for the calendar month controls. |
---|
254 | def calendarMonthControls = getCalendarMonthControls(showDate) |
---|
255 | |
---|
256 | if(isFilterApplied) { |
---|
257 | // filterPane: |
---|
258 | params.sort = params.sort ?: "id" |
---|
259 | params.order = params.order ?: "desc" |
---|
260 | if(params.sort == "attentionFlag") // See ticket #64 in Trac. |
---|
261 | params.sort = "id" |
---|
262 | // Prevent tasks in the trash being returned unless explicitly requested. |
---|
263 | if(!params.filter.op.trash) { |
---|
264 | params.filter.op.trash = "Equal" |
---|
265 | params.filter.trash = "false" |
---|
266 | } |
---|
267 | // Call filterService. |
---|
268 | taskInstanceList = filterService.filter( params, Task ) |
---|
269 | taskInstanceTotal = filterService.count( params, Task ) |
---|
270 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
271 | // Remember search. |
---|
272 | session.taskSearchCalendarFilterParams = new LinkedHashMap(filterParams) |
---|
273 | session.taskSearchCalendarFilter = new LinkedHashMap(params.filter) |
---|
274 | } |
---|
275 | else { |
---|
276 | // Quick Search: |
---|
277 | def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request)) |
---|
278 | taskInstanceList = result.taskInstanceList |
---|
279 | taskInstanceTotal = result.taskInstanceList.totalCount |
---|
280 | params.message = result.message |
---|
281 | params.quickSearch = result.quickSearch |
---|
282 | params.person = result.person |
---|
283 | params.startDate = result.startDate |
---|
284 | params.endDate = result.endDate |
---|
285 | params.includeCompleted = result.includeCompleted |
---|
286 | // Remember search. |
---|
287 | session.removeAttribute("taskSearchCalendarFilterParams") |
---|
288 | session.removeAttribute("taskSearchCalendarFilter") |
---|
289 | session.taskSearchCalendarQuickSearch = result.quickSearch |
---|
290 | session.taskCalendarQuickSearchPersonId = result.person.id |
---|
291 | session.taskCalendarQuickSearchStartDate = result.startDate |
---|
292 | session.taskCalendarQuickSearchEndDate = result.endDate |
---|
293 | session.taskCalendarQuickSearchIncludeCompleted = result.includeCompleted |
---|
294 | } |
---|
295 | |
---|
296 | // displayList = taskReportService.getWorkLoadSummary( |
---|
297 | // [taskInstanceList: taskInstanceList], RCU.getLocale(request) |
---|
298 | // ).displayList |
---|
299 | |
---|
300 | // export plugin: |
---|
301 | if(params?.format && params.format != "html") { |
---|
302 | |
---|
303 | def dateFmt = { date -> |
---|
304 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
305 | } |
---|
306 | |
---|
307 | String title |
---|
308 | if(params.quickSearch) |
---|
309 | title = params.message |
---|
310 | else |
---|
311 | title = "Filtered tasks." |
---|
312 | |
---|
313 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
314 | response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}") |
---|
315 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskType", "taskStatus"] |
---|
316 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
317 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", |
---|
318 | "taskType": "Task Type", "taskStatus": "Task Status"] |
---|
319 | Map formatters = [ targetStartDate: dateFmt] |
---|
320 | Map parameters = [title: title, separator: ","] |
---|
321 | |
---|
322 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
323 | } |
---|
324 | |
---|
325 | if(taskInstanceTotal > params.max) |
---|
326 | params.errorMessage = g.message(code:"task.search.calendar.text.too.many.results", args:[params.max]) |
---|
327 | |
---|
328 | // Add some basic params to filterParams. |
---|
329 | filterParams.max = params.max |
---|
330 | filterParams.offset = params.offset?.toInteger() ?: 0 |
---|
331 | filterParams.sort = params.sort ?: "id" |
---|
332 | filterParams.order = params.order ?: "desc" |
---|
333 | |
---|
334 | // Get some associatedProperty values for filterpane. |
---|
335 | def associatedPropertyValues = [:] |
---|
336 | def associatedPropertyMax = 10000 |
---|
337 | associatedPropertyValues.taskPriorityList = TaskPriority.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
338 | def lastNameQuery = 'select distinct p.lastName from Person p where p.isActive = ? order by p.lastName' |
---|
339 | associatedPropertyValues.lastNameList = Person.executeQuery(lastNameQuery, [true], [max:associatedPropertyMax]) |
---|
340 | def firstNameQuery = 'select distinct p.firstName from Person p where p.isActive = ? order by p.firstName' |
---|
341 | associatedPropertyValues.firstNameList = Person.executeQuery(firstNameQuery, [true], [max:associatedPropertyMax]) |
---|
342 | associatedPropertyValues.taskGroupList = TaskGroup.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
343 | associatedPropertyValues.assetList = Asset.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
344 | associatedPropertyValues.taskStatusList = TaskStatus.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
345 | associatedPropertyValues.taskTypeList = TaskType.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
346 | def startOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), -10)) |
---|
347 | def endOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), 10)) |
---|
348 | associatedPropertyValues.yearRange = startOfYearRange..endOfYearRange |
---|
349 | |
---|
350 | return[taskInstanceList: taskInstanceList, |
---|
351 | taskInstanceTotal: taskInstanceTotal, |
---|
352 | filterParams: filterParams, |
---|
353 | params: params, |
---|
354 | associatedPropertyValues: associatedPropertyValues, |
---|
355 | showDate: showDate, |
---|
356 | today: calendarMonthControls.today, |
---|
357 | previousMonth: calendarMonthControls.previousMonth, |
---|
358 | nextMonth: calendarMonthControls.nextMonth, |
---|
359 | previousYear: calendarMonthControls.previousYear, |
---|
360 | nextYear: calendarMonthControls.nextYear, |
---|
361 | quickSearchSelection: taskSearchService.quickSearchSelection] |
---|
362 | |
---|
363 | } // searchCalendar |
---|
364 | |
---|
365 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
366 | def show = { |
---|
367 | |
---|
368 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
369 | if(params._action_Show) |
---|
370 | params.action='show' |
---|
371 | |
---|
372 | // Used by navigation. |
---|
373 | if(params.id == 'nav') { |
---|
374 | params.id = session.currentTaskId ?: null |
---|
375 | redirect(action: show, id: params.id) |
---|
376 | return |
---|
377 | } |
---|
378 | |
---|
379 | def showTab = [:] |
---|
380 | switch (params.showTab) { |
---|
381 | case "showProcedureTab": |
---|
382 | showTab.procedure = new String("true") |
---|
383 | break |
---|
384 | case "showRecurrenceTab": |
---|
385 | showTab.recurrence = new String("true") |
---|
386 | break |
---|
387 | case "showInventoryTab": |
---|
388 | showTab.inventory = new String("true") |
---|
389 | break |
---|
390 | case "showSubTasksTab": |
---|
391 | showTab.subTasks = new String("true") |
---|
392 | break |
---|
393 | default: |
---|
394 | showTab.task = new String("true") |
---|
395 | } |
---|
396 | |
---|
397 | def taskInstance = Task.get( params.id ) |
---|
398 | |
---|
399 | if(!taskInstance) { |
---|
400 | flash.message = "Task not found with id ${params.id}" |
---|
401 | redirect(action: 'search') |
---|
402 | } |
---|
403 | else { |
---|
404 | // Remember the current task id for use with navigation. |
---|
405 | session.currentTaskId = params.id |
---|
406 | |
---|
407 | params.max = 10 |
---|
408 | params.order = "desc" |
---|
409 | params.sort = "id" |
---|
410 | |
---|
411 | def entryFaultList = Entry.withCriteria { |
---|
412 | eq("entryType", EntryType.get(1)) |
---|
413 | eq("task", taskInstance) |
---|
414 | } |
---|
415 | |
---|
416 | def entryCauseList = Entry.withCriteria { |
---|
417 | eq("entryType", EntryType.get(2)) |
---|
418 | eq("task", taskInstance) |
---|
419 | } |
---|
420 | |
---|
421 | def entryWorkDoneList = Entry.withCriteria { |
---|
422 | eq("entryType", EntryType.get(3)) |
---|
423 | eq("task", taskInstance) |
---|
424 | } |
---|
425 | |
---|
426 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
---|
427 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
---|
428 | |
---|
429 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
430 | |
---|
431 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
432 | |
---|
433 | def assignedGroupList = taskInstance.assignedGroups.sort { p1, p2 -> p1.personGroup.name.compareToIgnoreCase(p2.personGroup.name) } |
---|
434 | def assignedPersonList = taskInstance.assignedPersons.sort { p1, p2 -> p1.person.firstName.compareToIgnoreCase(p2.person.firstName) } |
---|
435 | |
---|
436 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
437 | def taskProcedureExits = new Boolean("true") |
---|
438 | if(!taskProcedureInstance) { |
---|
439 | taskProcedureExits = false |
---|
440 | } |
---|
441 | |
---|
442 | params.order = "asc" |
---|
443 | params.sort = "procedureStepNumber" |
---|
444 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
445 | |
---|
446 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
447 | def taskRecurringScheduleExits= new Boolean("true") |
---|
448 | if(!taskRecurringScheduleInstance) { |
---|
449 | taskRecurringScheduleExits = false |
---|
450 | } |
---|
451 | |
---|
452 | return [ taskInstance: taskInstance, |
---|
453 | entryFaultList: entryFaultList, |
---|
454 | entryCauseList: entryCauseList, |
---|
455 | entryWorkDoneList: entryWorkDoneList, |
---|
456 | taskProcedureInstance: taskProcedureInstance, |
---|
457 | taskProcedureExits: taskProcedureExits, |
---|
458 | showTab: showTab, |
---|
459 | subTaskInstanceList: subTaskInstanceList, |
---|
460 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
461 | subTaskInstanceMax: params.max, |
---|
462 | maintenanceActionList: maintenanceActionList, |
---|
463 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
464 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
465 | inventoryMovementList: inventoryMovementList, |
---|
466 | taskModificationList: taskModificationList, |
---|
467 | assignedGroupList: assignedGroupList, |
---|
468 | assignedPersonList: assignedPersonList] |
---|
469 | } |
---|
470 | } |
---|
471 | |
---|
472 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
473 | def restore = { |
---|
474 | |
---|
475 | def result = taskService.restore(params) |
---|
476 | |
---|
477 | if(!result.error) { |
---|
478 | flash.message = "Task ${params.id} has been restored." |
---|
479 | redirect(action: show, id: params.id) |
---|
480 | return |
---|
481 | } |
---|
482 | |
---|
483 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
484 | |
---|
485 | if(result.taskInstance) |
---|
486 | redirect(action: show, id: params.id) |
---|
487 | else |
---|
488 | redirect(action: 'search') |
---|
489 | |
---|
490 | } |
---|
491 | |
---|
492 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
493 | def trash = { |
---|
494 | |
---|
495 | def result = taskService.trash(params) |
---|
496 | |
---|
497 | if(!result.error) { |
---|
498 | flash.message = "Task ${params.id} has been moved to trash." |
---|
499 | redirect(action: 'search') |
---|
500 | return |
---|
501 | } |
---|
502 | |
---|
503 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
504 | |
---|
505 | if(result.taskInstance) |
---|
506 | redirect(action: show, id: params.id) |
---|
507 | else |
---|
508 | redirect(action: 'search') |
---|
509 | |
---|
510 | } |
---|
511 | |
---|
512 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
513 | def approve = { |
---|
514 | |
---|
515 | def result = taskService.approve(params) |
---|
516 | |
---|
517 | if(!result.error) { |
---|
518 | flash.message = "Task ${params.id} has been approved." |
---|
519 | redirect(action: show, id: params.id) |
---|
520 | return |
---|
521 | } |
---|
522 | |
---|
523 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
524 | |
---|
525 | if(result.taskInstance) |
---|
526 | redirect(action: show, id: params.id) |
---|
527 | else |
---|
528 | redirect(action: 'search') |
---|
529 | |
---|
530 | } |
---|
531 | |
---|
532 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
533 | def renegeApproval = { |
---|
534 | |
---|
535 | def result = taskService.renegeApproval(params) |
---|
536 | |
---|
537 | if(!result.error) { |
---|
538 | flash.message = "Task ${params.id} has had approval removed." |
---|
539 | redirect(action: show, id: params.id) |
---|
540 | return |
---|
541 | } |
---|
542 | |
---|
543 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
544 | |
---|
545 | if(result.taskInstance) |
---|
546 | redirect(action: show, id: params.id) |
---|
547 | else |
---|
548 | redirect(action: 'search') |
---|
549 | |
---|
550 | } |
---|
551 | |
---|
552 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
553 | def complete = { |
---|
554 | |
---|
555 | def result = taskService.complete(params) |
---|
556 | |
---|
557 | if(!result.error) { |
---|
558 | flash.message = "Task ${params.id} has been completed." |
---|
559 | redirect(action: show, id: params.id) |
---|
560 | return |
---|
561 | } |
---|
562 | |
---|
563 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
564 | |
---|
565 | if(result.taskInstance) |
---|
566 | redirect(action: show, id: params.id) |
---|
567 | else |
---|
568 | redirect(action: 'search') |
---|
569 | |
---|
570 | } |
---|
571 | |
---|
572 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
573 | def setAttentionFlag = { |
---|
574 | |
---|
575 | def result = taskService.setAttentionFlag(params) |
---|
576 | |
---|
577 | if(!result.error) { |
---|
578 | flash.message = "Task ${params.id} has been flagged for attention." |
---|
579 | redirect(action: show, id: params.id) |
---|
580 | return |
---|
581 | } |
---|
582 | |
---|
583 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
584 | |
---|
585 | if(result.taskInstance) |
---|
586 | redirect(action: show, id: params.id) |
---|
587 | else |
---|
588 | redirect(action: 'search') |
---|
589 | |
---|
590 | } |
---|
591 | |
---|
592 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
593 | def clearAttentionFlag = { |
---|
594 | |
---|
595 | def result = taskService.clearAttentionFlag(params) |
---|
596 | |
---|
597 | if(!result.error) { |
---|
598 | flash.message = "Task ${params.id} attention flag cleared." |
---|
599 | redirect(action: show, id: params.id) |
---|
600 | return |
---|
601 | } |
---|
602 | |
---|
603 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
604 | |
---|
605 | if(result.taskInstance) |
---|
606 | redirect(action: show, id: params.id) |
---|
607 | else |
---|
608 | redirect(action: 'search') |
---|
609 | |
---|
610 | } |
---|
611 | |
---|
612 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
613 | def reopen = { |
---|
614 | |
---|
615 | def result = taskService.reopen(params) |
---|
616 | |
---|
617 | if(!result.error) { |
---|
618 | flash.message = "Task ${params.id} has been reopened." |
---|
619 | redirect(action: show, id: params.id) |
---|
620 | return |
---|
621 | } |
---|
622 | |
---|
623 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
624 | |
---|
625 | if(result.taskInstance) |
---|
626 | redirect(action: show, id: params.id) |
---|
627 | else |
---|
628 | redirect(action: 'search') |
---|
629 | |
---|
630 | } |
---|
631 | |
---|
632 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
633 | def edit = { |
---|
634 | |
---|
635 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
636 | if(params._action_Edit) |
---|
637 | params.action='edit' |
---|
638 | |
---|
639 | // Used by navigation. |
---|
640 | if(params.id == 'nav') { |
---|
641 | params.id = session.currentTaskId ?: null |
---|
642 | redirect(action: edit, id: params.id) |
---|
643 | return |
---|
644 | } |
---|
645 | |
---|
646 | def taskInstance = Task.get( params.id ) |
---|
647 | |
---|
648 | if(!taskInstance) { |
---|
649 | flash.message = "Task not found with id ${params.id}" |
---|
650 | redirect(action: 'search') |
---|
651 | } |
---|
652 | else { |
---|
653 | // Remember the current task id for use with navigation. |
---|
654 | session.currentTaskId = params.id |
---|
655 | |
---|
656 | if(taskInstance.trash) { |
---|
657 | flash.message = "You may not edit tasks that are in the trash." |
---|
658 | redirect(action: 'show', id: taskInstance.id) |
---|
659 | return |
---|
660 | } |
---|
661 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
662 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
663 | return [ taskInstance : taskInstance ] |
---|
664 | } |
---|
665 | } |
---|
666 | |
---|
667 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
668 | def update = { |
---|
669 | |
---|
670 | def result = taskService.update(params) |
---|
671 | |
---|
672 | if(!result.error) { |
---|
673 | flash.message = "Task ${params.id} updated" |
---|
674 | redirect(action: show, id: params.id) |
---|
675 | return |
---|
676 | } |
---|
677 | |
---|
678 | if(result.error.code == "task.modifications.failedToSave") |
---|
679 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
680 | |
---|
681 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
---|
682 | |
---|
683 | } |
---|
684 | |
---|
685 | /** |
---|
686 | * The create action is used to create scheduled types of tasks. |
---|
687 | */ |
---|
688 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
689 | def create = { |
---|
690 | def taskInstance = new Task() |
---|
691 | |
---|
692 | // Set the targetStartDate if specified, used by searchCalendar view. |
---|
693 | if(params.year && params.month && params.day) { |
---|
694 | def date = dateUtilService.makeDate(params.year, params.month, params.day) |
---|
695 | taskInstance.targetStartDate = date |
---|
696 | taskInstance.targetCompletionDate = date |
---|
697 | } |
---|
698 | |
---|
699 | // Default leadPerson to current user, unless supplied in params. |
---|
700 | taskInstance.leadPerson = authService.currentUser |
---|
701 | |
---|
702 | // Apply params, overiding anything above. |
---|
703 | taskInstance.properties = params |
---|
704 | |
---|
705 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
706 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
707 | taskInstance.taskPriority = scheduledTaskPriorities.default |
---|
708 | return ['taskInstance': taskInstance, |
---|
709 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
710 | 'scheduledTaskPriorities': scheduledTaskPriorities.list] |
---|
711 | } |
---|
712 | |
---|
713 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
714 | def save = { |
---|
715 | def result = taskService.save(params) |
---|
716 | |
---|
717 | if(!result.error) { |
---|
718 | flash.message = "Task ${result.taskInstance.id} created." |
---|
719 | redirect(action: 'show', id: result.taskInstance.id) |
---|
720 | return |
---|
721 | } |
---|
722 | |
---|
723 | if(result.error.code == "task.modifications.failedToSave") |
---|
724 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
725 | |
---|
726 | |
---|
727 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
728 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
729 | render(view:'create', model:[taskInstance:result.taskInstance, |
---|
730 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
731 | 'scheduledTaskPriorities': scheduledTaskPriorities.list]) |
---|
732 | } |
---|
733 | |
---|
734 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
735 | def listSubTasks = { |
---|
736 | def parentTaskInstance = Task.get(params.id) |
---|
737 | |
---|
738 | if(!parentTaskInstance) { |
---|
739 | flash.message = "Task not found with id ${params.id}" |
---|
740 | redirect(action: 'search') |
---|
741 | } |
---|
742 | else { |
---|
743 | params.max = Math.min( params.max ? params.max.toInteger() : 200, 200) |
---|
744 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
745 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
746 | |
---|
747 | [ taskInstanceList: subTaskInstanceList, |
---|
748 | taskInstanceTotal: subTaskInstanceTotal, |
---|
749 | parentTaskInstance: parentTaskInstance] |
---|
750 | } |
---|
751 | } |
---|
752 | |
---|
753 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
754 | def createSubTask = { |
---|
755 | def parentTaskInstance = Task.get(params.id) |
---|
756 | |
---|
757 | if(parentTaskInstance) { |
---|
758 | |
---|
759 | def result = taskService.createSubTask(parentTaskInstance) |
---|
760 | if(!result.error) { |
---|
761 | flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements." |
---|
762 | redirect(action: 'edit', id: result.taskInstance.id) |
---|
763 | } |
---|
764 | else { |
---|
765 | if(result.taskInstance.errors.hasFieldErrors("parentTask")) { |
---|
766 | flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
767 | redirect(action: 'show', id: parentTaskInstance.id) |
---|
768 | } |
---|
769 | else { |
---|
770 | render(view: 'create', model:[taskInstance: result.taskInstance]) |
---|
771 | } |
---|
772 | } |
---|
773 | } |
---|
774 | |
---|
775 | else { |
---|
776 | flash.message = "Task not found with id ${params.id}" |
---|
777 | redirect(action: 'search') |
---|
778 | } |
---|
779 | } |
---|
780 | |
---|
781 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
782 | def createUnscheduled = { |
---|
783 | def taskInstance = new Task() |
---|
784 | |
---|
785 | // Default leadPerson to current user, unless supplied in params. |
---|
786 | taskInstance.leadPerson = authService.currentUser |
---|
787 | taskInstance.properties = params |
---|
788 | |
---|
789 | // Always for Unscheduled task. |
---|
790 | taskInstance.taskType = TaskType.get(2) // Unscheduled Breakin. |
---|
791 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
792 | taskInstance.taskPriority = unscheduledTaskPriorities.default |
---|
793 | |
---|
794 | return ['taskInstance': taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list] |
---|
795 | } |
---|
796 | |
---|
797 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
798 | def saveUnscheduled = { |
---|
799 | def result = taskService.saveUnscheduled(params) |
---|
800 | |
---|
801 | if(!result.error) { |
---|
802 | flash.message = "Task ${result.taskInstance.id} created." |
---|
803 | redirect(action: 'show', id: result.taskInstance.id) |
---|
804 | return |
---|
805 | } |
---|
806 | |
---|
807 | if(result.error.code == "task.modifications.failedToSave") |
---|
808 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
809 | |
---|
810 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
811 | |
---|
812 | render(view:'createUnscheduled', |
---|
813 | model: ['taskInstance': result.taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list]) |
---|
814 | } |
---|
815 | |
---|
816 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
817 | def createImmediateCallout = { |
---|
818 | def taskInstance = new Task() |
---|
819 | |
---|
820 | def entryFaultInstance = new Entry(entryType: EntryType.get(1)) // Fault. |
---|
821 | def entryCauseInstance = new Entry(entryType: EntryType.get(2)) // Cause. |
---|
822 | def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3)) // Work Done. |
---|
823 | |
---|
824 | return ['taskInstance': taskInstance, |
---|
825 | 'entryFaultInstance': entryFaultInstance, |
---|
826 | 'entryCauseInstance': entryCauseInstance, |
---|
827 | 'entryWorkDoneInstance': entryWorkDoneInstance] |
---|
828 | } |
---|
829 | |
---|
830 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
831 | def saveImmediateCallout = { |
---|
832 | def result = taskService.saveImmediateCallout(params) |
---|
833 | |
---|
834 | if(!result.error) { |
---|
835 | flash.message = "Task ${result.taskInstance.id} created." |
---|
836 | redirect(action: 'show', id: result.taskInstance.id) |
---|
837 | return |
---|
838 | } |
---|
839 | |
---|
840 | if(result.error.code == "task.modifications.failedToSave") |
---|
841 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
842 | |
---|
843 | render(view:'createImmediateCallout', |
---|
844 | model: ['taskInstance': result.taskInstance, |
---|
845 | 'entryFaultInstance': result.entryFaultInstance, |
---|
846 | 'entryCauseInstance': result.entryCauseInstance, |
---|
847 | 'entryWorkDoneInstance': result.entryWorkDoneInstance]) |
---|
848 | |
---|
849 | } |
---|
850 | |
---|
851 | /** |
---|
852 | * Render a users total work done hours. |
---|
853 | */ |
---|
854 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
855 | def workDone = { |
---|
856 | def result = taskSearchService.getWorkDone(params, RCU.getLocale(request)) |
---|
857 | |
---|
858 | params.message = result.message |
---|
859 | |
---|
860 | return[entries: result.entries, |
---|
861 | totalEntries : result.totalEntries, |
---|
862 | startOfDay: result.startOfDay, |
---|
863 | person: result.person, |
---|
864 | totalHours: result.totalHours, |
---|
865 | totalMinutes: result.totalMinutes] |
---|
866 | } // workDone |
---|
867 | |
---|
868 | /** |
---|
869 | * Render work load hours. |
---|
870 | */ |
---|
871 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
872 | def workLoad= { |
---|
873 | def result = taskSearchService.getWorkLoad(params, RCU.getLocale(request)) |
---|
874 | |
---|
875 | params.message = result.message |
---|
876 | params.errorMessage = result.errorMessage |
---|
877 | |
---|
878 | return[tasks: result.tasks, |
---|
879 | startDate: result.startDate, |
---|
880 | endDate: result.endDate, |
---|
881 | taskGroups: result.taskGroups, |
---|
882 | taskStatusList: result.taskStatusList, |
---|
883 | workLoadGroups: result.workLoadGroups, |
---|
884 | totalHours: result.totalHours, |
---|
885 | totalMinutes: result.totalMinutes] |
---|
886 | } // workLoad |
---|
887 | |
---|
888 | /** |
---|
889 | * Get some integers for use by the month control links. |
---|
890 | */ |
---|
891 | private getCalendarMonthControls(Date showDate) { |
---|
892 | def result = [:] |
---|
893 | result.today = [:] |
---|
894 | result.today.date = new Date() |
---|
895 | result.today.month = dateUtilService.getMonthFromDate(result.today.date) |
---|
896 | result.today.year = dateUtilService.getYearFromDate(result.today.date) |
---|
897 | result.nextMonth = [:] |
---|
898 | result.nextMonth.date = dateUtilService.plusMonth(showDate) |
---|
899 | result.nextMonth.month = dateUtilService.getMonthFromDate(result.nextMonth.date) |
---|
900 | result.nextMonth.year = dateUtilService.getYearFromDate(result.nextMonth.date) |
---|
901 | result.previousMonth = [:] |
---|
902 | result.previousMonth.date = dateUtilService.plusMonth(showDate, -1) |
---|
903 | result.previousMonth.month = dateUtilService.getMonthFromDate(result.previousMonth.date) |
---|
904 | result.previousMonth.year = dateUtilService.getYearFromDate(result.previousMonth.date) |
---|
905 | result.nextYear = [:] |
---|
906 | result.nextYear.date = dateUtilService.plusYear(showDate) |
---|
907 | result.nextYear.month = dateUtilService.getMonthFromDate(result.nextYear.date) |
---|
908 | result.nextYear.year = dateUtilService.getYearFromDate(result.nextYear.date) |
---|
909 | result.previousYear = [:] |
---|
910 | result.previousYear.date = dateUtilService.plusYear(showDate, -1) |
---|
911 | result.previousYear.month = dateUtilService.getMonthFromDate(result.previousYear.date) |
---|
912 | result.previousYear.year = dateUtilService.getYearFromDate(result.previousYear.date) |
---|
913 | return result |
---|
914 | } |
---|
915 | |
---|
916 | } // end of class. |
---|