Changeset 701


Ignore:
Timestamp:
Nov 2, 2010, 9:24:28 AM (14 years ago)
Author:
gav
Message:

New workLoad search view and logic to suite.

Location:
trunk/grails-app
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/TaskDetailedController.groovy

    r630 r701  
    835835                    totalMinutes: result.totalMinutes]
    836836    } // workDone
     837
     838    /**
     839    * Render work load hours.
     840    */
     841    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
     842    def workLoad= {
     843        def result = taskSearchService.getWorkLoad(params, RCU.getLocale(request))
     844
     845        params.message = result.message
     846        params.errorMessage = result.errorMessage
     847
     848        return[tasks: result.tasks,
     849                    startDate: result.startDate,
     850                    endDate: result.endDate,
     851                    taskGroups: result.taskGroups,
     852                    taskStatusList: result.taskStatusList,
     853                    workLoadGroups: result.workLoadGroups,
     854                    totalHours: result.totalHours,
     855                    totalMinutes: result.totalMinutes]
     856    } // workLoad
    837857
    838858    /**
  • trunk/grails-app/i18n/messages.properties

    r668 r701  
    406406task.search.text.work.done.message=Work done by {0} on {1}.
    407407task.search.text.work.done.none.found=No entries found for {0} on {1}.
     408task.search.text.work.load=Work Load
     409task.search.text.work.load.description=Work load by group and date.
     410task.search.text.work.load.message=Work load between {0} and {1}.
     411task.search.text.work.load.none.found=No tasks found between {0} and {1}.
     412task.search.text.work.load.too.many.results=Too many tasks found to perform calculatation, {0} / {1} shown.
    408413
    409414#
  • trunk/grails-app/services/TaskSearchService.groovy

    r582 r701  
    11import grails.orm.PagedResultList
     2import org.hibernate.FetchMode as FM
    23
    34/**
     
    348349    } // getWorkDone()
    349350
     351    /**
     352    * Get work load by task group and date.
     353    * Group ID's and date range may be specified in params otherwise no group and today are used.
     354    * @param params The request params.
     355    * @returns A map containing the results.
     356    */
     357    def getWorkLoad(params, locale) {
     358        def result = [:]
     359        def max = 1000
     360
     361        // TaskStatus..
     362        result.taskStatusList = []
     363        if(params.taskStatusList instanceof String)
     364            result.taskStatusList << TaskStatus.get(params.taskStatusList.toInteger())
     365        else if(params.taskStatusList)
     366            result.taskStatusList = TaskStatus.getAll( params.taskStatusList.collect {it.toInteger()} )
     367
     368        // TaskGroups.
     369        result.taskGroups = []
     370        if(params.taskGroups instanceof String)
     371            result.taskGroups << TaskGroup.get(params.taskGroups.toInteger())
     372        else if(params.taskGroups)
     373            result.taskGroups = TaskGroup.getAll( params.taskGroups.collect {it.toInteger()} )
     374
     375        // Start Date.
     376        if(params.startDate_year && params.startDate_month && params.startDate_day)
     377            result.startDate = dateUtilService.makeDate(params.startDate_year, params.startDate_month, params.startDate_day)
     378        else
     379            result.startDate = dateUtilService.today
     380
     381        // End Date.
     382        if(params.endDate_year && params.endDate_month && params.endDate_day)
     383            result.endDate = dateUtilService.makeDate(params.endDate_year, params.endDate_month, params.endDate_day)
     384        else
     385            result.endDate = result.startDate
     386
     387        // Normalise date range.
     388        if(result.endDate < result.startDate)
     389            result.endDate = result.startDate
     390
     391        def formattedStartDate = g.formatDate(format: "EEE, dd-MMM-yyyy", date: result.startDate)
     392        def formattedEndDate = g.formatDate(format: "EEE, dd-MMM-yyyy", date: result.endDate)
     393
     394        def getMessage = { Map m ->
     395            messageSource.getMessage(m.code, m.args == null ? null : m.args.toArray(), locale)
     396        }
     397
     398        result.tasks = new PagedResultList([], 0)
     399
     400        if(result.taskGroups && result.taskStatusList) {
     401
     402            result.tasks = Task.createCriteria().list(max: max) {
     403                eq("trash", false)
     404                lt("targetStartDate", result.endDate+1)
     405                ge("targetCompletionDate", result.startDate)
     406                inList("taskStatus", result.taskStatusList)
     407                inList("taskGroup", result.taskGroups)
     408                order("taskStatus", "asc")
     409                order("taskPriority", "asc")
     410                order("targetStartDate", "asc")
     411                fetchMode("assignedGroups", FM.EAGER)
     412                fetchMode("assignedGroups.personGroup", FM.EAGER)
     413            } // createCriteria
     414
     415        }
     416
     417        result.tasks.list.unique()
     418        result.totalHours = 0
     419        result.totalMinutes = 0
     420        result.workLoadGroups = [:]
     421
     422        // Exit early!
     423        if(result.tasks.totalCount > result.tasks.size()) {
     424            result.errorMessage = getMessage(code:"task.search.text.work.load.too.many.results",
     425                                                                args:[result.tasks.size(), result.tasks.totalCount])
     426            return result
     427        }
     428        else if(result.tasks.size() > 0)
     429            result.message = getMessage(code:"task.search.text.work.load.message",
     430                                                                args:[formattedStartDate, formattedEndDate])
     431        else
     432            result.message = getMessage(code:"task.search.text.work.load.none.found",
     433                                                                args:[formattedStartDate, formattedEndDate])
     434
     435        // Collect all assignedGroups.
     436        def assignedGroups = []
     437        for(task in result.tasks) {
     438            for(assignedGroup in task.assignedGroups) {
     439                assignedGroups << assignedGroup
     440            }
     441        }
     442
     443        // Calculate work load for each personGroup and minute totals.
     444        def tempHours = 0
     445        def tempMinutes = 0
     446        def personGroup
     447        for(assignedGroup in assignedGroups) {
     448            personGroup = assignedGroup.personGroup
     449            if(!result.workLoadGroups.containsKey(personGroup)) {
     450                result.workLoadGroups[personGroup] = [hours: 0, minutes: 0]
     451            }
     452
     453            tempMinutes = (assignedGroup.estimatedHour*60) + assignedGroup.estimatedMinute
     454            result.totalMinutes += tempMinutes
     455            result.workLoadGroups[personGroup].minutes += tempMinutes
     456        }
     457
     458        // Resolve totals and sort.
     459        result.workLoadGroups.each { workLoadGroup ->
     460            workLoadGroup.value.hours =  (workLoadGroup.value.minutes / 60).toInteger()
     461            workLoadGroup.value.minutes = workLoadGroup.value.minutes % 60
     462        }
     463        result.workLoadGroups = result.workLoadGroups.sort { p1, p2 -> p1.key.name.compareToIgnoreCase(p2.key.name) }
     464        result.totalHours = (result.totalMinutes / 60).toInteger()
     465        result.totalMinutes = result.totalMinutes % 60
     466
     467        // Success.
     468        return result
     469    } // getWorkLoad()
     470
    350471} // end class
  • trunk/grails-app/views/taskDetailed/_quickSearchPane.gsp

    r562 r701  
    103103                        </g:link> - <g:message code="task.search.text.work.done.description" />
    104104                        <br />
     105                        <g:link controller="taskDetailed"
     106                                        action="workLoad">
     107                                        <g:message code="task.search.text.work.load" />
     108                        </g:link> - <g:message code="task.search.text.work.load.description" />
    105109                    </td>
    106110                </tr>
Note: See TracChangeset for help on using the changeset viewer.