mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-21 00:47:26 +00:00
Extract getScale from BOM controller to VariantUnitManager, extract specs as well
This commit is contained in:
@@ -135,15 +135,7 @@ angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [
|
||||
true
|
||||
|
||||
$scope.getScale = (value, unitType) ->
|
||||
scaledValue = null
|
||||
validScales = []
|
||||
unitScales = VariantUnitManager.unitScales(unitType)
|
||||
|
||||
validScales.unshift scale for scale in unitScales when value/scale >= 1
|
||||
if validScales.length > 0
|
||||
validScales[0]
|
||||
else
|
||||
unitScales[0]
|
||||
VariantUnitManager.getScale(value, unitType)
|
||||
|
||||
$scope.getUnitName = (scale, unitType) ->
|
||||
VariantUnitManager.getUnitName(scale, unitType)
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
angular.module("admin.products").factory "VariantUnitManager", ->
|
||||
class VariantUnitManager
|
||||
@getScale = (value, unitType) ->
|
||||
scaledValue = null
|
||||
validScales = []
|
||||
unitScales = VariantUnitManager.unitScales(unitType)
|
||||
|
||||
validScales.unshift scale for scale in unitScales when value/scale >= 1
|
||||
if validScales.length > 0
|
||||
validScales[0]
|
||||
else
|
||||
unitScales[0]
|
||||
|
||||
@getUnitName: (scale, unitType) ->
|
||||
unitNames =
|
||||
'weight': {1.0: 'g', 1000.0: 'kg', 1000000.0: 'T'}
|
||||
|
||||
Reference in New Issue
Block a user