diff --git a/app/index.html b/app/index.html index 414f6139..4f119665 100644 --- a/app/index.html +++ b/app/index.html @@ -210,6 +210,7 @@
+ diff --git a/app/scripts/contenteditor/manager/stage-manager.js b/app/scripts/contenteditor/manager/stage-manager.js index d5f33782..6778d825 100644 --- a/app/scripts/contenteditor/manager/stage-manager.js +++ b/app/scripts/contenteditor/manager/stage-manager.js @@ -272,7 +272,9 @@ org.ekstep.contenteditor.stageManager = new (Class.extend({ content.theme['migration-media'].media = _.values(org.ekstep.contenteditor.mediaManager.migratedMediaMap) } content.theme.manifest.media = _.uniqBy(_.concat(content.theme.manifest.media, _.values(mediaMap)), 'id') - + if (!_.isEmpty(org.ekstep.contenteditor.migration.patch)) { + content.theme['patch'] = org.ekstep.contenteditor.migration.patch.toString() + } return _.cloneDeep(content) }, manifestGenerator: function (content) { diff --git a/app/scripts/contenteditor/migration/1_migration-task.js b/app/scripts/contenteditor/migration/1_migration-task.js index f1c970e7..33540e64 100644 --- a/app/scripts/contenteditor/migration/1_migration-task.js +++ b/app/scripts/contenteditor/migration/1_migration-task.js @@ -3,17 +3,23 @@ org.ekstep.contenteditor.migration = new (Class.extend({ migrationFlag: false, contentBackup: undefined, + patch: [], init: function () { org.ekstep.contenteditor.api.addEventListener('content:migration:start', this.execute, this) }, _startTime: undefined, tasks: ['mediamigration_task', 'basestage_task', 'orderstage_task', 'scribblemigration_task', 'imagemigration_task', 'readalongmigration_task', 'assessmentmigration_task', 'eventsmigration_task', 'settagmigration_task'], + questionPatchs: ['patch_1'], migrationErrors: [], execute: function (event, data) { + var instance = this var contentbody = data.body; var stageIcons = data.stageIcons this.contentBackup = _.cloneDeep(contentbody) if (!_.has(contentbody, 'theme.stage')) org.ekstep.services.telemetryService.error({ 'env': 'content', 'stage': '', 'action': 'migration', 'objectId': '', objectType: '', 'err': 'migration has errors', 'type': 'PORTAL', 'data': '', 'severity': 'error' }) + if (contentbody.theme && contentbody.theme.patch) { + this.patch = contentbody.theme.patch.split(',') + } if (this.isOldContent(contentbody)) { this.initLoadScreenMsg() this._startTime = (new Date()).getTime() @@ -21,11 +27,34 @@ org.ekstep.contenteditor.migration = new (Class.extend({ org.ekstep.contenteditor.migration[task].migrate(contentbody) }) this.postMigration(contentbody, stageIcons) + } else if (this.isAssessmentContent(contentbody)) { + this._startTime = (new Date()).getTime() + console.info('Question media migration started!') + _.forEach(this.questionPatchs, function (task) { + if (_.indexOf(instance.patch, task) === -1) { + org.ekstep.contenteditor.migration[task].migrate(contentbody) + } + }) + this.postQuestionMediaMigration(contentbody, stageIcons) } else { console.info('no need for migration') org.ekstep.contenteditor.stageManager.fromECML(contentbody, stageIcons) } }, + postQuestionMediaMigration: function (content, stageIcons) { + var instance = this + console.info('Question media migration completed!') + org.ekstep.contenteditor.stageManager.fromECML(content, stageIcons) + org.ekstep.services.telemetryService.log({ + type: 'process', + level: 'TRACE', + message: 'duration for question media migration', + params: [{ + // eslint-disable-next-line + duration: (new Date()).getTime() - instance._startTime + }] + }) + }, postMigration: function (content, stageIcons) { var instance = this org.ekstep.services.telemetryService.log({ @@ -82,5 +111,30 @@ org.ekstep.contenteditor.migration = new (Class.extend({ }, getBackupContent: function () { return this.contentBackup + }, + isAssessmentContent: function (contentbody) { + var instance = this + var assessmentContent = false + if (_.isEqual(_.sortBy(instance.patch), _.sortBy(instance.questionPatchs))) { + return false + } + _.forEach(contentbody.theme.stage, function (stage) { + _.forEach(stage['org.ekstep.questionset'], function (qSet, index) { + if (_.isArray(qSet['org.ekstep.question'])) { + _.forEach(qSet['org.ekstep.question'], function (question) { + if (question.pluginId === 'org.ekstep.questionset.quiz') { + return + } + assessmentContent = true + }) + } else { + if (qSet.pluginId === 'org.ekstep.questionset.quiz') { + return + } + assessmentContent = true + } + }) + }) + return assessmentContent } }))() diff --git a/app/scripts/contenteditor/migration/questionsetfix1-task.js b/app/scripts/contenteditor/migration/questionsetfix1-task.js new file mode 100644 index 00000000..8d08d5c9 --- /dev/null +++ b/app/scripts/contenteditor/migration/questionsetfix1-task.js @@ -0,0 +1,150 @@ +'use strict' + +org.ekstep.contenteditor.migration.patch_1 = new (Class.extend({ + init: function () { + }, + id: 'patch_1', + _startTime: undefined, + contentbody: undefined, + assetHostPaths: [ + 'https://ntpproductionall.blob.core.windows.net/ntp-content-production/', + 'https://ntpstagingall.blob.core.windows.net/ntp-content-staging/', + 'https://preprodall.blob.core.windows.net/ntp-content-preprod/', + 'https://sunbirddev.blob.core.windows.net/sunbird-content-dev/', + 'https://s3.ap-south-1.amazonaws.com/ekstep-public-dev/', + 'https://ekstep-public-dev.s3-ap-south-1.amazonaws.com/', + 'https://s3.ap-south-1.amazonaws.com/ekstep-public-qa/', + 'https://ekstep-public-qa.s3-ap-south-1.amazonaws.com/', + 'https://s3.ap-south-1.amazonaws.com/ekstep-public-preprod/', + 'https://ekstep-public-preprod.s3-ap-south-1.amazonaws.com/', + 'https://s3.ap-south-1.amazonaws.com/ekstep-public-prod/', + 'https://ekstep-public-prod.s3-ap-south-1.amazonaws.com/' + ], + migrate: function (contentbody) { + var instance = this + this._startTime = (new Date()).getTime() + this.contentbody = contentbody + _.forEach(contentbody.theme.stage, function (stage) { + if (stage['org.ekstep.questionset']) { + if (_.isArray(stage['org.ekstep.questionset'])) { + _.forEach(stage['org.ekstep.questionset'], function (qSet, index) { + _.forEach(qSet['org.ekstep.question'], function (question, qindex) { + if (question.pluginId === 'org.ekstep.questionset.quiz') { + return + } + var fixedQuestion = instance.updateQuestionMedia(question) + qSet['org.ekstep.question'][qindex] = fixedQuestion + instance.contentbody.theme.manifest.media = instance.updateContentManifestMedia(instance.contentbody.theme.manifest.media, fixedQuestion) + }) + }) + } else if (_.isObject(stage['org.ekstep.questionset'])) { + var question = stage['org.ekstep.questionset']['org.ekstep.question'] + if (question.pluginId === 'org.ekstep.questionset.quiz') { + return + } + var fixedQuestion = instance.updateQuestionMedia(question) + stage['org.ekstep.questionset']['org.ekstep.question'] = fixedQuestion + instance.contentbody.theme.manifest.media = instance.updateContentManifestMedia(instance.contentbody.theme.manifest.media, fixedQuestion) + } + } + }) + org.ekstep.contenteditor.migration.patch.push(instance.id) + org.ekstep.services.telemetryService.log({ + type: 'process', + level: 'TRACE', + message: 'questionsetfix_1 migration complted', + params: [{ + // eslint-disable-next-line + duration: (new Date()).getTime() - instance._startTime + }] + }) + }, + updateContentManifestMedia: function (contentMedia, question) { + var questionMedia = JSON.parse(question.data.__cdata).media + _.each(questionMedia, function (media) { + if (_.isUndefined(_.find(contentMedia, { 'src': media.src }))) { + contentMedia.push(media) + org.ekstep.contenteditor.mediaManager.addToMigratedMedia(media) + } + }) + return contentMedia + }, + updateQuestionMedia: function (question) { + var instance = this + var questionData = JSON.parse(question.data.__cdata) + var quesAssets = [] + + // For Question Title + if (questionData.question) { + instance.addAssets(questionData.question, quesAssets) + } + + // For Question Options + if (questionData.options) { + // For MCQ + _.each(questionData.options, function (o) { + instance.addAssets(o, quesAssets) + }) + } + + if (questionData.option) { + // For MTF + if (questionData.option.optionsLHS) { + _.each(questionData.option.optionsLHS, function (o) { + instance.addAssets(o, quesAssets) + }) + } + if (questionData.option.optionsRHS) { + _.each(questionData.option.optionsRHS, function (o) { + instance.addAssets(o, quesAssets) + }) + } + } + + _.each(questionData.media, function (media) { + media.src = instance.getRelativeURL(media.src) + }) + _.each(quesAssets, function (quesAsset) { + // quesAsset.url = getRelativeURL(quesAsset.url); + var mediaExist = _.find(questionData.media, function (m) { + return m.src === quesAsset.src + }) + if (!mediaExist) { + questionData.media.push(instance.getMediaObj(quesAsset.src, quesAsset.type)) + } + }) + question.data['__cdata'] = JSON.stringify(questionData) + return question + }, + addAssets: function (obj, targetArray) { + var instance = this + if (obj.image) { + obj.image = instance.getRelativeURL(obj.image) + targetArray.push({ 'type': 'image', 'src': obj.image }) + } + if (obj.audio) { + obj.audio = instance.getRelativeURL(obj.audio) + targetArray.push({ 'type': 'audio', 'src': obj.audio }) + } + }, + getRelativeURL: function (src) { + var instance = this + var relativeURLPrefix = '/assets/public/' + _.forEach(instance.assetHostPaths, function (url) { + if (src.indexOf(url) !== -1) { + src = src.replace(url, relativeURLPrefix) + } + }) + return src + }, + getMediaObj: function (src, type) { + var mediaId = Math.floor(Math.random() * 1000000000) + return { + 'id': mediaId + '-1', + 'src': src, + 'assetId': mediaId, + 'type': type, + 'preload': false + } + } +}))() diff --git a/gulpfile.js b/gulpfile.js index 9053dd2e..b0b97ceb 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -90,6 +90,7 @@ var contentEditorApp = [ "app/scripts/contenteditor/migration/eventsmigration-task.js", "app/scripts/contenteditor/migration/settagmigration-task.js", "app/scripts/contenteditor/migration/textmigration-task.js", + "app/scripts/contenteditor/migration/questionsetfix1-task.js", "app/scripts/contenteditor/manager/stage-manager.js" ]; diff --git a/webpack.config.js b/webpack.config.js index c708475d..7aa0e73d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -104,6 +104,7 @@ var EDITOR_APP = [ "./app/scripts/contenteditor/migration/eventsmigration-task.js", "./app/scripts/contenteditor/migration/settagmigration-task.js", "./app/scripts/contenteditor/migration/textmigration-task.js", + "./app/scripts/contenteditor/migration/questionsetfix1-task.js", "./app/scripts/contenteditor/manager/stage-manager.js" ]; const APP_STYLE = [