mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
ofnTrackProduct and ofnTrackVariant accept nested properties as arguments
This commit is contained in:
@@ -20,30 +20,31 @@ productEditModule.directive "ofnDecimal", ->
|
||||
viewValue
|
||||
|
||||
|
||||
productEditModule.directive "ofnTrackProduct", ->
|
||||
productEditModule.directive "ofnTrackProduct", ['$parse', ($parse) ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
property_name = attrs.ofnTrackProduct
|
||||
ngModel.$parsers.push (viewValue) ->
|
||||
if ngModel.$dirty
|
||||
addDirtyProperty scope.dirtyProducts, scope.product.id, property_name, viewValue
|
||||
parsedPropertyName = $parse(attrs.ofnTrackProduct)
|
||||
addDirtyProperty scope.dirtyProducts, scope.product.id, parsedPropertyName, viewValue
|
||||
scope.displayDirtyProducts()
|
||||
viewValue
|
||||
]
|
||||
|
||||
|
||||
productEditModule.directive "ofnTrackVariant", ->
|
||||
productEditModule.directive "ofnTrackVariant", ['$parse', ($parse) ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
property_name = attrs.ofnTrackVariant
|
||||
ngModel.$parsers.push (viewValue) ->
|
||||
dirtyVariants = {}
|
||||
dirtyVariants = scope.dirtyProducts[scope.product.id].variants if scope.dirtyProducts.hasOwnProperty(scope.product.id) and scope.dirtyProducts[scope.product.id].hasOwnProperty("variants")
|
||||
if ngModel.$dirty
|
||||
addDirtyProperty dirtyVariants, scope.variant.id, property_name, viewValue
|
||||
addDirtyProperty scope.dirtyProducts, scope.product.id, "variants", dirtyVariants
|
||||
parsedPropertyName = $parse(attrs.ofnTrackVariant)
|
||||
addDirtyProperty dirtyVariants, scope.variant.id, parsedPropertyName, viewValue
|
||||
addDirtyProperty scope.dirtyProducts, scope.product.id, $parse("variants"), dirtyVariants
|
||||
scope.displayDirtyProducts()
|
||||
viewValue
|
||||
|
||||
]
|
||||
|
||||
productEditModule.directive "ofnToggleVariants", ->
|
||||
link: (scope, element, attrs) ->
|
||||
@@ -515,13 +516,11 @@ filterSubmitProducts = (productsToFilter) ->
|
||||
filteredProducts
|
||||
|
||||
|
||||
addDirtyProperty = (dirtyObjects, objectID, propertyName, propertyValue) ->
|
||||
if dirtyObjects.hasOwnProperty(objectID)
|
||||
dirtyObjects[objectID][propertyName] = propertyValue
|
||||
else
|
||||
addDirtyProperty = (dirtyObjects, objectID, parsedPropertyName, propertyValue) ->
|
||||
if !dirtyObjects.hasOwnProperty(objectID)
|
||||
dirtyObjects[objectID] = {}
|
||||
dirtyObjects[objectID]["id"] = objectID
|
||||
dirtyObjects[objectID][propertyName] = propertyValue
|
||||
parsedPropertyName.assign(dirtyObjects[objectID], propertyValue)
|
||||
|
||||
|
||||
removeCleanProperty = (dirtyObjects, objectID, propertyName) ->
|
||||
|
||||
@@ -202,10 +202,17 @@ describe "filtering products for submission to database", ->
|
||||
|
||||
|
||||
describe "Maintaining a live record of dirty products and properties", ->
|
||||
parse = null
|
||||
beforeEach ->
|
||||
module "ofn.bulk_product_edit"
|
||||
beforeEach inject(($parse) ->
|
||||
parse = $parse
|
||||
)
|
||||
|
||||
describe "adding product properties to the dirtyProducts object", -> # Applies to both products and variants
|
||||
it "adds the product and the property to the list if property is dirty", ->
|
||||
dirtyProducts = {}
|
||||
addDirtyProperty dirtyProducts, 1, "name", "Product 1"
|
||||
addDirtyProperty dirtyProducts, 1, parse("name"), "Product 1"
|
||||
expect(dirtyProducts).toEqual 1:
|
||||
id: 1
|
||||
name: "Product 1"
|
||||
@@ -216,7 +223,7 @@ describe "Maintaining a live record of dirty products and properties", ->
|
||||
id: 1
|
||||
notaname: "something"
|
||||
|
||||
addDirtyProperty dirtyProducts, 1, "name", "Product 3"
|
||||
addDirtyProperty dirtyProducts, 1, parse("name"), "Product 3"
|
||||
expect(dirtyProducts).toEqual 1:
|
||||
id: 1
|
||||
notaname: "something"
|
||||
@@ -228,7 +235,7 @@ describe "Maintaining a live record of dirty products and properties", ->
|
||||
id: 1
|
||||
name: "Product 1"
|
||||
|
||||
addDirtyProperty dirtyProducts, 1, "name", "Product 2"
|
||||
addDirtyProperty dirtyProducts, 1, parse("name"), "Product 2"
|
||||
expect(dirtyProducts).toEqual 1:
|
||||
id: 1
|
||||
name: "Product 2"
|
||||
|
||||
Reference in New Issue
Block a user