Skip to content

Commit

Permalink
Merge pull request #2431 from oat-sa/feature/ADF-1579/update-lodash-to-4
Browse files Browse the repository at this point in the history
chore: update methods to lodash 4 version
  • Loading branch information
taopkorczak authored Feb 2, 2024
2 parents b45217e + 3fde131 commit 4707d6c
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"qtism/qtism": ">=0.28.3",
"oat-sa/generis" : ">=15.22",
"oat-sa/tao-core": ">=53.0.0",
"oat-sa/tao-core": ">=54.0.0",
"oat-sa/extension-tao-item" : ">=12.1.0",
"oat-sa/extension-tao-itemqti" : ">=30.0.0",
"oat-sa/extension-tao-test" : ">=16.0.0",
Expand Down
17 changes: 9 additions & 8 deletions views/js/controller/creator/encoders/dom2qti.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ define([
nodeName = normalizeNodeName(elt.nodeName);

object = _.merge(qtiElementHelper.create(nodeName, {
'id': '',
'class': '',
'xmlBase': '',
'lang': '',
'label': ''
}),
_.transform(elt.attributes, function (acc, value) {
'id': '',
'class': '',
'xmlBase': '',
'lang': '',
'label': ''
}), {
...(_.transform(elt.attributes, function (acc, value) {
const attrName = normalizeNodeName(value.nodeName);
if (attrName) {
if (typedAttributes[nodeName] && typedAttributes[nodeName][attrName]) {
Expand All @@ -171,7 +171,8 @@ define([
acc[attrName] = value.nodeValue;
}
}
}));
}))
});
if (elt.childNodes.length > 0) {
object.content = self.decode(elt.childNodes);
}
Expand Down
2 changes: 1 addition & 1 deletion views/js/controller/creator/helpers/categorySelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ define([
*/
function extractCategoriesFromPresets() {
return allPresets.reduce(function (prev, current) {
const groupIds = _.pluck(current.presets, 'qtiCategory');
const groupIds = _.map(current.presets, 'qtiCategory');
return prev.concat(groupIds);
}, []);
}
Expand Down
2 changes: 1 addition & 1 deletion views/js/controller/creator/helpers/outcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ define([
if (_.isFunction(outcomes)) {
check = outcomes;
} else {
outcomes = _.indexBy(_.isArray(outcomes) ? outcomes : [outcomes], function (outcome) {
outcomes = _.keyBy(_.isArray(outcomes) ? outcomes : [outcomes], function (outcome) {
return outcome;
});

Expand Down
6 changes: 3 additions & 3 deletions views/js/controller/creator/helpers/qtiTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ define(['jquery', 'lodash', 'taoQtiTest/controller/creator/helpers/validators'],
* @returns {String[]} the list of unique identifiers
*/
getIdentifiers: function getIdentifiers(model, includesOnlyTypes, excludeTypes) {
return _.uniq(_.pluck(validators.extractIdentifiers(model, includesOnlyTypes, excludeTypes), 'identifier'));
return _.uniq(_.map(validators.extractIdentifiers(model, includesOnlyTypes, excludeTypes), 'identifier'));
},

/**
Expand Down Expand Up @@ -151,7 +151,7 @@ define(['jquery', 'lodash', 'taoQtiTest/controller/creator/helpers/validators'],
const glue = '-';
let identifier;
let current;
if (_.contains(validators.qtiTypesForUniqueIds, qtiType)) {
if (_.includes(validators.qtiTypesForUniqueIds, qtiType)) {
current = this.getIdentifiers(model, validators.qtiTypesForUniqueIds);
} else {
current = this.getIdentifiersOf(model, qtiType);
Expand All @@ -162,7 +162,7 @@ define(['jquery', 'lodash', 'taoQtiTest/controller/creator/helpers/validators'],
do {
identifier = suggestion + glue + index++;
} while (
_.contains(current, identifier.toUpperCase()) || // identifier exist in model
_.includes(current, identifier.toUpperCase()) || // identifier exist in model
$(`#${identifier}`).length // identifier was in model but still exist in DOM
);

Expand Down
2 changes: 1 addition & 1 deletion views/js/controller/creator/helpers/scoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ define([
* @param {Object} model
*/
function removeScoring(model) {
var scoringOutcomes = _.indexBy(outcomeHelper.listOutcomes(model, getOutcomesRecipe), function (outcome) {
var scoringOutcomes = _.keyBy(outcomeHelper.listOutcomes(model, getOutcomesRecipe), function (outcome) {
return outcome;
});

Expand Down
4 changes: 2 additions & 2 deletions views/js/controller/creator/helpers/sectionCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ define(['lodash', 'i18n', 'core/errorHandler'], function (_, __, errorHandler) {
*/
function addCategories(model, categories) {
if (isValidSectionModel(model)) {
_.each(model.sectionParts, function (sectionPart) {
_.forEach(model.sectionParts, function (sectionPart) {
if (sectionPart['qti-type'] === 'assessmentItemRef') {
if (!_.isArray(sectionPart.categories)) {
sectionPart.categories = [];
Expand All @@ -141,7 +141,7 @@ define(['lodash', 'i18n', 'core/errorHandler'], function (_, __, errorHandler) {
*/
function removeCategories(model, categories) {
if (isValidSectionModel(model)) {
_.each(model.sectionParts, function (sectionPart) {
_.forEach(model.sectionParts, function (sectionPart) {
if (sectionPart['qti-type'] === 'assessmentItemRef' && _.isArray(sectionPart.categories)) {
sectionPart.categories = _.difference(sectionPart.categories, categories);
}
Expand Down
6 changes: 3 additions & 3 deletions views/js/controller/creator/helpers/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ define([
function validateModel(model) {
const identifiers = extractIdentifiers(model, qtiTypesForUniqueIds);
let nonUniqueIdentifiers = 0;
const outcomes = _.indexBy(outcomeHelper.listOutcomes(model));
const outcomes = _.keyBy(outcomeHelper.listOutcomes(model));
let messageDetails = '';

_(identifiers)
Expand Down Expand Up @@ -165,7 +165,7 @@ define([

const extract = function extract(element) {
if (element && _.has(element, 'identifier') && _.isString(element.identifier)) {
if (!includesOnlyTypes.length || _.contains(includesOnlyTypes, element['qti-type'])) {
if (!includesOnlyTypes.length || _.includes(includesOnlyTypes, element['qti-type'])) {
identifiers.push({
identifier: element.identifier.toUpperCase(),
originalIdentifier: element.identifier,
Expand All @@ -176,7 +176,7 @@ define([
}
_.forEach(element, function (subElement) {
if (_.isPlainObject(subElement) || _.isArray(subElement)) {
if (!excludeTypes.length || !_.contains(excludeTypes, subElement['qti-type'])) {
if (!excludeTypes.length || !_.includes(excludeTypes, subElement['qti-type'])) {
extract(subElement);
}
}
Expand Down
4 changes: 2 additions & 2 deletions views/js/controller/runtime/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ function (
*/
isCurrentItemAnswered: function(){
var answered = false;
_.each(this.getCurrentItemState(), function(state){
_.forEach(this.getCurrentItemState(), function(state){
if(state && _.isObject(state.response) && state.response.base !== null){
answered = true;//at least one response is not null so consider the item answered
return false;
Expand Down Expand Up @@ -789,7 +789,7 @@ function (
if (self.testContext.timerWarning && self.testContext.timerWarning[cst.qtiClassName]) {
cst.warnings = {};
_(self.testContext.timerWarning[cst.qtiClassName]).forEach(function (value, key) {
if (_.contains(['info', 'warning', 'danger'], value)) {
if (_.includes(['info', 'warning', 'danger'], value)) {
cst.warnings[key] = {
type: value,
showed: cst.seconds <= key,
Expand Down
2 changes: 1 addition & 1 deletion views/js/test/runner/mocks/areaBrokerMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ define(['jquery', 'lodash', 'ui/areaBroker', 'taoQtiTest/runner/ui/toolbox/toolb
if (!config.areas) {
config.areas = config.defaultAreas;
} else {
config.areas = _.keys(_.merge(_.object(config.areas), _.object(config.defaultAreas)));
config.areas = _.keys(_.merge(_.fromPairs(config.areas), _.fromPairs(config.defaultAreas)));
}

_.forEach(config.areas, areaId => {
Expand Down

0 comments on commit 4707d6c

Please sign in to comment.