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