From 783311f123f8f6b0823395dda9aa5e3297a532f8 Mon Sep 17 00:00:00 2001 From: artem-dudarev Date: Tue, 3 Oct 2023 22:40:45 +0200 Subject: [PATCH] Fix code smells --- .../blades/localizable-setting-value-details.js | 16 +++++++++------- .../blades/localizable-setting-value-list.js | 15 +++++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/VirtoCommerce.CoreModule.Web/Scripts/common/blades/localizable-setting-value-details.js b/src/VirtoCommerce.CoreModule.Web/Scripts/common/blades/localizable-setting-value-details.js index 6e8be263..bf34f8f3 100644 --- a/src/VirtoCommerce.CoreModule.Web/Scripts/common/blades/localizable-setting-value-details.js +++ b/src/VirtoCommerce.CoreModule.Web/Scripts/common/blades/localizable-setting-value-details.js @@ -22,11 +22,12 @@ angular.module('virtoCommerce.coreModule.common') canExecuteMethod: canSave } ]; + function initializeBlade() { blade.currentEntity = angular.copy(blade.dictionaryItem); blade.originalEntity = blade.dictionaryItem; blade.isLoading = false; - }; + } function isDirty() { return !angular.equals(blade.currentEntity, blade.originalEntity) && blade.hasUpdatePermission(); @@ -43,7 +44,7 @@ angular.module('virtoCommerce.coreModule.common') }; function saveChanges() { - let items = [convertItem(blade.currentEntity)]; + const items = [convertItem(blade.currentEntity)]; blade.allItems.forEach(function (item) { if (item.id !== blade.currentEntity.id) { @@ -59,19 +60,20 @@ angular.module('virtoCommerce.coreModule.common') blade.onSaveChanges(); } }); - }; + } function convertItem(item) { - let result = { + const result = { alias: item.alias, localizedValues: [] }; blade.languages.forEach(function (language) { if (item[language]) { - let localizedValue = {}; - localizedValue.languageCode = language; - localizedValue.value = item[language]; + const localizedValue = { + languageCode: language, + value: item[language] + }; result.localizedValues.push(localizedValue); } }); diff --git a/src/VirtoCommerce.CoreModule.Web/Scripts/common/blades/localizable-setting-value-list.js b/src/VirtoCommerce.CoreModule.Web/Scripts/common/blades/localizable-setting-value-list.js index 93b863d9..88dbbed6 100644 --- a/src/VirtoCommerce.CoreModule.Web/Scripts/common/blades/localizable-setting-value-list.js +++ b/src/VirtoCommerce.CoreModule.Web/Scripts/common/blades/localizable-setting-value-list.js @@ -22,7 +22,8 @@ angular.module('virtoCommerce.coreModule.common') let id = 1; response.items.forEach(function (item) { - item.id = id++; + item.id = id; + id++; }); var originalEntities = response.items; var currentEntities = angular.copy(originalEntities); @@ -39,7 +40,9 @@ angular.module('virtoCommerce.coreModule.common') $scope.currentEntities.forEach(function (item) { $scope.languages.forEach(function (language) { - var localizedValue = _.find(item.localizedValues, function (x) { return x.languageCode === language || (!x.languageCode && language === blade.defaultLanguage) }); + var localizedValue = _.find(item.localizedValues, function (x) { + return x.languageCode === language || (!x.languageCode && language === blade.defaultLanguage) + }); item[language] = localizedValue ? localizedValue.value : ''; }); }); @@ -54,7 +57,9 @@ angular.module('virtoCommerce.coreModule.common') }; function sort(entities) { - entities.sort(function (a, b) { return a.alias.localeCompare(b.alias); }) + entities.sort(function (a, b) { + return a.alias.localeCompare(b.alias); + }) if (blade.orderDesc) { entities.reverse(); @@ -63,7 +68,9 @@ angular.module('virtoCommerce.coreModule.common') $scope.filteredEntities = function () { var lowerCasedSearchText = blade.searchText.toLowerCase(); - return $scope.currentEntities ? _.filter($scope.currentEntities, function (x) { return !x.alias || x.alias.toLowerCase().includes(lowerCasedSearchText); }) : []; + return $scope.currentEntities ? _.filter($scope.currentEntities, function (x) { + return !x.alias || x.alias.toLowerCase().includes(lowerCasedSearchText); + }) : []; }; $scope.setGridOptions = function (gridOptions) {