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