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