Changeset 654 for trunk/grails-app
- Timestamp:
- Sep 23, 2010, 5:01:46 AM (14 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/ReportController.groovy
r652 r654 173 173 } // assetRegister 174 174 175 def equipmentRegister = { 176 177 params.reportTitle = "Equipment Register" 178 params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL() 179 params.currentUser = authService.currentUser 180 if(params.section.id == 'all') 181 params.section = "All" 182 else 183 params.section = Section.get(params.section.id.toLong()) 184 185 def dataModel = assetReportService.getEquipmentRegister(params, RCU.getLocale(request)) 186 187 // Jasper plugin controller expects data to be a Collection. 188 chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) 189 190 // render { 191 // dataModel.dataList.each { 192 // p("$it") 193 // } 194 // } 195 196 } // equipmentRegister 197 175 198 } // end of class. -
trunk/grails-app/services/AssetReportService.groovy
r652 r654 117 117 } // getAssetDetail 118 118 119 /** 120 * Selects and returns level 1 sub items (aka machines or equipment) and their details. 121 * @param params The request params, may contain params to specify the search. 122 * @param locale The locale to use when generating result.message. 123 */ 124 def getEquipmentRegister(params, locale) { 125 def result = [:] 126 127 // Inner join used to return only attribTypes that are used by AssetSubItemExtendedAttributes. 128 // So the result is only assetSubItem extendedAttributeTypes. 129 def attribTypesQ = new HqlBuilder().query { 130 select 'distinct attribT.name' 131 from 'AssetSubItemExtendedAttribute attrib', 132 'join attrib.extendedAttributeType as attribT' 133 order 'by attribT.name asc' 134 } 135 result.attribTypes = Asset.executeQuery(attribTypesQ.query, attribTypesQ.namedParams) 136 137 // Since there will be nothing to show in the report table for assets without level 1 assetSubItems, 138 // a list needs to be given to the user. 139 def assetsWithoutEquipmentQ = new HqlBuilder().query { 140 select 'distinct asset' 141 from 'Asset asset', 142 'left join asset.assetSubItems as assetSubItem' 143 where 'assetSubItem = null' 144 } 145 result.assetsWithoutEquipment = AssetSubItem.executeQuery(assetsWithoutEquipmentQ.query, assetsWithoutEquipmentQ.namedParams) 146 147 // A result is returned for every level 1 assetSubItem and for any extended attributes. 148 def q = new HqlBuilder().query { 149 select 'new map(asset.name as assetName', 150 'assetSubItem.name as name', 151 'assetSubItem.description as description', 152 'assetSubItem.comment as comment', 153 'attribT.name as attribType', 154 'attrib.value as attribValue)' 155 from 'AssetSubItem assetSubItem', 156 'inner join assetSubItem.assets as asset', 157 'left join assetSubItem.assetSubItemExtendedAttributes as attrib', 158 'left join attrib.extendedAttributeType as attribT' 159 where 'asset != null' // ensure that only level 1 assetSubItems are returned. 160 if(params.section instanceof Section) { 161 namedParams.section = params.section 162 and 'asset.section = :section' 163 } 164 order 'by asset.name asc, assetSubItem.name asc, attribT.name asc' 165 } 166 def equipmentResults = AssetSubItem.executeQuery(q.query, q.namedParams) 167 168 // Build the report table rows. 169 // Rows are keyed by equipmentResult.assetName+equipmentResult.name` while the value is a Map of the attributes. 170 // The report table then groups by assetName. 171 def rows = [:] 172 equipmentResults.each { equipmentResult -> 173 // Create row if it does not exist yet. 174 def rowKey = equipmentResult.assetName+equipmentResult.name 175 if(!rows.containsKey(rowKey)) { 176 rows[rowKey] = ['assetName': equipmentResult.assetName, 177 'name':equipmentResult.name, 178 'description':equipmentResult.description, 179 'comment':equipmentResult.comment] 180 181 // Add all attribType columns. 182 result.attribTypes.each { column -> 183 rows[rowKey][column] = null 184 } 185 } 186 187 // Assign value to column. 188 rows[rowKey][equipmentResult.attribType] = equipmentResult.attribValue 189 } 190 191 // The value of each row is the dataList used by the report table. 192 result.dataList = rows.collect {it.value} 193 // Print formatting, since we are done with these as objects. 194 result.attribTypes = result.attribTypes.join(', ') 195 result.assetsWithoutEquipment = result.assetsWithoutEquipment.collect {it.name}.join(', ') 196 197 // Success. 198 return result 199 200 } // getEquipmentRegister 201 119 202 } // end class -
trunk/grails-app/views/appCore/start.gsp
r652 r654 148 148 </g:select> 149 149 </g:jasperReport> 150 <br /> 150 151 <g:jasperReport controller="report" 151 152 action="assetRegister" … … 161 162 <br /> 162 163 <g:jasperReport controller="report" 164 action="equipmentRegister" 165 jasper="equipmentRegister" 166 name="Equipment Register" 167 format="PDF, XLS"> 168 <g:select optionKey="id" 169 from="${Section.findAllByIsActive(true).sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }}" 170 name="section.id" 171 noSelection="['all':/${g.message(code:'default.all.select.text')}/]"> 172 </g:select> 173 </g:jasperReport> 174 <br /> 175 <g:jasperReport controller="report" 163 176 action="templatePortrait" 164 177 jasper="templatePortrait"
Note: See TracChangeset
for help on using the changeset viewer.