[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 |
---|
[476] | 4 | import org.springframework.web.servlet.support.RequestContextUtils as RCU |
---|
[69] | 5 | |
---|
[298] | 6 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[85] | 7 | class TaskDetailedController extends BaseController { |
---|
[66] | 8 | |
---|
[291] | 9 | def authService |
---|
[180] | 10 | def taskService |
---|
[143] | 11 | def taskSearchService |
---|
[585] | 12 | def taskReportService |
---|
[140] | 13 | def filterService |
---|
[165] | 14 | def exportService |
---|
[214] | 15 | def dateUtilService |
---|
[139] | 16 | |
---|
[181] | 17 | // these actions only accept POST requests |
---|
[418] | 18 | static allowedMethods = [save:'POST',update:'POST',restore:'POST', trash:'POST', |
---|
| 19 | approve:'POST', renegeApproval:'POST', complete:'POST', |
---|
| 20 | reopen:'POST', setAttentionFlag:'POST', clearAttentionFlag:'POST'] |
---|
[66] | 21 | |
---|
[298] | 22 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[196] | 23 | def index = { redirect(action: 'search', params: params) } |
---|
[140] | 24 | |
---|
[298] | 25 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[326] | 26 | def setSearchParamsMax = { |
---|
[262] | 27 | def max = 1000 |
---|
[615] | 28 | if(params.newMax?.isInteger()) { |
---|
[260] | 29 | def i = params.newMax.toInteger() |
---|
[262] | 30 | if(i > 0 && i <= max) |
---|
| 31 | session.taskSearchParamsMax = params.newMax |
---|
| 32 | if(i > max) |
---|
| 33 | session.taskSearchParamsMax = max |
---|
| 34 | } |
---|
[260] | 35 | forward(action: 'search', params: params) |
---|
| 36 | } |
---|
| 37 | |
---|
[298] | 38 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[476] | 39 | def setSearchCalendarParamsMax = { |
---|
| 40 | def max = 1000 |
---|
[615] | 41 | if(params.newMax?.isInteger()) { |
---|
[476] | 42 | def i = params.newMax.toInteger() |
---|
| 43 | if(i > 0 && i <= max) |
---|
| 44 | session.taskSearchCalendarParamsMax = params.newMax |
---|
| 45 | if(i > max) |
---|
| 46 | session.taskSearchCalendarParamsMax = max |
---|
| 47 | } |
---|
| 48 | forward(action: 'searchCalendar', params: params) |
---|
| 49 | } |
---|
| 50 | |
---|
[483] | 51 | /** |
---|
| 52 | * Search for tasks. |
---|
| 53 | */ |
---|
[476] | 54 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[139] | 55 | def search = { |
---|
[143] | 56 | |
---|
[260] | 57 | if(session.taskSearchParamsMax) |
---|
| 58 | params.max = session.taskSearchParamsMax |
---|
| 59 | |
---|
[468] | 60 | // Protect filterPane. |
---|
[525] | 61 | params.max = Math.min( params.max ? params.max.toInteger() : 100, 1000 ) |
---|
[260] | 62 | |
---|
[713] | 63 | // View main data. |
---|
[260] | 64 | def taskInstanceList = [] |
---|
| 65 | def taskInstanceTotal |
---|
[476] | 66 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
| 67 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
[260] | 68 | |
---|
[476] | 69 | // Restore search unless a new search is being requested. |
---|
| 70 | if(!params.quickSearch && !filterParams) { |
---|
[713] | 71 | if(session.taskSearchFilterParams) { |
---|
[476] | 72 | session.taskSearchFilterParams.each() { params[it.key] = it.value } |
---|
| 73 | params.filter = session.taskSearchFilter |
---|
| 74 | isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
[144] | 75 | } |
---|
[476] | 76 | } |
---|
[713] | 77 | if(!params.quickSearch) { |
---|
| 78 | if(session.taskSearchQuickSearch) { |
---|
| 79 | params.quickSearch = session.taskSearchQuickSearch |
---|
| 80 | params.person = Person.get(session.taskQuickSearchPersonId.toLong()) |
---|
| 81 | params.startDate = session.taskQuickSearchStartDate |
---|
| 82 | params.endDate = session.taskQuickSearchEndDate |
---|
| 83 | params.includeCompleted = session.taskQuickSearchIncludeCompleted |
---|
| 84 | } |
---|
| 85 | } |
---|
[260] | 86 | |
---|
[486] | 87 | // Remember sort if supplied, otherwise try to restore. |
---|
| 88 | if(params.sort && params.order) { |
---|
[582] | 89 | // Reset to defaultSort if requested. |
---|
| 90 | if(params.sort == 'defaultSort') { |
---|
| 91 | params.sort = null |
---|
| 92 | params.order = null |
---|
| 93 | session.removeAttribute("taskSearchSort") |
---|
| 94 | session.removeAttribute("taskSearchOrder") |
---|
| 95 | } |
---|
| 96 | else { |
---|
| 97 | session.taskSearchSort = params.sort |
---|
| 98 | session.taskSearchOrder = params.order |
---|
| 99 | } |
---|
[486] | 100 | } |
---|
| 101 | else if(session.taskSearchSort && session.taskSearchOrder) { |
---|
| 102 | params.sort = session.taskSearchSort |
---|
| 103 | params.order = session.taskSearchOrder |
---|
| 104 | } |
---|
| 105 | |
---|
[476] | 106 | if(isFilterApplied) { |
---|
[260] | 107 | // filterPane: |
---|
[582] | 108 | params.sort = params.sort ?: "id" |
---|
| 109 | params.order = params.order ?: "desc" |
---|
[513] | 110 | if(params.sort == "attentionFlag") // See ticket #64 in Trac. |
---|
| 111 | params.sort = "id" |
---|
[516] | 112 | // Prevent tasks in the trash being returned unless explicitly requested. |
---|
| 113 | if(!params.filter.op.trash) { |
---|
| 114 | params.filter.op.trash = "Equal" |
---|
| 115 | params.filter.trash = "false" |
---|
| 116 | } |
---|
| 117 | // Call filterService. |
---|
[260] | 118 | taskInstanceList = filterService.filter( params, Task ) |
---|
| 119 | taskInstanceTotal = filterService.count( params, Task ) |
---|
| 120 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
[476] | 121 | // Remember search. |
---|
| 122 | session.taskSearchFilterParams = new LinkedHashMap(filterParams) |
---|
| 123 | session.taskSearchFilter = new LinkedHashMap(params.filter) |
---|
[260] | 124 | } |
---|
[476] | 125 | else { |
---|
| 126 | // Quick Search: |
---|
| 127 | def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request)) |
---|
| 128 | taskInstanceList = result.taskInstanceList |
---|
| 129 | taskInstanceTotal = result.taskInstanceList.totalCount |
---|
| 130 | params.message = result.message |
---|
[713] | 131 | params.quickSearch = result.quickSearch |
---|
| 132 | params.person = result.person |
---|
| 133 | params.startDate = result.startDate |
---|
| 134 | params.endDate = result.endDate |
---|
| 135 | params.includeCompleted = result.includeCompleted |
---|
[476] | 136 | // Remember search. |
---|
[488] | 137 | session.removeAttribute("taskSearchFilterParams") |
---|
| 138 | session.removeAttribute("taskSearchFilter") |
---|
[476] | 139 | session.taskSearchQuickSearch = result.quickSearch |
---|
[713] | 140 | session.taskQuickSearchPersonId = result.person.id |
---|
| 141 | session.taskQuickSearchStartDate = result.startDate |
---|
| 142 | session.taskQuickSearchEndDate = result.endDate |
---|
| 143 | session.taskQuickSearchIncludeCompleted = result.includeCompleted |
---|
[476] | 144 | } |
---|
[143] | 145 | |
---|
[260] | 146 | // export plugin: |
---|
| 147 | if(params?.format && params.format != "html") { |
---|
| 148 | |
---|
| 149 | def dateFmt = { date -> |
---|
| 150 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | String title |
---|
| 154 | if(params.quickSearch) |
---|
[476] | 155 | title = params.message |
---|
[260] | 156 | else |
---|
| 157 | title = "Filtered tasks." |
---|
| 158 | |
---|
| 159 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
[390] | 160 | response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}") |
---|
[475] | 161 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskType", "taskStatus"] |
---|
[260] | 162 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
[475] | 163 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", |
---|
| 164 | "taskType": "Task Type", "taskStatus": "Task Status"] |
---|
[260] | 165 | Map formatters = [ targetStartDate: dateFmt] |
---|
| 166 | Map parameters = [title: title, separator: ","] |
---|
| 167 | |
---|
| 168 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | // Add some basic params to filterParams. |
---|
| 172 | filterParams.max = params.max |
---|
| 173 | filterParams.offset = params.offset?.toInteger() ?: 0 |
---|
[582] | 174 | filterParams.sort = params.sort ?: "id" |
---|
[260] | 175 | filterParams.order = params.order ?: "desc" |
---|
| 176 | |
---|
[552] | 177 | // Get some associatedProperty values for filterpane. |
---|
| 178 | def associatedPropertyValues = [:] |
---|
| 179 | def associatedPropertyMax = 10000 |
---|
| 180 | associatedPropertyValues.taskPriorityList = TaskPriority.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
| 181 | def lastNameQuery = 'select distinct p.lastName from Person p where p.isActive = ? order by p.lastName' |
---|
| 182 | associatedPropertyValues.lastNameList = Person.executeQuery(lastNameQuery, [true], [max:associatedPropertyMax]) |
---|
| 183 | def firstNameQuery = 'select distinct p.firstName from Person p where p.isActive = ? order by p.firstName' |
---|
| 184 | associatedPropertyValues.firstNameList = Person.executeQuery(firstNameQuery, [true], [max:associatedPropertyMax]) |
---|
| 185 | associatedPropertyValues.taskGroupList = TaskGroup.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
| 186 | associatedPropertyValues.assetList = Asset.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
| 187 | associatedPropertyValues.taskStatusList = TaskStatus.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
| 188 | associatedPropertyValues.taskTypeList = TaskType.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
| 189 | def startOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), -10)) |
---|
| 190 | def endOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), 10)) |
---|
| 191 | associatedPropertyValues.yearRange = startOfYearRange..endOfYearRange |
---|
| 192 | |
---|
[260] | 193 | return[ taskInstanceList: taskInstanceList, |
---|
[476] | 194 | taskInstanceTotal: taskInstanceTotal, |
---|
| 195 | filterParams: filterParams, |
---|
[552] | 196 | params: params, |
---|
[713] | 197 | associatedPropertyValues: associatedPropertyValues, |
---|
| 198 | quickSearchSelection: taskSearchService.quickSearchSelection] |
---|
[260] | 199 | |
---|
[476] | 200 | } // search |
---|
[260] | 201 | |
---|
[298] | 202 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[155] | 203 | def searchCalendar = { |
---|
[140] | 204 | |
---|
[476] | 205 | // No pagination for calendar. |
---|
| 206 | params.offset = 0 |
---|
[474] | 207 | |
---|
[476] | 208 | // Restore params.max |
---|
| 209 | if(session.taskSearchCalendarParamsMax) |
---|
| 210 | params.max = session.taskSearchCalendarParamsMax |
---|
| 211 | |
---|
[474] | 212 | // Protect filterPane. |
---|
[476] | 213 | params.max = Math.min( params.max ? params.max.toInteger() : 100, 1000 ) |
---|
[474] | 214 | |
---|
[585] | 215 | def displayList = [] |
---|
[476] | 216 | def taskInstanceList = [] |
---|
| 217 | def taskInstanceTotal |
---|
| 218 | def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
| 219 | def isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
[474] | 220 | |
---|
[476] | 221 | // Restore search unless a new search is being requested. |
---|
| 222 | if(!params.quickSearch && !filterParams) { |
---|
[713] | 223 | if(session.taskSearchCalendarFilterParams) { |
---|
[476] | 224 | session.taskSearchCalendarFilterParams.each() { params[it.key] = it.value } |
---|
| 225 | params.filter = session.taskSearchCalendarFilter |
---|
| 226 | isFilterApplied = FilterUtils.isFilterApplied(params) |
---|
| 227 | } |
---|
| 228 | } |
---|
[713] | 229 | if(!params.quickSearch) { |
---|
| 230 | if(session.taskSearchCalendarQuickSearch) { |
---|
| 231 | params.quickSearch = session.taskSearchCalendarQuickSearch |
---|
| 232 | params.person = Person.get(session.taskCalendarQuickSearchPersonId.toLong()) |
---|
| 233 | params.startDate = session.taskCalendarQuickSearchStartDate |
---|
| 234 | params.endDate = session.taskCalendarQuickSearchEndDate |
---|
| 235 | params.includeCompleted = session.taskCalendarQuickSearchIncludeCompleted |
---|
| 236 | } |
---|
| 237 | } |
---|
[474] | 238 | |
---|
[476] | 239 | // The date the calendar will use to determine the month to show. |
---|
| 240 | // Use session, if not specified in params, otherwise use today. |
---|
| 241 | def showDate = new Date() |
---|
| 242 | if(params.showMonth) { |
---|
| 243 | if(params.showYear) |
---|
| 244 | showDate = dateUtilService.makeDate(params.showYear, params.showMonth) |
---|
| 245 | else |
---|
| 246 | showDate = dateUtilService.makeDate(dateUtilService.getYearFromDate(showDate), params.showMonth) |
---|
| 247 | // Remember the showDate. |
---|
| 248 | session.taskSearchCalendarShowDate = showDate |
---|
| 249 | } |
---|
| 250 | else if(session.taskSearchCalendarShowDate) |
---|
| 251 | showDate = session.taskSearchCalendarShowDate |
---|
[155] | 252 | |
---|
[476] | 253 | // Get the dates for the calendar month controls. |
---|
| 254 | def calendarMonthControls = getCalendarMonthControls(showDate) |
---|
| 255 | |
---|
| 256 | if(isFilterApplied) { |
---|
| 257 | // filterPane: |
---|
[589] | 258 | params.sort = params.sort ?: "id" |
---|
| 259 | params.order = params.order ?: "desc" |
---|
[516] | 260 | if(params.sort == "attentionFlag") // See ticket #64 in Trac. |
---|
| 261 | params.sort = "id" |
---|
| 262 | // Prevent tasks in the trash being returned unless explicitly requested. |
---|
| 263 | if(!params.filter.op.trash) { |
---|
| 264 | params.filter.op.trash = "Equal" |
---|
| 265 | params.filter.trash = "false" |
---|
| 266 | } |
---|
| 267 | // Call filterService. |
---|
[476] | 268 | taskInstanceList = filterService.filter( params, Task ) |
---|
| 269 | taskInstanceTotal = filterService.count( params, Task ) |
---|
| 270 | filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) |
---|
| 271 | // Remember search. |
---|
| 272 | session.taskSearchCalendarFilterParams = new LinkedHashMap(filterParams) |
---|
| 273 | session.taskSearchCalendarFilter = new LinkedHashMap(params.filter) |
---|
[139] | 274 | } |
---|
[476] | 275 | else { |
---|
| 276 | // Quick Search: |
---|
| 277 | def result = taskSearchService.getQuickSearch(params, RCU.getLocale(request)) |
---|
| 278 | taskInstanceList = result.taskInstanceList |
---|
| 279 | taskInstanceTotal = result.taskInstanceList.totalCount |
---|
| 280 | params.message = result.message |
---|
[713] | 281 | params.quickSearch = result.quickSearch |
---|
| 282 | params.person = result.person |
---|
| 283 | params.startDate = result.startDate |
---|
| 284 | params.endDate = result.endDate |
---|
| 285 | params.includeCompleted = result.includeCompleted |
---|
[476] | 286 | // Remember search. |
---|
[488] | 287 | session.removeAttribute("taskSearchCalendarFilterParams") |
---|
| 288 | session.removeAttribute("taskSearchCalendarFilter") |
---|
[476] | 289 | session.taskSearchCalendarQuickSearch = result.quickSearch |
---|
[713] | 290 | session.taskCalendarQuickSearchPersonId = result.person.id |
---|
| 291 | session.taskCalendarQuickSearchStartDate = result.startDate |
---|
| 292 | session.taskCalendarQuickSearchEndDate = result.endDate |
---|
| 293 | session.taskCalendarQuickSearchIncludeCompleted = result.includeCompleted |
---|
[476] | 294 | } |
---|
[140] | 295 | |
---|
[588] | 296 | // displayList = taskReportService.getWorkLoadSummary( |
---|
| 297 | // [taskInstanceList: taskInstanceList], RCU.getLocale(request) |
---|
| 298 | // ).displayList |
---|
[585] | 299 | |
---|
[476] | 300 | // export plugin: |
---|
| 301 | if(params?.format && params.format != "html") { |
---|
[165] | 302 | |
---|
[476] | 303 | def dateFmt = { date -> |
---|
| 304 | formatDate(format: "EEE, dd-MMM-yyyy", date: date) |
---|
[165] | 305 | } |
---|
[260] | 306 | |
---|
[476] | 307 | String title |
---|
| 308 | if(params.quickSearch) |
---|
| 309 | title = params.message |
---|
| 310 | else |
---|
| 311 | title = "Filtered tasks." |
---|
[165] | 312 | |
---|
[476] | 313 | response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] |
---|
| 314 | response.setHeader("Content-disposition", "attachment; filename=Tasks.${params.extension}") |
---|
| 315 | List fields = ["id", "targetStartDate", "description", "leadPerson", "taskPriority", "taskType", "taskStatus"] |
---|
| 316 | Map labels = ["id": "ID", "targetStartDate": "Target Start Date", "description": "Description", |
---|
| 317 | "leadPerson": "Lead Person", "taskPriority": "Task Priority", |
---|
| 318 | "taskType": "Task Type", "taskStatus": "Task Status"] |
---|
| 319 | Map formatters = [ targetStartDate: dateFmt] |
---|
| 320 | Map parameters = [title: title, separator: ","] |
---|
| 321 | |
---|
| 322 | exportService.export(params.format, response.outputStream, taskInstanceList, fields, labels, formatters, parameters) |
---|
[165] | 323 | } |
---|
| 324 | |
---|
[588] | 325 | if(taskInstanceTotal > params.max) |
---|
| 326 | params.errorMessage = g.message(code:"task.search.calendar.text.too.many.results", args:[params.max]) |
---|
[476] | 327 | |
---|
| 328 | // Add some basic params to filterParams. |
---|
| 329 | filterParams.max = params.max |
---|
| 330 | filterParams.offset = params.offset?.toInteger() ?: 0 |
---|
[589] | 331 | filterParams.sort = params.sort ?: "id" |
---|
| 332 | filterParams.order = params.order ?: "desc" |
---|
[476] | 333 | |
---|
[589] | 334 | // Get some associatedProperty values for filterpane. |
---|
| 335 | def associatedPropertyValues = [:] |
---|
| 336 | def associatedPropertyMax = 10000 |
---|
| 337 | associatedPropertyValues.taskPriorityList = TaskPriority.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
| 338 | def lastNameQuery = 'select distinct p.lastName from Person p where p.isActive = ? order by p.lastName' |
---|
| 339 | associatedPropertyValues.lastNameList = Person.executeQuery(lastNameQuery, [true], [max:associatedPropertyMax]) |
---|
| 340 | def firstNameQuery = 'select distinct p.firstName from Person p where p.isActive = ? order by p.firstName' |
---|
| 341 | associatedPropertyValues.firstNameList = Person.executeQuery(firstNameQuery, [true], [max:associatedPropertyMax]) |
---|
| 342 | associatedPropertyValues.taskGroupList = TaskGroup.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
| 343 | associatedPropertyValues.assetList = Asset.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
| 344 | associatedPropertyValues.taskStatusList = TaskStatus.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
| 345 | associatedPropertyValues.taskTypeList = TaskType.findAllByIsActive(true, [max:associatedPropertyMax, sort:'name']) |
---|
| 346 | def startOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), -10)) |
---|
| 347 | def endOfYearRange = dateUtilService.getYearFromDate(dateUtilService.plusYear(new Date(), 10)) |
---|
| 348 | associatedPropertyValues.yearRange = startOfYearRange..endOfYearRange |
---|
| 349 | |
---|
[588] | 350 | return[taskInstanceList: taskInstanceList, |
---|
[476] | 351 | taskInstanceTotal: taskInstanceTotal, |
---|
| 352 | filterParams: filterParams, |
---|
| 353 | params: params, |
---|
[589] | 354 | associatedPropertyValues: associatedPropertyValues, |
---|
[476] | 355 | showDate: showDate, |
---|
| 356 | today: calendarMonthControls.today, |
---|
| 357 | previousMonth: calendarMonthControls.previousMonth, |
---|
| 358 | nextMonth: calendarMonthControls.nextMonth, |
---|
| 359 | previousYear: calendarMonthControls.previousYear, |
---|
[713] | 360 | nextYear: calendarMonthControls.nextYear, |
---|
| 361 | quickSearchSelection: taskSearchService.quickSearchSelection] |
---|
[476] | 362 | |
---|
| 363 | } // searchCalendar |
---|
| 364 | |
---|
[298] | 365 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 366 | def show = { |
---|
[147] | 367 | |
---|
[139] | 368 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 369 | if(params._action_Show) |
---|
[375] | 370 | params.action='show' |
---|
[139] | 371 | |
---|
[433] | 372 | // Used by navigation. |
---|
| 373 | if(params.id == 'nav') { |
---|
| 374 | params.id = session.currentTaskId ?: null |
---|
| 375 | redirect(action: show, id: params.id) |
---|
| 376 | return |
---|
| 377 | } |
---|
| 378 | |
---|
[225] | 379 | def showTab = [:] |
---|
| 380 | switch (params.showTab) { |
---|
| 381 | case "showProcedureTab": |
---|
| 382 | showTab.procedure = new String("true") |
---|
| 383 | break |
---|
| 384 | case "showRecurrenceTab": |
---|
| 385 | showTab.recurrence = new String("true") |
---|
| 386 | break |
---|
| 387 | case "showInventoryTab": |
---|
| 388 | showTab.inventory = new String("true") |
---|
| 389 | break |
---|
| 390 | case "showSubTasksTab": |
---|
| 391 | showTab.subTasks = new String("true") |
---|
| 392 | break |
---|
| 393 | default: |
---|
| 394 | showTab.task = new String("true") |
---|
| 395 | } |
---|
| 396 | |
---|
[66] | 397 | def taskInstance = Task.get( params.id ) |
---|
| 398 | |
---|
| 399 | if(!taskInstance) { |
---|
| 400 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 401 | redirect(action: 'search') |
---|
[66] | 402 | } |
---|
[133] | 403 | else { |
---|
[433] | 404 | // Remember the current task id for use with navigation. |
---|
| 405 | session.currentTaskId = params.id |
---|
| 406 | |
---|
[179] | 407 | params.max = 10 |
---|
| 408 | params.order = "desc" |
---|
| 409 | params.sort = "id" |
---|
[134] | 410 | |
---|
[418] | 411 | def entryFaultList = Entry.withCriteria { |
---|
| 412 | eq("entryType", EntryType.get(1)) |
---|
| 413 | eq("task", taskInstance) |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | def entryCauseList = Entry.withCriteria { |
---|
[190] | 417 | eq("entryType", EntryType.get(2)) |
---|
[179] | 418 | eq("task", taskInstance) |
---|
| 419 | } |
---|
| 420 | |
---|
[418] | 421 | def entryWorkDoneList = Entry.withCriteria { |
---|
| 422 | eq("entryType", EntryType.get(3)) |
---|
[179] | 423 | eq("task", taskInstance) |
---|
| 424 | } |
---|
| 425 | |
---|
[833] | 426 | def entryPMList = Entry.withCriteria { |
---|
| 427 | eq("entryType", EntryType.get(6)) |
---|
| 428 | eq("task", taskInstance) |
---|
| 429 | } |
---|
| 430 | |
---|
[196] | 431 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
---|
| 432 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
---|
[134] | 433 | |
---|
[175] | 434 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
| 435 | |
---|
[180] | 436 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
| 437 | |
---|
[253] | 438 | def assignedGroupList = taskInstance.assignedGroups.sort { p1, p2 -> p1.personGroup.name.compareToIgnoreCase(p2.personGroup.name) } |
---|
| 439 | def assignedPersonList = taskInstance.assignedPersons.sort { p1, p2 -> p1.person.firstName.compareToIgnoreCase(p2.person.firstName) } |
---|
| 440 | |
---|
[809] | 441 | def taskProcedureRevision = TaskProcedureRevision.get(taskInstance.taskProcedureRevision?.id) |
---|
[133] | 442 | def taskProcedureExits = new Boolean("true") |
---|
[809] | 443 | if(!taskProcedureRevision) { |
---|
[133] | 444 | taskProcedureExits = false |
---|
| 445 | } |
---|
[175] | 446 | |
---|
[134] | 447 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
| 448 | def taskRecurringScheduleExits= new Boolean("true") |
---|
[175] | 449 | if(!taskRecurringScheduleInstance) { |
---|
[134] | 450 | taskRecurringScheduleExits = false |
---|
| 451 | } |
---|
[179] | 452 | |
---|
[137] | 453 | return [ taskInstance: taskInstance, |
---|
[418] | 454 | entryFaultList: entryFaultList, |
---|
| 455 | entryCauseList: entryCauseList, |
---|
[179] | 456 | entryWorkDoneList: entryWorkDoneList, |
---|
[833] | 457 | entryPMList: entryPMList, |
---|
[809] | 458 | taskProcedureRevision: taskProcedureRevision, |
---|
[133] | 459 | taskProcedureExits: taskProcedureExits, |
---|
[225] | 460 | showTab: showTab, |
---|
[179] | 461 | subTaskInstanceList: subTaskInstanceList, |
---|
| 462 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
| 463 | subTaskInstanceMax: params.max, |
---|
| 464 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
| 465 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
[180] | 466 | inventoryMovementList: inventoryMovementList, |
---|
[253] | 467 | taskModificationList: taskModificationList, |
---|
| 468 | assignedGroupList: assignedGroupList, |
---|
| 469 | assignedPersonList: assignedPersonList] |
---|
[131] | 470 | } |
---|
[66] | 471 | } |
---|
| 472 | |
---|
[418] | 473 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 474 | def restore = { |
---|
| 475 | |
---|
| 476 | def result = taskService.restore(params) |
---|
| 477 | |
---|
| 478 | if(!result.error) { |
---|
| 479 | flash.message = "Task ${params.id} has been restored." |
---|
[418] | 480 | redirect(action: show, id: params.id) |
---|
| 481 | return |
---|
[181] | 482 | } |
---|
| 483 | |
---|
[418] | 484 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 485 | |
---|
| 486 | if(result.taskInstance) |
---|
| 487 | redirect(action: show, id: params.id) |
---|
| 488 | else |
---|
| 489 | redirect(action: 'search') |
---|
| 490 | |
---|
[181] | 491 | } |
---|
| 492 | |
---|
[418] | 493 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 494 | def trash = { |
---|
| 495 | |
---|
| 496 | def result = taskService.trash(params) |
---|
| 497 | |
---|
| 498 | if(!result.error) { |
---|
| 499 | flash.message = "Task ${params.id} has been moved to trash." |
---|
[196] | 500 | redirect(action: 'search') |
---|
[418] | 501 | return |
---|
[181] | 502 | } |
---|
| 503 | |
---|
[418] | 504 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 505 | |
---|
| 506 | if(result.taskInstance) |
---|
| 507 | redirect(action: show, id: params.id) |
---|
| 508 | else |
---|
| 509 | redirect(action: 'search') |
---|
| 510 | |
---|
[66] | 511 | } |
---|
| 512 | |
---|
[418] | 513 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[181] | 514 | def approve = { |
---|
| 515 | |
---|
| 516 | def result = taskService.approve(params) |
---|
| 517 | |
---|
| 518 | if(!result.error) { |
---|
| 519 | flash.message = "Task ${params.id} has been approved." |
---|
[418] | 520 | redirect(action: show, id: params.id) |
---|
| 521 | return |
---|
[181] | 522 | } |
---|
| 523 | |
---|
[418] | 524 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 525 | |
---|
| 526 | if(result.taskInstance) |
---|
| 527 | redirect(action: show, id: params.id) |
---|
| 528 | else |
---|
| 529 | redirect(action: 'search') |
---|
| 530 | |
---|
[181] | 531 | } |
---|
| 532 | |
---|
[465] | 533 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[181] | 534 | def renegeApproval = { |
---|
| 535 | |
---|
| 536 | def result = taskService.renegeApproval(params) |
---|
| 537 | |
---|
| 538 | if(!result.error) { |
---|
| 539 | flash.message = "Task ${params.id} has had approval removed." |
---|
[418] | 540 | redirect(action: show, id: params.id) |
---|
| 541 | return |
---|
[181] | 542 | } |
---|
| 543 | |
---|
[418] | 544 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 545 | |
---|
| 546 | if(result.taskInstance) |
---|
| 547 | redirect(action: show, id: params.id) |
---|
| 548 | else |
---|
| 549 | redirect(action: 'search') |
---|
| 550 | |
---|
[181] | 551 | } |
---|
| 552 | |
---|
[298] | 553 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 554 | def complete = { |
---|
| 555 | |
---|
| 556 | def result = taskService.complete(params) |
---|
| 557 | |
---|
| 558 | if(!result.error) { |
---|
| 559 | flash.message = "Task ${params.id} has been completed." |
---|
[418] | 560 | redirect(action: show, id: params.id) |
---|
| 561 | return |
---|
[181] | 562 | } |
---|
[418] | 563 | |
---|
| 564 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 565 | |
---|
| 566 | if(result.taskInstance) |
---|
| 567 | redirect(action: show, id: params.id) |
---|
| 568 | else |
---|
| 569 | redirect(action: 'search') |
---|
| 570 | |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
| 574 | def setAttentionFlag = { |
---|
| 575 | |
---|
| 576 | def result = taskService.setAttentionFlag(params) |
---|
| 577 | |
---|
| 578 | if(!result.error) { |
---|
| 579 | flash.message = "Task ${params.id} has been flagged for attention." |
---|
| 580 | redirect(action: show, id: params.id) |
---|
| 581 | return |
---|
[181] | 582 | } |
---|
| 583 | |
---|
[418] | 584 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 585 | |
---|
| 586 | if(result.taskInstance) |
---|
| 587 | redirect(action: show, id: params.id) |
---|
| 588 | else |
---|
| 589 | redirect(action: 'search') |
---|
| 590 | |
---|
[181] | 591 | } |
---|
| 592 | |
---|
[298] | 593 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[418] | 594 | def clearAttentionFlag = { |
---|
[181] | 595 | |
---|
[418] | 596 | def result = taskService.clearAttentionFlag(params) |
---|
| 597 | |
---|
| 598 | if(!result.error) { |
---|
| 599 | flash.message = "Task ${params.id} attention flag cleared." |
---|
| 600 | redirect(action: show, id: params.id) |
---|
| 601 | return |
---|
[181] | 602 | } |
---|
| 603 | |
---|
[418] | 604 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 605 | |
---|
| 606 | if(result.taskInstance) |
---|
| 607 | redirect(action: show, id: params.id) |
---|
| 608 | else |
---|
| 609 | redirect(action: 'search') |
---|
| 610 | |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
| 614 | def reopen = { |
---|
| 615 | |
---|
[181] | 616 | def result = taskService.reopen(params) |
---|
| 617 | |
---|
| 618 | if(!result.error) { |
---|
| 619 | flash.message = "Task ${params.id} has been reopened." |
---|
[418] | 620 | redirect(action: show, id: params.id) |
---|
| 621 | return |
---|
[181] | 622 | } |
---|
| 623 | |
---|
[418] | 624 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 625 | |
---|
| 626 | if(result.taskInstance) |
---|
| 627 | redirect(action: show, id: params.id) |
---|
| 628 | else |
---|
| 629 | redirect(action: 'search') |
---|
| 630 | |
---|
[181] | 631 | } |
---|
| 632 | |
---|
[298] | 633 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 634 | def edit = { |
---|
[147] | 635 | |
---|
[139] | 636 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 637 | if(params._action_Edit) |
---|
[375] | 638 | params.action='edit' |
---|
[169] | 639 | |
---|
[433] | 640 | // Used by navigation. |
---|
| 641 | if(params.id == 'nav') { |
---|
| 642 | params.id = session.currentTaskId ?: null |
---|
| 643 | redirect(action: edit, id: params.id) |
---|
| 644 | return |
---|
| 645 | } |
---|
| 646 | |
---|
[66] | 647 | def taskInstance = Task.get( params.id ) |
---|
| 648 | |
---|
| 649 | if(!taskInstance) { |
---|
| 650 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 651 | redirect(action: 'search') |
---|
[66] | 652 | } |
---|
| 653 | else { |
---|
[433] | 654 | // Remember the current task id for use with navigation. |
---|
| 655 | session.currentTaskId = params.id |
---|
| 656 | |
---|
[181] | 657 | if(taskInstance.trash) { |
---|
[196] | 658 | flash.message = "You may not edit tasks that are in the trash." |
---|
| 659 | redirect(action: 'show', id: taskInstance.id) |
---|
| 660 | return |
---|
[181] | 661 | } |
---|
[246] | 662 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
| 663 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
| 664 | return [ taskInstance : taskInstance ] |
---|
[84] | 665 | } |
---|
| 666 | } |
---|
| 667 | |
---|
[298] | 668 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 669 | def update = { |
---|
[179] | 670 | |
---|
[180] | 671 | def result = taskService.update(params) |
---|
| 672 | |
---|
| 673 | if(!result.error) { |
---|
[66] | 674 | flash.message = "Task ${params.id} updated" |
---|
[418] | 675 | redirect(action: show, id: params.id) |
---|
| 676 | return |
---|
[180] | 677 | } |
---|
| 678 | |
---|
[418] | 679 | if(result.error.code == "task.modifications.failedToSave") |
---|
| 680 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 681 | |
---|
| 682 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
---|
| 683 | |
---|
[66] | 684 | } |
---|
| 685 | |
---|
[473] | 686 | /** |
---|
| 687 | * The create action is used to create scheduled types of tasks. |
---|
| 688 | */ |
---|
| 689 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[66] | 690 | def create = { |
---|
| 691 | def taskInstance = new Task() |
---|
[214] | 692 | |
---|
| 693 | // Set the targetStartDate if specified, used by searchCalendar view. |
---|
[476] | 694 | if(params.year && params.month && params.day) { |
---|
| 695 | def date = dateUtilService.makeDate(params.year, params.month, params.day) |
---|
| 696 | taskInstance.targetStartDate = date |
---|
| 697 | taskInstance.targetCompletionDate = date |
---|
| 698 | } |
---|
[214] | 699 | |
---|
[196] | 700 | // Default leadPerson to current user, unless supplied in params. |
---|
[291] | 701 | taskInstance.leadPerson = authService.currentUser |
---|
[487] | 702 | |
---|
| 703 | // Apply params, overiding anything above. |
---|
[66] | 704 | taskInstance.properties = params |
---|
[433] | 705 | |
---|
| 706 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
| 707 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
| 708 | taskInstance.taskPriority = scheduledTaskPriorities.default |
---|
| 709 | return ['taskInstance': taskInstance, |
---|
| 710 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
| 711 | 'scheduledTaskPriorities': scheduledTaskPriorities.list] |
---|
[66] | 712 | } |
---|
| 713 | |
---|
[298] | 714 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 715 | def save = { |
---|
[394] | 716 | def result = taskService.save(params) |
---|
[180] | 717 | |
---|
| 718 | if(!result.error) { |
---|
| 719 | flash.message = "Task ${result.taskInstance.id} created." |
---|
[196] | 720 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[418] | 721 | return |
---|
[66] | 722 | } |
---|
[180] | 723 | |
---|
[418] | 724 | if(result.error.code == "task.modifications.failedToSave") |
---|
| 725 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 726 | |
---|
[433] | 727 | |
---|
| 728 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
| 729 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
| 730 | render(view:'create', model:[taskInstance:result.taskInstance, |
---|
| 731 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
| 732 | 'scheduledTaskPriorities': scheduledTaskPriorities.list]) |
---|
[66] | 733 | } |
---|
[179] | 734 | |
---|
[298] | 735 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[179] | 736 | def listSubTasks = { |
---|
| 737 | def parentTaskInstance = Task.get(params.id) |
---|
| 738 | |
---|
[134] | 739 | if(!parentTaskInstance) { |
---|
| 740 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 741 | redirect(action: 'search') |
---|
[133] | 742 | } |
---|
| 743 | else { |
---|
[630] | 744 | params.max = Math.min( params.max ? params.max.toInteger() : 200, 200) |
---|
[196] | 745 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
| 746 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
[179] | 747 | |
---|
[134] | 748 | [ taskInstanceList: subTaskInstanceList, |
---|
[179] | 749 | taskInstanceTotal: subTaskInstanceTotal, |
---|
| 750 | parentTaskInstance: parentTaskInstance] |
---|
| 751 | } |
---|
| 752 | } |
---|
| 753 | |
---|
[298] | 754 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[196] | 755 | def createSubTask = { |
---|
| 756 | def parentTaskInstance = Task.get(params.id) |
---|
| 757 | |
---|
| 758 | if(parentTaskInstance) { |
---|
| 759 | |
---|
| 760 | def result = taskService.createSubTask(parentTaskInstance) |
---|
| 761 | if(!result.error) { |
---|
| 762 | flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements." |
---|
| 763 | redirect(action: 'edit', id: result.taskInstance.id) |
---|
| 764 | } |
---|
| 765 | else { |
---|
| 766 | if(result.taskInstance.errors.hasFieldErrors("parentTask")) { |
---|
[418] | 767 | flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
[196] | 768 | redirect(action: 'show', id: parentTaskInstance.id) |
---|
| 769 | } |
---|
| 770 | else { |
---|
| 771 | render(view: 'create', model:[taskInstance: result.taskInstance]) |
---|
| 772 | } |
---|
| 773 | } |
---|
| 774 | } |
---|
| 775 | |
---|
| 776 | else { |
---|
| 777 | flash.message = "Task not found with id ${params.id}" |
---|
| 778 | redirect(action: 'search') |
---|
| 779 | } |
---|
| 780 | } |
---|
| 781 | |
---|
[395] | 782 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[433] | 783 | def createUnscheduled = { |
---|
| 784 | def taskInstance = new Task() |
---|
| 785 | |
---|
| 786 | // Default leadPerson to current user, unless supplied in params. |
---|
| 787 | taskInstance.leadPerson = authService.currentUser |
---|
| 788 | taskInstance.properties = params |
---|
| 789 | |
---|
| 790 | // Always for Unscheduled task. |
---|
| 791 | taskInstance.taskType = TaskType.get(2) // Unscheduled Breakin. |
---|
| 792 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
| 793 | taskInstance.taskPriority = unscheduledTaskPriorities.default |
---|
| 794 | |
---|
| 795 | return ['taskInstance': taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list] |
---|
| 796 | } |
---|
| 797 | |
---|
| 798 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
| 799 | def saveUnscheduled = { |
---|
| 800 | def result = taskService.saveUnscheduled(params) |
---|
| 801 | |
---|
| 802 | if(!result.error) { |
---|
| 803 | flash.message = "Task ${result.taskInstance.id} created." |
---|
| 804 | redirect(action: 'show', id: result.taskInstance.id) |
---|
| 805 | return |
---|
| 806 | } |
---|
| 807 | |
---|
| 808 | if(result.error.code == "task.modifications.failedToSave") |
---|
| 809 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 810 | |
---|
| 811 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
| 812 | |
---|
| 813 | render(view:'createUnscheduled', |
---|
| 814 | model: ['taskInstance': result.taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list]) |
---|
| 815 | } |
---|
| 816 | |
---|
| 817 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[418] | 818 | def createImmediateCallout = { |
---|
[395] | 819 | def taskInstance = new Task() |
---|
| 820 | |
---|
| 821 | def entryFaultInstance = new Entry(entryType: EntryType.get(1)) // Fault. |
---|
[418] | 822 | def entryCauseInstance = new Entry(entryType: EntryType.get(2)) // Cause. |
---|
| 823 | def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3)) // Work Done. |
---|
[395] | 824 | |
---|
| 825 | return ['taskInstance': taskInstance, |
---|
| 826 | 'entryFaultInstance': entryFaultInstance, |
---|
[418] | 827 | 'entryCauseInstance': entryCauseInstance, |
---|
[395] | 828 | 'entryWorkDoneInstance': entryWorkDoneInstance] |
---|
| 829 | } |
---|
| 830 | |
---|
| 831 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[418] | 832 | def saveImmediateCallout = { |
---|
| 833 | def result = taskService.saveImmediateCallout(params) |
---|
[395] | 834 | |
---|
| 835 | if(!result.error) { |
---|
| 836 | flash.message = "Task ${result.taskInstance.id} created." |
---|
| 837 | redirect(action: 'show', id: result.taskInstance.id) |
---|
| 838 | return |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | if(result.error.code == "task.modifications.failedToSave") |
---|
| 842 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 843 | |
---|
[418] | 844 | render(view:'createImmediateCallout', |
---|
[395] | 845 | model: ['taskInstance': result.taskInstance, |
---|
| 846 | 'entryFaultInstance': result.entryFaultInstance, |
---|
[418] | 847 | 'entryCauseInstance': result.entryCauseInstance, |
---|
[395] | 848 | 'entryWorkDoneInstance': result.entryWorkDoneInstance]) |
---|
| 849 | |
---|
| 850 | } |
---|
| 851 | |
---|
[476] | 852 | /** |
---|
[490] | 853 | * Render a users total work done hours. |
---|
| 854 | */ |
---|
| 855 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
| 856 | def workDone = { |
---|
| 857 | def result = taskSearchService.getWorkDone(params, RCU.getLocale(request)) |
---|
| 858 | |
---|
| 859 | params.message = result.message |
---|
| 860 | |
---|
| 861 | return[entries: result.entries, |
---|
| 862 | totalEntries : result.totalEntries, |
---|
| 863 | startOfDay: result.startOfDay, |
---|
| 864 | person: result.person, |
---|
| 865 | totalHours: result.totalHours, |
---|
| 866 | totalMinutes: result.totalMinutes] |
---|
| 867 | } // workDone |
---|
| 868 | |
---|
| 869 | /** |
---|
[701] | 870 | * Render work load hours. |
---|
| 871 | */ |
---|
| 872 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
| 873 | def workLoad= { |
---|
| 874 | def result = taskSearchService.getWorkLoad(params, RCU.getLocale(request)) |
---|
| 875 | |
---|
| 876 | params.message = result.message |
---|
| 877 | params.errorMessage = result.errorMessage |
---|
| 878 | |
---|
| 879 | return[tasks: result.tasks, |
---|
| 880 | startDate: result.startDate, |
---|
| 881 | endDate: result.endDate, |
---|
| 882 | taskGroups: result.taskGroups, |
---|
| 883 | taskStatusList: result.taskStatusList, |
---|
| 884 | workLoadGroups: result.workLoadGroups, |
---|
| 885 | totalHours: result.totalHours, |
---|
| 886 | totalMinutes: result.totalMinutes] |
---|
| 887 | } // workLoad |
---|
| 888 | |
---|
| 889 | /** |
---|
[476] | 890 | * Get some integers for use by the month control links. |
---|
| 891 | */ |
---|
| 892 | private getCalendarMonthControls(Date showDate) { |
---|
| 893 | def result = [:] |
---|
| 894 | result.today = [:] |
---|
| 895 | result.today.date = new Date() |
---|
| 896 | result.today.month = dateUtilService.getMonthFromDate(result.today.date) |
---|
| 897 | result.today.year = dateUtilService.getYearFromDate(result.today.date) |
---|
| 898 | result.nextMonth = [:] |
---|
[553] | 899 | result.nextMonth.date = dateUtilService.plusMonth(showDate) |
---|
[476] | 900 | result.nextMonth.month = dateUtilService.getMonthFromDate(result.nextMonth.date) |
---|
| 901 | result.nextMonth.year = dateUtilService.getYearFromDate(result.nextMonth.date) |
---|
| 902 | result.previousMonth = [:] |
---|
[553] | 903 | result.previousMonth.date = dateUtilService.plusMonth(showDate, -1) |
---|
[476] | 904 | result.previousMonth.month = dateUtilService.getMonthFromDate(result.previousMonth.date) |
---|
| 905 | result.previousMonth.year = dateUtilService.getYearFromDate(result.previousMonth.date) |
---|
| 906 | result.nextYear = [:] |
---|
[552] | 907 | result.nextYear.date = dateUtilService.plusYear(showDate) |
---|
[476] | 908 | result.nextYear.month = dateUtilService.getMonthFromDate(result.nextYear.date) |
---|
| 909 | result.nextYear.year = dateUtilService.getYearFromDate(result.nextYear.date) |
---|
| 910 | result.previousYear = [:] |
---|
[552] | 911 | result.previousYear.date = dateUtilService.plusYear(showDate, -1) |
---|
[476] | 912 | result.previousYear.month = dateUtilService.getMonthFromDate(result.previousYear.date) |
---|
| 913 | result.previousYear.year = dateUtilService.getYearFromDate(result.previousYear.date) |
---|
| 914 | return result |
---|
| 915 | } |
---|
| 916 | |
---|
[196] | 917 | } // end of class. |
---|