Convert angular.isArray to Utilities.isArray (#7934)

This commit is contained in:
Mike Masey
2020-04-10 17:34:23 +01:00
committed by GitHub
parent 318fcbe3ba
commit b5b319f917
34 changed files with 54 additions and 54 deletions
@@ -31,7 +31,7 @@
if (scope.user.avatars) {
scope.avatar = [];
if (angular.isArray(scope.user.avatars)) {
if (Utilities.isArray(scope.user.avatars)) {
for (var i = 0; i < scope.user.avatars.length; i++) {
scope.avatar.push({ value: scope.user.avatars[i] });
}
@@ -46,7 +46,7 @@
if (scope.user.avatars) {
scope.avatar = [];
if (angular.isArray(scope.user.avatars)) {
if (Utilities.isArray(scope.user.avatars)) {
for (var i = 0; i < scope.user.avatars.length; i++) {
scope.avatar.push({ value: scope.user.avatars[i] });
}
@@ -9,7 +9,7 @@ angular.module('umbraco.directives')
.directive('checklistModel', ['$parse', '$compile', function($parse, $compile) {
// contains
function contains(arr, item) {
if (angular.isArray(arr)) {
if (Utilities.isArray(arr)) {
for (var i = 0; i < arr.length; i++) {
if (angular.equals(arr[i], item)) {
return true;
@@ -21,7 +21,7 @@ angular.module('umbraco.directives')
// add
function add(arr, item) {
arr = angular.isArray(arr) ? arr : [];
arr = Utilities.isArray(arr) ? arr : [];
for (var i = 0; i < arr.length; i++) {
if (angular.equals(arr[i], item)) {
return arr;
@@ -33,7 +33,7 @@ angular.module('umbraco.directives')
// remove
function remove(arr, item) {
if (angular.isArray(arr)) {
if (Utilities.isArray(arr)) {
for (var i = 0; i < arr.length; i++) {
if (angular.equals(arr[i], item)) {
arr.splice(i, 1);
@@ -191,7 +191,7 @@
}
}
}
else if (angular.isArray(vm.value)) {
else if (Utilities.isArray(vm.value)) {
vm.viewModel = vm.value;
}
}
@@ -87,7 +87,7 @@ function umbTreeDirective($q, $rootScope, treeService, notificationsService, use
/** Helper function to emit tree events */
function emitEvent(eventName, args) {
if (registeredCallbacks[eventName] && angular.isArray(registeredCallbacks[eventName])) {
if (registeredCallbacks[eventName] && Utilities.isArray(registeredCallbacks[eventName])) {
_.each(registeredCallbacks[eventName], function (c) {
c(args);//call it
});
@@ -314,7 +314,7 @@ Use this directive to generate a thumbnail grid of media items.
};
var unbindItemsWatcher = scope.$watch('items', function(newValue, oldValue) {
if (angular.isArray(newValue)) {
if (Utilities.isArray(newValue)) {
activate();
}
});
@@ -101,7 +101,7 @@ function valPropertyMsg(serverValidationManager, localizationService) {
var errCount = 0;
for (var e in formCtrl.$error) {
if (angular.isArray(formCtrl.$error[e])) {
if (Utilities.isArray(formCtrl.$error[e])) {
errCount++;
}
}
@@ -111,8 +111,8 @@ function valPropertyMsg(serverValidationManager, localizationService) {
// is the only one, then we'll clear.
if (errCount === 0
|| (errCount === 1 && angular.isArray(formCtrl.$error.valPropertyMsg))
|| (formCtrl.$invalid && angular.isArray(formCtrl.$error.valServer))) {
|| (errCount === 1 && Utilities.isArray(formCtrl.$error.valPropertyMsg))
|| (formCtrl.$invalid && Utilities.isArray(formCtrl.$error.valServer))) {
scope.errorMsg = "";
formCtrl.$setValidity('valPropertyMsg', true);
} else if (showValidation && scope.errorMsg === "") {
@@ -40,7 +40,7 @@
function link(scope, el, attr, ctrl) {
//if there are no containing form or valFormManager controllers, then we do nothing
if (!ctrl || !angular.isArray(ctrl) || ctrl.length !== 2 || !ctrl[0] || !ctrl[1]) {
if (!ctrl || !Utilities.isArray(ctrl) || ctrl.length !== 2 || !ctrl[0] || !ctrl[1]) {
return;
}
@@ -44,7 +44,7 @@
var headers = config.headers ? config.headers : {};
//Here we'll check if we should ignore the error (either based on the original header set or the request configuration)
if (headers["x-umb-ignore-error"] === "ignore" || config.umbIgnoreErrors === true || (angular.isArray(config.umbIgnoreStatus) && config.umbIgnoreStatus.indexOf(rejection.status) !== -1)) {
if (headers["x-umb-ignore-error"] === "ignore" || config.umbIgnoreErrors === true || (Utilities.isArray(config.umbIgnoreStatus) && config.umbIgnoreStatus.indexOf(rejection.status) !== -1)) {
//exit/ignore
return $q.reject(rejection);
}
@@ -1003,10 +1003,10 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
loginPageId: loginPageId,
errorPageId: errorPageId
};
if (angular.isArray(groups) && groups.length) {
if (Utilities.isArray(groups) && groups.length) {
publicAccess.groups = groups;
}
else if (angular.isArray(usernames) && usernames.length) {
else if (Utilities.isArray(usernames) && usernames.length) {
publicAccess.usernames = usernames;
}
else {
@@ -33,7 +33,7 @@ function angularHelper($q) {
//this is sequential promise chaining, it's not pretty but we need to do it this way.
//$q.all doesn't execute promises in sequence but that's what we want to do here.
if (!angular.isArray(promises)) {
if (!Utilities.isArray(promises)) {
throw "promises must be an array";
}
@@ -256,7 +256,7 @@ angular.module('umbraco.services')
load: function (pathArray, scope, defaultAssetType) {
var promise;
if (!angular.isArray(pathArray)) {
if (!Utilities.isArray(pathArray)) {
throw "pathArray must be an array";
}
@@ -40,7 +40,7 @@ function fileManager($rootScope) {
}
var metaData = [];
if (angular.isArray(args.metaData)) {
if (Utilities.isArray(args.metaData)) {
metaData = args.metaData;
}
@@ -83,7 +83,7 @@ function formHelper(angularHelper, serverValidationManager, notificationsService
if (!args || !args.notifications) {
return false;
}
if (angular.isArray(args.notifications)) {
if (Utilities.isArray(args.notifications)) {
for (var i = 0; i < args.notifications.length; i++) {
notificationsService.showNotification(args.notifications[i]);
}
@@ -332,14 +332,14 @@
selection.length = 0;
if (angular.isArray(items)) {
if (Utilities.isArray(items)) {
for (i = 0; items.length > i; i++) {
var item = items[i];
item.selected = false;
}
}
if(angular.isArray(folders)) {
if(Utilities.isArray(folders)) {
for (i = 0; folders.length > i; i++) {
var folder = folders[i];
folder.selected = false;
@@ -366,7 +366,7 @@
var checkbox = $event.target;
var clearSelection = false;
if (!angular.isArray(items)) {
if (!Utilities.isArray(items)) {
return;
}
@@ -413,7 +413,7 @@
function selectAllItemsToggle(items, selection) {
if (!angular.isArray(items)) {
if (!Utilities.isArray(items)) {
return;
}
@@ -480,7 +480,7 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s
//now we need to check if this custom config key is defined in our baseline, if it is we don't want to
//overwrite the baseline config item if it is an array, we want to concat the items in the array, otherwise
//if it's an object it will overwrite the baseline
if (angular.isArray(config[i]) && angular.isArray(tinyMceConfig.customConfig[i])) {
if (Utilities.isArray(config[i]) && Utilities.isArray(tinyMceConfig.customConfig[i])) {
//concat it and below this concat'd array will overwrite the baseline in angular.extend
tinyMceConfig.customConfig[i] = config[i].concat(tinyMceConfig.customConfig[i]);
}
@@ -47,7 +47,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
/** Internal method to track expanded paths on a tree */
_trackExpandedPaths: function (node, expandedPaths) {
if (!node.children || !angular.isArray(node.children) || node.children.length == 0) {
if (!node.children || !Utilities.isArray(node.children) || node.children.length == 0) {
return;
}
@@ -174,7 +174,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
//we determine this based on the server variables
if (Umbraco.Sys.ServerVariables.umbracoPlugins &&
Umbraco.Sys.ServerVariables.umbracoPlugins.trees &&
angular.isArray(Umbraco.Sys.ServerVariables.umbracoPlugins.trees)) {
Utilities.isArray(Umbraco.Sys.ServerVariables.umbracoPlugins.trees)) {
var found = _.find(Umbraco.Sys.ServerVariables.umbracoPlugins.trees, function (item) {
return invariantEquals(item.alias, treeAlias);
@@ -473,7 +473,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
for (var i = 0; i < treeNode.children.length; i++) {
var child = treeNode.children[i];
if (child.children && angular.isArray(child.children) && child.children.length > 0) {
if (child.children && Utilities.isArray(child.children) && child.children.length > 0) {
//recurse
found = this.getDescendantNode(child, id);
if (found) {
@@ -773,7 +773,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
if (!args.path) {
throw "No path defined on args object for syncTree";
}
if (!angular.isArray(args.path)) {
if (!Utilities.isArray(args.path)) {
throw "Path must be an array";
}
if (args.path.length < 1) {
@@ -44,7 +44,7 @@ function umbRequestHelper($http, $q, notificationsService, eventsService, formHe
*/
dictionaryToQueryString: function (queryStrings) {
if (angular.isArray(queryStrings)) {
if (Utilities.isArray(queryStrings)) {
return _.map(queryStrings, function (item) {
var key = null;
var val = null;
@@ -254,7 +254,7 @@ function umbRequestHelper($http, $q, notificationsService, eventsService, formHe
// so we know which property it belongs to on the server side
var fileKey = "file_" + args.files[f].alias + "_" + (args.files[f].culture ? args.files[f].culture : "");
if (angular.isArray(args.files[f].metaData) && args.files[f].metaData.length > 0) {
if (Utilities.isArray(args.files[f].metaData) && args.files[f].metaData.length > 0) {
fileKey += ("_" + args.files[f].metaData.join("_"));
}
formData.append(fileKey, args.files[f].file);
@@ -322,7 +322,7 @@ function umbRequestHelper($http, $q, notificationsService, eventsService, formHe
//validate input, jsonData can be an array of key/value pairs or just one key/value pair.
if (!jsonData) { throw "jsonData cannot be null"; }
if (angular.isArray(jsonData)) {
if (Utilities.isArray(jsonData)) {
_.each(jsonData, function (item) {
if (!item.key || !item.value) { throw "jsonData array item must have both a key and a value property"; }
});
@@ -340,7 +340,7 @@ function umbRequestHelper($http, $q, notificationsService, eventsService, formHe
transformRequest: function(data) {
var formData = new FormData();
//add the json data
if (angular.isArray(data)) {
if (Utilities.isArray(data)) {
_.each(data, function(item) {
formData.append(item.key, !Utilities.isString(item.value) ? Utilities.toJson(item.value) : item.value);
});
@@ -42,7 +42,7 @@ function MacroPickerController($scope, entityResource, macroResource, umbPropEdi
.then(function (data) {
//go to next page if there are params otherwise we can just exit
if (!angular.isArray(data) || data.length === 0) {
if (!Utilities.isArray(data) || data.length === 0) {
if (insertIfNoParameters) {
$scope.model.submit($scope.model);
@@ -104,12 +104,12 @@ function MacroPickerController($scope, entityResource, macroResource, umbPropEdi
entityResource.getAll("Macro", ($scope.model.dialogData && $scope.model.dialogData.richTextEditor && $scope.model.dialogData.richTextEditor === true) ? "UseInEditor=true" : null)
.then(function (data) {
if (angular.isArray(data) && data.length == 0) {
if (Utilities.isArray(data) && data.length == 0) {
$scope.nomacros = true;
}
//if 'allowedMacros' is specified, we need to filter
if (angular.isArray($scope.model.dialogData.allowedMacros) && $scope.model.dialogData.allowedMacros.length > 0) {
if (Utilities.isArray($scope.model.dialogData.allowedMacros) && $scope.model.dialogData.allowedMacros.length > 0) {
$scope.macros = _.filter(data, function(d) {
return _.contains($scope.model.dialogData.allowedMacros, d.alias);
});
@@ -497,7 +497,7 @@ angular.module("umbraco")
var folderImage = $scope.images[folderIndex];
var imageIsSelected = false;
if ($scope.model && angular.isArray($scope.model.selection)) {
if ($scope.model && Utilities.isArray($scope.model.selection)) {
for (var selectedIndex = 0;
selectedIndex < $scope.model.selection.length;
selectedIndex++) {
@@ -271,7 +271,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
openMiniListView(args.node);
}
if (angular.isArray(args.children)) {
if (Utilities.isArray(args.children)) {
//iterate children
_.each(args.children,
@@ -97,7 +97,7 @@ function DocumentTypesCreateController($scope, $location, navigationService, con
$scope.error = err;
//show any notifications
if (angular.isArray(err.data.notifications)) {
if (Utilities.isArray(err.data.notifications)) {
for (var i = 0; i < err.data.notifications.length; i++) {
notificationsService.showNotification(err.data.notifications[i]);
}
@@ -19,7 +19,7 @@ angular.module("umbraco").controller("Umbraco.PrevalueEditors.ColorPickerControl
// Make an array from the dictionary
var items = [];
if (angular.isArray($scope.model.prevalues)) {
if (Utilities.isArray($scope.model.prevalues)) {
for (var i in $scope.model.prevalues) {
var oldValue = $scope.model.prevalues[i];
@@ -7,7 +7,7 @@ angular.module("umbraco").controller("Umbraco.PrevalueEditors.MultiValuesControl
$scope.hasError = false;
$scope.focusOnNew = false;
if (!angular.isArray($scope.model.value)) {
if (!Utilities.isArray($scope.model.value)) {
//make an array from the dictionary
var items = [];
@@ -118,7 +118,7 @@ angular.module('umbraco')
}
function populate(data) {
if (angular.isArray(data)) {
if (Utilities.isArray(data)) {
_.each(data, function (item, i) {
$scope.add(item);
});
@@ -25,7 +25,7 @@ function ColorPickerController($scope, $timeout) {
initActiveColor();
}
if (!angular.isArray($scope.model.config.items)) {
if (!Utilities.isArray($scope.model.config.items)) {
//make an array from the dictionary
var items = [];
for (var i in $scope.model.config.items) {
@@ -55,7 +55,7 @@
});
});
if (!angular.isArray($scope.model.value)) {
if (!Utilities.isArray($scope.model.value)) {
//make an array from the dictionary
var items = [];
for (var i in $scope.model.value) {
@@ -152,7 +152,7 @@ function contentPickerController($scope, entityResource, editorState, iconHelper
dataTypeKey: $scope.model.dataTypeKey,
currentNode: editorState ? editorState.current : null,
callback: function (data) {
if (angular.isArray(data)) {
if (Utilities.isArray(data)) {
_.each(data, function (item, i) {
$scope.add(item);
});
@@ -233,7 +233,7 @@ function contentPickerController($scope, entityResource, editorState, iconHelper
$scope.currentPicker = dialogOptions;
$scope.currentPicker.submit = function (model) {
if (angular.isArray(model.selection)) {
if (Utilities.isArray(model.selection)) {
_.each(model.selection, function (item, i) {
$scope.add(item);
});
@@ -45,7 +45,7 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.DropdownFlexibleCo
$scope.model.value = [$scope.model.singleDropdownValue];
}
if (angular.isArray($scope.model.config.items)) {
if (Utilities.isArray($scope.model.config.items)) {
//PP: I dont think this will happen, but we have tests that expect it to happen..
//if array is simple values, convert to array of objects
if (!Utilities.isObject($scope.model.config.items[0])){
@@ -745,7 +745,7 @@ angular.module("umbraco")
if ($scope.model.value && $scope.model.value.sections && $scope.model.value.sections.length > 0 && $scope.model.value.sections[0].rows && $scope.model.value.sections[0].rows.length > 0) {
if ($scope.model.value.name && angular.isArray($scope.model.config.items.templates)) {
if ($scope.model.value.name && Utilities.isArray($scope.model.config.items.templates)) {
//This will occur if it is an existing value, in which case
// we need to determine which layout was applied by looking up
@@ -756,7 +756,7 @@ angular.module("umbraco")
return t.name === $scope.model.value.name;
});
if (found && angular.isArray(found.sections) && found.sections.length === $scope.model.value.sections.length) {
if (found && Utilities.isArray(found.sections) && found.sections.length === $scope.model.value.sections.length) {
//Cool, we've found the template associated with our current value with matching sections counts, now we need to
// merge this template data on to our current value (as if it was new) so that we can preserve what is and isn't
@@ -382,7 +382,7 @@ function listViewController($scope, $interpolate, $routeParams, $injector, $time
return serial(selected, fn, getStatusMsg, 0).then(function (result) {
// executes once the whole selection has been processed
// in case of an error (caught by serial), result will be the error
if (!(result.data && angular.isArray(result.data.notifications)))
if (!(result.data && Utilities.isArray(result.data.notifications)))
showNotificationsAndReset(result, true, getSuccessMsg(selected.length));
});
}
@@ -20,7 +20,7 @@ function memberPickerController($scope, entityResource, iconHelper, angularHelpe
},
filterCssClass: "not-allowed",
callback: function(data) {
if (angular.isArray(data)) {
if (Utilities.isArray(data)) {
_.each(data, function (item, i) {
$scope.add(item);
});
@@ -80,7 +80,7 @@
};
$scope.add = function ($event) {
if (!angular.isArray($scope.model.value)) {
if (!Utilities.isArray($scope.model.value)) {
$scope.model.value = [];
}
@@ -2,7 +2,7 @@ angular.module('umbraco').controller("Umbraco.PropertyEditors.UrlListController"
function($rootScope, $scope, $filter) {
function formatDisplayValue() {
if (angular.isArray($scope.model.value)) {
if (Utilities.isArray($scope.model.value)) {
//it's the json value
$scope.renderModel = _.map($scope.model.value, function (item) {
return {
@@ -42,4 +42,4 @@ angular.module('umbraco').controller("Umbraco.PropertyEditors.UrlListController"
formatDisplayValue();
};
});
});
@@ -692,7 +692,7 @@ angular.mock.dump = function (object) {
out.append(angular.element(element).clone());
});
out = out.html();
} else if (angular.isArray(object)) {
} else if (Utilities.isArray(object)) {
out = [];
angular.forEach(object, function (o) {
out.push(serialize(o));