From 53243a347f15f01181c0cfab5e034f9e2695831c Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 9 Mar 2025 17:12:48 +0300 Subject: [PATCH 1/6] Disable no-else-return eslint rule --- config/eslint.config.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/config/eslint.config.mjs b/config/eslint.config.mjs index a24dc08f5..6d695bbf6 100644 --- a/config/eslint.config.mjs +++ b/config/eslint.config.mjs @@ -102,7 +102,6 @@ export default [ "no-caller": "error", "no-console": "warn", "no-div-regex": "error", - "no-else-return": ["error", { allowElseIf: false }], "no-eq-null": "error", "no-eval": "error", "no-extend-native": "error", From 06ac13de3c9e024befc7964cd0aad3d3d2f7a608 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 9 Mar 2025 16:04:42 +0300 Subject: [PATCH 2/6] Remove unitTemplate from formatDistance Undoes part of a3c45f6ed66862ee394e2a207dedf400acef9b07 to make I18n string references searchable again. --- app/assets/javascripts/index/directions.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 2d948d4b2..a2b383ba0 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -71,10 +71,13 @@ OSM.Directions = function (map) { }); function formatDistance(m) { - const unitTemplate = "javascripts.directions.distance_"; - if (m < 1000) return I18n.t(unitTemplate + "m", { distance: Math.round(m) }); - if (m < 10000) return I18n.t(unitTemplate + "km", { distance: (m / 1000.0).toFixed(1) }); - return I18n.t(unitTemplate + "km", { distance: Math.round(m / 1000) }); + if (m < 1000) { + return I18n.t("javascripts.directions.distance_m", { distance: Math.round(m) }); + } else if (m < 10000) { + return I18n.t("javascripts.directions.distance_km", { distance: (m / 1000.0).toFixed(1) }); + } else { + return I18n.t("javascripts.directions.distance_km", { distance: Math.round(m / 1000) }); + } } function formatHeight(m) { From 0925d30b5c1885ab2a00b2d0dde083bce57cf2c3 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 9 Mar 2025 16:13:51 +0300 Subject: [PATCH 3/6] Move getDistText next to other formatting functions --- app/assets/javascripts/index/directions.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index a2b383ba0..044d73baa 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -80,6 +80,14 @@ OSM.Directions = function (map) { } } + function getDistText(dist) { + if (dist < 5) return ""; + if (dist < 200) return String(Math.round(dist / 10) * 10) + "m"; + if (dist < 1500) return String(Math.round(dist / 100) * 100) + "m"; + if (dist < 5000) return String(Math.round(dist / 100) / 10) + "km"; + return String(Math.round(dist / 1000)) + "km"; + } + function formatHeight(m) { return I18n.t("javascripts.directions.distance_m", { distance: Math.round(m) }); } @@ -221,14 +229,6 @@ OSM.Directions = function (map) { }).finally(function () { controller = null; }); - - function getDistText(dist) { - if (dist < 5) return ""; - if (dist < 200) return String(Math.round(dist / 10) * 10) + "m"; - if (dist < 1500) return String(Math.round(dist / 100) * 100) + "m"; - if (dist < 5000) return String(Math.round(dist / 100) / 10) + "km"; - return String(Math.round(dist / 1000)) + "km"; - } } function hideRoute(e) { From 35581deab486dc908590f46a09dc0aeec46d0081 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 9 Mar 2025 16:29:22 +0300 Subject: [PATCH 4/6] Return to a previous structure of getDistText Undoes part of a3c45f6ed66862ee394e2a207dedf400acef9b07 to make getDistText similar to formatDistance. --- app/assets/javascripts/index/directions.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 044d73baa..a679d945f 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -81,11 +81,17 @@ OSM.Directions = function (map) { } function getDistText(dist) { - if (dist < 5) return ""; - if (dist < 200) return String(Math.round(dist / 10) * 10) + "m"; - if (dist < 1500) return String(Math.round(dist / 100) * 100) + "m"; - if (dist < 5000) return String(Math.round(dist / 100) / 10) + "km"; - return String(Math.round(dist / 1000)) + "km"; + if (dist < 5) { + return ""; + } else if (dist < 200) { + return String(Math.round(dist / 10) * 10) + "m"; + } else if (dist < 1500) { + return String(Math.round(dist / 100) * 100) + "m"; + } else if (dist < 5000) { + return String(Math.round(dist / 100) / 10) + "km"; + } else { + return String(Math.round(dist / 1000)) + "km"; + } } function formatHeight(m) { From a62cf867cf9b39d1ef73939496748984b8fe66c0 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 9 Mar 2025 16:30:49 +0300 Subject: [PATCH 5/6] Rename distance formatting functions --- app/assets/javascripts/index/directions.js | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index a679d945f..eb1b9d0df 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -70,7 +70,7 @@ OSM.Directions = function (map) { OSM.router.route("/" + OSM.formatHash(map)); }); - function formatDistance(m) { + function formatTotalDistance(m) { if (m < 1000) { return I18n.t("javascripts.directions.distance_m", { distance: Math.round(m) }); } else if (m < 10000) { @@ -80,17 +80,17 @@ OSM.Directions = function (map) { } } - function getDistText(dist) { - if (dist < 5) { + function formatStepDistance(m) { + if (m < 5) { return ""; - } else if (dist < 200) { - return String(Math.round(dist / 10) * 10) + "m"; - } else if (dist < 1500) { - return String(Math.round(dist / 100) * 100) + "m"; - } else if (dist < 5000) { - return String(Math.round(dist / 100) / 10) + "km"; + } else if (m < 200) { + return String(Math.round(m / 10) * 10) + "m"; + } else if (m < 1500) { + return String(Math.round(m / 100) * 100) + "m"; + } else if (m < 5000) { + return String(Math.round(m / 100) / 10) + "km"; } else { - return String(Math.round(dist / 1000)) + "km"; + return String(Math.round(m / 1000)) + "km"; } } @@ -164,7 +164,7 @@ OSM.Directions = function (map) { } const distanceText = $("

").append( - I18n.t("javascripts.directions.distance") + ": " + formatDistance(route.distance) + ". " + + I18n.t("javascripts.directions.distance") + ": " + formatTotalDistance(route.distance) + ". " + I18n.t("javascripts.directions.time") + ": " + formatTime(route.time) + "."); if (typeof route.ascend !== "undefined" && typeof route.descend !== "undefined") { distanceText.append( @@ -194,7 +194,7 @@ OSM.Directions = function (map) { row.append(""); } row.append("" + instruction); - row.append("" + getDistText(dist)); + row.append("" + formatStepDistance(dist)); row.on("click", function () { popup From b264e380c283709658fea48d60718ded8f9c4785 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 9 Mar 2025 16:39:01 +0300 Subject: [PATCH 6/6] Translate step distance units --- app/assets/javascripts/index/directions.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index eb1b9d0df..aee262e02 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -84,13 +84,13 @@ OSM.Directions = function (map) { if (m < 5) { return ""; } else if (m < 200) { - return String(Math.round(m / 10) * 10) + "m"; + return I18n.t("javascripts.directions.distance_m", { distance: String(Math.round(m / 10) * 10) }); } else if (m < 1500) { - return String(Math.round(m / 100) * 100) + "m"; + return I18n.t("javascripts.directions.distance_m", { distance: String(Math.round(m / 100) * 100) }); } else if (m < 5000) { - return String(Math.round(m / 100) / 10) + "km"; + return I18n.t("javascripts.directions.distance_km", { distance: String(Math.round(m / 100) / 10) }); } else { - return String(Math.round(m / 1000)) + "km"; + return I18n.t("javascripts.directions.distance_km", { distance: String(Math.round(m / 1000)) }); } }