[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 | |
---|
[85] | 5 | class TaskDetailedController extends BaseController { |
---|
[66] | 6 | |
---|
[185] | 7 | def personService |
---|
[180] | 8 | def taskService |
---|
[143] | 9 | def taskSearchService |
---|
[140] | 10 | def filterService |
---|
[165] | 11 | def exportService |
---|
[214] | 12 | def dateUtilService |
---|
[139] | 13 | |
---|
[181] | 14 | // these actions only accept POST requests |
---|
| 15 | static allowedMethods = [save:'POST', update:'POST', restore:'POST', trash:'POST', approve:'POST', renegeApproval:'POST', complete:'POST', reopen:'POST'] |
---|
[66] | 16 | |
---|
[196] | 17 | def index = { redirect(action: 'search', params: params) } |
---|
[140] | 18 | |
---|
[66] | 19 | def list = { |
---|
[143] | 20 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
[124] | 21 | [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ] |
---|
[66] | 22 | } |
---|
[143] | 23 | |
---|
[260] | 24 | def setTaskSearchParamsMax = { |
---|
[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 | |
---|
[139] | 36 | def search = { |
---|
[143] | 37 | |
---|
[260] | 38 | if(session.taskSearchParamsMax) |
---|
| 39 | params.max = session.taskSearchParamsMax |
---|
| 40 | |
---|
| 41 | // TaskSearchService protects itself but filterPane does not. |
---|
[262] | 42 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 1000 ) |
---|
[260] | 43 | |
---|
| 44 | def taskInstanceList = [] |
---|
| 45 | def taskInstanceTotal |
---|
| 46 | def filterParams = [:] |
---|
| 47 | def personInstance = personService.currentUser |
---|
| 48 | |
---|
[155] | 49 | // Quick Search: |
---|
[209] | 50 | if(!FilterUtils.isFilterApplied(params)) { |
---|
[143] | 51 | |
---|
[155] | 52 | if(params.quickSearch == "searchMyTodays") { |
---|
[144] | 53 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
| 54 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
| 55 | else { params.message = "No tasks found for today." } |
---|
| 56 | } |
---|
[155] | 57 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
[144] | 58 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
| 59 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
[185] | 60 | else { params.message = "No tasks found for the last week." } |
---|
[144] | 61 | } |
---|
[155] | 62 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
[144] | 63 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
| 64 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
[185] | 65 | else { params.message = "No tasks found for the last week." } |
---|
[144] | 66 | } |
---|
| 67 | else { |
---|
| 68 | //Default: |
---|
| 69 | taskInstanceList = taskSearchService.getTodays(params) |
---|
| 70 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
| 71 | else { params.message = "No tasks found for today." } |
---|
[155] | 72 | params.quickSearch = "searchTodays" |
---|
[144] | 73 | } |
---|
[260] | 74 | |
---|
| 75 | taskInstanceTotal = taskInstanceList.totalCount |
---|
| 76 | filterParams.quickSearch = params.quickSearch |
---|
[139] | 77 | } |
---|
[260] | 78 | else { |
---|
| 79 | // filterPane: |
---|
| 80 | taskInstanceList = filterService.filter( params, Task ) |
---|
| 81 | taskInstanceTotal = filterService.count( params, Task ) |
---|
| 82 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
| 83 | } |
---|
[143] | 84 | |
---|
[260] | 85 | // export plugin: |
---|
| 86 | if(params?.format && params.format != "html") { |
---|
| 87 | |
---|
| 88 | def dateFmt = { date -> |
---|
| 89 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | String title |
---|
| 93 | if(params.quickSearch) |
---|
| 94 | title = "${params.quickSearch} tasks." |
---|
| 95 | else |
---|
| 96 | title = "Filtered tasks." |
---|
| 97 | |
---|
| 98 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
| 99 | response.setHeader("Content-disposition", "attachment; filename=tasks.${params.extension}") |
---|
| 100 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskStatus"] |
---|
| 101 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
| 102 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", "taskStatus": "Task Status"] |
---|
| 103 | Map formatters = [ targetStartDate: dateFmt] |
---|
| 104 | Map parameters = [title: title, separator: ","] |
---|
| 105 | |
---|
| 106 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | // Add some basic params to filterParams. |
---|
| 110 | filterParams.max = params.max |
---|
| 111 | filterParams.offset = params.offset?.toInteger() ?: 0 |
---|
| 112 | filterParams.sort = params.sort ?: "id" |
---|
| 113 | filterParams.order = params.order ?: "desc" |
---|
| 114 | |
---|
| 115 | return[ taskInstanceList: taskInstanceList, |
---|
| 116 | taskInstanceTotal: taskInstanceTotal, |
---|
| 117 | filterParams: filterParams ] |
---|
| 118 | |
---|
| 119 | } // end search() |
---|
| 120 | |
---|
[155] | 121 | def searchCalendar = { |
---|
| 122 | params.max = 30 |
---|
[140] | 123 | |
---|
[155] | 124 | // Quick Search: |
---|
[209] | 125 | if(!FilterUtils.isFilterApplied(params)) { |
---|
[155] | 126 | def taskInstanceList = [] |
---|
[216] | 127 | def personInstance = personService.currentUser |
---|
[155] | 128 | |
---|
| 129 | if(params.quickSearch == "searchMyTodays") { |
---|
| 130 | taskInstanceList = taskSearchService.getMyTodays(params) |
---|
| 131 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
| 132 | else { params.message = "No tasks found for today." } |
---|
| 133 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 134 | } |
---|
| 135 | else if(params.quickSearch == "searchInTheLastWeek") { |
---|
| 136 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
---|
| 137 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
---|
[185] | 138 | else { params.message = "No tasks found for the last week." } |
---|
[155] | 139 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 140 | } |
---|
| 141 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
---|
| 142 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
---|
| 143 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
---|
[185] | 144 | else { params.message = "No tasks found for the last week." } |
---|
[155] | 145 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 146 | } |
---|
| 147 | else { |
---|
| 148 | //Default: |
---|
| 149 | taskInstanceList = taskSearchService.getTodays(params) |
---|
| 150 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
---|
| 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 | params.quickSearch = "searchTodays" |
---|
| 154 | } |
---|
| 155 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
[139] | 156 | } |
---|
[155] | 157 | // filterPane: |
---|
| 158 | def taskInstanceTotal = filterService.count( params, Task ) |
---|
| 159 | if(taskInstanceTotal > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
---|
| 160 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
| 161 | taskInstanceTotal: taskInstanceTotal, |
---|
| 162 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
| 163 | params:params ] |
---|
[139] | 164 | } |
---|
[140] | 165 | |
---|
[165] | 166 | def budget = { |
---|
| 167 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
---|
| 168 | |
---|
| 169 | // Quick Search: |
---|
[209] | 170 | if(!FilterUtils.isFilterApplied(params)) { |
---|
[165] | 171 | def taskInstanceList = [] |
---|
[216] | 172 | def personInstance = personService.currentUser |
---|
[165] | 173 | |
---|
| 174 | if(params.quickSearch == "budgetUnplanned") { |
---|
| 175 | taskInstanceList = taskSearchService.getBudgetUnplanned(params) |
---|
| 176 | if(taskInstanceList.totalCount > 0) { params.message = "Budget unplanned tasks in the last week." } |
---|
| 177 | else { params.message = "No tasks found." } |
---|
| 178 | } |
---|
| 179 | //else if(params.quickSearch == "budgetPlanned") { |
---|
| 180 | else { |
---|
| 181 | //Default: |
---|
| 182 | taskInstanceList = taskSearchService.getBudgetPlanned(params) |
---|
| 183 | if(taskInstanceList.totalCount > 0) { params.message = "Budget planned Tasks in the last week." } |
---|
| 184 | else { params.message = "No tasks found.." } |
---|
| 185 | } |
---|
| 186 | // export plugin: |
---|
| 187 | if(params?.format && params.format != "html") { |
---|
[260] | 188 | |
---|
| 189 | def dateFmt = { date -> |
---|
| 190 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
| 191 | } |
---|
[165] | 192 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
| 193 | response.setHeader("Content-disposition", "attachment; filename=tasks.${params.extension}") |
---|
| 194 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskStatus", "taskType"] |
---|
| 195 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
| 196 | "leadPerson": "Lead Person", "taskStatus": "Task Status", "taskType": "Task Type"] |
---|
[260] | 197 | Map formatters = [ targetStartDate: dateFmt] |
---|
[165] | 198 | String title = "${params.quickSearch} tasks in the last week." |
---|
[260] | 199 | Map parameters = [title: title, separator: ","] |
---|
[165] | 200 | |
---|
| 201 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
| 202 | } |
---|
| 203 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
---|
| 204 | } |
---|
| 205 | // filterPane: |
---|
| 206 | return[ taskInstanceList: filterService.filter( params, Task ), |
---|
| 207 | taskInstanceTotal: filterService.count( params, Task ), |
---|
| 208 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
---|
| 209 | params:params ] |
---|
| 210 | } |
---|
| 211 | |
---|
[66] | 212 | def show = { |
---|
[147] | 213 | |
---|
[139] | 214 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 215 | if(params._action_Show) |
---|
| 216 | { params.action='show' } |
---|
| 217 | |
---|
[225] | 218 | def showTab = [:] |
---|
| 219 | switch (params.showTab) { |
---|
| 220 | case "showProcedureTab": |
---|
| 221 | showTab.procedure = new String("true") |
---|
| 222 | break |
---|
| 223 | case "showRecurrenceTab": |
---|
| 224 | showTab.recurrence = new String("true") |
---|
| 225 | break |
---|
| 226 | case "showInventoryTab": |
---|
| 227 | showTab.inventory = new String("true") |
---|
| 228 | break |
---|
| 229 | case "showSubTasksTab": |
---|
| 230 | showTab.subTasks = new String("true") |
---|
| 231 | break |
---|
| 232 | default: |
---|
| 233 | showTab.task = new String("true") |
---|
| 234 | } |
---|
| 235 | |
---|
[66] | 236 | def taskInstance = Task.get( params.id ) |
---|
| 237 | |
---|
| 238 | if(!taskInstance) { |
---|
| 239 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 240 | redirect(action: 'search') |
---|
[66] | 241 | } |
---|
[133] | 242 | else { |
---|
[179] | 243 | params.max = 10 |
---|
| 244 | params.order = "desc" |
---|
| 245 | params.sort = "id" |
---|
[134] | 246 | |
---|
[179] | 247 | def entryWorkDoneList = Entry.withCriteria { |
---|
[190] | 248 | eq("entryType", EntryType.get(2)) |
---|
[179] | 249 | eq("task", taskInstance) |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | def entryFaultList = Entry.withCriteria { |
---|
[190] | 253 | eq("entryType", EntryType.get(1)) |
---|
[179] | 254 | eq("task", taskInstance) |
---|
| 255 | } |
---|
| 256 | |
---|
[196] | 257 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
---|
| 258 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
---|
[134] | 259 | |
---|
[175] | 260 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
| 261 | |
---|
[180] | 262 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
| 263 | |
---|
[253] | 264 | def assignedGroupList = taskInstance.assignedGroups.sort { p1, p2 -> p1.personGroup.name.compareToIgnoreCase(p2.personGroup.name) } |
---|
| 265 | def assignedPersonList = taskInstance.assignedPersons.sort { p1, p2 -> p1.person.firstName.compareToIgnoreCase(p2.person.firstName) } |
---|
| 266 | |
---|
[133] | 267 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
| 268 | def taskProcedureExits = new Boolean("true") |
---|
| 269 | if(!taskProcedureInstance) { |
---|
| 270 | taskProcedureExits = false |
---|
| 271 | } |
---|
[175] | 272 | |
---|
| 273 | params.order = "asc" |
---|
| 274 | params.sort = "procedureStepNumber" |
---|
| 275 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
| 276 | |
---|
[134] | 277 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
| 278 | def taskRecurringScheduleExits= new Boolean("true") |
---|
[175] | 279 | if(!taskRecurringScheduleInstance) { |
---|
[134] | 280 | taskRecurringScheduleExits = false |
---|
| 281 | } |
---|
[179] | 282 | |
---|
[137] | 283 | return [ taskInstance: taskInstance, |
---|
[179] | 284 | entryWorkDoneList: entryWorkDoneList, |
---|
| 285 | entryFaultList: entryFaultList, |
---|
[133] | 286 | taskProcedureInstance: taskProcedureInstance, |
---|
| 287 | taskProcedureExits: taskProcedureExits, |
---|
[225] | 288 | showTab: showTab, |
---|
[179] | 289 | subTaskInstanceList: subTaskInstanceList, |
---|
| 290 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
| 291 | subTaskInstanceMax: params.max, |
---|
| 292 | maintenanceActionList: maintenanceActionList, |
---|
| 293 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
| 294 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
[180] | 295 | inventoryMovementList: inventoryMovementList, |
---|
[253] | 296 | taskModificationList: taskModificationList, |
---|
| 297 | assignedGroupList: assignedGroupList, |
---|
| 298 | assignedPersonList: assignedPersonList] |
---|
[131] | 299 | } |
---|
[66] | 300 | } |
---|
| 301 | |
---|
[181] | 302 | def restore = { |
---|
| 303 | |
---|
| 304 | if(!Task.exists(params.id)) { |
---|
| 305 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 306 | redirect(action: 'search') |
---|
[181] | 307 | } |
---|
| 308 | |
---|
| 309 | def result = taskService.restore(params) |
---|
| 310 | |
---|
| 311 | if(!result.error) { |
---|
| 312 | flash.message = "Task ${params.id} has been restored." |
---|
[196] | 313 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 314 | } |
---|
| 315 | else { |
---|
| 316 | if(result.taskInstance) { |
---|
| 317 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
[96] | 318 | } |
---|
[181] | 319 | else { |
---|
| 320 | flash.message = "Task could not be updated." |
---|
[196] | 321 | redirect(action: 'search') |
---|
[96] | 322 | } |
---|
[66] | 323 | } |
---|
[181] | 324 | |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | def trash = { |
---|
| 328 | |
---|
| 329 | if(!Task.exists(params.id)) { |
---|
| 330 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 331 | redirect(action: 'search') |
---|
[181] | 332 | } |
---|
| 333 | |
---|
| 334 | def result = taskService.trash(params) |
---|
| 335 | |
---|
| 336 | if(!result.error) { |
---|
| 337 | flash.message = "Task ${params.id} has been moved to trash." |
---|
[196] | 338 | redirect(action: 'search') |
---|
[181] | 339 | } |
---|
[66] | 340 | else { |
---|
[181] | 341 | if(result.taskInstance) { |
---|
| 342 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 343 | } |
---|
| 344 | else { |
---|
| 345 | flash.message = "Task could not be updated." |
---|
[196] | 346 | redirect(action: 'search') |
---|
[181] | 347 | } |
---|
[66] | 348 | } |
---|
[181] | 349 | |
---|
[66] | 350 | } |
---|
| 351 | |
---|
[181] | 352 | def approve = { |
---|
| 353 | |
---|
| 354 | if(!Task.exists(params.id)) { |
---|
| 355 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 356 | redirect(action: 'search') |
---|
[181] | 357 | } |
---|
| 358 | |
---|
| 359 | def result = taskService.approve(params) |
---|
| 360 | |
---|
| 361 | if(!result.error) { |
---|
| 362 | flash.message = "Task ${params.id} has been approved." |
---|
[196] | 363 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 364 | } |
---|
| 365 | else { |
---|
| 366 | if(result.taskInstance) { |
---|
| 367 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 368 | } |
---|
| 369 | else { |
---|
| 370 | flash.message = "Task could not be updated." |
---|
[196] | 371 | redirect(action: 'search') |
---|
[181] | 372 | } |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | def renegeApproval = { |
---|
| 378 | |
---|
| 379 | if(!Task.exists(params.id)) { |
---|
| 380 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 381 | redirect(action: 'search') |
---|
[181] | 382 | } |
---|
| 383 | |
---|
| 384 | def result = taskService.renegeApproval(params) |
---|
| 385 | |
---|
| 386 | if(!result.error) { |
---|
| 387 | flash.message = "Task ${params.id} has had approval removed." |
---|
[196] | 388 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 389 | } |
---|
| 390 | else { |
---|
| 391 | if(result.taskInstance) { |
---|
| 392 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 393 | } |
---|
| 394 | else { |
---|
| 395 | flash.message = "Task could not be updated." |
---|
[196] | 396 | redirect(action: 'search') |
---|
[181] | 397 | } |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | def complete = { |
---|
| 403 | |
---|
| 404 | if(!Task.exists(params.id)) { |
---|
| 405 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 406 | redirect(action: 'search') |
---|
[181] | 407 | } |
---|
| 408 | |
---|
| 409 | def result = taskService.complete(params) |
---|
| 410 | |
---|
| 411 | if(!result.error) { |
---|
| 412 | flash.message = "Task ${params.id} has been completed." |
---|
[196] | 413 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 414 | } |
---|
| 415 | else { |
---|
| 416 | if(result.taskInstance) { |
---|
| 417 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 418 | } |
---|
| 419 | else { |
---|
| 420 | flash.message = "Task could not be updated." |
---|
[196] | 421 | redirect(action: 'search') |
---|
[181] | 422 | } |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | def reopen = { |
---|
| 428 | |
---|
| 429 | if(!Task.exists(params.id)) { |
---|
| 430 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 431 | redirect(action: 'search') |
---|
[181] | 432 | } |
---|
| 433 | |
---|
| 434 | def result = taskService.reopen(params) |
---|
| 435 | |
---|
| 436 | if(!result.error) { |
---|
| 437 | flash.message = "Task ${params.id} has been reopened." |
---|
[196] | 438 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 439 | } |
---|
| 440 | else { |
---|
| 441 | if(result.taskInstance) { |
---|
| 442 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 443 | } |
---|
| 444 | else { |
---|
| 445 | flash.message = "Task could not be updated." |
---|
[196] | 446 | redirect(action: 'search') |
---|
[181] | 447 | } |
---|
| 448 | } |
---|
| 449 | |
---|
| 450 | } |
---|
| 451 | |
---|
[66] | 452 | def edit = { |
---|
[147] | 453 | |
---|
[139] | 454 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 455 | if(params._action_Edit) |
---|
| 456 | { params.action='edit' } |
---|
[169] | 457 | |
---|
[66] | 458 | def taskInstance = Task.get( params.id ) |
---|
| 459 | |
---|
| 460 | if(!taskInstance) { |
---|
| 461 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 462 | redirect(action: 'search') |
---|
[66] | 463 | } |
---|
| 464 | else { |
---|
[181] | 465 | if(taskInstance.trash) { |
---|
[196] | 466 | flash.message = "You may not edit tasks that are in the trash." |
---|
| 467 | redirect(action: 'show', id: taskInstance.id) |
---|
| 468 | return |
---|
[181] | 469 | } |
---|
[246] | 470 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
| 471 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
| 472 | return [ taskInstance : taskInstance ] |
---|
[84] | 473 | } |
---|
| 474 | } |
---|
| 475 | |
---|
[66] | 476 | def update = { |
---|
[179] | 477 | |
---|
[180] | 478 | if(!Task.exists(params.id)) { |
---|
| 479 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 480 | redirect(action: 'search') |
---|
[180] | 481 | } |
---|
| 482 | |
---|
| 483 | def result = taskService.update(params) |
---|
| 484 | |
---|
| 485 | if(!result.error) { |
---|
[66] | 486 | flash.message = "Task ${params.id} updated" |
---|
[196] | 487 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[180] | 488 | } |
---|
| 489 | else { |
---|
[206] | 490 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
---|
[66] | 491 | } |
---|
[180] | 492 | |
---|
[66] | 493 | } |
---|
| 494 | |
---|
| 495 | def create = { |
---|
| 496 | def taskInstance = new Task() |
---|
[214] | 497 | |
---|
| 498 | // Set the targetStartDate if specified, used by searchCalendar view. |
---|
| 499 | if(params.year && params.month && params.day) |
---|
| 500 | taskInstance.targetStartDate = dateUtilService.makeDate(params.year, params.month, params.day) |
---|
| 501 | |
---|
[196] | 502 | // Default leadPerson to current user, unless supplied in params. |
---|
[216] | 503 | taskInstance.leadPerson = personService.currentUser |
---|
[66] | 504 | taskInstance.properties = params |
---|
[196] | 505 | return ['taskInstance': taskInstance] |
---|
[66] | 506 | } |
---|
| 507 | |
---|
| 508 | def save = { |
---|
[180] | 509 | def result = taskService.create(params) |
---|
| 510 | |
---|
| 511 | if(!result.error) { |
---|
| 512 | flash.message = "Task ${result.taskInstance.id} created." |
---|
[196] | 513 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[66] | 514 | } |
---|
| 515 | else { |
---|
[180] | 516 | if(result.taskInstance) { |
---|
[196] | 517 | render(view:'create', model:[taskInstance:result.taskInstance]) |
---|
[180] | 518 | } |
---|
| 519 | else { |
---|
| 520 | flash.message = "Could not create task." |
---|
[196] | 521 | redirect(action: 'search') |
---|
[180] | 522 | } |
---|
| 523 | |
---|
[66] | 524 | } |
---|
| 525 | } |
---|
[179] | 526 | |
---|
| 527 | def listSubTasks = { |
---|
| 528 | def parentTaskInstance = Task.get(params.id) |
---|
| 529 | |
---|
[134] | 530 | if(!parentTaskInstance) { |
---|
| 531 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 532 | redirect(action: 'search') |
---|
[133] | 533 | } |
---|
| 534 | else { |
---|
[179] | 535 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
[196] | 536 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
| 537 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
[179] | 538 | |
---|
[134] | 539 | [ taskInstanceList: subTaskInstanceList, |
---|
[179] | 540 | taskInstanceTotal: subTaskInstanceTotal, |
---|
| 541 | parentTaskInstance: parentTaskInstance] |
---|
| 542 | } |
---|
| 543 | } |
---|
| 544 | |
---|
[196] | 545 | def createSubTask = { |
---|
| 546 | def parentTaskInstance = Task.get(params.id) |
---|
| 547 | |
---|
| 548 | if(parentTaskInstance) { |
---|
| 549 | |
---|
| 550 | def result = taskService.createSubTask(parentTaskInstance) |
---|
| 551 | if(!result.error) { |
---|
| 552 | flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements." |
---|
| 553 | redirect(action: 'edit', id: result.taskInstance.id) |
---|
| 554 | } |
---|
| 555 | else { |
---|
| 556 | if(result.taskInstance.errors.hasFieldErrors("parentTask")) { |
---|
| 557 | flash.message = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
| 558 | redirect(action: 'show', id: parentTaskInstance.id) |
---|
| 559 | } |
---|
| 560 | else { |
---|
| 561 | render(view: 'create', model:[taskInstance: result.taskInstance]) |
---|
| 562 | } |
---|
| 563 | } |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | else { |
---|
| 567 | flash.message = "Task not found with id ${params.id}" |
---|
| 568 | redirect(action: 'search') |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | } // end of class. |
---|