[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 | |
---|
[133] | 202 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
| 203 | def taskProcedureExits = new Boolean("true") |
---|
| 204 | if(!taskProcedureInstance) { |
---|
| 205 | taskProcedureExits = false |
---|
| 206 | } |
---|
[175] | 207 | |
---|
| 208 | params.order = "asc" |
---|
| 209 | params.sort = "procedureStepNumber" |
---|
| 210 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
---|
| 211 | |
---|
[134] | 212 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
| 213 | def taskRecurringScheduleExits= new Boolean("true") |
---|
[175] | 214 | if(!taskRecurringScheduleInstance) { |
---|
[134] | 215 | taskRecurringScheduleExits = false |
---|
| 216 | } |
---|
[179] | 217 | |
---|
[137] | 218 | return [ taskInstance: taskInstance, |
---|
[179] | 219 | entryWorkDoneList: entryWorkDoneList, |
---|
| 220 | entryFaultList: entryFaultList, |
---|
[133] | 221 | taskProcedureInstance: taskProcedureInstance, |
---|
| 222 | taskProcedureExits: taskProcedureExits, |
---|
[225] | 223 | showTab: showTab, |
---|
[179] | 224 | subTaskInstanceList: subTaskInstanceList, |
---|
| 225 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
| 226 | subTaskInstanceMax: params.max, |
---|
| 227 | maintenanceActionList: maintenanceActionList, |
---|
| 228 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
| 229 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
[180] | 230 | inventoryMovementList: inventoryMovementList, |
---|
| 231 | taskModificationList: taskModificationList] |
---|
[131] | 232 | } |
---|
[66] | 233 | } |
---|
| 234 | |
---|
[181] | 235 | def restore = { |
---|
| 236 | |
---|
| 237 | if(!Task.exists(params.id)) { |
---|
| 238 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 239 | redirect(action: 'search') |
---|
[181] | 240 | } |
---|
| 241 | |
---|
| 242 | def result = taskService.restore(params) |
---|
| 243 | |
---|
| 244 | if(!result.error) { |
---|
| 245 | flash.message = "Task ${params.id} has been restored." |
---|
[196] | 246 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 247 | } |
---|
| 248 | else { |
---|
| 249 | if(result.taskInstance) { |
---|
| 250 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
[96] | 251 | } |
---|
[181] | 252 | else { |
---|
| 253 | flash.message = "Task could not be updated." |
---|
[196] | 254 | redirect(action: 'search') |
---|
[96] | 255 | } |
---|
[66] | 256 | } |
---|
[181] | 257 | |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | def trash = { |
---|
| 261 | |
---|
| 262 | if(!Task.exists(params.id)) { |
---|
| 263 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 264 | redirect(action: 'search') |
---|
[181] | 265 | } |
---|
| 266 | |
---|
| 267 | def result = taskService.trash(params) |
---|
| 268 | |
---|
| 269 | if(!result.error) { |
---|
| 270 | flash.message = "Task ${params.id} has been moved to trash." |
---|
[196] | 271 | redirect(action: 'search') |
---|
[181] | 272 | } |
---|
[66] | 273 | else { |
---|
[181] | 274 | if(result.taskInstance) { |
---|
| 275 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 276 | } |
---|
| 277 | else { |
---|
| 278 | flash.message = "Task could not be updated." |
---|
[196] | 279 | redirect(action: 'search') |
---|
[181] | 280 | } |
---|
[66] | 281 | } |
---|
[181] | 282 | |
---|
[66] | 283 | } |
---|
| 284 | |
---|
[181] | 285 | def approve = { |
---|
| 286 | |
---|
| 287 | if(!Task.exists(params.id)) { |
---|
| 288 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 289 | redirect(action: 'search') |
---|
[181] | 290 | } |
---|
| 291 | |
---|
| 292 | def result = taskService.approve(params) |
---|
| 293 | |
---|
| 294 | if(!result.error) { |
---|
| 295 | flash.message = "Task ${params.id} has been approved." |
---|
[196] | 296 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 297 | } |
---|
| 298 | else { |
---|
| 299 | if(result.taskInstance) { |
---|
| 300 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 301 | } |
---|
| 302 | else { |
---|
| 303 | flash.message = "Task could not be updated." |
---|
[196] | 304 | redirect(action: 'search') |
---|
[181] | 305 | } |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | def renegeApproval = { |
---|
| 311 | |
---|
| 312 | if(!Task.exists(params.id)) { |
---|
| 313 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 314 | redirect(action: 'search') |
---|
[181] | 315 | } |
---|
| 316 | |
---|
| 317 | def result = taskService.renegeApproval(params) |
---|
| 318 | |
---|
| 319 | if(!result.error) { |
---|
| 320 | flash.message = "Task ${params.id} has had approval removed." |
---|
[196] | 321 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 322 | } |
---|
| 323 | else { |
---|
| 324 | if(result.taskInstance) { |
---|
| 325 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 326 | } |
---|
| 327 | else { |
---|
| 328 | flash.message = "Task could not be updated." |
---|
[196] | 329 | redirect(action: 'search') |
---|
[181] | 330 | } |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | def complete = { |
---|
| 336 | |
---|
| 337 | if(!Task.exists(params.id)) { |
---|
| 338 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 339 | redirect(action: 'search') |
---|
[181] | 340 | } |
---|
| 341 | |
---|
| 342 | def result = taskService.complete(params) |
---|
| 343 | |
---|
| 344 | if(!result.error) { |
---|
| 345 | flash.message = "Task ${params.id} has been completed." |
---|
[196] | 346 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 347 | } |
---|
| 348 | else { |
---|
| 349 | if(result.taskInstance) { |
---|
| 350 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 351 | } |
---|
| 352 | else { |
---|
| 353 | flash.message = "Task could not be updated." |
---|
[196] | 354 | redirect(action: 'search') |
---|
[181] | 355 | } |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | def reopen = { |
---|
| 361 | |
---|
| 362 | if(!Task.exists(params.id)) { |
---|
| 363 | flash.message = "Task not found with id ${params.id}." |
---|
[196] | 364 | redirect(action: 'search') |
---|
[181] | 365 | } |
---|
| 366 | |
---|
| 367 | def result = taskService.reopen(params) |
---|
| 368 | |
---|
| 369 | if(!result.error) { |
---|
| 370 | flash.message = "Task ${params.id} has been reopened." |
---|
[196] | 371 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[181] | 372 | } |
---|
| 373 | else { |
---|
| 374 | if(result.taskInstance) { |
---|
| 375 | render(view:'edit',model:[taskInstance:result.taskInstance]) |
---|
| 376 | } |
---|
| 377 | else { |
---|
| 378 | flash.message = "Task could not be updated." |
---|
[196] | 379 | redirect(action: 'search') |
---|
[181] | 380 | } |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | } |
---|
| 384 | |
---|
[66] | 385 | def edit = { |
---|
[147] | 386 | |
---|
[139] | 387 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 388 | if(params._action_Edit) |
---|
| 389 | { params.action='edit' } |
---|
[169] | 390 | |
---|
[66] | 391 | def taskInstance = Task.get( params.id ) |
---|
| 392 | |
---|
| 393 | if(!taskInstance) { |
---|
| 394 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 395 | redirect(action: 'search') |
---|
[66] | 396 | } |
---|
| 397 | else { |
---|
[181] | 398 | if(taskInstance.trash) { |
---|
[196] | 399 | flash.message = "You may not edit tasks that are in the trash." |
---|
| 400 | redirect(action: 'show', id: taskInstance.id) |
---|
| 401 | return |
---|
[181] | 402 | } |
---|
[246] | 403 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
| 404 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
| 405 | return [ taskInstance : taskInstance ] |
---|
[84] | 406 | } |
---|
| 407 | } |
---|
| 408 | |
---|
[66] | 409 | def update = { |
---|
[179] | 410 | |
---|
[180] | 411 | if(!Task.exists(params.id)) { |
---|
| 412 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 413 | redirect(action: 'search') |
---|
[180] | 414 | } |
---|
| 415 | |
---|
| 416 | def result = taskService.update(params) |
---|
| 417 | |
---|
| 418 | if(!result.error) { |
---|
[66] | 419 | flash.message = "Task ${params.id} updated" |
---|
[196] | 420 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[180] | 421 | } |
---|
| 422 | else { |
---|
[206] | 423 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
---|
[66] | 424 | } |
---|
[180] | 425 | |
---|
[66] | 426 | } |
---|
| 427 | |
---|
| 428 | def create = { |
---|
| 429 | def taskInstance = new Task() |
---|
[214] | 430 | |
---|
| 431 | // Set the targetStartDate if specified, used by searchCalendar view. |
---|
| 432 | if(params.year && params.month && params.day) |
---|
| 433 | taskInstance.targetStartDate = dateUtilService.makeDate(params.year, params.month, params.day) |
---|
| 434 | |
---|
[196] | 435 | // Default leadPerson to current user, unless supplied in params. |
---|
[216] | 436 | taskInstance.leadPerson = personService.currentUser |
---|
[66] | 437 | taskInstance.properties = params |
---|
[196] | 438 | return ['taskInstance': taskInstance] |
---|
[66] | 439 | } |
---|
| 440 | |
---|
| 441 | def save = { |
---|
[180] | 442 | def result = taskService.create(params) |
---|
| 443 | |
---|
| 444 | if(!result.error) { |
---|
| 445 | flash.message = "Task ${result.taskInstance.id} created." |
---|
[196] | 446 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[66] | 447 | } |
---|
| 448 | else { |
---|
[180] | 449 | if(result.taskInstance) { |
---|
[196] | 450 | render(view:'create', model:[taskInstance:result.taskInstance]) |
---|
[180] | 451 | } |
---|
| 452 | else { |
---|
| 453 | flash.message = "Could not create task." |
---|
[196] | 454 | redirect(action: 'search') |
---|
[180] | 455 | } |
---|
| 456 | |
---|
[66] | 457 | } |
---|
| 458 | } |
---|
[179] | 459 | |
---|
| 460 | def listSubTasks = { |
---|
| 461 | def parentTaskInstance = Task.get(params.id) |
---|
| 462 | |
---|
[134] | 463 | if(!parentTaskInstance) { |
---|
| 464 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 465 | redirect(action: 'search') |
---|
[133] | 466 | } |
---|
| 467 | else { |
---|
[179] | 468 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
[196] | 469 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
| 470 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
[179] | 471 | |
---|
[134] | 472 | [ taskInstanceList: subTaskInstanceList, |
---|
[179] | 473 | taskInstanceTotal: subTaskInstanceTotal, |
---|
| 474 | parentTaskInstance: parentTaskInstance] |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | |
---|
[196] | 478 | def createSubTask = { |
---|
| 479 | def parentTaskInstance = Task.get(params.id) |
---|
| 480 | |
---|
| 481 | if(parentTaskInstance) { |
---|
| 482 | |
---|
| 483 | def result = taskService.createSubTask(parentTaskInstance) |
---|
| 484 | if(!result.error) { |
---|
| 485 | flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements." |
---|
| 486 | redirect(action: 'edit', id: result.taskInstance.id) |
---|
| 487 | } |
---|
| 488 | else { |
---|
| 489 | if(result.taskInstance.errors.hasFieldErrors("parentTask")) { |
---|
| 490 | flash.message = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
| 491 | redirect(action: 'show', id: parentTaskInstance.id) |
---|
| 492 | } |
---|
| 493 | else { |
---|
| 494 | render(view: 'create', model:[taskInstance: result.taskInstance]) |
---|
| 495 | } |
---|
| 496 | } |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | else { |
---|
| 500 | flash.message = "Task not found with id ${params.id}" |
---|
| 501 | redirect(action: 'search') |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | } // end of class. |
---|