Replace instances of angular.forEach with vanilla JS forEach (#7928)

This commit is contained in:
Jan Skovgaard
2020-04-14 10:14:25 +02:00
committed by GitHub
parent 021b39378a
commit d74d9ffb2b
6 changed files with 111 additions and 109 deletions
@@ -30,7 +30,7 @@ angular.module("umbraco.directives")
.directive('localize', function ($log, localizationService) {
return {
restrict: 'E',
scope:{
scope: {
key: '@',
tokens: '=',
watchTokens: '@'
@@ -40,13 +40,13 @@ angular.module("umbraco.directives")
link: function (scope, element, attrs) {
var key = scope.key;
scope.text = "";
// A render function to be able to update tokens as values update.
function render() {
element.html(localizationService.tokenReplace(scope.text, scope.tokens || null));
}
localizationService.localize(key).then(function(value){
localizationService.localize(key).then(function (value) {
scope.text = value;
render();
});
@@ -64,19 +64,19 @@ angular.module("umbraco.directives")
//Support one or more attribute properties to update
var keys = attrs.localize.split(',');
angular.forEach(keys, function(value, key){
keys.forEach((value, key) => {
var attr = element.attr(value);
if(attr){
if(attr[0] === '@'){
if (attr) {
if (attr[0] === '@') {
//If the translation key starts with @ then remove it
attr = attr.substring(1);
}
var t = localizationService.tokenize(attr, scope);
localizationService.localize(t.key, t.tokens).then(function(val){
element.attr(value, val);
localizationService.localize(t.key, t.tokens).then(function (val) {
element.attr(value, val);
});
}
});
@@ -120,26 +120,26 @@ When this combination is hit an overview is opened with shortcuts based on the m
scope.toggleShortcutsOverlay = function () {
if(overlay) {
if (overlay) {
scope.close();
} else {
scope.open();
}
if(scope.onToggle) {
if (scope.onToggle) {
scope.onToggle();
}
};
scope.open = function() {
if(!overlay) {
scope.open = function () {
if (!overlay) {
overlay = {
title: "Keyboard shortcuts",
view: "keyboardshortcuts",
hideSubmitButton: true,
shortcuts: scope.model,
close: function() {
close: function () {
scope.close();
}
};
@@ -147,20 +147,20 @@ When this combination is hit an overview is opened with shortcuts based on the m
}
};
scope.close = function() {
if(overlay) {
scope.close = function () {
if (overlay) {
overlayService.close();
overlay = null;
if(scope.onClose) {
if (scope.onClose) {
scope.onClose();
}
}
};
function onInit() {
angular.forEach(scope.model, function (shortcutGroup) {
angular.forEach(shortcutGroup.shortcuts, function (shortcut) {
scope.model.forEach(shortcutGroup => {
shortcutGroup.shortcuts.forEach(shortcut => {
shortcut.platformKeys = [];
// get shortcut keys for mac
@@ -173,30 +173,29 @@ When this combination is hit an overview is opened with shortcuts based on the m
} else if (shortcut.keys && shortcut && shortcut.keys.length > 0) {
shortcut.platformKeys = shortcut.keys;
}
});
})
});
}
onInit();
eventBindings.push(scope.$watch('model', function(newValue, oldValue){
eventBindings.push(scope.$watch('model', function (newValue, oldValue) {
if (newValue !== oldValue) {
onInit();
}
}));
eventBindings.push(scope.$watch('showOverlay', function(newValue, oldValue){
eventBindings.push(scope.$watch('showOverlay', function (newValue, oldValue) {
if(newValue === oldValue) {
if (newValue === oldValue) {
return;
}
if(newValue === true) {
if (newValue === true) {
scope.open();
}
if(newValue === false) {
if (newValue === false) {
scope.close();
}
@@ -9,7 +9,7 @@
'use strict';
function tourService(eventsService, currentUserResource, $q, tourResource) {
var tours = [];
var currentTour = null;
@@ -18,14 +18,16 @@
*/
function registerAllTours() {
tours = [];
return tourResource.getTours().then(function(tourFiles) {
angular.forEach(tourFiles, function (tourFile) {
angular.forEach(tourFile.tours, function(newTour) {
return tourResource.getTours().then(function (tourFiles) {
tourFiles.forEach(tourFile => {
tourFile.tours.forEach(newTour => {
validateTour(newTour);
validateTourRegistration(newTour);
tours.push(newTour);
tours.push(newTour);
});
});
eventsService.emit("appState.tour.updatedTours", tours);
});
}
@@ -74,7 +76,7 @@
tour.disabled = true;
currentUserResource
.saveTourStatus({ alias: tour.alias, disabled: tour.disabled, completed: tour.completed }).then(
function() {
function () {
eventsService.emit("appState.tour.end", tour);
currentTour = null;
deferred.resolve(tour);
@@ -96,7 +98,7 @@
tour.completed = true;
currentUserResource
.saveTourStatus({ alias: tour.alias, disabled: tour.disabled, completed: tour.completed }).then(
function() {
function () {
eventsService.emit("appState.tour.complete", tour);
currentTour = null;
deferred.resolve(tour);
@@ -130,10 +132,10 @@
function getGroupedTours() {
var deferred = $q.defer();
var tours = getTours();
setTourStatuses(tours).then(function() {
setTourStatuses(tours).then(function () {
var groupedTours = [];
tours.forEach(function (item) {
if (item.contentType === null || item.contentType === '') {
var groupExists = false;
var newGroup = {
@@ -149,9 +151,9 @@
}
groupExists = true;
if(item.hidden === false){
group.tours.push(item);
}
if (item.hidden === false) {
group.tours.push(item);
}
}
});
@@ -162,7 +164,7 @@
newGroup.groupOrder = item.groupOrder;
}
if(item.hidden === false){
if (item.hidden === false) {
newGroup.tours.push(item);
groupedTours.push(newGroup);
}
@@ -242,14 +244,14 @@
throw "Tour " + tour.alias + " is missing the required sections";
}
}
/**
* Validates a tour before it gets registered in the service
* @param {any} tour
*/
function validateTourRegistration(tour) {
// check for existing tours with the same alias
angular.forEach(tours, function (existingTour) {
tours.forEach(existingTour => {
if (existingTour.alias === tour.alias) {
throw "A tour with the alias " + tour.alias + " is already registered";
}
@@ -265,16 +267,17 @@
var deferred = $q.defer();
currentUserResource.getTours().then(function (storedTours) {
angular.forEach(storedTours, function (storedTour) {
storedTours.forEach(storedTour => {
if (storedTour.completed === true) {
angular.forEach(tours, function (tour) {
tours.forEach(tour => {
if (storedTour.alias === tour.alias) {
tour.completed = true;
}
});
}
if (storedTour.disabled === true) {
angular.forEach(tours, function (tour) {
tours.forEach(tour => {
if (storedTour.alias === tour.alias) {
tour.disabled = true;
}
@@ -296,7 +299,7 @@
getCurrentTour: getCurrentTour,
getGroupedTours: getGroupedTours,
getTourByAlias: getTourByAlias,
getToursForDoctype : getToursForDoctype
getToursForDoctype: getToursForDoctype
};
return service;
@@ -142,7 +142,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
var isInit = false;
var evts = [];
//Listen for global state changes
evts.push(eventsService.on("appState.globalState.changed", function (e, args) {
if (args.key === "showNavigation") {
@@ -200,7 +200,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
$scope.treeApi.load({ section: $scope.currentSection, customTreeParams: $scope.customTreeParams, cacheKey: $scope.treeCacheKey });
});
}
//show/hide search results
if (args.key === "showSearchResults") {
$scope.showSearchResults = args.value;
@@ -222,7 +222,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
} else {
$location.search("mculture", null);
}
var currentEditorState = editorState.getCurrent();
if (currentEditorState && currentEditorState.path) {
$scope.treeApi.syncTree({ path: currentEditorState.path, activate: true });
@@ -233,13 +233,13 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
//Emitted when a language is created or an existing one saved/edited
evts.push(eventsService.on("editors.languages.languageSaved", function (e, args) {
if(args.isNew){
if (args.isNew) {
//A new language has been created - reload languages for tree
loadLanguages().then(function (languages) {
$scope.languages = languages;
});
}
else if(args.language.isDefault){
else if (args.language.isDefault) {
//A language was saved and was set to be the new default (refresh the tree, so its at the top)
loadLanguages().then(function (languages) {
$scope.languages = languages;
@@ -282,7 +282,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
/**
* For multi language sites, this ensures that mculture is set to either the last selected language or the default one
*/
*/
function ensureMainCulture() {
if ($location.search().mculture) {
return;
@@ -295,7 +295,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
$timeout(function () {
$scope.selectLanguage(language);
});
}
}
/**
* Based on the current state of the application, this configures the scope variables that control the main tree and language drop down
@@ -432,7 +432,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
//the nav is ready, let the app know
eventsService.emit("app.navigationReady", { treeApi: $scope.treeApi });
}
});
});
@@ -469,7 +469,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
// add the selected culture to a cookie so the user will log back into the same culture later on (cookie lifetime = one year)
var expireDate = new Date();
expireDate.setDate(expireDate.getDate() + 365);
$cookies.put("UMB_MCULTURE", language.culture, {path: "/", expires: expireDate});
$cookies.put("UMB_MCULTURE", language.culture, { path: "/", expires: expireDate });
// close the language selector
$scope.page.languageSelectorIsOpen = false;
@@ -495,9 +495,10 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
//execute them sequentially
// set selected language to active
angular.forEach($scope.languages, function(language){
$scope.languages.forEach(language => {
language.active = false;
});
language.active = true;
angularHelper.executeSequentialPromises(promises);
@@ -538,7 +539,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
closeTree();
};
$scope.onOutsideClick = function() {
$scope.onOutsideClick = function () {
closeTree();
};
@@ -1,13 +1,13 @@
//used for the media picker dialog
angular.module("umbraco")
.controller("Umbraco.Editors.MediaPickerController",
function ($scope, $timeout, mediaResource, entityResource, userService, mediaHelper, mediaTypeHelper, eventsService, treeService, localStorageService, localizationService, editorService, umbSessionStorage) {
function ($scope, $timeout, mediaResource, entityResource, userService, mediaHelper, mediaTypeHelper, eventsService, treeService, localStorageService, localizationService, editorService, umbSessionStorage) {
var vm = this;
vm.submit = submit;
vm.close = close;
vm.toggle = toggle;
vm.upload = upload;
vm.dragLeave = dragLeave;
@@ -26,7 +26,7 @@ angular.module("umbraco")
vm.shouldShowUrl = shouldShowUrl;
var dialogOptions = $scope.model;
$scope.disableFolderSelect = (dialogOptions.disableFolderSelect && dialogOptions.disableFolderSelect !== "0") ? true : false;
$scope.disableFocalPoint = (dialogOptions.disableFocalPoint && dialogOptions.disableFocalPoint !== "0") ? true : false;
$scope.onlyImages = (dialogOptions.onlyImages && dialogOptions.onlyImages !== "0") ? true : false;
@@ -133,21 +133,21 @@ angular.module("umbraco")
// media object so we need to look it up
var id = $scope.target.udi ? $scope.target.udi : $scope.target.id;
var altText = $scope.target.altText;
// ID of a UDI or legacy int ID still could be null/undefinied here
// As user may dragged in an image that has not been saved to media section yet
if (id) {
entityResource.getById(id, "Media")
.then(function (node) {
$scope.target = node;
if (ensureWithinStartNode(node)) {
selectMedia(node);
$scope.target.url = mediaHelper.resolveFileFromEntity(node);
$scope.target.thumbnail = mediaHelper.resolveFileFromEntity(node, true);
$scope.target.altText = altText;
openDetailsDialog();
}
}, gotoStartNode);
.then(function (node) {
$scope.target = node;
if (ensureWithinStartNode(node)) {
selectMedia(node);
$scope.target.url = mediaHelper.resolveFileFromEntity(node);
$scope.target.thumbnail = mediaHelper.resolveFileFromEntity(node, true);
$scope.target.altText = altText;
openDetailsDialog();
}
}, gotoStartNode);
} else {
// No ID set - then this is going to be a tmpimg that has not been uploaded
// User editing this will want to be changing the ALT text
@@ -240,16 +240,16 @@ angular.module("umbraco")
}
} else {
if ($scope.showDetails) {
$scope.target = media;
// handle both entity and full media object
if (media.image) {
$scope.target.url = media.image;
} else {
$scope.target.url = mediaHelper.resolveFile(media);
}
openDetailsDialog();
} else {
selectMedia(media);
@@ -301,7 +301,7 @@ angular.module("umbraco")
$timeout(function () {
if ($scope.multiPicker) {
var images = _.rest($scope.images, $scope.images.length - files.length);
_.each(images, function(image) {
_.each(images, function (image) {
selectMedia(image);
});
} else {
@@ -373,7 +373,7 @@ angular.module("umbraco")
if (vm.searchOptions.filter) {
searchMedia();
} else {
// reset pagination
vm.searchOptions = {
pageNumber: 1,
@@ -383,7 +383,7 @@ angular.module("umbraco")
filter: '',
dataTypeKey: dataTypeKey
};
getChildren($scope.currentFolder.id);
}
});
@@ -411,9 +411,9 @@ angular.module("umbraco")
entityResource.getPagedDescendants($scope.filterOptions.excludeSubFolders ? $scope.currentFolder.id : $scope.startNodeId, "Media", vm.searchOptions)
.then(function (data) {
// update image data to work with image grid
angular.forEach(data.items, function (mediaItem) {
setMediaMetaData(mediaItem);
});
if (data.items) {
data.items.forEach(mediaItem => setMediaMetaData(mediaItem));
}
// update images
$scope.images = data.items ? data.items : [];
@@ -1,4 +1,4 @@
(function() {
(function () {
"use strict";
function HealthCheckController($scope, healthCheckResource) {
@@ -22,7 +22,7 @@
// Get a (grouped) list of all health checks
healthCheckResource.getAllChecks()
.then(function(response) {
.then(function (response) {
vm.groups = response;
});
@@ -33,11 +33,11 @@
var totalInfo = 0;
// count total number of statusses
angular.forEach(group.checks,
function(check) {
angular.forEach(check.status,
function(status) {
switch (status.resultType) {
group.checks.forEach(check => {
if (check.status) {
check.status.forEach(status => {
switch (status.resultType) {
case SUCCESS:
totalSuccess = totalSuccess + 1;
break;
@@ -50,9 +50,10 @@
case INFO:
totalInfo = totalInfo + 1;
break;
}
});
});
}
});
}
});
group.totalSuccess = totalSuccess;
group.totalError = totalError;
@@ -66,7 +67,7 @@
check.loading = true;
check.status = null;
healthCheckResource.getStatus(check.id)
.then(function(response) {
.then(function (response) {
check.loading = false;
check.status = response;
});
@@ -75,7 +76,7 @@
function executeAction(check, index, action) {
check.loading = true;
healthCheckResource.executeAction(action)
.then(function(response) {
.then(function (response) {
check.status[index] = response;
check.loading = false;
});
@@ -94,24 +95,22 @@
group.checkCounter = 0;
group.loading = true;
angular.forEach(checks,
function(check) {
checks.forEach(check => {
check.loading = true;
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) {