Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some decoupling from underscore => _.each #8475

Merged
merged 5 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@
searchService.searchAll(search).then(function (result) {
//result is a dictionary of group Title and it's results
var filtered = {};
_.each(result, function (value, key) {
Object.keys(result).forEach(key => {
let value = result[key];
if (value.results.length > 0) {
filtered[key] = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ function umbTreeDirective($q, $rootScope, treeService, notificationsService, use
/** Helper function to emit tree events */
function emitEvent(eventName, args) {
if (registeredCallbacks[eventName] && Utilities.isArray(registeredCallbacks[eventName])) {
_.each(registeredCallbacks[eventName], function (c) {
c(args);//call it
});
// call it
registeredCallbacks[eventName].forEach(c => c(args));
}
}

Expand Down Expand Up @@ -342,26 +341,17 @@ function umbTreeDirective($q, $rootScope, treeService, notificationsService, use

var css = [];
if (node.cssClasses) {
_.each(node.cssClasses, function (c) {
css.push(c);
});
node.cssClasses.forEach(c => css.push(c));
}

return css.join(" ");
};

$scope.selectEnabledNodeClass = function (node) {
return node ?
node.selected ?
'icon umb-tree-icon sprTree icon-check green temporary' :
'' :
'';
};
$scope.selectEnabledNodeClass = node =>
node && node.selected ? 'icon umb-tree-icon sprTree icon-check green temporary' : '';

/* helper to force reloading children of a tree node */
$scope.loadChildren = function (node, forceReload) {
return loadChildren(node, forceReload);
};
$scope.loadChildren = (node, forceReload) => loadChildren(node, forceReload);

/**
Method called when the options button next to the root node is called.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ angular.module("umbraco.directives")

var css = [];
if (node.cssClasses) {
_.each(node.cssClasses, function(c) {
css.push(c);
});
node.cssClasses.forEach(c => css.push(c));
}
if (node.selected) {
css.push("umb-tree-node-checked");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,17 @@
var resourceLookup = scope.contentType === "documentType" ? contentTypeResource.getAvailableCompositeContentTypes : mediaTypeResource.getAvailableCompositeContentTypes;

return resourceLookup(scope.model.id, selectedContentTypeAliases, propAliasesExisting).then(function (filteredAvailableCompositeTypes) {
_.each(scope.compositionsDialogModel.availableCompositeContentTypes, function (current) {
scope.compositionsDialogModel.availableCompositeContentTypes.forEach(current => {
//reset first
current.allowed = true;
//see if this list item is found in the response (allowed) list
var found = _.find(filteredAvailableCompositeTypes, function (f) {
return current.contentType.alias === f.contentType.alias;
});
var found = filteredAvailableCompositeTypes.find(f => current.contentType.alias === f.contentType.alias);

//allow if the item was found in the response (allowed) list -
// and ensure its set to allowed if it is currently checked,
// DO not allow if it's a locked content type.
current.allowed = scope.model.lockedCompositeContentTypes.indexOf(current.contentType.alias) === -1 &&
(selectedContentTypeAliases.indexOf(current.contentType.alias) !== -1) || ((found !== null && found !== undefined) ? found.allowed : false);
current.allowed = scope.model.lockedCompositeContentTypes.includes(current.contentType.alias) &&
(selectedContentTypeAliases.includes(current.contentType.alias)) || (found ? found.allowed : false);

});
});
Expand All @@ -192,15 +190,15 @@
function setupAvailableContentTypesModel(result) {
scope.compositionsDialogModel.availableCompositeContentTypes = result;
//iterate each one and set it up
_.each(scope.compositionsDialogModel.availableCompositeContentTypes, function (c) {
scope.compositionsDialogModel.availableCompositeContentTypes.forEach(c => {
//enable it if it's part of the selected model
if (scope.compositionsDialogModel.compositeContentTypes.indexOf(c.contentType.alias) !== -1) {
if (scope.compositionsDialogModel.compositeContentTypes.includes(c.contentType.alias)) {
c.allowed = true;
}

//set the inherited flags
c.inherited = false;
if (scope.model.lockedCompositeContentTypes.indexOf(c.contentType.alias) > -1) {
if (scope.model.lockedCompositeContentTypes.includes(c.contentType.alias)) {
c.inherited = true;
}
// convert icons for composite content types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
}
// update children
miniListView.children = data.items;
_.each(miniListView.children, function(c) {
miniListView.children.forEach(c => {
// child allowed by default
c.allowed = true;

Expand Down Expand Up @@ -95,7 +95,8 @@
var filtered = angular.isFunction(scope.entityTypeFilter.filter)
? _.filter(miniListView.children, scope.entityTypeFilter.filter)
: _.where(miniListView.children, scope.entityTypeFilter.filter);
_.each(filtered, (node) => node.allowed = false);

filtered.forEach(node => node.allowed = false);
}

// update pagination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function valFormManager(serverValidationManager, $rootScope, $timeout, $location
var parts = nextPath.split("?");
var query = {};
if (parts.length > 1) {
_.each(parts[1].split("&"), function(q) {
parts[1].split("&").forEach(q => {
var keyVal = q.split("=");
query[keyVal[0]] = keyVal[1];
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ angular.module('umbraco.mocks').
}

function returnNodebyIds(status, data, headers) {
var ids = mocksUtils.getParameterByName(data, "ids") || "1234,1234,4234";
var ids = mocksUtils.getParameterByName(data, "ids") || ['1234','1234','4234'];
var items = [];

_.each(ids, function(id){
items.push(_getNode( parseInt( id, 10 )) );
});
for (var i = 0; i < ids.length; i += 1) {
items.push(_getNode(parseInt(ids[i], 10)));
}

return [200, items, null];
}
Expand All @@ -26,8 +26,6 @@ angular.module('umbraco.mocks').

var id = mocksUtils.getParameterByName(data, "id") || 1234;
id = parseInt(id, 10);



return [200, _getNode(id), null];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
getByIds: function (ids) {

var idQuery = "";
_.each(ids, function (item) {
idQuery += "ids=" + item + "&";
});
ids.forEach(id => idQuery += `ids=${id}&`);

return umbRequestHelper.resourcePromise(
$http.get(
Expand All @@ -455,9 +453,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
'Failed to retrieve data for content with multiple ids')
.then(function (result) {
//each item needs to be re-formatted
_.each(result, function (r) {
umbDataFormatter.formatContentGetData(r)
});
result.forEach(r => umbDataFormatter.formatContentGetData(r));
return $q.when(result);
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) {
getByIds: function (ids) {

var idQuery = "";
_.each(ids, function (item) {
idQuery += "ids=" + item + "&";
});
ids.forEach(id => idQuery += `ids=${id}&`);

return umbRequestHelper.resourcePromise(
$http.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ function memberGroupResource($q, $http, umbRequestHelper) {
getByIds: function (ids) {

var idQuery = "";
_.each(ids, function (item) {
idQuery += "ids=" + item + "&";
});
ids.forEach(id => idQuery += `ids=${id}&`);

return umbRequestHelper.resourcePromise(
$http.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ function memberTypeResource($q, $http, umbRequestHelper, umbDataFormatter) {
}

var query = "";
_.each(filterContentTypes, function (item) {
query += "filterContentTypes=" + item + "&";
});
filterContentTypes.forEach(fct => query += `filterContentTypes=${fct}&`);

// if filterContentTypes array is empty we need a empty variable in the querystring otherwise the service returns a error
if (filterContentTypes.length === 0) {
query += "filterContentTypes=&";
}
_.each(filterPropertyTypes, function (item) {
query += "filterPropertyTypes=" + item + "&";
});

filterPropertyTypes.forEach(fpt => query += `filterPropertyTypes=${fpt}&`);

// if filterPropertyTypes array is empty we need a empty variable in the querystring otherwise the service returns a error
if (filterPropertyTypes.length === 0) {
query += "filterPropertyTypes=&";
Expand Down
14 changes: 6 additions & 8 deletions src/Umbraco.Web.UI.Client/src/common/services/assets.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ angular.module('umbraco.services')
//blocking
var promises = [];
var assets = [];
_.each(nonEmpty, function (path) {
nonEmpty.forEach(path => {
path = convertVirtualPath(path);
var asset = service._getAssetPromise(path);
//if not previously loaded, add to list of promises
Expand Down Expand Up @@ -325,19 +325,17 @@ angular.module('umbraco.services')
scope = $rootScope;
}
angularHelper.safeApply(scope,
function () {
asset.deferred.resolve(true);
});
() => asset.deferred.resolve(true));
}

if (cssAssets.length > 0) {
var cssPaths = _.map(cssAssets, function (asset) { return appendRnd(asset.path) });
LazyLoad.css(cssPaths, function () { _.each(cssAssets, assetLoaded); });
var cssPaths = cssAssets.map(css => appendRnd(css.path));
LazyLoad.css(cssPaths, () => cssAssets.forEach(assetLoaded));
}

if (jsAssets.length > 0) {
var jsPaths = _.map(jsAssets, function (asset) { return appendRnd(asset.path) });
LazyLoad.js(jsPaths, function () { _.each(jsAssets, assetLoaded); });
var jsPaths = jsAssets.map(js => appendRnd(js.path));
LazyLoad.js(jsPaths, () => jsAssets.forEach(assetLoaded));
}

return promise;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function navigationService($routeParams, $location, $q, $injector, eventsService
//if the routing parameter keys are the same, we'll compare their values to see if any have changed and if so then the routing will be allowed.
if (diff1.length === 0 && diff2.length === 0) {
var partsChanged = 0;
_.each(currRoutingKeys, function (k) {
currRoutingKeys.forEach(k => {
if (currUrlParams[k] != nextUrlParams[k]) {
partsChanged++;
}
Expand Down Expand Up @@ -206,7 +206,8 @@ function navigationService($routeParams, $location, $q, $injector, eventsService
var toRetain = _.union(retainedQueryStrings, toRetain);
var currentSearch = $location.search();
$location.search('');
_.each(toRetain, function (k) {

toRetain.forEach(k => {
if (currentSearch[k]) {
$location.search(k, currentSearch[k]);
}
Expand Down Expand Up @@ -240,7 +241,7 @@ function navigationService($routeParams, $location, $q, $injector, eventsService
var toRetain = Utilities.copy(nextRouteParams);
var updated = false;

_.each(retainedQueryStrings, function (r) {
retainedQueryStrings.forEach(r => {
// if mculture is set to null in nextRouteParams, the value will be undefined and we will not retain any query string that has a value of "null"
if (currRouteParams[r] && nextRouteParams[r] !== undefined && !nextRouteParams[r]) {
toRetain[r] = currRouteParams[r];
Expand Down
18 changes: 5 additions & 13 deletions src/Umbraco.Web.UI.Client/src/common/services/search.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ angular.module('umbraco.services')
}

return entityResource.search(args.term, "Member", args.searchFrom).then(function (data) {
_.each(data, function (item) {
searchResultFormatter.configureMemberResult(item);
});
data.forEach(item => searchResultFormatter.configureMemberResult(item));
return data;
});
},
Expand All @@ -68,9 +66,7 @@ angular.module('umbraco.services')
}

return entityResource.search(args.term, "Document", args.searchFrom, args.canceler, args.dataTypeKey).then(function (data) {
_.each(data, function (item) {
searchResultFormatter.configureContentResult(item);
});
data.forEach(item => searchResultFormatter.configureContentResult(item));
return data;
});
},
Expand All @@ -93,9 +89,7 @@ angular.module('umbraco.services')
}

return entityResource.search(args.term, "Media", args.searchFrom, args.canceler, args.dataTypeKey).then(function (data) {
_.each(data, function (item) {
searchResultFormatter.configureMediaResult(item);
});
data.forEach(item => searchResultFormatter.configureMediaResult(item));
return data;
});
},
Expand All @@ -119,7 +113,7 @@ angular.module('umbraco.services')

return entityResource.searchAll(args.term, args.canceler).then(function (data) {

_.each(data, function (resultByType) {
data.forEach(resultByType => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathanwoulfe Uh oh! This one seems to have broken!

image

Little help please? 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduce by trying to search in the backoffice:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I thought I'd sorted that... I'm guessing data isn't an array, but an object/dictionary. I'll grab the laptop...


//we need to format the search result data to include things like the subtitle, urls, etc...
// this is done with registered angular services as part of the SearchableTreeAttribute, if that
Expand All @@ -140,20 +134,18 @@ angular.module('umbraco.services')
}
}
//now apply the formatter for each result
_.each(resultByType.results, function (item) {
resultByType.results.forEach(item => {
formatterMethod.apply(this, [item, resultByType.treeAlias, resultByType.appAlias]);
});

});

return data;
});

},

// TODO: This doesn't do anything!
setCurrent: function (sectionAlias) {

var currentSection = sectionAlias;
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/Umbraco.Web.UI.Client/src/common/services/tree.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
//take the last child
var childPath = this.getPath(node.children[node.children.length - 1]).join(",");
//check if this already exists, if so exit
if (expandedPaths.indexOf(childPath) !== -1) {
if (expandedPaths.includes(childPath)) {
return;
}

Expand All @@ -65,18 +65,18 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS

var clonedPaths = expandedPaths.slice(0); //make a copy to iterate over so we can modify the original in the iteration

_.each(clonedPaths, function (p) {
clonedPaths.forEach(p => {
if (childPath.startsWith(p + ",")) {
//this means that the node's path supercedes this path stored so we can remove the current 'p' and replace it with node.path
expandedPaths.splice(expandedPaths.indexOf(p), 1); //remove it
if (expandedPaths.indexOf(childPath) === -1) {
if (expandedPaths.includes(childPath) === false) {
expandedPaths.push(childPath); //replace it
}
}
else if (p.startsWith(childPath + ",")) {
//this means we've already tracked a deeper node so we shouldn't track this one
}
else if (expandedPaths.indexOf(childPath) === -1) {
else if (expandedPaths.includes(childPath) === false) {
expandedPaths.push(childPath); //track it
}
});
Expand Down
Loading