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