Skip to content

Commit

Permalink
Replace angular.forEach with Utilities.forEach (#10759)
Browse files Browse the repository at this point in the history
* Replace angular.forEach with Utilities.forEach

* Use localizeMany to localize translations in a single request

* Replace angular.forEach

* Replace angular.forEach in mocks
  • Loading branch information
bjarnef authored Aug 1, 2021
1 parent 168abbf commit 56790f7
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,24 @@ Use this directive to render an umbraco button. The directive can be used to gen
if (vm.buttonStyle) {

// make it possible to pass in multiple styles
if(vm.buttonStyle.startsWith("[") && vm.buttonStyle.endsWith("]")) {
if (vm.buttonStyle.startsWith("[") && vm.buttonStyle.endsWith("]")) {

// when using an attr it will always be a string so we need to remove square brackets
// and turn it into and array
var withoutBrackets = vm.buttonStyle.replace(/[\[\]']+/g,'');
// split array by , + make sure to catch whitespaces
var array = withoutBrackets.split(/\s?,\s?/g);

angular.forEach(array, function(item){
Utilities.forEach(array, item => {
vm.style = vm.style + " " + "btn-" + item;
if(item === "block") {
if (item === "block") {
vm.blockElement = true;
}
});

} else {
vm.style = "btn-" + vm.buttonStyle;
if(vm.buttonStyle === "block") {
if (vm.buttonStyle === "block") {
vm.blockElement = true;
}
}
Expand All @@ -167,7 +167,7 @@ Use this directive to render an umbraco button. The directive can be used to gen

// watch for state changes
if (changes.state) {
if(changes.state.currentValue) {
if (changes.state.currentValue) {
vm.innerState = changes.state.currentValue;
}
if (changes.state.currentValue === 'success' || changes.state.currentValue === 'error') {
Expand All @@ -179,25 +179,25 @@ Use this directive to render an umbraco button. The directive can be used to gen
}

// watch for disabled changes
if(changes.disabled) {
if(changes.disabled.currentValue) {
if (changes.disabled) {
if (changes.disabled.currentValue) {
vm.disabled = changes.disabled.currentValue;
}
}

// watch for label changes
if(changes.label && changes.label.currentValue) {
if (changes.label && changes.label.currentValue) {
vm.buttonLabel = changes.label.currentValue;
setButtonLabel();
}

// watch for label key changes
if(changes.labelKey && changes.labelKey.currentValue) {
if (changes.labelKey && changes.labelKey.currentValue) {
setButtonLabel();
}

// watch for type changes
if(changes.type) {
if (changes.type) {
if (!vm.type) {
vm.type = "button";// set the default
}
Expand All @@ -206,23 +206,23 @@ Use this directive to render an umbraco button. The directive can be used to gen
}

function clickButton(event) {
if(vm.action) {
if (vm.action) {
vm.action({$event: event});
}
}

function setButtonLabel() {
// if the button opens a dialog add "..." to the label
if(vm.addEllipsis === "true") {
if (vm.addEllipsis === "true") {
vm.buttonLabel = vm.buttonLabel + "...";
}

// look up localization key
if(vm.labelKey) {
localizationService.localize(vm.labelKey).then(function(value){
if (vm.labelKey) {
localizationService.localize(vm.labelKey).then(value => {
vm.buttonLabel = value;
// if the button opens a dialog add "..." to the label
if(vm.addEllipsis === "true") {
if (vm.addEllipsis === "true") {
vm.buttonLabel = vm.buttonLabel + "...";
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@
scope.loadingAuditTrail = true;

logResource.getPagedEntityLog(scope.auditTrailOptions)
.then(function (data) {
.then(data => {

// get current backoffice user and format dates
userService.getCurrentUser().then(function (currentUser) {
angular.forEach(data.items, function (item) {
userService.getCurrentUser().then(currentUser => {
Utilities.forEach(data.items, item => {
item.timestampFormatted = dateHelper.getLocalDate(item.timestamp, currentUser.locale, 'LLL');
});
});
Expand All @@ -232,12 +232,12 @@
function loadRedirectUrls() {
scope.loadingRedirectUrls = true;
//check if Redirect URL Management is enabled
redirectUrlsResource.getEnableState().then(function (response) {
redirectUrlsResource.getEnableState().then(response => {
scope.urlTrackerDisabled = response.enabled !== true;
if (scope.urlTrackerDisabled === false) {

redirectUrlsResource.getRedirectsForContentItem(scope.node.udi)
.then(function (data) {
.then(data => {
scope.redirectUrls = data.searchResults;
scope.hasRedirects = (typeof data.searchResults !== 'undefined' && data.searchResults.length > 0);
scope.loadingRedirectUrls = false;
Expand All @@ -250,7 +250,7 @@
}

function setAuditTrailLogTypeColor(auditTrail) {
angular.forEach(auditTrail, function (item) {
Utilities.forEach(auditTrail, item => {

switch (item.logType) {
case "Save":
Expand Down Expand Up @@ -304,7 +304,7 @@

function formatDatesToLocal() {
// get current backoffice user and format dates
userService.getCurrentUser().then(function (currentUser) {
userService.getCurrentUser().then(currentUser => {
scope.currentVariant.createDateFormatted = dateHelper.getLocalDate(scope.currentVariant.createDate, currentUser.locale, 'LLL');
scope.currentVariant.releaseDateFormatted = dateHelper.getLocalDate(scope.currentVariant.releaseDate, currentUser.locale, 'LLL');
scope.currentVariant.expireDateFormatted = dateHelper.getLocalDate(scope.currentVariant.expireDate, currentUser.locale, 'LLL');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@
name: "More"
};

scope.openNavigationItem = function(item) {
scope.openNavigationItem = item => {

scope.showDropdown = false;
runItemAction(item);
setItemToActive(item);
if(scope.onSelect) {
if (scope.onSelect) {
scope.onSelect({"item": item});
}
eventsService.emit("app.tabChange", item);
};

scope.openAnchorItem = function(item, anchor) {
if(scope.onAnchorSelect) {
scope.openAnchorItem = (item, anchor) => {
if (scope.onAnchorSelect) {
scope.onAnchorSelect({"item": item, "anchor": anchor});
}
if (item.active !== true) {
scope.openNavigationItem(item);
}
};

scope.toggleDropdown = function () {
scope.toggleDropdown = () => {
scope.showDropdown = !scope.showDropdown;
};

scope.hideDropdown = function() {
scope.hideDropdown = () => {
scope.showDropdown = false;
};

Expand All @@ -60,7 +60,7 @@
function calculateVisibleItems(windowWidth) {

// if we don't get a windowWidth stick with the default item limit
if(!windowWidth) {
if (!windowWidth) {
return;
}

Expand Down Expand Up @@ -94,7 +94,7 @@
if (selectedItem.view) {

// deselect all items
angular.forEach(scope.navigation, function(item, index){
Utilities.forEach(scope.navigation, item => {
item.active = false;
});

Expand All @@ -112,8 +112,8 @@
}
}

var resizeCallback = function(size) {
if(size && size.width) {
var resizeCallback = size => {
if (size && size.width) {
calculateVisibleItems(size.width);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
scope.memberOptions.entityType = "MEMBER";
scope.hasMemberReferences = false;


function onInit() {

userService.getCurrentUser().then(function(user){
userService.getCurrentUser().then(user => {
// only allow change of media type if user has access to the settings sections
angular.forEach(user.sections, function(section){
if(section.alias === "settings") {
Utilities.forEach(user.sections, section => {
if (section.alias === "settings") {
scope.allowChangeMediaType = true;
}
});
Expand All @@ -52,7 +51,7 @@

function formatDatesToLocal() {
// get current backoffice user and format dates
userService.getCurrentUser().then(function (currentUser) {
userService.getCurrentUser().then(currentUser => {
scope.node.createDateFormatted = dateHelper.getLocalDate(scope.node.createDate, currentUser.locale, 'LLL');
scope.node.updateDateFormatted = dateHelper.getLocalDate(scope.node.updateDate, currentUser.locale, 'LLL');
});
Expand All @@ -73,20 +72,20 @@
scope.node.extension = mediaHelper.getFileExtension(scope.nodeUrl);
}

scope.openMediaType = function (mediaType) {
scope.openMediaType = mediaType => {
var editor = {
id: mediaType.id,
submit: function(model) {
submit: model => {
editorService.close();
},
close: function() {
close: () => {
editorService.close();
}
};
editorService.mediaTypeEditor(editor);
};

scope.openSVG = function () {
scope.openSVG = () => {
var popup = window.open('', '_blank');
var html = '<!DOCTYPE html><body><img src="' + scope.nodeUrl + '"/>' +
'<script>history.pushState(null, null,"' + $location.$$absUrl + '");</script></body>';
Expand Down Expand Up @@ -136,15 +135,15 @@

function loadMediaRelations() {
return mediaResource.getPagedReferences(scope.node.id, scope.mediaOptions)
.then(function (data) {
.then(data => {
scope.mediaReferences = data;
scope.hasMediaReferences = data.items.length > 0;
});
}

function loadMemberRelations() {
return mediaResource.getPagedReferences(scope.node.id, scope.memberOptions)
.then(function (data) {
.then(data => {
scope.memberReferences = data;
scope.hasMemberReferences = data.items.length > 0;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
}

// onLoad callbacks
angular.forEach(opts.callbacks, function(cb) {
Utilities.forEach(opts.callbacks, cb => {
if (Utilities.isFunction(cb)) {
cb(acee);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,31 @@ Use this directive to render a ui component for selecting child items to a paren
scope.dialogModel = {};
scope.showDialog = false;

scope.removeChild = function(selectedChild, $index) {
if(scope.onRemove) {
scope.removeChild = (selectedChild, $index) => {
if (scope.onRemove) {
scope.onRemove(selectedChild, $index);
}
};

scope.addChild = function($event) {
if(scope.onAdd) {
scope.addChild = $event => {
if (scope.onAdd) {
scope.onAdd($event);
}
};

function syncParentName() {

// update name on available item
angular.forEach(scope.availableChildren, function(availableChild){
if(availableChild.id === scope.parentId) {
availableChild.name = scope.parentName;
Utilities.forEach(scope.availableChildren, availableChild => {
if (availableChild.id === scope.parentId) {
availableChild.name = scope.parentName;
}
});

// update name on selected child
angular.forEach(scope.selectedChildren, function(selectedChild){
if(selectedChild.id === scope.parentId) {
selectedChild.name = scope.parentName;
Utilities.forEach(scope.selectedChildren, selectedChild => {
if (selectedChild.id === scope.parentId) {
selectedChild.name = scope.parentName;
}
});

Expand All @@ -159,16 +159,16 @@ Use this directive to render a ui component for selecting child items to a paren
function syncParentIcon() {

// update icon on available item
angular.forEach(scope.availableChildren, function(availableChild){
if(availableChild.id === scope.parentId) {
availableChild.icon = scope.parentIcon;
Utilities.forEach(scope.availableChildren, availableChild => {
if (availableChild.id === scope.parentId) {
availableChild.icon = scope.parentIcon;
}
});

// update icon on selected child
angular.forEach(scope.selectedChildren, function(selectedChild){
if(selectedChild.id === scope.parentId) {
selectedChild.icon = scope.parentIcon;
Utilities.forEach(scope.selectedChildren, selectedChild => {
if (selectedChild.id === scope.parentId) {
selectedChild.icon = scope.parentIcon;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,26 @@
}

// update selected items
angular.forEach(scope.selectedItems, function (selectedItem) {
Utilities.forEach(scope.selectedItems, selectedItem => {
if (selectedItem.placeholder) {

selectedItem.name = scope.name;

if (scope.alias !== null && scope.alias !== undefined) {
selectedItem.alias = scope.alias;
}

}
});

// update availableItems
angular.forEach(scope.availableItems, function (availableItem) {
Utilities.forEach(scope.availableItems, availableItem => {
if (availableItem.placeholder) {

availableItem.name = scope.name;

if (scope.alias !== null && scope.alias !== undefined) {
availableItem.alias = scope.alias;
}

}
});

Expand Down
Loading

0 comments on commit 56790f7

Please sign in to comment.