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