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