- Timestamp:
- Apr 13, 2010, 12:37:51 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/InventoryItemDetailedController.groovy
r453 r485 1 1 import org.codehaus.groovy.grails.plugins.springsecurity.Secured 2 2 import org.codehaus.groovy.grails.commons.ConfigurationHolder 3 import com.zeddware.grails.plugins.filterpane.FilterUtils 4 import org.springframework.web.servlet.support.RequestContextUtils as RCU 3 5 4 6 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager']) … … 9 11 def inventoryCsvService 10 12 def inventoryItemService 13 def inventoryItemSearchService 11 14 def inventoryMovementService 12 15 … … 114 117 } 115 118 119 /** 120 * Search for Inventory items. 121 */ 116 122 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser']) 117 123 def search = { … … 120 126 params.max = session.inventoryItemSearchParamsMax 121 127 122 params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) 128 // Protect filterPane. 129 params.max = Math.min( params.max ? params.max.toInteger() : 10, 1000) 123 130 124 131 def inventoryItemInstanceList = [] 125 132 def inventoryItemInstanceTotal 126 def filterParams = [:] 127 128 // Quick Search: 129 if(!params.filter) { 130 inventoryItemInstanceList = InventoryItem.list( params ) 131 inventoryItemInstanceTotal = InventoryItem.count() 132 filterParams = params 133 } 134 else { 135 // filterPane: 133 def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) 134 def isFilterApplied = FilterUtils.isFilterApplied(params) 135 136 // Restore search unless a new search is being requested. 137 if(!params.quickSearch && !filterParams) { 138 if(session.inventoryItemQuickSearch) 139 params.quickSearch = session.inventoryItemQuickSearch 140 else if(session.inventoryItemSearchFilterParams) { 141 session.inventoryItemSearchFilterParams.each() { params[it.key] = it.value } 142 params.filter = session.inventoryItemSearchFilter 143 isFilterApplied = FilterUtils.isFilterApplied(params) 144 } 145 } 146 147 // Remember sort if supplied, otherwise try to restore. 148 if(params.sort && params.order) { 149 session.inventoryItemSearchSort = params.sort 150 session.inventoryItemSearchOrder = params.order 151 } 152 else if(session.inventoryItemSearchSort && session.inventoryItemSearchOrder) { 153 params.sort = session.inventoryItemSearchSort 154 params.order = session.inventoryItemSearchOrder 155 } 156 157 if(isFilterApplied) { 158 // filterPane: 136 159 inventoryItemInstanceList = filterService.filter( params, InventoryItem ) 137 160 inventoryItemInstanceTotal = filterService.count( params, InventoryItem ) 138 161 filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params) 162 // Remember search. 163 session.inventoryItemSearchFilterParams = new LinkedHashMap(filterParams) 164 session.inventoryItemSearchFilter = new LinkedHashMap(params.filter) 165 session.inventoryItemQuickSearch = null 166 } 167 else { 168 // Quick Search: 169 if(!params.quickSearch) params.quickSearch = "all" 170 def result = inventoryItemSearchService.getQuickSearch(params, RCU.getLocale(request)) 171 inventoryItemInstanceList = result.inventoryItemList 172 inventoryItemInstanceTotal = result.inventoryItemList.totalCount 173 params.message = result.message 174 filterParams.quickSearch = result.quickSearch 175 // Remember search. 176 session.inventoryItemSearchFilterParams = null 177 session.inventoryItemSearchFilter = null 178 session.inventoryItemQuickSearch = result.quickSearch 139 179 } 140 180 … … 145 185 formatDate(format: "EEE, dd-MMM-yyyy", date: date) 146 186 } 147 String title = "Inventory List." 187 188 String title 189 if(params.quickSearch) 190 title = params.message 191 else 192 title = "Filtered Inventory List." 148 193 149 194 response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] … … 152 197 "description", 153 198 "unitsInStock", 199 "reorderPoint", 154 200 "unitOfMeasure", 155 201 "inventoryLocation", … … 158 204 "description": "Description", 159 205 "unitsInStock":"In Stock", 206 "reorderPoint":"Reorder Point", 160 207 "unitOfMeasure": "UOM", 161 208 "inventoryLocation": "Location", … … 177 224 filterParams.max = params.max 178 225 filterParams.offset = params.offset?.toInteger() ?: 0 179 filterParams.sort = params.sort ?: " id"180 filterParams.order = params.order ?: " desc"226 filterParams.sort = params.sort ?: "name" 227 filterParams.order = params.order ?: "asc" 181 228 182 229 return[ inventoryItemInstanceList: inventoryItemInstanceList, 183 230 inventoryItemInstanceTotal: inventoryItemInstanceTotal, 184 filterParams: filterParams ] 231 filterParams: filterParams, 232 params: params ] 185 233 } // end search() 186 234
Note: See TracChangeset
for help on using the changeset viewer.