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