From 0018ef6eb4e678b5e287fea2a8e5c1535120d9ec Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Fri, 7 Aug 2020 20:54:25 -0700 Subject: [PATCH] refactor variant_unit_manager.coffee and add systems to scales --- .../services/variant_unit_manager.js.coffee | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/admin/products/services/variant_unit_manager.js.coffee b/app/assets/javascripts/admin/products/services/variant_unit_manager.js.coffee index fc24c07f56..2d2922924c 100644 --- a/app/assets/javascripts/admin/products/services/variant_unit_manager.js.coffee +++ b/app/assets/javascripts/admin/products/services/variant_unit_manager.js.coffee @@ -1,19 +1,35 @@ angular.module("admin.products").factory "VariantUnitManager", -> class VariantUnitManager - @unitNames: + @units: 'weight': - 1.0: 'g' - 1000.0: 'kg' - 1000000.0: 'T' - 453.6: 'lb' - 28.34952: 'oz' + 1.0: + name: 'g' + system: 'metric' + 1000.0: + name: 'kg' + system: 'metric' + 1000000.0: + name: 'T' + system: 'metric' + 453.6: + name: 'lb' + system: 'imperial' + 28.34952: + name: 'oz' + system: 'imperial' 'volume': - 0.001: 'mL' - 1.0: 'L' - 1000.0: 'kL' + 0.001: + name: 'mL' + system: 'metric' + 1.0: + name: 'L' + system: 'metric' + 1000.0: + name: 'kL' + system: 'metric' @variantUnitOptions: -> - options = for unit_type, scale_with_name of @unitNames + options = for unit_type, _ of @units for scale in @unitScales(unit_type) name = @getUnitName(scale, unit_type) ["#{I18n.t(unit_type)} (#{name})", "#{unit_type}_#{scale}"] @@ -32,8 +48,10 @@ angular.module("admin.products").factory "VariantUnitManager", -> unitScales[0] @getUnitName: (scale, unitType) -> - @unitNames[unitType][scale] + @units[unitType][scale]['name'] @unitScales: (unitType) -> - (parseFloat(scale) for scale in Object.keys(@unitNames[unitType])).sort (a, b) -> + (parseFloat(scale) for scale in Object.keys(@units[unitType])).sort (a, b) -> a - b + + @compatibleUnitScales