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