Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit01c79b4

Browse files
authored
OBPIH-6993 fix. Wrap text within select2 options and fix product avai… (#5565)
1 parent0f2ec1b commit01c79b4

File tree

4 files changed

+118
-30
lines changed

4 files changed

+118
-30
lines changed

‎grails-app/services/org/pih/warehouse/inventory/ProductAvailabilityService.groovy‎

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.pih.warehouse.api.AvailableItem
3030
importorg.pih.warehouse.core.ApplicationExceptionEvent
3131
importorg.pih.warehouse.core.Constants
3232
importorg.pih.warehouse.core.Location
33+
importorg.pih.warehouse.core.db.GormUtil
3334
importorg.pih.warehouse.inventory.product.availability.AvailableItemMap
3435
importorg.pih.warehouse.jobs.RefreshProductAvailabilityJob
3536
importorg.pih.warehouse.order.OrderStatus
@@ -715,38 +716,46 @@ class ProductAvailabilityService {
715716

716717
ListgetAvailableItems(Locationlocation,List<String>productsIds,booleanexcludeNegativeQuantity=false,booleanexcludeZeroQuantity=false) {
717718
log.info("getQuantityOnHandByBinLocation: location=${location} product=${productsIds}")
719+
720+
if (!location) {
721+
return []
722+
}
723+
718724
String quantityCondition= ((excludeNegativeQuantity&& excludeZeroQuantity)|| excludeZeroQuantity)?"and pa.quantityOnHand <> 0"
719725
: (excludeNegativeQuantity)?"and pa.quantityOnHand > 0":""
720726

721-
List<AvailableItem> data= []
722-
if (location) {
723-
def results=ProductAvailability.executeQuery("""
724-
select
725-
ii,
726-
pa.binLocation,
727-
pa.quantityOnHand,
728-
pa.quantityAvailableToPromise
729-
from ProductAvailability pa
730-
left outer join pa.inventoryItem ii
731-
left outer join pa.binLocation bl
732-
where pa.location = :location
733-
"""+
734-
"${quantityCondition}"+
735-
"and pa.product.id in (:products)", [location: location,products: productsIds])
736-
737-
data= results.collect {
738-
InventoryItem inventoryItem= it[0]
739-
Location binLocation= it[1]
740-
Integer quantityOnHand= it[2]
741-
Integer quantityAvailableToPromise= it[3]
742-
743-
returnnewAvailableItem(
744-
inventoryItem : inventoryItem,
745-
binLocation : binLocation,
746-
quantityOnHand : quantityOnHand,
747-
quantityAvailable : quantityAvailableToPromise
748-
)
749-
}
727+
String sql="""
728+
SELECT
729+
ii,
730+
pa.binLocation,
731+
pa.quantityOnHand,
732+
pa.quantityAvailableToPromise
733+
FROM
734+
ProductAvailability pa
735+
LEFT OUTER JOIN pa.inventoryItem ii
736+
LEFT OUTER JOIN pa.binLocation bl
737+
WHERE
738+
pa.location = :location
739+
${quantityCondition}
740+
${productsIds ? "AND pa.product.id IN (:products)" : ""}
741+
"""
742+
def results=ProductAvailability.executeQuery(sql,GormUtil.sanitizeExecuteQueryArgs(sql, [
743+
location: location,
744+
products: productsIds,
745+
]))
746+
747+
List<AvailableItem> data= results.collect {
748+
InventoryItem inventoryItem= it[0]
749+
Location binLocation= it[1]
750+
Integer quantityOnHand= it[2]
751+
Integer quantityAvailableToPromise= it[3]
752+
753+
returnnewAvailableItem(
754+
inventoryItem : inventoryItem,
755+
binLocation : binLocation,
756+
quantityOnHand : quantityOnHand,
757+
quantityAvailable : quantityAvailableToPromise
758+
)
750759
}
751760
return data
752761
}

‎grails-app/taglib/org/pih/warehouse/SelectTagLib.groovy‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,32 @@ class SelectTagLib {
122122
123123
jQuery(document).ready(function() {
124124
125+
// If we upgrade to select2 4.1 we can replace this with a "selectionCssClass: "some-class"
126+
// config option below and then style .some-class with {"white-space": normal}.
127+
function formatSelectedOptions (state) {
128+
if (!state.id) {
129+
return state.text;
130+
}
131+
132+
var\$state =\$(
133+
"<span><span></span></span>"
134+
);
135+
136+
\$state.find("span").text(state.text);
137+
\$state.find("span").css("white-space", "normal");
138+
139+
return\$state;
140+
};
141+
142+
// https://select2.org/configuration/options-api
125143
jQuery('#${id}').select2({
126144
127145
placeholder: "${placeholder}",
128146
minimumInputLength: "${minSearchValueLength ?: "3"}",
129147
width: "100%",
130-
allowClear:true,
148+
allowClear:false,
131149
cache: true,
150+
templateSelection: formatSelectedOptions,
132151
133152
ajax: {
134153
url: "${request.contextPath}${url}",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
packageorg.pih.warehouse.core.db
2+
3+
/**
4+
* Utility methods assisting with using GORM (Grails Object Relational Mapping) methods.
5+
*/
6+
classGormUtil {
7+
8+
privatestaticfinalStringPARAM_IDENTIFIER=":"
9+
10+
/**
11+
* Given a SQL query and a map of values to use for the params/variables in the query (identified
12+
* by ":<param>"), filters the given params down to only those that actually exist in the query.
13+
* Helps to ensure we have valid SQL in our queries.
14+
*
15+
* For example:
16+
* If given a query: "SELECT id FROM Table t WHERE t.product_id IN (:products)"
17+
* And params: [products: "a,b,c", somethingElse: "1"]
18+
* Returns: [products: "a,b,c"] (because the "somethingElse" param doesn't exist in the query).
19+
*
20+
* Note that s long as we pass user input variables as args to execute query (and not by directly
21+
* adding them to the SQL string) we don't need to worry about handling any SQL injection attacks.
22+
* Hibernate and GORM will handle that for us.
23+
*/
24+
staticMapsanitizeExecuteQueryArgs(Stringsql,Mapargs) {
25+
if (!args) {
26+
return [:]
27+
}
28+
return args.findAll {paramName,paramValue->
29+
sql.contains("${PARAM_IDENTIFIER}${paramName}")
30+
}
31+
}
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
packageunit.org.pih.warehouse.core.db
2+
3+
importgrails.testing.gorm.DomainUnitTest
4+
importspock.lang.Specification
5+
importspock.lang.Unroll
6+
7+
importorg.pih.warehouse.core.Person
8+
importorg.pih.warehouse.core.db.GormUtil
9+
10+
@Unroll
11+
classGormUtilSpecextendsSpecificationimplementsDomainUnitTest<Person> {
12+
13+
void'GormUtil.sanitizeExecuteQueryArgs should return #expectedSqlArgs when given #givenSqlArgs'() {
14+
given:"a SQL query containing a single parameter 'x'"
15+
String sql="SELECT z FROM Table t WHERE t.x = :x"
16+
17+
expect:
18+
GormUtil.sanitizeExecuteQueryArgs(sql, givenSqlArgs)== expectedSqlArgs
19+
20+
where:
21+
givenSqlArgs|| expectedSqlArgs
22+
null|| [:]
23+
[:]|| [:]
24+
[x:"x"]|| [x:"x"]
25+
[y:"y"]|| [:]
26+
[x:"x",y:"y"]|| [x:"x"]
27+
}
28+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp