mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-05 02:41:33 +00:00
Extract JS unit options into option value namer
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [
|
||||
"$scope", "$http", "dataFetcher", "blankOption", "pendingChanges"
|
||||
($scope, $http, dataFetcher, blankOption, pendingChanges) ->
|
||||
"$scope", "$http", "dataFetcher", "blankOption", "pendingChanges", "optionValueNamer",
|
||||
($scope, $http, dataFetcher, blankOption, pendingChanges, optionValueNamer) ->
|
||||
|
||||
$scope.initialiseVariables = ->
|
||||
start = daysFromToday -7
|
||||
@@ -137,21 +137,16 @@ angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [
|
||||
$scope.getScale = (value, unitType) ->
|
||||
scaledValue = null
|
||||
validScales = []
|
||||
unitScales =
|
||||
'weight': [1.0, 1000.0, 1000000.0]
|
||||
'volume': [0.001, 1.0, 1000.0]
|
||||
unitScales = optionValueNamer.unitScales(unitType)
|
||||
|
||||
validScales.unshift scale for scale in unitScales[unitType] when value/scale >= 1
|
||||
validScales.unshift scale for scale in unitScales when value/scale >= 1
|
||||
if validScales.length > 0
|
||||
validScales[0]
|
||||
else
|
||||
unitScales[unitType][0]
|
||||
unitScales[0]
|
||||
|
||||
$scope.getUnitName = (scale, unitType) ->
|
||||
unitNames =
|
||||
'weight': {1.0: 'g', 1000.0: 'kg', 1000000.0: 'T'}
|
||||
'volume': {0.001: 'mL', 1.0: 'L', 1000.0: 'kL'}
|
||||
unitNames[unitType][scale]
|
||||
optionValueNamer.getUnitName(scale, unitType)
|
||||
|
||||
$scope.formattedValueWithUnitName = (value, unitsProduct, unitsVariant) ->
|
||||
# A Units Variant is an API object which holds unit properies of a variant
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
angular.module("ofn.admin").controller "AdminProductEditCtrl", [
|
||||
"$scope", "$timeout", "$http", "dataFetcher", "DirtyProducts"
|
||||
($scope, $timeout, $http, dataFetcher, DirtyProducts) ->
|
||||
"$scope", "$timeout", "$http", "dataFetcher", "DirtyProducts", "optionValueNamer",
|
||||
($scope, $timeout, $http, dataFetcher, DirtyProducts, optionValueNamer) ->
|
||||
$scope.updateStatusMessage =
|
||||
text: ""
|
||||
style: {}
|
||||
@@ -14,15 +14,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [
|
||||
taxons: {name: "Taxons", visible: false}
|
||||
available_on: {name: "Available On", visible: false}
|
||||
|
||||
$scope.variant_unit_options = [
|
||||
["Weight (g)", "weight_1"],
|
||||
["Weight (kg)", "weight_1000"],
|
||||
["Weight (T)", "weight_1000000"],
|
||||
["Volume (mL)", "volume_0.001"],
|
||||
["Volume (L)", "volume_1"],
|
||||
["Volume (kL)", "volume_1000"],
|
||||
["Items", "items"]
|
||||
]
|
||||
$scope.variant_unit_options = optionValueNamer.variant_unit_options
|
||||
|
||||
$scope.filterableColumns = [
|
||||
{ name: "Supplier", db_column: "supplier_name" },
|
||||
|
||||
@@ -26,15 +26,7 @@ angular.module("admin.products")
|
||||
|
||||
$scope.placeholder_text = new optionValueNamer($scope.product.master).name()
|
||||
|
||||
$scope.variant_unit_options = [
|
||||
["Weight (g)", "weight_1"],
|
||||
["Weight (kg)", "weight_1000"],
|
||||
["Weight (T)", "weight_1000000"],
|
||||
["Volume (mL)", "volume_0.001"],
|
||||
["Volume (L)", "volume_1"],
|
||||
["Volume (kL)", "volume_1000"],
|
||||
["Items", "items"]
|
||||
]
|
||||
$scope.variant_unit_options = optionValueNamer.variant_unit_options
|
||||
|
||||
$scope.hasVariants = (product) ->
|
||||
Object.keys(product.variants).length > 0
|
||||
|
||||
@@ -1,5 +1,28 @@
|
||||
angular.module("admin.products").factory "optionValueNamer", ->
|
||||
class OptionValueNamer
|
||||
@getUnitName: (scale, unitType) ->
|
||||
unitNames =
|
||||
'weight': {1.0: 'g', 1000.0: 'kg', 1000000.0: 'T'}
|
||||
'volume': {0.001: 'mL', 1.0: 'L', 1000.0: 'kL'}
|
||||
unitNames[unitType][scale]
|
||||
|
||||
@unitScales: (unitType) ->
|
||||
unitScales =
|
||||
'weight': [1.0, 1000.0, 1000000.0]
|
||||
'volume': [0.001, 1.0, 1000.0]
|
||||
unitScales[unitType]
|
||||
|
||||
@variant_unit_options: [
|
||||
["Weight (g)", "weight_1"],
|
||||
["Weight (kg)", "weight_1000"],
|
||||
["Weight (T)", "weight_1000000"],
|
||||
["Volume (mL)", "volume_0.001"],
|
||||
["Volume (L)", "volume_1"],
|
||||
["Volume (kL)", "volume_1000"],
|
||||
["Items", "items"]
|
||||
]
|
||||
|
||||
|
||||
constructor: (@variant) ->
|
||||
|
||||
name: ->
|
||||
|
||||
Reference in New Issue
Block a user