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