From 1086e13b2e904f7821c7b8efad7c42333f67e77d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 12:20:15 +0100 Subject: [PATCH] 2187 - Sort by translated module name --- front/core/services/modules.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/front/core/services/modules.js b/front/core/services/modules.js index 1021bc4fa..6b4e9dfe1 100644 --- a/front/core/services/modules.js +++ b/front/core/services/modules.js @@ -2,10 +2,11 @@ import ngModule from '../module'; import getMainRoute from '../lib/get-main-route'; export default class Modules { - constructor(aclService, $window) { + constructor(aclService, $window, $translate) { Object.assign(this, { aclService, - $window + $window, + $translate }); } @@ -17,7 +18,7 @@ export default class Modules { if (this.modules) return this.modules; - this.modules = []; + const modules = []; for (let mod of this.$window.routes) { if (!mod || !mod.routes) continue; @@ -31,7 +32,7 @@ export default class Modules { if (res) keyBind = res.key.toUpperCase(); } - this.modules.push({ + modules.push({ name: mod.name || mod.module, icon: mod.icon || null, route, @@ -39,9 +40,15 @@ export default class Modules { }); } - return this.modules; + const sortedModules = modules.sort((a, b) => { + const translatedNameA = this.$translate.instant(a.name); + const translatedNameB = this.$translate.instant(b.name); + return translatedNameA.localeCompare(translatedNameB); + }); + + return sortedModules; } } -Modules.$inject = ['aclService', '$window']; +Modules.$inject = ['aclService', '$window', '$translate']; ngModule.service('vnModules', Modules);