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

chore: update methods to lodash 4 verios #2426

Merged
merged 18 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -73,7 +73,7 @@ define([
levelData = {};

//build select option data for the template
_.each(levels, function(lvl){
_.forEach(levels, function(lvl){
levelData[lvl] = {
label : lvl,
selected : (lvl === level)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ define([
levelData = {};

//build select option data for the template
_.each(levels, function(lvl){
_.forEach(levels, function(lvl){
levelData[lvl] = {
label : lvl,
selected : (lvl === level)
Expand Down
6 changes: 3 additions & 3 deletions views/js/legacyPortableSharedLib/OAT/sts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ define([

function init($container, config) {
config.is = config.is || {};

// just in case...
if(!$container.length){
return;
Expand Down Expand Up @@ -135,7 +135,7 @@ define([

// set up the controls for resize, rotate etc.
setupControls($container, $controls);

if (config.is.movable) {

$content.on('mousedown', function () {
Expand All @@ -160,7 +160,7 @@ define([
});
}

if (_.any(config.is.rotatable)) {
if (_.some(config.is.rotatable)) {
rotator.init(tool, handleSelector);
}
}
Expand Down
2 changes: 1 addition & 1 deletion views/js/portableElementRegistry/ciRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define(['lodash', 'taoQtiItem/portableElementRegistry/factory/ciRegistry', 'modu
providers = config.providers;
}

_.each(providers, function(provider){
_.forEach(providers, function(provider){
if(provider.name && provider.module){
registry.registerProvider(provider.module);
}
Expand Down
4 changes: 2 additions & 2 deletions views/js/portableElementRegistry/factory/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ define(['lodash', 'core/promise', 'core/eventifier'], function (_, Promise, even
}
});
_requirejs(providerLoadingStack, function(){
_.each([].slice.call(arguments), function(provider){
_.forEach([].slice.call(arguments), function(provider){
if(isPortableElementProvider(provider)){
__providers[providerLoadingStack.shift()] = provider;
}
Expand Down Expand Up @@ -383,7 +383,7 @@ define(['lodash', 'core/promise', 'core/eventifier'], function (_, Promise, even
//@todo support caching?
_requirejs(requiredCreatorHooks, function (){
var creators = {};
_.each(arguments, function (creatorHook){
_.forEach(arguments, function (creatorHook){
var id = creatorHook.getTypeIdentifier();
var portableElementModel = self.get(id);
var i = _.findIndex(self._registry[id], {version : portableElementModel.version});
Expand Down
2 changes: 1 addition & 1 deletion views/js/portableElementRegistry/icRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define(['lodash', 'taoQtiItem/portableElementRegistry/factory/icRegistry', 'modu
providers = config.providers;
}

_.each(providers, function(provider){
_.forEach(providers, function(provider){
if(provider.name && provider.module){
registry.registerProvider(provider.module);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ define(['lodash', 'context', 'core/promise'], function(_, context, Promise){
});
require(_requiredManifests, function(){
var ok = true;
_.each([].slice.call(arguments), function(manifest){
_.some([].slice.call(arguments), function(manifest){
var id;
if(manifest && manifest.typeIdentifier){
id = manifest.typeIdentifier;
if(!_portableElementManifests[id]){
reject('typeIdentifier mismatch');
ok = false;
return false;
return true;
}

manifest = useSource(manifest);
Expand Down
6 changes: 3 additions & 3 deletions views/js/portableLib/OAT/sts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ define([

function init($container, config) {
config.is = config.is || {};

// just in case...
if(!$container.length){
return;
Expand Down Expand Up @@ -135,7 +135,7 @@ define([

// set up the controls for resize, rotate etc.
setupControls($container, $controls);

if (config.is.movable) {

$content.on('mousedown', function () {
Expand All @@ -160,7 +160,7 @@ define([
});
}

if (_.any(config.is.rotatable)) {
if (_.some(config.is.rotatable)) {
rotator.init(tool, handleSelector);
}
}
Expand Down
2 changes: 1 addition & 1 deletion views/js/qtiCreator/editor/MathEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ define([
callback : null
};

_.each(args, function(arg){
_.forEach(args, function(arg){
if(_.isFunction(arg)){
ret.callback = arg;
}else if(arg instanceof $){
Expand Down
2 changes: 1 addition & 1 deletion views/js/qtiCreator/editor/ckEditor/groupToggler.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ define(['lodash', 'core/eventifier'], function(_, eventifier){
}
}).on('show', function(id){

_.each(_registry, function(element){
_.forEach(_registry, function(element){
if(element.id !== id){
//a single element has been shown, informe the others
element.dom.trigger('showanother.grouptoggler', id);
Expand Down
6 changes: 3 additions & 3 deletions views/js/qtiCreator/editor/ckEditor/htmlEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ define([
options = options || {};

//re-init all widgets:
_.each(_.values(container.elements), function (elt) {
_.forEach(_.values(container.elements), function (elt) {
const widget = elt.data('widget'),
currentState = widget.getCurrentState().name;

Expand Down Expand Up @@ -400,7 +400,7 @@ define([
const deleted = [];
const container = $container.data('qti-container');

_.each(widgets, function (w) {
_.forEach(widgets, function (w) {
if (!w.element.data('removed')) {
const $widget = _findWidgetContainer($container, w.serial);
if (!$widget.length) {
Expand All @@ -415,7 +415,7 @@ define([

$messageBox
.on('confirm.deleting', function () {
_.each(deleted, function (w) {
_.forEach(deleted, function (w) {
w.element.remove();
w.destroy();
});
Expand Down
4 changes: 2 additions & 2 deletions views/js/qtiCreator/editor/containerEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ define([
container.setRootElement(item);

if (options.metadata) {
_.each(options.metadata, function (value, name) {
_.forEach(options.metadata, function (value, name) {
item.data(name, value);
});
}
Expand All @@ -150,7 +150,7 @@ define([
container.postRender();

//resolve xinclude
_.each(container.getComposingElements(), function(element){
_.forEach(container.getComposingElements(), function(element){
if(element.qtiClass === 'include'){
xincludeRenderer.render(element.data('widget'), baseUrl);
}
Expand Down
2 changes: 1 addition & 1 deletion views/js/qtiCreator/editor/elementSelector/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ define([
function _renderContent(interactions){

var groups = [];
_.each(_filterInteractions(interactions), function(interaction){
_.forEach(_filterInteractions(interactions), function(interaction){

var groupName = interaction.tags[0];
var panel = _.find(groups, {name : groupName});
Expand Down
2 changes: 1 addition & 1 deletion views/js/qtiCreator/editor/gridEditor/droppable.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ define([
}else{
$newCol.attr('class', 'new-col col-' + distributedUnits.middle);
}
_.each(distributedUnits.cols, function(col){
_.forEach(distributedUnits.cols, function(col){
col.elt.attr('class', 'col-' + col.refactoredUnits);
});
}
Expand Down
2 changes: 1 addition & 1 deletion views/js/qtiCreator/editor/interactionsToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ define([

function create($sidebar, interactions){

_.each(interactions, function(interactionAuthoringData){
_.forEach(interactions, function(interactionAuthoringData){
add($sidebar, interactionAuthoringData);
});

Expand Down
20 changes: 10 additions & 10 deletions views/js/qtiCreator/editor/response/choiceSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,27 @@ define([
var choices = this.config.interaction.getChoices();
var response = this.config.interaction.getResponseDeclaration();
var config = _.defaults(this.config || {}, _defaults);

config.multiple = response.isCardinality(['multiple', 'ordered']);
config.options = [];

_.each(choices, function(choice) {
_.some(choices, function(choice) {
var id = choice.id();
var choiceText = '';
var option = {
value: id,
label: id,
selected: selected.indexOf(id) > -1
};

if(choice.is('containerChoice')){
choiceText = choice.body();
}else if(choice.is('textVariableChoice')){
choiceText = choice.val();
}else{
return;//not available yet
return true;//not available yet
taopkorczak marked this conversation as resolved.
Show resolved Hide resolved
}

// 0 as titleLength => no title
if(config.titleLength) {
option.title = createOptionTitle(choiceText, config.titleLength);
Expand All @@ -111,7 +111,7 @@ define([

var self = this;
var $selectBox = this.$component.find('select');

$selectBox.select2({
dropdownAutoWidth: true,
placeholder: $selectBox.attr('placeholder'),
Expand All @@ -132,13 +132,13 @@ define([
*
*/
var choiceSelectorFactory = function choiceSelectorFactory(config) {

var _selectedChoices = {};
var choices = {};
_.each(config.interaction.getChoices(), function(choice){
_.forEach(config.interaction.getChoices(), function(choice){
choices[choice.id()] = choice;
});

/**
* Exposed methods
* @type {{getChoices: choiceSelector.getChoices, getSelectedChoices: choiceSelector.getSelectedChoices}}
Expand All @@ -153,7 +153,7 @@ define([
});
}
};

return component(choiceSelector)
.on('init', init)
.on('destroy', destroy)
Expand Down
2 changes: 1 addition & 1 deletion views/js/qtiCreator/editor/styleEditor/fontSizeChanger.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ define(['jquery', 'lodash', 'taoQtiItem/qtiCreator/editor/styleEditor/styleEdito
*/
$input.on('keydown', function (e) {
const c = e.keyCode;
return _.contains([8, 37, 39, 46], c) || (c >= 48 && c <= 57) || (c >= 96 && c <= 105);
return _.includes([8, 37, 39, 46], c) || (c >= 48 && c <= 57) || (c >= 96 && c <= 105);
});

/**
Expand Down
2 changes: 1 addition & 1 deletion views/js/qtiCreator/editor/styleEditor/itemResizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ define([

input.on('keydown', function(e) {
var c = e.keyCode;
return (_.contains([8, 37, 39, 46], c)
return (_.includes([8, 37, 39, 46], c)
|| (c >= 48 && c <= 57)
|| (c >= 96 && c <= 105));
});
Expand Down
2 changes: 1 addition & 1 deletion views/js/qtiCreator/helper/creatorRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define([
var _extractInteractionsConfig = function _extractInteractionsConfig(config){
var ret = {};
if(config && config.properties){
_.each(_configurableInteractions, function(interactionName){
_.forEach(_configurableInteractions, function(interactionName){
if(config.properties[interactionName]){
ret[interactionName] = config.properties[interactionName];
}
Expand Down
2 changes: 1 addition & 1 deletion views/js/qtiCreator/helper/devTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ define([
var states = {},
elements = item.getComposingElements();

_.each(elements, function(element){
_.forEach(elements, function(element){
var widget = element.data('widget');
if(widget){
states[element.getSerial()] = widget.getCurrentState().name;
Expand Down
18 changes: 9 additions & 9 deletions views/js/qtiCreator/helper/gridUnits.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ define(['lodash'], function(_){
positive = [],
ret = [];

_.each(cols, function(col){
_.forEach(cols, function(col){
_cols.push(col);
totalUnits += col.units;
});
Expand All @@ -132,7 +132,7 @@ define(['lodash'], function(_){
throw 'the total number of units exceed the maximum of ' + max;
}

_.each(_cols, function(col){
_.forEach(_cols, function(col){

var refactoredUnits = col.units * max / totalUnits;
var rounded = Math.round(refactoredUnits);
Expand All @@ -155,31 +155,31 @@ define(['lodash'], function(_){
//too much !

//@todo : start with the hightest refactored
_.eachRight(positive, function(col){
for (let i = positive.length - 1; i >= 0; i--) {
taopkorczak marked this conversation as resolved.
Show resolved Hide resolved
col.refactoredUnits --;
totalRefactoredUnits--;
if(totalRefactoredUnits === max){
return false;
break;
}
});
}

}else if(totalRefactoredUnits < max){

//@todo : start with the lowest refactored
_.each(negative, function(col){
_.some(negative, function(col){
col.refactoredUnits ++;
totalRefactoredUnits++;
if(totalRefactoredUnits === max){
return false;
return true;
}
});

}

_.each(negative, function(col){
_.forEach(negative, function(col){
ret.push(col);
});
_.each(positive, function(col){
_.forEach(positive, function(col){
ret.push(col);
});

Expand Down
4 changes: 2 additions & 2 deletions views/js/qtiCreator/helper/qtiElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ define(['jquery', 'lodash', 'i18n', 'services/features'], function ($, _, __, fe
ret = _.union(ret, QtiElements.getAllowedContents(parents[i], recursive, checked));
}

return _.uniq(ret, false);
return _.uniqBy(ret, false);
},

isAllowedClass(qtiContainerClass, qtiContentClass) {
Expand All @@ -259,7 +259,7 @@ define(['jquery', 'lodash', 'i18n', 'services/features'], function ($, _, __, fe
for (let i in ret) {
ret = _.union(ret, QtiElements.getParentClasses(ret[i], recursive));
}
ret = _.uniq(ret, false);
ret = _.uniqBy(ret, false);
}
}
QtiElements.cache.parents[qtiClass] = ret;
Expand Down
Loading
Loading