Skip to content

Commit

Permalink
Fix code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev committed Oct 3, 2023
1 parent 35cfdf0 commit 783311f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 : '';
});
});
Expand All @@ -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();
Expand All @@ -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) {
Expand Down

0 comments on commit 783311f

Please sign in to comment.