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