[69] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
[165] | 2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
[209] | 3 | import com.zeddware.grails.plugins.filterpane.FilterUtils |
---|
[476] | 4 | import org.springframework.web.servlet.support.RequestContextUtils as RCU |
---|
[69] | 5 | |
---|
[298] | 6 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[85] | 7 | class TaskDetailedController extends BaseController { |
---|
[66] | 8 | |
---|
[291] | 9 | def authService |
---|
[180] | 10 | def taskService |
---|
[143] | 11 | def taskSearchService |
---|
[140] | 12 | def filterService |
---|
[165] | 13 | def exportService |
---|
[214] | 14 | def dateUtilService |
---|
[139] | 15 | |
---|
[181] | 16 | // these actions only accept POST requests |
---|
[418] | 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'] |
---|
[66] | 20 | |
---|
[298] | 21 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[196] | 22 | def index = { redirect(action: 'search', params: params) } |
---|
[140] | 23 | |
---|
[298] | 24 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[326] | 25 | def setSearchParamsMax = { |
---|
[262] | 26 | def max = 1000 |
---|
| 27 | if(params.newMax.isInteger()) { |
---|
[260] | 28 | def i = params.newMax.toInteger() |
---|
[262] | 29 | if(i > 0 && i <= max) |
---|
| 30 | session.taskSearchParamsMax = params.newMax |
---|
| 31 | if(i > max) |
---|
| 32 | session.taskSearchParamsMax = max |
---|
| 33 | } |
---|
[260] | 34 | forward(action: 'search', params: params) |
---|
| 35 | } |
---|
| 36 | |
---|
[298] | 37 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[476] | 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 | |
---|
[483] | 50 | /** |
---|
| 51 | * Search for tasks. |
---|
| 52 | */ |
---|
[476] | 53 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[139] | 54 | def search = { |
---|
[143] | 55 | |
---|
[260] | 56 | if(session.taskSearchParamsMax) |
---|
| 57 | params.max = session.taskSearchParamsMax |
---|
| 58 | |
---|
[468] | 59 | // Protect filterPane. |
---|
[476] | 60 | params.max = Math.min( params.max ? params.max.toInteger() : 20, 1000 ) |
---|
[260] | 61 | |
---|
| 62 | def taskInstanceList = [] |
---|
| 63 | def taskInstanceTotal |
---|
[476] | 64 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
| 65 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
[260] | 66 | |
---|
[476] | 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) |
---|
[144] | 75 | } |
---|
[476] | 76 | } |
---|
[260] | 77 | |
---|
[476] | 78 | if(isFilterApplied) { |
---|
[260] | 79 | // filterPane: |
---|
| 80 | taskInstanceList = filterService.filter( params, Task ) |
---|
| 81 | taskInstanceTotal = filterService.count( params, Task ) |
---|
| 82 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
[476] | 83 | // Remember search. |
---|
| 84 | session.taskSearchFilterParams = new LinkedHashMap(filterParams) |
---|
| 85 | session.taskSearchFilter = new LinkedHashMap(params.filter) |
---|
| 86 | session.taskSearchQuickSearch = null |
---|
[260] | 87 | } |
---|
[476] | 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 | } |
---|
[143] | 101 | |
---|
[260] | 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) |
---|
[476] | 111 | title = params.message |
---|
[260] | 112 | else |
---|
| 113 | title = "Filtered tasks." |
---|
| 114 | |
---|
| 115 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
[390] | 116 | response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}") |
---|
[475] | 117 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskType", "taskStatus"] |
---|
[260] | 118 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
[475] | 119 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", |
---|
| 120 | "taskType": "Task Type", "taskStatus": "Task Status"] |
---|
[260] | 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 |
---|
[418] | 130 | filterParams.sort = params.sort ?: "attentionFlag" |
---|
[260] | 131 | filterParams.order = params.order ?: "desc" |
---|
| 132 | |
---|
| 133 | return[ taskInstanceList: taskInstanceList, |
---|
[476] | 134 | taskInstanceTotal: taskInstanceTotal, |
---|
| 135 | filterParams: filterParams, |
---|
| 136 | params: params ] |
---|
[260] | 137 | |
---|
[476] | 138 | } // search |
---|
[260] | 139 | |
---|
[298] | 140 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[155] | 141 | def searchCalendar = { |
---|
[140] | 142 | |
---|
[476] | 143 | // No pagination for calendar. |
---|
| 144 | params.offset = 0 |
---|
[474] | 145 | |
---|
[476] | 146 | // Restore params.max |
---|
| 147 | if(session.taskSearchCalendarParamsMax) |
---|
| 148 | params.max = session.taskSearchCalendarParamsMax |
---|
| 149 | |
---|
[474] | 150 | // Protect filterPane. |
---|
[476] | 151 | params.max = Math.min( params.max ? params.max.toInteger() : 100, 1000 ) |
---|
[474] | 152 | |
---|
[476] | 153 | def taskInstanceList = [] |
---|
| 154 | def taskInstanceTotal |
---|
| 155 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
| 156 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
[474] | 157 | |
---|
[476] | 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 | } |
---|
[474] | 168 | |
---|
[476] | 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 |
---|
[155] | 182 | |
---|
[476] | 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 |
---|
[139] | 195 | } |
---|
[476] | 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 | } |
---|
[140] | 208 | |
---|
[476] | 209 | // export plugin: |
---|
| 210 | if(params?.format && params.format != "html") { |
---|
[165] | 211 | |
---|
[476] | 212 | def dateFmt = { date -> |
---|
| 213 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
[165] | 214 | } |
---|
[260] | 215 | |
---|
[476] | 216 | String title |
---|
| 217 | if(params.quickSearch) |
---|
| 218 | title = params.message |
---|
| 219 | else |
---|
| 220 | title = "Filtered tasks." |
---|
[165] | 221 | |
---|
[476] | 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) |
---|
[165] | 232 | } |
---|
| 233 | |
---|
[476] | 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 | |
---|
[298] | 254 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 255 | def show = { |
---|
[147] | 256 | |
---|
[139] | 257 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 258 | if(params._action_Show) |
---|
[375] | 259 | params.action='show' |
---|
[139] | 260 | |
---|
[433] | 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 | |
---|
[225] | 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 | |
---|
[66] | 286 | def taskInstance = Task.get( params.id ) |
---|
| 287 | |
---|
| 288 | if(!taskInstance) { |
---|
| 289 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 290 | redirect(action: 'search') |
---|
[66] | 291 | } |
---|
[133] | 292 | else { |
---|
[433] | 293 | // Remember the current task id for use with navigation. |
---|
| 294 | session.currentTaskId = params.id |
---|
| 295 | |
---|
[179] | 296 | params.max = 10 |
---|
| 297 | params.order = "desc" |
---|
| 298 | params.sort = "id" |
---|
[134] | 299 | |
---|
[418] | 300 | def entryFaultList = Entry.withCriteria { |
---|
| 301 | eq("entryType", EntryType.get(1)) |
---|
| 302 | eq("task", taskInstance) |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | def entryCauseList = Entry.withCriteria { |
---|
[190] | 306 | eq("entryType", EntryType.get(2)) |
---|
[179] | 307 | eq("task", taskInstance) |
---|
| 308 | } |
---|
| 309 | |
---|
[418] | 310 | def entryWorkDoneList = Entry.withCriteria { |
---|
| 311 | eq("entryType", EntryType.get(3)) |
---|
[179] | 312 | eq("task", taskInstance) |
---|
| 313 | } |
---|
| 314 | |
---|
[196] | 315 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
---|
| 316 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
---|
[134] | 317 | |
---|
[175] | 318 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
| 319 | |
---|
[180] | 320 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
| 321 | |
---|
[253] | 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 | |
---|
[133] | 325 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
| 326 | def taskProcedureExits = new Boolean("true") |
---|
| 327 | if(!taskProcedureInstance) { |
---|
| 328 | taskProcedureExits = false |
---|
| 329 | } |
---|
[175] | 330 | |
---|
| 331 | params.order = "asc" |
---|
| 332 | params.sort = "procedureStepNumber" |
---|
| 333 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
| 334 | |
---|
[134] | 335 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
| 336 | def taskRecurringScheduleExits= new Boolean("true") |
---|
[175] | 337 | if(!taskRecurringScheduleInstance) { |
---|
[134] | 338 | taskRecurringScheduleExits = false |
---|
| 339 | } |
---|
[179] | 340 | |
---|
[137] | 341 | return [ taskInstance: taskInstance, |
---|
[418] | 342 | entryFaultList: entryFaultList, |
---|
| 343 | entryCauseList: entryCauseList, |
---|
[179] | 344 | entryWorkDoneList: entryWorkDoneList, |
---|
[133] | 345 | taskProcedureInstance: taskProcedureInstance, |
---|
| 346 | taskProcedureExits: taskProcedureExits, |
---|
[225] | 347 | showTab: showTab, |
---|
[179] | 348 | subTaskInstanceList: subTaskInstanceList, |
---|
| 349 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
| 350 | subTaskInstanceMax: params.max, |
---|
| 351 | maintenanceActionList: maintenanceActionList, |
---|
| 352 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
| 353 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
[180] | 354 | inventoryMovementList: inventoryMovementList, |
---|
[253] | 355 | taskModificationList: taskModificationList, |
---|
| 356 | assignedGroupList: assignedGroupList, |
---|
| 357 | assignedPersonList: assignedPersonList] |
---|
[131] | 358 | } |
---|
[66] | 359 | } |
---|
| 360 | |
---|
[418] | 361 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 362 | def restore = { |
---|
| 363 | |
---|
| 364 | def result = taskService.restore(params) |
---|
| 365 | |
---|
| 366 | if(!result.error) { |
---|
| 367 | flash.message = "Task ${params.id} has been restored." |
---|
[418] | 368 | redirect(action: show, id: params.id) |
---|
| 369 | return |
---|
[181] | 370 | } |
---|
| 371 | |
---|
[418] | 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 | |
---|
[181] | 379 | } |
---|
| 380 | |
---|
[418] | 381 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 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." |
---|
[196] | 388 | redirect(action: 'search') |
---|
[418] | 389 | return |
---|
[181] | 390 | } |
---|
| 391 | |
---|
[418] | 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 | |
---|
[66] | 399 | } |
---|
| 400 | |
---|
[418] | 401 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[181] | 402 | def approve = { |
---|
| 403 | |
---|
| 404 | def result = taskService.approve(params) |
---|
| 405 | |
---|
| 406 | if(!result.error) { |
---|
| 407 | flash.message = "Task ${params.id} has been approved." |
---|
[418] | 408 | redirect(action: show, id: params.id) |
---|
| 409 | return |
---|
[181] | 410 | } |
---|
| 411 | |
---|
[418] | 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 | |
---|
[181] | 419 | } |
---|
| 420 | |
---|
[465] | 421 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[181] | 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." |
---|
[418] | 428 | redirect(action: show, id: params.id) |
---|
| 429 | return |
---|
[181] | 430 | } |
---|
| 431 | |
---|
[418] | 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 | |
---|
[181] | 439 | } |
---|
| 440 | |
---|
[298] | 441 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 442 | def complete = { |
---|
| 443 | |
---|
| 444 | def result = taskService.complete(params) |
---|
| 445 | |
---|
| 446 | if(!result.error) { |
---|
| 447 | flash.message = "Task ${params.id} has been completed." |
---|
[418] | 448 | redirect(action: show, id: params.id) |
---|
| 449 | return |
---|
[181] | 450 | } |
---|
[418] | 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 |
---|
[181] | 470 | } |
---|
| 471 | |
---|
[418] | 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 | |
---|
[181] | 479 | } |
---|
| 480 | |
---|
[298] | 481 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[418] | 482 | def clearAttentionFlag = { |
---|
[181] | 483 | |
---|
[418] | 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 |
---|
[181] | 490 | } |
---|
| 491 | |
---|
[418] | 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 | |
---|
[181] | 504 | def result = taskService.reopen(params) |
---|
| 505 | |
---|
| 506 | if(!result.error) { |
---|
| 507 | flash.message = "Task ${params.id} has been reopened." |
---|
[418] | 508 | redirect(action: show, id: params.id) |
---|
| 509 | return |
---|
[181] | 510 | } |
---|
| 511 | |
---|
[418] | 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 | |
---|
[181] | 519 | } |
---|
| 520 | |
---|
[298] | 521 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 522 | def edit = { |
---|
[147] | 523 | |
---|
[139] | 524 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 525 | if(params._action_Edit) |
---|
[375] | 526 | params.action='edit' |
---|
[169] | 527 | |
---|
[433] | 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 | |
---|
[66] | 535 | def taskInstance = Task.get( params.id ) |
---|
| 536 | |
---|
| 537 | if(!taskInstance) { |
---|
| 538 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 539 | redirect(action: 'search') |
---|
[66] | 540 | } |
---|
| 541 | else { |
---|
[433] | 542 | // Remember the current task id for use with navigation. |
---|
| 543 | session.currentTaskId = params.id |
---|
| 544 | |
---|
[181] | 545 | if(taskInstance.trash) { |
---|
[196] | 546 | flash.message = "You may not edit tasks that are in the trash." |
---|
| 547 | redirect(action: 'show', id: taskInstance.id) |
---|
| 548 | return |
---|
[181] | 549 | } |
---|
[246] | 550 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
| 551 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
| 552 | return [ taskInstance : taskInstance ] |
---|
[84] | 553 | } |
---|
| 554 | } |
---|
| 555 | |
---|
[298] | 556 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 557 | def update = { |
---|
[179] | 558 | |
---|
[180] | 559 | def result = taskService.update(params) |
---|
| 560 | |
---|
| 561 | if(!result.error) { |
---|
[66] | 562 | flash.message = "Task ${params.id} updated" |
---|
[418] | 563 | redirect(action: show, id: params.id) |
---|
| 564 | return |
---|
[180] | 565 | } |
---|
| 566 | |
---|
[418] | 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 | |
---|
[66] | 572 | } |
---|
| 573 | |
---|
[473] | 574 | /** |
---|
| 575 | * The create action is used to create scheduled types of tasks. |
---|
| 576 | */ |
---|
| 577 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[66] | 578 | def create = { |
---|
| 579 | def taskInstance = new Task() |
---|
[214] | 580 | |
---|
| 581 | // Set the targetStartDate if specified, used by searchCalendar view. |
---|
[476] | 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 | } |
---|
[214] | 587 | |
---|
[196] | 588 | // Default leadPerson to current user, unless supplied in params. |
---|
[291] | 589 | taskInstance.leadPerson = authService.currentUser |
---|
[66] | 590 | taskInstance.properties = params |
---|
[433] | 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] |
---|
[66] | 598 | } |
---|
| 599 | |
---|
[298] | 600 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 601 | def save = { |
---|
[394] | 602 | def result = taskService.save(params) |
---|
[180] | 603 | |
---|
| 604 | if(!result.error) { |
---|
| 605 | flash.message = "Task ${result.taskInstance.id} created." |
---|
[196] | 606 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[418] | 607 | return |
---|
[66] | 608 | } |
---|
[180] | 609 | |
---|
[418] | 610 | if(result.error.code == "task.modifications.failedToSave") |
---|
| 611 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 612 | |
---|
[433] | 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]) |
---|
[66] | 619 | } |
---|
[179] | 620 | |
---|
[298] | 621 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[179] | 622 | def listSubTasks = { |
---|
| 623 | def parentTaskInstance = Task.get(params.id) |
---|
| 624 | |
---|
[134] | 625 | if(!parentTaskInstance) { |
---|
| 626 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 627 | redirect(action: 'search') |
---|
[133] | 628 | } |
---|
| 629 | else { |
---|
[179] | 630 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
[196] | 631 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
| 632 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
[179] | 633 | |
---|
[134] | 634 | [ taskInstanceList: subTaskInstanceList, |
---|
[179] | 635 | taskInstanceTotal: subTaskInstanceTotal, |
---|
| 636 | parentTaskInstance: parentTaskInstance] |
---|
| 637 | } |
---|
| 638 | } |
---|
| 639 | |
---|
[298] | 640 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[196] | 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")) { |
---|
[418] | 653 | flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
[196] | 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 | |
---|
[395] | 668 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[433] | 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']) |
---|
[418] | 704 | def createImmediateCallout = { |
---|
[395] | 705 | def taskInstance = new Task() |
---|
| 706 | |
---|
| 707 | def entryFaultInstance = new Entry(entryType: EntryType.get(1)) // Fault. |
---|
[418] | 708 | def entryCauseInstance = new Entry(entryType: EntryType.get(2)) // Cause. |
---|
| 709 | def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3)) // Work Done. |
---|
[395] | 710 | |
---|
| 711 | return ['taskInstance': taskInstance, |
---|
| 712 | 'entryFaultInstance': entryFaultInstance, |
---|
[418] | 713 | 'entryCauseInstance': entryCauseInstance, |
---|
[395] | 714 | 'entryWorkDoneInstance': entryWorkDoneInstance] |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[418] | 718 | def saveImmediateCallout = { |
---|
| 719 | def result = taskService.saveImmediateCallout(params) |
---|
[395] | 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 | |
---|
[418] | 730 | render(view:'createImmediateCallout', |
---|
[395] | 731 | model: ['taskInstance': result.taskInstance, |
---|
| 732 | 'entryFaultInstance': result.entryFaultInstance, |
---|
[418] | 733 | 'entryCauseInstance': result.entryCauseInstance, |
---|
[395] | 734 | 'entryWorkDoneInstance': result.entryWorkDoneInstance]) |
---|
| 735 | |
---|
| 736 | } |
---|
| 737 | |
---|
[476] | 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 | |
---|
[196] | 766 | } // end of class. |
---|