From ce268ec1758c5b92afed00d4ed963a5f0df12da0 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 23 Jul 2024 16:38:13 +1000 Subject: [PATCH] Add systemOfMeasurement to VariantUnitManager --- .../js/services/variant_unit_manager.js | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/webpacker/js/services/variant_unit_manager.js b/app/webpacker/js/services/variant_unit_manager.js index 1711025fcd..f13af68264 100644 --- a/app/webpacker/js/services/variant_unit_manager.js +++ b/app/webpacker/js/services/variant_unit_manager.js @@ -7,33 +7,41 @@ export default class VariantUnitManager { getUnitName(scale, unitType) { if (this.units[unitType][scale]) { - return this.units[unitType][scale]['name']; + return this.units[unitType][scale]["name"]; } else { - return ''; + return ""; } - }; + } - // Filter by measurement system + // Filter by measurement system compatibleUnitScales(scale, unitType) { - const scaleSystem = this.units[unitType][scale]['system']; + const scaleSystem = this.units[unitType][scale]["system"]; return Object.entries(this.units[unitType]) .filter(([scale, scaleInfo]) => { - return scaleInfo['system'] == scaleSystem; + return scaleInfo["system"] == scaleSystem; }) .map(([scale, _]) => parseFloat(scale)) .sort(); } + systemOfMeasurement(scale, unitType) { + if (this.units[unitType][scale]) { + return this.units[unitType][scale]["system"]; + } else { + return "custom"; + } + } + // private #loadUnits(units) { // Transform unit scale to a JS Number for compatibility. This would be way simpler in Ruby or Coffeescript!! const unitsTransformed = Object.entries(units).map(([measurement, measurementInfo]) => { - const measurementInfoTransformed = Object.fromEntries(Object.entries(measurementInfo).map(([scale, unitInfo]) => - [ parseFloat(scale), unitInfo ] - )); - return [ measurement, measurementInfoTransformed ]; + const measurementInfoTransformed = Object.fromEntries( + Object.entries(measurementInfo).map(([scale, unitInfo]) => [parseFloat(scale), unitInfo]), + ); + return [measurement, measurementInfoTransformed]; }); return Object.fromEntries(unitsTransformed); }