Skip to content

Commit

Permalink
chore: update methods to lodash 4 version
Browse files Browse the repository at this point in the history
  • Loading branch information
taopkorczak committed Dec 28, 2023
1 parent 362b82c commit e79c8bf
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion views/js/controller/creator/encoders/dom2qti.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ define([
* @returns {Array}
*/
function getAttributes(object) {
return _.omit(object, [
return _.omitBy(object, [
'qti-type',
'content',
'xmlBase',
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 _.uniqBy(_.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
2 changes: 1 addition & 1 deletion views/js/controller/runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ define([
providerLoader(config.providers, context.bundle)
.then(function (results) {

const testRunnerConfig = _.omit(config, ['providers']);
const testRunnerConfig = _.omitBy(config, ['providers']);
testRunnerConfig.renderTo = $container;

if (results.proxy && typeof results.proxy.getAvailableProviders === 'function') {
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
8 changes: 4 additions & 4 deletions views/js/test/creator/helpers/scoring/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ define([

modelOverseer.on('scoring-write', function(writtenModel) {

model = _.omit(model, 'scoring');
writtenModel = _.omit(writtenModel, 'scoring');
model = _.omitBy(model, 'scoring');
writtenModel = _.omitBy(writtenModel, 'scoring');

assert.deepEqual(writtenModel, data.expected, 'The written model is as expected');
assert.deepEqual(model, data.expected, 'The score processing has been set');
Expand All @@ -293,8 +293,8 @@ define([

modelOverseer.on('scoring-write', function(writtenModel) {

model = _.omit(model, 'scoring');
writtenModel = _.omit(writtenModel, 'scoring');
model = _.omitBy(model, 'scoring');
writtenModel = _.omitBy(writtenModel, 'scoring');

assert.deepEqual(writtenModel, scoringCustomSample, 'The written model is as expected');
assert.deepEqual(model, scoringCustomSample, 'The score processing has been set');
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
2 changes: 1 addition & 1 deletion views/js/testRunner/actionBar/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ define([
* @returns {button}
*/
init : function init(id, config, testContext, testRunner) {
this.config = _.omit(config || {}, function(value) {
this.config = _.omitBy(config || {}, function(value) {
return value === undefined || value === null;
});
this.config.id = id;
Expand Down
2 changes: 1 addition & 1 deletion views/js/testRunner/testMetaData.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* Data for each service call id will be stored in local storage to be able get data
* after reloading the page or resuming the test session.
*
* To clear all data related to current test_call_id used <i>clearData</i> method.
* To clear all data related to current test_.every_id used <i>clearData</i> method.
*/
define([
'lodash'
Expand Down

0 comments on commit e79c8bf

Please sign in to comment.