| [69] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
|---|
| [165] | 2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
|---|
| [69] | 3 | |
|---|
| [85] | 4 | class TaskDetailedController extends BaseController { |
|---|
| [66] | 5 | |
|---|
| [140] | 6 | def authenticateService |
|---|
| 7 | def dateUtilService |
|---|
| [143] | 8 | def taskSearchService |
|---|
| [140] | 9 | def filterService |
|---|
| [165] | 10 | def exportService |
|---|
| [139] | 11 | |
|---|
| [66] | 12 | // the delete, save and update actions only accept POST requests |
|---|
| [85] | 13 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
|---|
| [66] | 14 | |
|---|
| [140] | 15 | def index = { redirect(action:search,params:params) } |
|---|
| 16 | |
|---|
| [66] | 17 | def list = { |
|---|
| [143] | 18 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
|---|
| [124] | 19 | [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ] |
|---|
| [66] | 20 | } |
|---|
| [143] | 21 | |
|---|
| [139] | 22 | def search = { |
|---|
| [144] | 23 | // println params |
|---|
| [143] | 24 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
|---|
| 25 | |
|---|
| [155] | 26 | // Quick Search: |
|---|
| [143] | 27 | if(!params.filter) |
|---|
| [139] | 28 | { |
|---|
| [144] | 29 | def taskInstanceList = [] |
|---|
| 30 | def personInstance = Person.get(authenticateService.userDomain().id) |
|---|
| [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." } |
|---|
| 40 | else { params.message = "No tasks found for today." } |
|---|
| 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}." } |
|---|
| 45 | else { params.message = "No tasks found for today." } |
|---|
| 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 | // println params |
|---|
| 65 | params.max = 30 |
|---|
| [140] | 66 | |
|---|
| [155] | 67 | // Quick Search: |
|---|
| 68 | if(!params.filter) |
|---|
| [139] | 69 | { |
|---|
| [155] | 70 | def taskInstanceList = [] |
|---|
| 71 | def personInstance = Person.get(authenticateService.userDomain().id) |
|---|
| 72 | |
|---|
| 73 | if(params.quickSearch == "searchMyTodays") { |
|---|
| 74 | taskInstanceList = taskSearchService.getMyTodays(params) |
|---|
| 75 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks for ${personInstance.firstName} ${personInstance.lastName}." } |
|---|
| 76 | else { params.message = "No tasks found for today." } |
|---|
| 77 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
|---|
| 78 | } |
|---|
| 79 | else if(params.quickSearch == "searchInTheLastWeek") { |
|---|
| 80 | taskInstanceList = taskSearchService.getInTheLastWeek(params) |
|---|
| 81 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week." } |
|---|
| 82 | else { params.message = "No tasks found for today." } |
|---|
| 83 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
|---|
| 84 | } |
|---|
| 85 | else if(params.quickSearch == "searchMyInTheLastWeek") { |
|---|
| 86 | taskInstanceList = taskSearchService.getMyInTheLastWeek(params) |
|---|
| 87 | if(taskInstanceList.totalCount > 0) { params.message = "Tasks with Target Start Date in the last week for ${personInstance.firstName} ${personInstance.lastName}." } |
|---|
| 88 | else { params.message = "No tasks found for today." } |
|---|
| 89 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
|---|
| 90 | } |
|---|
| 91 | else { |
|---|
| 92 | //Default: |
|---|
| 93 | taskInstanceList = taskSearchService.getTodays(params) |
|---|
| 94 | if(taskInstanceList.totalCount > 0) { params.message = "Today's tasks." } |
|---|
| 95 | else { params.message = "No tasks found for today." } |
|---|
| 96 | if(taskInstanceList.totalCount > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
|---|
| 97 | params.quickSearch = "searchTodays" |
|---|
| 98 | } |
|---|
| 99 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
|---|
| [139] | 100 | } |
|---|
| [155] | 101 | // filterPane: |
|---|
| 102 | def taskInstanceTotal = filterService.count( params, Task ) |
|---|
| 103 | if(taskInstanceTotal > params.max) { params.message = "Too many results, only the first ${params.max} shown" } |
|---|
| 104 | return[ taskInstanceList: filterService.filter( params, Task ), |
|---|
| 105 | taskInstanceTotal: taskInstanceTotal, |
|---|
| 106 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
|---|
| 107 | params:params ] |
|---|
| [139] | 108 | } |
|---|
| [140] | 109 | |
|---|
| [165] | 110 | def budget = { |
|---|
| 111 | // println params |
|---|
| 112 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100 ) |
|---|
| 113 | |
|---|
| 114 | // Quick Search: |
|---|
| 115 | if(!params.filter) |
|---|
| 116 | { |
|---|
| 117 | def taskInstanceList = [] |
|---|
| 118 | def personInstance = Person.get(authenticateService.userDomain().id) |
|---|
| 119 | |
|---|
| 120 | if(params.quickSearch == "budgetUnplanned") { |
|---|
| 121 | taskInstanceList = taskSearchService.getBudgetUnplanned(params) |
|---|
| 122 | if(taskInstanceList.totalCount > 0) { params.message = "Budget unplanned tasks in the last week." } |
|---|
| 123 | else { params.message = "No tasks found." } |
|---|
| 124 | } |
|---|
| 125 | //else if(params.quickSearch == "budgetPlanned") { |
|---|
| 126 | else { |
|---|
| 127 | //Default: |
|---|
| 128 | taskInstanceList = taskSearchService.getBudgetPlanned(params) |
|---|
| 129 | if(taskInstanceList.totalCount > 0) { params.message = "Budget planned Tasks in the last week." } |
|---|
| 130 | else { params.message = "No tasks found.." } |
|---|
| 131 | } |
|---|
| 132 | // export plugin: |
|---|
| 133 | if(params?.format && params.format != "html") { |
|---|
| 134 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
|---|
| 135 | response.setHeader("Content-disposition", "attachment; filename=tasks.${params.extension}") |
|---|
| 136 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskStatus", "taskType"] |
|---|
| 137 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
|---|
| 138 | "leadPerson": "Lead Person", "taskStatus": "Task Status", "taskType": "Task Type"] |
|---|
| 139 | Map formatters = [:] |
|---|
| 140 | String title = "${params.quickSearch} tasks in the last week." |
|---|
| 141 | Map parameters = [title: title] |
|---|
| 142 | |
|---|
| 143 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
|---|
| 144 | } |
|---|
| 145 | return[taskInstanceList: taskInstanceList, taskInstanceTotal: taskInstanceList.totalCount, filterParams: params] |
|---|
| 146 | } |
|---|
| 147 | // filterPane: |
|---|
| 148 | return[ taskInstanceList: filterService.filter( params, Task ), |
|---|
| 149 | taskInstanceTotal: filterService.count( params, Task ), |
|---|
| 150 | filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params), |
|---|
| 151 | params:params ] |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| [66] | 154 | def show = { |
|---|
| [147] | 155 | |
|---|
| [139] | 156 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
|---|
| 157 | if(params._action_Show) |
|---|
| 158 | { params.action='show' } |
|---|
| 159 | |
|---|
| [66] | 160 | def taskInstance = Task.get( params.id ) |
|---|
| 161 | |
|---|
| 162 | if(!taskInstance) { |
|---|
| 163 | flash.message = "Task not found with id ${params.id}" |
|---|
| [139] | 164 | redirect(action:search) |
|---|
| [66] | 165 | } |
|---|
| [133] | 166 | else { |
|---|
| [134] | 167 | params.max = 10 |
|---|
| 168 | params.order = "desc" |
|---|
| 169 | params.sort = "id" |
|---|
| [137] | 170 | |
|---|
| 171 | def entryWorkDoneList = Entry.withCriteria { |
|---|
| 172 | def entryType = EntryType.findByName("WorkDone") |
|---|
| 173 | eq("entryType", entryType) |
|---|
| 174 | eq("task", taskInstance) |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | def entryFaultList = Entry.withCriteria { |
|---|
| 178 | def entryType = EntryType.findByName("Fault") |
|---|
| 179 | eq("entryType", entryType) |
|---|
| 180 | eq("task", taskInstance) |
|---|
| 181 | } |
|---|
| [134] | 182 | |
|---|
| 183 | def subTaskInstanceList = Task.findAllByParentTask(taskInstance, params) |
|---|
| 184 | def subTaskInstanceTotal = Task.countByParentTask(taskInstance) |
|---|
| 185 | def showTaskTab = new String("true") |
|---|
| 186 | |
|---|
| [133] | 187 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
|---|
| 188 | def taskProcedureExits = new Boolean("true") |
|---|
| 189 | if(!taskProcedureInstance) { |
|---|
| 190 | taskProcedureExits = false |
|---|
| 191 | } |
|---|
| [134] | 192 | // else { |
|---|
| 193 | params.order = "asc" |
|---|
| 194 | params.sort = "procedureStepNumber" |
|---|
| 195 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, params) |
|---|
| 196 | // } |
|---|
| 197 | |
|---|
| 198 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
|---|
| 199 | def taskRecurringScheduleExits= new Boolean("true") |
|---|
| 200 | if(!taskRecurringScheduleInstance) { |
|---|
| 201 | taskRecurringScheduleExits = false |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| [137] | 204 | return [ taskInstance: taskInstance, |
|---|
| 205 | entryWorkDoneList: entryWorkDoneList, |
|---|
| 206 | entryFaultList: entryFaultList, |
|---|
| [133] | 207 | taskProcedureInstance: taskProcedureInstance, |
|---|
| 208 | taskProcedureExits: taskProcedureExits, |
|---|
| [134] | 209 | showTaskTab: showTaskTab, |
|---|
| 210 | subTaskInstanceList: subTaskInstanceList, |
|---|
| 211 | subTaskInstanceTotal: subTaskInstanceTotal, |
|---|
| 212 | subTaskInstanceMax: params.max, |
|---|
| 213 | maintenanceActionList: maintenanceActionList, |
|---|
| 214 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
|---|
| 215 | taskRecurringScheduleExits: taskRecurringScheduleExits] |
|---|
| [131] | 216 | } |
|---|
| [66] | 217 | } |
|---|
| 218 | |
|---|
| 219 | def delete = { |
|---|
| 220 | def taskInstance = Task.get( params.id ) |
|---|
| 221 | if(taskInstance) { |
|---|
| [96] | 222 | try { |
|---|
| [106] | 223 | taskInstance.isActive = false |
|---|
| 224 | flash.message = "Task ${params.id} has been set to inactive." |
|---|
| [139] | 225 | redirect(action:search) |
|---|
| [96] | 226 | } |
|---|
| 227 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
|---|
| 228 | flash.message = "Task ${params.id} could not be deleted" |
|---|
| 229 | redirect(action:show,id:params.id) |
|---|
| 230 | } |
|---|
| [66] | 231 | } |
|---|
| 232 | else { |
|---|
| 233 | flash.message = "Task not found with id ${params.id}" |
|---|
| [139] | 234 | redirect(action:search) |
|---|
| [66] | 235 | } |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | def edit = { |
|---|
| [147] | 239 | |
|---|
| [139] | 240 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
|---|
| 241 | if(params._action_Edit) |
|---|
| 242 | { params.action='edit' } |
|---|
| [169] | 243 | |
|---|
| [66] | 244 | def taskInstance = Task.get( params.id ) |
|---|
| 245 | |
|---|
| 246 | if(!taskInstance) { |
|---|
| 247 | flash.message = "Task not found with id ${params.id}" |
|---|
| [139] | 248 | redirect(action:search) |
|---|
| [66] | 249 | } |
|---|
| 250 | else { |
|---|
| [84] | 251 | def criteria = taskInstance.createCriteria() |
|---|
| [169] | 252 | def possibleParentList = criteria { |
|---|
| [84] | 253 | and { |
|---|
| 254 | notEqual('id', taskInstance.id) |
|---|
| [169] | 255 | taskInstance.subTasks.each() { notEqual('id', it.id) } |
|---|
| [84] | 256 | } |
|---|
| 257 | } |
|---|
| [169] | 258 | return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
|---|
| [84] | 259 | } |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| [66] | 262 | def update = { |
|---|
| 263 | def taskInstance = Task.get( params.id ) |
|---|
| 264 | if(taskInstance) { |
|---|
| [96] | 265 | if(params.version) { |
|---|
| 266 | def version = params.version.toLong() |
|---|
| 267 | if(taskInstance.version > version) { |
|---|
| 268 | |
|---|
| 269 | taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.") |
|---|
| 270 | render(view:'edit',model:[taskInstance:taskInstance]) |
|---|
| 271 | return |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| [66] | 274 | taskInstance.properties = params |
|---|
| 275 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
|---|
| 276 | flash.message = "Task ${params.id} updated" |
|---|
| 277 | redirect(action:show,id:taskInstance.id) |
|---|
| 278 | } |
|---|
| 279 | else { |
|---|
| 280 | render(view:'edit',model:[taskInstance:taskInstance]) |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | else { |
|---|
| 284 | flash.message = "Task not found with id ${params.id}" |
|---|
| 285 | redirect(action:edit,id:params.id) |
|---|
| 286 | } |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | def create = { |
|---|
| 290 | def taskInstance = new Task() |
|---|
| 291 | taskInstance.properties = params |
|---|
| 292 | return ['taskInstance':taskInstance] |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | def save = { |
|---|
| 296 | def taskInstance = new Task(params) |
|---|
| 297 | if(!taskInstance.hasErrors() && taskInstance.save()) { |
|---|
| 298 | flash.message = "Task ${taskInstance.id} created" |
|---|
| 299 | redirect(action:show,id:taskInstance.id) |
|---|
| 300 | } |
|---|
| 301 | else { |
|---|
| 302 | render(view:'create',model:[taskInstance:taskInstance]) |
|---|
| 303 | } |
|---|
| 304 | } |
|---|
| [134] | 305 | |
|---|
| 306 | def listSubTasks = { |
|---|
| 307 | def parentTaskInstance = Task.get(params.id) |
|---|
| 308 | |
|---|
| 309 | if(!parentTaskInstance) { |
|---|
| 310 | flash.message = "Task not found with id ${params.id}" |
|---|
| [139] | 311 | redirect(action:search) |
|---|
| [133] | 312 | } |
|---|
| 313 | else { |
|---|
| [134] | 314 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
|---|
| 315 | def subTaskInstanceList = Task.findAllByParentTask(parentTaskInstance, params) |
|---|
| 316 | def subTaskInstanceTotal = Task.countByParentTask(parentTaskInstance) |
|---|
| 317 | |
|---|
| 318 | [ taskInstanceList: subTaskInstanceList, |
|---|
| 319 | taskInstanceTotal: subTaskInstanceTotal, |
|---|
| 320 | parentTaskInstance: parentTaskInstance] |
|---|
| 321 | } |
|---|
| 322 | } |
|---|
| [133] | 323 | |
|---|
| [66] | 324 | } |
|---|