[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 | |
---|
[196] | 426 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params) |
---|
| 427 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false) |
---|
[134] | 428 | |
---|
[175] | 429 | def inventoryMovementList = InventoryMovement.findAllByTask(taskInstance, [max:100, sort:"id", order:"desc", offset:0]) |
---|
| 430 | |
---|
[180] | 431 | def taskModificationList = TaskModification.findAllByTask(taskInstance, [max:100, sort:"id", order:"asc", offset:0]) |
---|
| 432 | |
---|
[253] | 433 | def assignedGroupList = taskInstance.assignedGroups.sort { p1, p2 -> p1.personGroup.name.compareToIgnoreCase(p2.personGroup.name) } |
---|
| 434 | def assignedPersonList = taskInstance.assignedPersons.sort { p1, p2 -> p1.person.firstName.compareToIgnoreCase(p2.person.firstName) } |
---|
| 435 | |
---|
[133] | 436 | def taskProcedureInstance = TaskProcedure.get(taskInstance.taskProcedure?.id) |
---|
| 437 | def taskProcedureExits = new Boolean("true") |
---|
| 438 | if(!taskProcedureInstance) { |
---|
| 439 | taskProcedureExits = false |
---|
| 440 | } |
---|
[175] | 441 | |
---|
[747] | 442 | def maParams = [:] |
---|
| 443 | maParams.max = 100 |
---|
| 444 | maParams.order = "asc" |
---|
| 445 | maParams.sort = "procedureStepNumber" |
---|
| 446 | def maintenanceActionList = MaintenanceAction.findAllByTaskProcedure(taskProcedureInstance, maParams) |
---|
[175] | 447 | |
---|
[134] | 448 | def taskRecurringScheduleInstance = TaskRecurringSchedule.get(taskInstance.taskRecurringSchedule?.id) |
---|
| 449 | def taskRecurringScheduleExits= new Boolean("true") |
---|
[175] | 450 | if(!taskRecurringScheduleInstance) { |
---|
[134] | 451 | taskRecurringScheduleExits = false |
---|
| 452 | } |
---|
[179] | 453 | |
---|
[137] | 454 | return [ taskInstance: taskInstance, |
---|
[418] | 455 | entryFaultList: entryFaultList, |
---|
| 456 | entryCauseList: entryCauseList, |
---|
[179] | 457 | entryWorkDoneList: entryWorkDoneList, |
---|
[133] | 458 | taskProcedureInstance: taskProcedureInstance, |
---|
| 459 | taskProcedureExits: taskProcedureExits, |
---|
[225] | 460 | showTab: showTab, |
---|
[179] | 461 | subTaskInstanceList: subTaskInstanceList, |
---|
| 462 | subTaskInstanceTotal: subTaskInstanceTotal, |
---|
| 463 | subTaskInstanceMax: params.max, |
---|
| 464 | maintenanceActionList: maintenanceActionList, |
---|
| 465 | taskRecurringScheduleInstance: taskRecurringScheduleInstance, |
---|
| 466 | taskRecurringScheduleExits: taskRecurringScheduleExits, |
---|
[180] | 467 | inventoryMovementList: inventoryMovementList, |
---|
[253] | 468 | taskModificationList: taskModificationList, |
---|
| 469 | assignedGroupList: assignedGroupList, |
---|
| 470 | assignedPersonList: assignedPersonList] |
---|
[131] | 471 | } |
---|
[66] | 472 | } |
---|
| 473 | |
---|
[418] | 474 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 475 | def restore = { |
---|
| 476 | |
---|
| 477 | def result = taskService.restore(params) |
---|
| 478 | |
---|
| 479 | if(!result.error) { |
---|
| 480 | flash.message = "Task ${params.id} has been restored." |
---|
[418] | 481 | redirect(action: show, id: params.id) |
---|
| 482 | return |
---|
[181] | 483 | } |
---|
| 484 | |
---|
[418] | 485 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 486 | |
---|
| 487 | if(result.taskInstance) |
---|
| 488 | redirect(action: show, id: params.id) |
---|
| 489 | else |
---|
| 490 | redirect(action: 'search') |
---|
| 491 | |
---|
[181] | 492 | } |
---|
| 493 | |
---|
[418] | 494 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 495 | def trash = { |
---|
| 496 | |
---|
| 497 | def result = taskService.trash(params) |
---|
| 498 | |
---|
| 499 | if(!result.error) { |
---|
| 500 | flash.message = "Task ${params.id} has been moved to trash." |
---|
[196] | 501 | redirect(action: 'search') |
---|
[418] | 502 | return |
---|
[181] | 503 | } |
---|
| 504 | |
---|
[418] | 505 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 506 | |
---|
| 507 | if(result.taskInstance) |
---|
| 508 | redirect(action: show, id: params.id) |
---|
| 509 | else |
---|
| 510 | redirect(action: 'search') |
---|
| 511 | |
---|
[66] | 512 | } |
---|
| 513 | |
---|
[418] | 514 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[181] | 515 | def approve = { |
---|
| 516 | |
---|
| 517 | def result = taskService.approve(params) |
---|
| 518 | |
---|
| 519 | if(!result.error) { |
---|
| 520 | flash.message = "Task ${params.id} has been approved." |
---|
[418] | 521 | redirect(action: show, id: params.id) |
---|
| 522 | return |
---|
[181] | 523 | } |
---|
| 524 | |
---|
[418] | 525 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 526 | |
---|
| 527 | if(result.taskInstance) |
---|
| 528 | redirect(action: show, id: params.id) |
---|
| 529 | else |
---|
| 530 | redirect(action: 'search') |
---|
| 531 | |
---|
[181] | 532 | } |
---|
| 533 | |
---|
[465] | 534 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[181] | 535 | def renegeApproval = { |
---|
| 536 | |
---|
| 537 | def result = taskService.renegeApproval(params) |
---|
| 538 | |
---|
| 539 | if(!result.error) { |
---|
| 540 | flash.message = "Task ${params.id} has had approval removed." |
---|
[418] | 541 | redirect(action: show, id: params.id) |
---|
| 542 | return |
---|
[181] | 543 | } |
---|
| 544 | |
---|
[418] | 545 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 546 | |
---|
| 547 | if(result.taskInstance) |
---|
| 548 | redirect(action: show, id: params.id) |
---|
| 549 | else |
---|
| 550 | redirect(action: 'search') |
---|
| 551 | |
---|
[181] | 552 | } |
---|
| 553 | |
---|
[298] | 554 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[181] | 555 | def complete = { |
---|
| 556 | |
---|
| 557 | def result = taskService.complete(params) |
---|
| 558 | |
---|
| 559 | if(!result.error) { |
---|
| 560 | flash.message = "Task ${params.id} has been completed." |
---|
[418] | 561 | redirect(action: show, id: params.id) |
---|
| 562 | return |
---|
[181] | 563 | } |
---|
[418] | 564 | |
---|
| 565 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 566 | |
---|
| 567 | if(result.taskInstance) |
---|
| 568 | redirect(action: show, id: params.id) |
---|
| 569 | else |
---|
| 570 | redirect(action: 'search') |
---|
| 571 | |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
| 575 | def setAttentionFlag = { |
---|
| 576 | |
---|
| 577 | def result = taskService.setAttentionFlag(params) |
---|
| 578 | |
---|
| 579 | if(!result.error) { |
---|
| 580 | flash.message = "Task ${params.id} has been flagged for attention." |
---|
| 581 | redirect(action: show, id: params.id) |
---|
| 582 | return |
---|
[181] | 583 | } |
---|
| 584 | |
---|
[418] | 585 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 586 | |
---|
| 587 | if(result.taskInstance) |
---|
| 588 | redirect(action: show, id: params.id) |
---|
| 589 | else |
---|
| 590 | redirect(action: 'search') |
---|
| 591 | |
---|
[181] | 592 | } |
---|
| 593 | |
---|
[298] | 594 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[418] | 595 | def clearAttentionFlag = { |
---|
[181] | 596 | |
---|
[418] | 597 | def result = taskService.clearAttentionFlag(params) |
---|
| 598 | |
---|
| 599 | if(!result.error) { |
---|
| 600 | flash.message = "Task ${params.id} attention flag cleared." |
---|
| 601 | redirect(action: show, id: params.id) |
---|
| 602 | return |
---|
[181] | 603 | } |
---|
| 604 | |
---|
[418] | 605 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 606 | |
---|
| 607 | if(result.taskInstance) |
---|
| 608 | redirect(action: show, id: params.id) |
---|
| 609 | else |
---|
| 610 | redirect(action: 'search') |
---|
| 611 | |
---|
| 612 | } |
---|
| 613 | |
---|
| 614 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
| 615 | def reopen = { |
---|
| 616 | |
---|
[181] | 617 | def result = taskService.reopen(params) |
---|
| 618 | |
---|
| 619 | if(!result.error) { |
---|
| 620 | flash.message = "Task ${params.id} has been reopened." |
---|
[418] | 621 | redirect(action: show, id: params.id) |
---|
| 622 | return |
---|
[181] | 623 | } |
---|
| 624 | |
---|
[418] | 625 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 626 | |
---|
| 627 | if(result.taskInstance) |
---|
| 628 | redirect(action: show, id: params.id) |
---|
| 629 | else |
---|
| 630 | redirect(action: 'search') |
---|
| 631 | |
---|
[181] | 632 | } |
---|
| 633 | |
---|
[298] | 634 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 635 | def edit = { |
---|
[147] | 636 | |
---|
[139] | 637 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 638 | if(params._action_Edit) |
---|
[375] | 639 | params.action='edit' |
---|
[169] | 640 | |
---|
[433] | 641 | // Used by navigation. |
---|
| 642 | if(params.id == 'nav') { |
---|
| 643 | params.id = session.currentTaskId ?: null |
---|
| 644 | redirect(action: edit, id: params.id) |
---|
| 645 | return |
---|
| 646 | } |
---|
| 647 | |
---|
[66] | 648 | def taskInstance = Task.get( params.id ) |
---|
| 649 | |
---|
| 650 | if(!taskInstance) { |
---|
| 651 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 652 | redirect(action: 'search') |
---|
[66] | 653 | } |
---|
| 654 | else { |
---|
[433] | 655 | // Remember the current task id for use with navigation. |
---|
| 656 | session.currentTaskId = params.id |
---|
| 657 | |
---|
[181] | 658 | if(taskInstance.trash) { |
---|
[196] | 659 | flash.message = "You may not edit tasks that are in the trash." |
---|
| 660 | redirect(action: 'show', id: taskInstance.id) |
---|
| 661 | return |
---|
[181] | 662 | } |
---|
[246] | 663 | // def possibleParentList = taskService.possibleParentList(taskInstance) |
---|
| 664 | // return [ taskInstance : taskInstance, possibleParentList: possibleParentList ] |
---|
| 665 | return [ taskInstance : taskInstance ] |
---|
[84] | 666 | } |
---|
| 667 | } |
---|
| 668 | |
---|
[298] | 669 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 670 | def update = { |
---|
[179] | 671 | |
---|
[180] | 672 | def result = taskService.update(params) |
---|
| 673 | |
---|
| 674 | if(!result.error) { |
---|
[66] | 675 | flash.message = "Task ${params.id} updated" |
---|
[418] | 676 | redirect(action: show, id: params.id) |
---|
| 677 | return |
---|
[180] | 678 | } |
---|
| 679 | |
---|
[418] | 680 | if(result.error.code == "task.modifications.failedToSave") |
---|
| 681 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 682 | |
---|
| 683 | render(view:'edit',model:[taskInstance:result.taskInstance.attach()]) |
---|
| 684 | |
---|
[66] | 685 | } |
---|
| 686 | |
---|
[473] | 687 | /** |
---|
| 688 | * The create action is used to create scheduled types of tasks. |
---|
| 689 | */ |
---|
| 690 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager']) |
---|
[66] | 691 | def create = { |
---|
| 692 | def taskInstance = new Task() |
---|
[214] | 693 | |
---|
| 694 | // Set the targetStartDate if specified, used by searchCalendar view. |
---|
[476] | 695 | if(params.year && params.month && params.day) { |
---|
| 696 | def date = dateUtilService.makeDate(params.year, params.month, params.day) |
---|
| 697 | taskInstance.targetStartDate = date |
---|
| 698 | taskInstance.targetCompletionDate = date |
---|
| 699 | } |
---|
[214] | 700 | |
---|
[196] | 701 | // Default leadPerson to current user, unless supplied in params. |
---|
[291] | 702 | taskInstance.leadPerson = authService.currentUser |
---|
[487] | 703 | |
---|
| 704 | // Apply params, overiding anything above. |
---|
[66] | 705 | taskInstance.properties = params |
---|
[433] | 706 | |
---|
| 707 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
| 708 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
| 709 | taskInstance.taskPriority = scheduledTaskPriorities.default |
---|
| 710 | return ['taskInstance': taskInstance, |
---|
| 711 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
| 712 | 'scheduledTaskPriorities': scheduledTaskPriorities.list] |
---|
[66] | 713 | } |
---|
| 714 | |
---|
[298] | 715 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[66] | 716 | def save = { |
---|
[394] | 717 | def result = taskService.save(params) |
---|
[180] | 718 | |
---|
| 719 | if(!result.error) { |
---|
| 720 | flash.message = "Task ${result.taskInstance.id} created." |
---|
[196] | 721 | redirect(action: 'show', id: result.taskInstance.id) |
---|
[418] | 722 | return |
---|
[66] | 723 | } |
---|
[180] | 724 | |
---|
[418] | 725 | if(result.error.code == "task.modifications.failedToSave") |
---|
| 726 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 727 | |
---|
[433] | 728 | |
---|
| 729 | def scheduledTaskTypes = taskService.scheduledTaskTypes |
---|
| 730 | def scheduledTaskPriorities = taskService.scheduledTaskPriorities |
---|
| 731 | render(view:'create', model:[taskInstance:result.taskInstance, |
---|
| 732 | 'scheduledTaskTypes': scheduledTaskTypes, |
---|
| 733 | 'scheduledTaskPriorities': scheduledTaskPriorities.list]) |
---|
[66] | 734 | } |
---|
[179] | 735 | |
---|
[298] | 736 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[179] | 737 | def listSubTasks = { |
---|
| 738 | def parentTaskInstance = Task.get(params.id) |
---|
| 739 | |
---|
[134] | 740 | if(!parentTaskInstance) { |
---|
| 741 | flash.message = "Task not found with id ${params.id}" |
---|
[196] | 742 | redirect(action: 'search') |
---|
[133] | 743 | } |
---|
| 744 | else { |
---|
[630] | 745 | params.max = Math.min( params.max ? params.max.toInteger() : 200, 200) |
---|
[196] | 746 | def subTaskInstanceList = Task.findAllByParentTaskAndTrash(parentTaskInstance, false, params) |
---|
| 747 | def subTaskInstanceTotal = Task.countByParentTaskAndTrash(parentTaskInstance, false) |
---|
[179] | 748 | |
---|
[134] | 749 | [ taskInstanceList: subTaskInstanceList, |
---|
[179] | 750 | taskInstanceTotal: subTaskInstanceTotal, |
---|
| 751 | parentTaskInstance: parentTaskInstance] |
---|
| 752 | } |
---|
| 753 | } |
---|
| 754 | |
---|
[298] | 755 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[196] | 756 | def createSubTask = { |
---|
| 757 | def parentTaskInstance = Task.get(params.id) |
---|
| 758 | |
---|
| 759 | if(parentTaskInstance) { |
---|
| 760 | |
---|
| 761 | def result = taskService.createSubTask(parentTaskInstance) |
---|
| 762 | if(!result.error) { |
---|
| 763 | flash.message = "Sub Task ${result.taskInstance.id} created, please edit and update to your requirements." |
---|
| 764 | redirect(action: 'edit', id: result.taskInstance.id) |
---|
| 765 | } |
---|
| 766 | else { |
---|
| 767 | if(result.taskInstance.errors.hasFieldErrors("parentTask")) { |
---|
[418] | 768 | flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash") |
---|
[196] | 769 | redirect(action: 'show', id: parentTaskInstance.id) |
---|
| 770 | } |
---|
| 771 | else { |
---|
| 772 | render(view: 'create', model:[taskInstance: result.taskInstance]) |
---|
| 773 | } |
---|
| 774 | } |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | else { |
---|
| 778 | flash.message = "Task not found with id ${params.id}" |
---|
| 779 | redirect(action: 'search') |
---|
| 780 | } |
---|
| 781 | } |
---|
| 782 | |
---|
[395] | 783 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[433] | 784 | def createUnscheduled = { |
---|
| 785 | def taskInstance = new Task() |
---|
| 786 | |
---|
| 787 | // Default leadPerson to current user, unless supplied in params. |
---|
| 788 | taskInstance.leadPerson = authService.currentUser |
---|
| 789 | taskInstance.properties = params |
---|
| 790 | |
---|
| 791 | // Always for Unscheduled task. |
---|
| 792 | taskInstance.taskType = TaskType.get(2) // Unscheduled Breakin. |
---|
| 793 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
| 794 | taskInstance.taskPriority = unscheduledTaskPriorities.default |
---|
| 795 | |
---|
| 796 | return ['taskInstance': taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list] |
---|
| 797 | } |
---|
| 798 | |
---|
| 799 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
| 800 | def saveUnscheduled = { |
---|
| 801 | def result = taskService.saveUnscheduled(params) |
---|
| 802 | |
---|
| 803 | if(!result.error) { |
---|
| 804 | flash.message = "Task ${result.taskInstance.id} created." |
---|
| 805 | redirect(action: 'show', id: result.taskInstance.id) |
---|
| 806 | return |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | if(result.error.code == "task.modifications.failedToSave") |
---|
| 810 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 811 | |
---|
| 812 | def unscheduledTaskPriorities = taskService.unscheduledTaskPriorities |
---|
| 813 | |
---|
| 814 | render(view:'createUnscheduled', |
---|
| 815 | model: ['taskInstance': result.taskInstance, 'unscheduledTaskPriorities': unscheduledTaskPriorities.list]) |
---|
| 816 | } |
---|
| 817 | |
---|
| 818 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[418] | 819 | def createImmediateCallout = { |
---|
[395] | 820 | def taskInstance = new Task() |
---|
| 821 | |
---|
| 822 | def entryFaultInstance = new Entry(entryType: EntryType.get(1)) // Fault. |
---|
[418] | 823 | def entryCauseInstance = new Entry(entryType: EntryType.get(2)) // Cause. |
---|
| 824 | def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3)) // Work Done. |
---|
[395] | 825 | |
---|
| 826 | return ['taskInstance': taskInstance, |
---|
| 827 | 'entryFaultInstance': entryFaultInstance, |
---|
[418] | 828 | 'entryCauseInstance': entryCauseInstance, |
---|
[395] | 829 | 'entryWorkDoneInstance': entryWorkDoneInstance] |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
[418] | 833 | def saveImmediateCallout = { |
---|
| 834 | def result = taskService.saveImmediateCallout(params) |
---|
[395] | 835 | |
---|
| 836 | if(!result.error) { |
---|
| 837 | flash.message = "Task ${result.taskInstance.id} created." |
---|
| 838 | redirect(action: 'show', id: result.taskInstance.id) |
---|
| 839 | return |
---|
| 840 | } |
---|
| 841 | |
---|
| 842 | if(result.error.code == "task.modifications.failedToSave") |
---|
| 843 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 844 | |
---|
[418] | 845 | render(view:'createImmediateCallout', |
---|
[395] | 846 | model: ['taskInstance': result.taskInstance, |
---|
| 847 | 'entryFaultInstance': result.entryFaultInstance, |
---|
[418] | 848 | 'entryCauseInstance': result.entryCauseInstance, |
---|
[395] | 849 | 'entryWorkDoneInstance': result.entryWorkDoneInstance]) |
---|
| 850 | |
---|
| 851 | } |
---|
| 852 | |
---|
[476] | 853 | /** |
---|
[490] | 854 | * Render a users total work done hours. |
---|
| 855 | */ |
---|
| 856 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
| 857 | def workDone = { |
---|
| 858 | def result = taskSearchService.getWorkDone(params, RCU.getLocale(request)) |
---|
| 859 | |
---|
| 860 | params.message = result.message |
---|
| 861 | |
---|
| 862 | return[entries: result.entries, |
---|
| 863 | totalEntries : result.totalEntries, |
---|
| 864 | startOfDay: result.startOfDay, |
---|
| 865 | person: result.person, |
---|
| 866 | totalHours: result.totalHours, |
---|
| 867 | totalMinutes: result.totalMinutes] |
---|
| 868 | } // workDone |
---|
| 869 | |
---|
| 870 | /** |
---|
[701] | 871 | * Render work load hours. |
---|
| 872 | */ |
---|
| 873 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser']) |
---|
| 874 | def workLoad= { |
---|
| 875 | def result = taskSearchService.getWorkLoad(params, RCU.getLocale(request)) |
---|
| 876 | |
---|
| 877 | params.message = result.message |
---|
| 878 | params.errorMessage = result.errorMessage |
---|
| 879 | |
---|
| 880 | return[tasks: result.tasks, |
---|
| 881 | startDate: result.startDate, |
---|
| 882 | endDate: result.endDate, |
---|
| 883 | taskGroups: result.taskGroups, |
---|
| 884 | taskStatusList: result.taskStatusList, |
---|
| 885 | workLoadGroups: result.workLoadGroups, |
---|
| 886 | totalHours: result.totalHours, |
---|
| 887 | totalMinutes: result.totalMinutes] |
---|
| 888 | } // workLoad |
---|
| 889 | |
---|
| 890 | /** |
---|
[476] | 891 | * Get some integers for use by the month control links. |
---|
| 892 | */ |
---|
| 893 | private getCalendarMonthControls(Date showDate) { |
---|
| 894 | def result = [:] |
---|
| 895 | result.today = [:] |
---|
| 896 | result.today.date = new Date() |
---|
| 897 | result.today.month = dateUtilService.getMonthFromDate(result.today.date) |
---|
| 898 | result.today.year = dateUtilService.getYearFromDate(result.today.date) |
---|
| 899 | result.nextMonth = [:] |
---|
[553] | 900 | result.nextMonth.date = dateUtilService.plusMonth(showDate) |
---|
[476] | 901 | result.nextMonth.month = dateUtilService.getMonthFromDate(result.nextMonth.date) |
---|
| 902 | result.nextMonth.year = dateUtilService.getYearFromDate(result.nextMonth.date) |
---|
| 903 | result.previousMonth = [:] |
---|
[553] | 904 | result.previousMonth.date = dateUtilService.plusMonth(showDate, -1) |
---|
[476] | 905 | result.previousMonth.month = dateUtilService.getMonthFromDate(result.previousMonth.date) |
---|
| 906 | result.previousMonth.year = dateUtilService.getYearFromDate(result.previousMonth.date) |
---|
| 907 | result.nextYear = [:] |
---|
[552] | 908 | result.nextYear.date = dateUtilService.plusYear(showDate) |
---|
[476] | 909 | result.nextYear.month = dateUtilService.getMonthFromDate(result.nextYear.date) |
---|
| 910 | result.nextYear.year = dateUtilService.getYearFromDate(result.nextYear.date) |
---|
| 911 | result.previousYear = [:] |
---|
[552] | 912 | result.previousYear.date = dateUtilService.plusYear(showDate, -1) |
---|
[476] | 913 | result.previousYear.month = dateUtilService.getMonthFromDate(result.previousYear.date) |
---|
| 914 | result.previousYear.year = dateUtilService.getYearFromDate(result.previousYear.date) |
---|
| 915 | return result |
---|
| 916 | } |
---|
| 917 | |
---|
[196] | 918 | } // end of class. |
---|