diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/localization/localize.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/localization/localize.directive.js index 34bfb01019..e957d78660 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/localization/localize.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/localization/localize.directive.js @@ -64,7 +64,7 @@ angular.module("umbraco.directives") //Support one or more attribute properties to update var keys = attrs.localize.split(','); - keys.forEach((value, key) => { + Utilities.forEach(keys, (value, key) => { var attr = element.attr(value); if (attr) { diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbkeyboardshortcutsoverview.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbkeyboardshortcutsoverview.directive.js index 2d3db7c162..c499a8bfc6 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbkeyboardshortcutsoverview.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbkeyboardshortcutsoverview.directive.js @@ -158,9 +158,9 @@ When this combination is hit an overview is opened with shortcuts based on the m }; function onInit() { - scope.model.forEach(shortcutGroup => { + Utilities.forEach(scope.model, shortcutGroup => { - shortcutGroup.shortcuts.forEach(shortcut => { + Utilities.forEach(shortcutGroup.shortcuts, shortcut => { shortcut.platformKeys = []; // get shortcut keys for mac diff --git a/src/Umbraco.Web.UI.Client/src/common/services/tour.service.js b/src/Umbraco.Web.UI.Client/src/common/services/tour.service.js index a11a9d6c82..4166725c39 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/tour.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/tour.service.js @@ -19,9 +19,9 @@ function registerAllTours() { tours = []; return tourResource.getTours().then(function (tourFiles) { - tourFiles.forEach(tourFile => { + Utilities.forEach(tourFiles, tourFile => { - tourFile.tours.forEach(newTour => { + Utilities.forEach(tourFile.tours, newTour => { validateTour(newTour); validateTourRegistration(newTour); tours.push(newTour); @@ -251,7 +251,7 @@ */ function validateTourRegistration(tour) { // check for existing tours with the same alias - tours.forEach(existingTour => { + Utilities.forEach(tours, existingTour => { if (existingTour.alias === tour.alias) { throw "A tour with the alias " + tour.alias + " is already registered"; } @@ -267,17 +267,17 @@ var deferred = $q.defer(); currentUserResource.getTours().then(function (storedTours) { - storedTours.forEach(storedTour => { + Utilities.forEach(storedTours, storedTour => { if (storedTour.completed === true) { - tours.forEach(tour => { + Utilities.forEach(tours, tour => { if (storedTour.alias === tour.alias) { tour.completed = true; } }); } if (storedTour.disabled === true) { - tours.forEach(tour => { + Utilities.forEach(tours, tour => { if (storedTour.alias === tour.alias) { tour.disabled = true; } diff --git a/src/Umbraco.Web.UI.Client/src/navigation.controller.js b/src/Umbraco.Web.UI.Client/src/navigation.controller.js index ee8d13e320..a383c2d44a 100644 --- a/src/Umbraco.Web.UI.Client/src/navigation.controller.js +++ b/src/Umbraco.Web.UI.Client/src/navigation.controller.js @@ -495,7 +495,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar //execute them sequentially // set selected language to active - $scope.languages.forEach(language => { + Utilities.forEach($scope.languages, language => { language.active = false; }); diff --git a/src/Umbraco.Web.UI.Client/src/utilities.js b/src/Umbraco.Web.UI.Client/src/utilities.js index edf804e08b..9121ba0e25 100644 --- a/src/Umbraco.Web.UI.Client/src/utilities.js +++ b/src/Umbraco.Web.UI.Client/src/utilities.js @@ -104,6 +104,16 @@ return JSON.parse(val); } + /** + * Not equivalent to angular.forEach. But like the angularJS method this does not fail on null or undefined. + */ + const forEach = (obj, iterator) => { + if (obj) { + return obj.forEach(iterator); + } + return obj; + } + let _utilities = { noop: noop, copy: copy, @@ -117,7 +127,8 @@ isNumber: isNumber, isObject: isObject, fromJson: fromJson, - toJson: toJson + toJson: toJson, + forEach: forEach }; if (typeof (window.Utilities) === 'undefined') { diff --git a/src/Umbraco.Web.UI.Client/src/views/dashboard/settings/healthcheck.controller.js b/src/Umbraco.Web.UI.Client/src/views/dashboard/settings/healthcheck.controller.js index f5ceb877c8..991a8132cf 100644 --- a/src/Umbraco.Web.UI.Client/src/views/dashboard/settings/healthcheck.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/dashboard/settings/healthcheck.controller.js @@ -33,7 +33,7 @@ var totalInfo = 0; // count total number of statusses - group.checks.forEach(check => { + Utilities.forEach(group.checks, check => { if (check.status) { check.status.forEach(status => { @@ -95,22 +95,24 @@ group.checkCounter = 0; group.loading = true; - checks.forEach(check => { - check.loading = true; + if (checks) { + checks.forEach(check => { + check.loading = true; - healthCheckResource.getStatus(check.id) - .then(function (response) { - check.status = response; - group.checkCounter = group.checkCounter + 1; - check.loading = false; + healthCheckResource.getStatus(check.id) + .then(function (response) { + check.status = response; + group.checkCounter = group.checkCounter + 1; + check.loading = false; - // when all checks are done, set global group result - if (group.checkCounter === checks.length) { - setGroupGlobalResultType(group); - group.loading = false; - } - }); - }); + // when all checks are done, set global group result + if (group.checkCounter === checks.length) { + setGroupGlobalResultType(group); + group.loading = false; + } + }); + }); + } } function openGroup(group) {