Changeset 489
- Timestamp:
- Apr 16, 2010, 2:10:52 PM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/InventoryItemDetailedController.groovy
r485 r489 136 136 // Restore search unless a new search is being requested. 137 137 if(!params.quickSearch && !filterParams) { 138 if(session.inventoryItemQuickSearch) 138 if(session.inventoryItemQuickSearch) { 139 139 params.quickSearch = session.inventoryItemQuickSearch 140 if(session.inventoryItemQuickSearchDaysBack) 141 params.daysBack = session.inventoryItemQuickSearchDaysBack.toString() 142 } 140 143 else if(session.inventoryItemSearchFilterParams) { 141 144 session.inventoryItemSearchFilterParams.each() { params[it.key] = it.value } … … 163 166 session.inventoryItemSearchFilterParams = new LinkedHashMap(filterParams) 164 167 session.inventoryItemSearchFilter = new LinkedHashMap(params.filter) 165 session.inventoryItemQuickSearch = null 168 session.removeAttribute("inventoryItemQuickSearch") 169 session.removeAttribute("inventoryItemQuickSearchDaysBack") 166 170 } 167 171 else { … … 174 178 filterParams.quickSearch = result.quickSearch 175 179 // Remember search. 176 session. inventoryItemSearchFilterParams = null177 session. inventoryItemSearchFilter = null180 session.removeAttribute("inventoryItemSearchFilterParams") 181 session.removeAttribute("inventoryItemSearchFilter") 178 182 session.inventoryItemQuickSearch = result.quickSearch 183 if(result.daysBack) 184 session.inventoryItemQuickSearchDaysBack = result.daysBack 179 185 } 180 186 -
trunk/grails-app/i18n/messages.properties
r485 r489 297 297 inventoryItem.search.text.all.description=All inventory items. 298 298 inventoryItem.search.text.all.none.found=No inventory items found. 299 inventoryItem.search.text.recently.used=Recently Used 300 inventoryItem.search.text.recently.used.description=Items used in the last {0} days. 301 inventoryItem.search.text.recently.used.none.found=No items used in the last {0} days. -
trunk/grails-app/services/InventoryItemSearchService.groovy
r485 r489 1 import grails.orm.PagedResultList 2 1 3 /** 2 4 * Service class that encapsulates the business logic for InventoryItem searches. … … 6 8 boolean transactional = false 7 9 10 def dateUtilService 8 11 def messageSource 9 12 … … 37 40 else 38 41 result.message = getMessage(code:"inventoryItem.search.text.below.reorder.none.found") 42 break 43 case "recentlyUsed": 44 result.daysBack = params.daysBack?.isInteger() ? params.daysBack.toInteger() : 14 45 result.inventoryItemList = getRecentlyUsed(params, result.daysBack) 46 if(result.inventoryItemList.totalCount > 0) 47 result.message = getMessage(code:"inventoryItem.search.text.recently.used.description", args:[result.daysBack]) 48 else 49 result.message = getMessage(code:"inventoryItem.search.text.recently.used.none.found", args:[result.daysBack]) 39 50 break 40 51 default: … … 93 104 } // getInventoryBelowReorder 94 105 106 /** 107 * Get a list of recently used inventory items. 108 * @param params The request params. 109 * @param daysBack The number of days back to get results for. 110 */ 111 def getRecentlyUsed(params, daysBack) { 112 def paginateParams = [:] 113 paginateParams.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 114 paginateParams.offset = params?.offset?.toInteger() ?: 0 115 116 def sort = "inventoryItem." + (params?.sort ?: "name") 117 def order = params?.order == "desc" ? "desc" : "asc" 118 def orderBy = " order by " + sort + ' ' + order 119 120 def namedParams = [:] 121 namedParams.startOfDay = dateUtilService.today - daysBack 122 123 def baseQuery = "from InventoryItem as inventoryItem \ 124 left join inventoryItem.inventoryMovements as inventoryMovement \ 125 where (inventoryItem.isActive = true \ 126 and inventoryMovement.date > :startOfDay \ 127 and inventoryMovement.inventoryMovementType = 1 \ 128 )" 129 130 def searchQuery = "select distinct inventoryItem " + baseQuery + orderBy 131 def list = InventoryItem.executeQuery(searchQuery, namedParams, paginateParams) 132 133 def countQuery = "select count(distinct inventoryItem) as inventoryItemCount " + baseQuery 134 def totalCount = InventoryItem.executeQuery(countQuery, namedParams)[0].toInteger() 135 136 def inventoryItemInstanceList = new PagedResultList(list, totalCount) 137 return inventoryItemInstanceList 138 } // getRecentlyUsed 139 95 140 } // end class -
trunk/grails-app/views/inventoryItemDetailed/search.gsp
r485 r489 217 217 <g:message code="inventoryItem.search.text.below.reorder.all" /> 218 218 </g:link> - <g:message code="inventoryItem.search.text.below.reorder.all.description" /> 219 <br /> 220 <g:link controller="inventoryItemDetailed" 221 action="search" 222 params="[quickSearch: 'recentlyUsed', daysBack: '14']"> 223 <g:message code="inventoryItem.search.text.recently.used" /> 224 </g:link> - <g:message code="inventoryItem.search.text.recently.used.description" args="[14]"/> 225 <br /> 226 <g:link controller="inventoryItemDetailed" 227 action="search" 228 params="[quickSearch: 'recentlyUsed', daysBack: '30']"> 229 <g:message code="inventoryItem.search.text.recently.used" /> 230 </g:link> - <g:message code="inventoryItem.search.text.recently.used.description" args="[30]"/> 219 231 </td> 220 232 </tr>
Note: See TracChangeset
for help on using the changeset viewer.