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