Skip to content

Commit

Permalink
Update to Lodash 4
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Jul 13, 2018
1 parent 22040ae commit 5fedb66
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 50 deletions.
11 changes: 7 additions & 4 deletions modules/culture.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ define([
'use strict';
// Config
var config = module && module.config() || {},
translationFallback = config.translationFallback || false;
translationFallback = config.translationFallback || false,
includes = _.contains || _.includes;

// Global state
var availableCultures = [],
Expand Down Expand Up @@ -129,7 +130,9 @@ define([
var standardCalendar = culture.calendars.standard,
currency = culture.numberFormat.currency,
number = culture.numberFormat,
eras = standardCalendar.eras.map(function (era) { return era.name; });
eras = standardCalendar.eras.map(function (era) {
return era.name;
});

function buildNumberPattern(patterns) {
return {
Expand Down Expand Up @@ -1307,8 +1310,8 @@ define([
}), function (elt) {
return '{globalize}/cultures/globalize.culture.' + elt;
}), function () {
availableCultures = _.pluck(_.filter(globalize.cultures, function (elt, key) {
return key !== 'default' && (key !== 'en' || _.contains(config.available, 'en'));
availableCultures = _.map(_.filter(globalize.cultures, function (elt, key) {
return key !== 'default' && (key !== 'en' || includes(config.available, 'en'));
}), 'name');

availableCultureObjects = _.map(availableCultures, function (name) {
Expand Down
59 changes: 30 additions & 29 deletions modules/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ define([
var w20CoreSecurity = angular.module('w20CoreSecurity', ['w20CoreEnv', 'ngResource']),
config = module && module.config() || {},
allProviders = {},
allRealms = {};
allRealms = {},
includes = _.contains || _.includes;

var BasicAuthenticationProvider = ['$resource', '$window', '$q', function ($resource, $window, $q) {
var AuthenticationResource, AuthorizationsResource, realm, authenticationUrl, clearCredentials;
Expand Down Expand Up @@ -364,7 +365,7 @@ define([
return false;
}

return _.all(authProviders, function (provider) {
return _.every(authProviders, function (provider) {
return provider.isAuthentifiable();
});
},
Expand Down Expand Up @@ -395,8 +396,8 @@ define([
deferred = null;

$log.info('subject ' + currentSubject.id + ' authenticated on realm(s): ' + subjects.map(function (elt) {
return elt.realm;
}));
return elt.realm;
}));

/**
* @ngdoc event
Expand Down Expand Up @@ -523,8 +524,8 @@ define([
deferred = null;

$log.info('subject ' + currentSubject.id + ' refreshed on realm(s): ' + subjects.map(function (elt) {
return elt.realm;
}));
return elt.realm;
}));

/**
* @ngdoc event
Expand Down Expand Up @@ -640,7 +641,7 @@ define([
function checkWithAttributeFilter(attributes) {
return !(_.keys(attributeFilter).length > 0 && !_.find(attributeFilter, function (valueToCheck, attributeToCheck) {
if (attributes && attributes[attributeToCheck]) {
return _.contains(attributes[attributeToCheck], '*') || _.contains(attributes[attributeToCheck], valueToCheck);
return includes(attributes[attributeToCheck], '*') || includes(attributes[attributeToCheck], valueToCheck);
} else {
return true;
}
Expand Down Expand Up @@ -757,7 +758,7 @@ define([
invalidAttributes = {};

_.each(value, function (attrValue, attrName) {
if (!_.contains(validAttributes[attrName], attrValue)) {
if (!includes(validAttributes[attrName], attrValue)) {
invalidAttributes[attrName] = attrValue;
}
});
Expand Down Expand Up @@ -840,8 +841,8 @@ define([
}

if (typeof attributes !== 'undefined') {
return _.all(attributes, function (value, attribute) {
return _.contains(roleDefinition.$attributes[attribute], value);
return _.every(attributes, function (value, attribute) {
return includes(roleDefinition.$attributes[attribute], value);
});
} else {
return true;
Expand Down Expand Up @@ -870,20 +871,20 @@ define([
}

if (values.length === 0) {
var result = _.any(parent.$roles, function (role) {
return checkWithRoleFilter(currentRoles[realm][role] && currentRoles[realm][role].$unifiedRole);
}) && checkWithAttributeFilter(parent.$attributes);
var result = _.some(parent.$roles, function (role) {
return checkWithRoleFilter(currentRoles[realm][role] && currentRoles[realm][role].$unifiedRole);
}) && checkWithAttributeFilter(parent.$attributes);

if (typeof attributes === 'undefined') {
return result; // no attribute check, return the result as-is
} else {
return result && _.all(attributes, function (value, attribute) {
return _.contains(parent.$attributes[attribute], '*') || _.contains(parent.$attributes[attribute], value);
});
return result && _.every(attributes, function (value, attribute) {
return includes(parent.$attributes[attribute], '*') || includes(parent.$attributes[attribute], value);
});
}
}

return _.all(values.shift().split(','), function (value) {
return _.every(values.shift().split(','), function (value) {
if (value.indexOf('$') === 0) {
throw new Error('permissions cannot start with a $');
}
Expand Down Expand Up @@ -992,20 +993,20 @@ define([
_.each(config.roleMapping, function (definition, name) {
var mergedAttributes = {};

if (_.all(definition, function (role, realm) {
var realRole = currentRoles[realm] && currentRoles[realm][role];
if (realRole) {
_.map(realRole.$attributes, function (values, attribute) {
mergedAttributes[attribute] = _.union(values, mergedAttributes[attribute] || []);
});
if (_.every(definition, function (role, realm) {
var realRole = currentRoles[realm] && currentRoles[realm][role];
if (realRole) {
_.map(realRole.$attributes, function (values, attribute) {
mergedAttributes[attribute] = _.union(values, mergedAttributes[attribute] || []);
});

realRole.$unifiedRole = name;
realRole.$unifiedRole = name;

return true;
} else {
return false;
}
})) {
return true;
} else {
return false;
}
})) {
unifiedRoles[name] = {
$attributes: mergedAttributes
};
Expand Down
23 changes: 15 additions & 8 deletions modules/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ define([
*/
var w20CoreUI = angular.module('w20CoreUI', ['w20CoreEnv', 'w20CoreSecurity', 'w20CoreCulture']),
config = module && module.config() || {},
allNavigation = {};
allNavigation = {},
includes = _.contains || _.includes;

/**
* @ngdoc service
Expand Down Expand Up @@ -329,7 +330,7 @@ define([
_.each(keys, function (key) {
while (key.lastIndexOf('.') > 0) {
key = key.substring(0, key.lastIndexOf('.'));
if (!_.contains(keys, key)) {
if (!includes(keys, key)) {
pathByCategory[key] = [];
}
}
Expand Down Expand Up @@ -462,12 +463,18 @@ define([
if (!parentMenuTree) {
return null;
}
return _.sortBy(_.compact(_.filter(_.values(parentMenuTree),
return _.sortBy(
_.compact(
_.filter(_.values(parentMenuTree), function (elt) {
return _.isArray(elt);
}).concat(_.map(_.compact(parentMenuTree), 'route'))
),
function (elt) {
return _.isArray(elt);
}).concat(_.pluck(_.compact(parentMenuTree), 'route'))),
function (elt) {
return typeof elt.categoryPosition !== 'undefined' ? elt.categoryPosition : (typeof elt.sortKey !== 'undefined' ? elt.sortKey : elt);
if (_.isArray(elt)) {
return elt.categoryPosition || 0;
} else {
return 1000000 + elt.sortKey || 0;
}
});
},

Expand Down Expand Up @@ -659,7 +666,7 @@ define([
}

function getAll() {
return _.pluck(_.sortBy(_.filter(items, function (item) {
return _.map(_.sortBy(_.filter(items, function (item) {
return !item.security || securityExpressionService.evaluate(item.security);
}), 'sortKey'), 'name');
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@w20/w20",
"version": "2.4.5",
"version": "2.4.6",
"description": "W20 Web framework",
"license": "MPL-2.0",
"contributors": [
Expand Down Expand Up @@ -43,7 +43,7 @@
"globalize": "^0.1.1",
"jgrowl": "^1.4.6",
"jquery": "^3.0.0",
"lodash": "^2.4.2",
"lodash": "^4.17.10",
"require-css": "^0.1.10",
"requirejs": "^2.1.22",
"requirejs-text": "^2.0.15",
Expand Down
2 changes: 1 addition & 1 deletion specs/notification.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ define([

var notifications = notificationHistoryService.getNotifications();

expect(_.pluck(notifications, 'id')).toEqual([1, 2, 3, 4, 5]);
expect(_.map(notifications, 'id')).toEqual([1, 2, 3, 4, 5]);
});

it('should be able to get clear all notifications', function() {
Expand Down
10 changes: 9 additions & 1 deletion specs/ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ define([
testRoute11: {
category: 'category1.category11'
},
testRoute12: {
category: 'category1.category12'
},
testRoute122: {
category: 'category1.category12'
},
testRouteInvisible: {
category: 'invisible',
hidden: true
Expand Down Expand Up @@ -226,7 +232,9 @@ define([
subSubTree = navigationService.computeSubTree(subTree[0]);
expect(subSubTree[0]).toEqual(jasmine.any(Array));
expect(subSubTree[0][0].category).toEqual('category1.category11');
expect(subSubTree[1].category).toEqual('category1');
expect(subSubTree[1][0].category).toEqual('category1.category12');
expect(subSubTree[1][1].category).toEqual('category1.category12');
expect(subSubTree[2].category).toEqual('category1');

subSubTree = navigationService.computeSubTree(subTree[1]);
expect(subSubTree[0]).toEqual(jasmine.any(Array));
Expand Down
6 changes: 1 addition & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1665,11 +1665,7 @@ lodash@3.x, lodash@^3.10.1, lodash@^3.8.0:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"

lodash@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-2.4.2.tgz#fadd834b9683073da179b3eae6d9c0d15053f73e"

lodash@^4.0.0, lodash@^4.0.1, lodash@^4.17.0, lodash@~4.17.10, lodash@~4.17.5:
lodash@^4.0.0, lodash@^4.0.1, lodash@^4.17.0, lodash@^4.17.10, lodash@~4.17.10, lodash@~4.17.5:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"

Expand Down

0 comments on commit 5fedb66

Please sign in to comment.