From d78862b9798c24bd09502df234cb88524c9076c5 Mon Sep 17 00:00:00 2001 From: Jagadish Pujari Date: Tue, 17 Jul 2018 12:19:36 +0530 Subject: [PATCH 01/11] Issue #15 fix: Metadata form scope related issue --- editor/question-ctrl.js | 3 +- editor/question.js | 504 ---------------------------------------- editor/style.css | 1 + 3 files changed, 3 insertions(+), 505 deletions(-) delete mode 100644 editor/question.js diff --git a/editor/question-ctrl.js b/editor/question-ctrl.js index 174e30c..5e3e7a3 100644 --- a/editor/question-ctrl.js +++ b/editor/question-ctrl.js @@ -150,6 +150,7 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) $scope.showTemplates(); } else { var metaFormScope = $('#question-meta-form #content-meta-form').scope(); + metaFormScope.isSubmit = false; $scope.questionData.questionTitle = metaFormScope.contentMeta.name; $scope.questionData.qcMedium = metaFormScope.contentMeta.medium; $scope.questionData.qcLevel = metaFormScope.contentMeta.level; @@ -199,7 +200,7 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) $scope.sendMetaData = function () { var formElement = $("#questionMetaDataTemplate").find("#content-meta-form"); var frmScope = formElement.scope(); - ecEditor.dispatchEvent("metadata:form:onsuccess", {form: frmScope.metaForm}); + ecEditor.dispatchEvent("metadata:form:onsuccess", {target: '#questionMetaDataTemplate', form: frmScope.metaForm}); }; $scope.saveMetaData = function (event, object) { var metaDataObject = object.formData.metaData; diff --git a/editor/question.js b/editor/question.js deleted file mode 100644 index ae48871..0000000 --- a/editor/question.js +++ /dev/null @@ -1,504 +0,0 @@ -/* - * Plugin to create question - * @class org.ekstep.question.QuestionCreationFormController - * @author Jagadish Pujari - */ -angular.module('org.ekstep.question', ['org.ekstep.metadataform']) - .controller('QuestionCreationFormController', ['$scope', 'instance', 'questionData', function ($scope, instance, questionData) { - var ctrl = this; - ctrl.templatesScreen = true; - ctrl.questionMetadataScreen = false; - ctrl.Totalconcepts = 0; - ctrl.category = ''; - ctrl.editState = false; - ctrl.questionUnitTemplateURL = ''; - ctrl.editMode = false; - ctrl.defaultActiveMenu = 'MCQ'; - ctrl.selectedTemplatePluginData = {}; - ctrl.questionCreationFormData = {}; - ctrl.TotalconceptsData = []; - ctrl.selectedConceptsData = []; - ctrl.questionUnitValidated = false; - ctrl.level = ['EASY', 'MEDIUM', 'DIFFICULT']; - ctrl.conceptsCheck = false; - ctrl.questionData = {'questionMaxScore': 1}; - ctrl.plugins = {'concepts': 'org.ekstep.conceptselector:init'}; - ctrl.templatesType = ['Horizontal', 'Vertical', 'Grid']; - ctrl.questionData.isShuffleOption = false; - ctrl.questionData.isPartialScore = true; - ctrl.questionData.templateType = ctrl.templatesType[0]; - ctrl.refreshPreview = false; - ctrl.noTemplatesFound = ""; - ctrl.questionTemplates = []; - ctrl.questionMetaData = {}; - ctrl._constants = { - previewPlugin: 'org.ekstep.questionset.preview', - questionPlugin: 'org.ekstep.question', - questionsetPlugin: 'org.ekstep.questionset', - questionbankPlugin: 'org.ekstep.questionbank' - }; - - ctrl.init = function () { - ecEditor.addEventListener('editor:template:loaded', function (event, object) { - if(object.formAction == 'question-meta-save') { - ctrl.metadataform = object.templatePath; - } - }); - - if (!ecEditor._.isEmpty(questionData)) { - ctrl.editState = true; - ctrl.showQuestionForm(); - } else { - ctrl.showTemplates(); - } - - ecEditor.dispatchEvent(ctrl.plugins.concepts, { - element: 'conceptsTextBoxMeta', - selectedConcepts: ctrl.TotalconceptsData, // All composite keys except mediaType - callback: function (data) { - ctrl.Totalconcepts = data.length; - if (data.length > 0) - ctrl.conceptsCheck = true; - _.each(data, function (val, key) { - ctrl.selectedConceptsData[key] = val.id; - }); - $scope.$safeApply(); - } - }); - - $scope.$on('question:form:valid', ctrl.formValid); - $scope.$on('question:form:inValid', ctrl.formInValid); - EventBus.listeners['editor:form:data'] = undefined; - ecEditor.addEventListener('editor:form:data', ctrl.saveMetaData); - } - - - ctrl.loadPlugins = function(plugins, manifestMedia, cb) { - var pluginObj = []; - if (!Array.isArray(plugins)) { - pluginObj.push(plugins); - plugins = pluginObj; - } - org.ekstep.pluginframework.pluginManager.loadAllPlugins(plugins, manifestMedia, function() { - if (typeof PluginManager != 'undefined') { - PluginManager.pluginMap = org.ekstep.pluginframework.pluginManager.plugins; - } - if (cb) cb(); - }); - }; - - ctrl.showTemplates = function() { - ctrl.templatesScreen = true; - ctrl.questionMetadataScreen = false; - var qsInstance = org.ekstep.pluginframework.pluginManager.getPluginManifest(ctrl._constants.questionsetPlugin); - var qsVesrion = qsInstance.ver.split('.')[0]; - var data = { - "request": { - "filters": { - "objectType": ["Content"], - "contentType": ["Plugin"], - "targets.id": ctrl._constants.questionsetPlugin, - "targets.ver": {'<=': Number(qsVesrion)}, - "status": "Live" - }, - "limit": 50, - "fields": ['contentType','semanticVersion','appIcon'] - } - }; - - ecEditor.getService('search').search(data, function(err, resp) { - - var PluginsData = resp.data.result.content; - var plugins = [] - - ecEditor._.forEach(PluginsData, function(value, key) { - if (value) { - var obj = { - "id": value.identifier, - "ver": value.semanticVersion, - "type": 'plugin' - } - plugins.push(obj); - } - }); - - ctrl.loadPlugins(plugins, [], function() { - ctrl.questionTemplates = []; - _.each(PluginsData, function(val, key) { // eslint-disable-line no-unused-vars - if (val.contentType == "Plugin") { - var instance = org.ekstep.pluginframework.pluginManager.getPluginManifest(val.identifier); - var pluginID = val.identifier; - var ver = val.semanticVersion; - if (!_.isUndefined(instance.templates)) { - _.each(instance.templates, function(v, k) { // eslint-disable-line no-unused-vars - v.pluginID = pluginID; - v.ver = ver; - var thumbnail = val.appIcon; - v.thumbnail1 = thumbnail; - var allMenus = v; - ctrl.questionTemplates.push(allMenus); - }); - } else { - ctrl.noTemplatesFound = "There are no templates available"; - } - } - }); - $scope.$safeApply(); - }); - }); - } - - ctrl.showQuestionForm = function () { - ctrl.templatesScreen = false; - ctrl.questionMetadataScreen = false; - ctrl.editMode = true; - var questionData1 = typeof questionData.body == "string" ? JSON.parse(questionData.body) : questionData.body; - ctrl.assessmentId = questionData.identifier; - ctrl.questionData = questionData1; - ctrl.questionCreationFormData = questionData1.data.data; - ctrl.questionData.qcMedium = questionData1.data.config.metadata.medium; - ctrl.questionData.questionTitle = questionData1.data.config.metadata.title; - ctrl.questionData.qcLevel = questionData1.data.config.metadata.qlevel; - ctrl.questionData.subject = questionData1.data.config.metadata.subject; - ctrl.questionData.board = questionData1.data.config.metadata.board; - ctrl.questionData.templateType = questionData1.data.config.layout; - ctrl.questionData.isPartialScore = questionData1.data.config.partial_scoring; - ctrl.questionData.qcGrade = questionData1.data.config.metadata.gradeLevel; - ctrl.questionData.isShuffleOption = questionData1.data.config.isShuffleOption; - ctrl.category = questionData.category; - if (questionData1.data.config.metadata.concepts) { - ctrl.Totalconcepts = questionData1.data.config.metadata.concepts.length; - } - ctrl.questionData.concepts = questionData1.data.config.metadata.concepts; - ctrl.selectedConceptsData = questionData1.data.config.metadata.concepts; - ctrl.questionData.questionDesc = questionData1.data.config.metadata.description; - ctrl.questionData.questionMaxScore = questionData1.data.config.metadata.max_score; - ctrl.conceptsCheck = true; - $scope.questionEditData = questionData1.data; //Using this variable in question unit plugin for editing question - var pluginID = questionData1.data.plugin.id; - var pluginVer = questionData1.data.plugin.version; - var pluginTemplateId = questionData1.data.plugin.templateId; - var editCreateQuestionFormInstance = org.ekstep.pluginframework.pluginManager.getPluginManifest(questionData1.data.plugin.id); - _.each(editCreateQuestionFormInstance.templates, function (value, key) { // eslint-disable-line no-unused-vars - if (value.editor.template == questionData1.data.plugin.templateId) { - var templatePathEdit = ecEditor.resolvePluginResource(pluginID, pluginVer, value.editor.templateURL); - ctrl.questionUnitTemplateURL = templatePathEdit; - } - }); - - ctrl.selectedTemplatePluginData.plugin = { // Question Unit Plugin Information - "id": pluginID, // Id of plugin - "version": pluginVer, // Version of plugin - "templateId": pluginTemplateId // Template Id of the question unit - }; - $scope.$safeApply(); - }; - - ctrl.setPreviewData = function () { - var confData = {}; - var qObj = { - "config": '{"metadata":{"title":"question title","description":"question description","medium":"English"},"max_time":0,"max_score":1,"partial_scoring":' + ctrl.questionData.isPartialScore + ',"isShuffleOption":' + ctrl.questionData.isShuffleOption + ',"layout":' + JSON.stringify(ctrl.questionData.templateType) + '}', - "data": JSON.stringify(ctrl.questionCreationFormData), - "id": "c943d0a907274471a0572e593eab49c2", - "pluginId": ctrl.selectedTemplatePluginData.plugin.id, - "pluginVer": ctrl.selectedTemplatePluginData.plugin.version, - "templateId": ctrl.selectedTemplatePluginData.plugin.templateId, - "type": "unit" - } - var questions = []; - var data = { - "org.ekstep.questionset": {} - }; - - questions.push(qObj); - data[ctrl._constants.questionsetPlugin][ctrl._constants.questionPlugin] = questions; - confData = {"contentBody": {}, "parentElement": true, "element": "#iframeArea"}; - document.getElementById("iframeArea").contentDocument.location.reload(true); - var pluginInstances = ecEditor.getPluginInstances(); - var previewInstance = _.find(pluginInstances, function (pi) { - return pi.manifest.id === ctrl._constants.previewPlugin - }); - if (_.isUndefined(previewInstance)) { - previewInstance = ecEditor.instantiatePlugin(ctrl._constants.previewPlugin); - } - confData.contentBody = previewInstance.getQuestionPreviwContent(data[ctrl._constants.questionsetPlugin]); - ecEditor.dispatchEvent("atpreview:show", confData); - }; - - ctrl.loadPreview = function () { - if (ctrl.editMode === true) { - setTimeout(function () { - ctrl.setPreviewData(); - }, 100); - } - }; - - ctrl.loadDropdown = function () { - $('.ui.dropdown').dropdown({}); - }; - - ctrl.updatePreview = function () { - ctrl.showPreview(); - }; - - ctrl.showMetaform = function () { - ctrl.refreshPreview = false; - ctrl.validateQuestionCreationForm(); - }; - - ctrl.showPreview = function () { - ctrl.refreshPreview = true; - if (!ctrl.questionMetadataScreen) { - ctrl.validateQuestionCreationForm(); - } else { - ctrl.setPreviewData(); - } - }; - - ctrl.cancel = function () { - $scope.closeThisDialog(); - }; - - ctrl.setBackButtonState = function () { - if (ctrl.editState) { - if (ctrl.questionMetadataScreen) { - return false; - } else { - return true; - } - } else { - return false; - } - }; - - ctrl.back = function () { - if (!ctrl.questionMetadataScreen) { - ctrl.questionMetadataScreen = true; - ctrl.templatesScreen = true; - ctrl.showTemplates(); - } else { - var metaFormScope = $('#question-meta-form #content-meta-form').scope(); - ctrl.questionData.questionTitle = metaFormScope.contentMeta.name; - ctrl.questionData.qcMedium = metaFormScope.contentMeta.medium; - ctrl.questionData.qcLevel = metaFormScope.contentMeta.level; - ctrl.questionData.questionDesc = metaFormScope.contentMeta.description; - ctrl.questionData.questionMaxScore = metaFormScope.contentMeta.max_score; - ctrl.questionData.qcGrade = metaFormScope.contentMeta.gradeLevel; - ctrl.questionData.concepts = metaFormScope.contentMeta.concepts; - - ctrl.questionMetadataScreen = false; - } - }; - - ctrl.addCreateQuestionForm = function (obj) { - $('.ui.dropdown').dropdown({}); - ctrl.category = obj.category; - ctrl.templatesScreen = false; - ctrl.questionMetadataScreen = false; - ctrl.templateName = obj.title; - ctrl.selectedTemplatePluginData.plugin = { // Question Unit Plugin Information - "id": obj.pluginID, // Id of plugin - "version": obj.ver, // Version of plugin - "templateId": obj.editor.template // Template Id of the question unit - }; - ctrl.unitPlugin = obj.pluginID; - ctrl.pluginVer = obj.ver; - ctrl.templateId = obj.editor.template; - // var controllerPath = ecEditor.resolvePluginResource(obj.pluginID, obj.ver, obj.editor.controllerURL); - var templatePath = ecEditor.resolvePluginResource(obj.pluginID, obj.ver, obj.editor.templateURL); - ctrl.questionUnitTemplateURL = templatePath + '?BUILDNUMBER'; - }; - - ctrl.validateQuestionCreationForm = function (event) { // eslint-disable-line no-unused-vars - $scope.$broadcast('question:form:val'); - }; - - ctrl.formValid = function (event, data) { - ctrl.questionCreationFormData = data; - ctrl.setPreviewData(); - if (!ctrl.refreshPreview) { - ctrl.formIsValid(); - } - }; - - ctrl.formInValid = function () { - - }; - - ctrl.formIsValid = function () { - ctrl.questionMetadataScreen = true; - //comment because in edit question the question and question title are not - if (ctrl.category == 'FTB') { - ctrl.questionData.questionTitle = _.isUndefined(ctrl.questionData.questionTitle) ? ctrl.questionCreationFormData.question.text.replace(/\[\[.*?\]\]/g, '____') : ctrl.questionData.questionTitle; - } else { - ctrl.questionData.questionTitle = _.isUndefined(ctrl.questionData.questionTitle) ? ctrl.questionCreationFormData.question.text : ctrl.questionData.questionTitle; - } - ctrl.questionData.questionTitle = ctrl.extractHTML(ctrl.questionData.questionTitle); - $('.QuestionMetaForm .ui.dropdown').dropdown({}); - ctrl.questionMetaData.name = ctrl.questionData.questionTitle; - ctrl.questionMetaData.medium = ctrl.questionData.qcMedium; - ctrl.questionMetaData.level = ctrl.questionData.qcLevel; - ctrl.questionMetaData.description = ctrl.questionData.questionDesc; - ctrl.questionMetaData.max_score = ctrl.questionData.questionMaxScore; - ctrl.questionMetaData.gradeLevel = ctrl.questionData.qcGrade; - ctrl.questionMetaData.concepts = ctrl.questionData.concepts; - ctrl.questionMetaData.subject = ctrl.questionData.subject; - ctrl.questionMetaData.board = ctrl.questionData.board; - if (ctrl.questionMetaData.concepts) { - ctrl.questionMetaData.conceptData = "(" + ctrl.questionData.concepts.length + ") concepts selected"; - } - - ecEditor.dispatchEvent('org.ekstep.editcontentmeta:showpopup', { - action: 'question-meta-save', - subType: 'questions', - framework: ecEditor.getContext('framework'), - rootOrgId: ecEditor.getContext('channel'), - type: 'content', - popup: false, - metadata: ctrl.questionMetaData - }); - }; - - ctrl.saveQuestion = function (assessmentId, data) { - //If identifier present update the question data - ecEditor.getService('assessment').saveQuestionV3(assessmentId, data, function (err, resp) { - if (!err) { - var qMetadata = ctrl.qFormData.request.assessment_item.metadata; - qMetadata.identifier = resp.data.result.node_id; - ecEditor.dispatchEvent(ctrl._constants.questionbankPlugin + ':saveQuestion', qMetadata); - $scope.closeThisDialog(); - } else { - //toast with error message - ecEditor.dispatchEvent("org.ekstep.toaster:error", { - title: 'Failed to save question...', - position: 'topCenter', - }); - } - }); - } - - ctrl.sendMetaData = function () { - var formElement = $("#questionMetadataTemplate").find("#content-meta-form"); - var frmScope = formElement.scope(); - ecEditor.dispatchEvent("metadata:form:onsuccess", {form: frmScope.metaForm}); - }; - - ctrl.saveMetaData = function (event, object) { - var metaDataObject = object.formData.metaData; - for (var property in object.formData.metaData) { - if (metaDataObject[property]) { - ctrl.questionMetaData[property] = metaDataObject[property]; - } - } - var questionFormData = {}; - var data = {}; // TODO: You have to get this from Q.Unit plugin(getData()) - data.plugin = ctrl.selectedTemplatePluginData.plugin; - data.data = ctrl.questionCreationFormData; - - var metadataObj = { category: ctrl.category, title: ctrl.questionMetaData.name, medium: ctrl.questionMetaData.medium, qlevel: ctrl.questionMetaData.level, gradeLevel: ctrl.questionMetaData.gradeLevel, concepts: ctrl.questionMetaData.concepts, description: ctrl.questionMetaData.description, max_score: ctrl.questionMetaData.max_score, subject: ctrl.questionMetaData.subject, board: ctrl.questionMetaData.board }; - data.config = { "metadata": metadataObj, "max_time": 0, "max_score": ctrl.questionData.questionMaxScore, "partial_scoring": ctrl.questionData.isPartialScore, "layout": ctrl.questionData.templateType, "isShuffleOption" : ctrl.questionData.isShuffleOption, "questionCount": ctrl.questionCreationFormData.questionCount}; - - data.media = ctrl.questionCreationFormData.media; - questionFormData.data = data; - var metadata = { - "code": "NA", - "name": ctrl.questionMetaData.name, - "qlevel": ctrl.questionMetaData.level, - "title": ctrl.questionMetaData.name, - "question": ctrl.questionCreationFormData.question.text, - "max_score": ctrl.questionMetaData.max_score, - "isShuffleOption" : ctrl.questionData.isShuffleOption, - "body": JSON.stringify(questionFormData), - "medium": ctrl.questionMetaData.medium, - "subject": ctrl.questionMetaData.subject, - "board": ctrl.questionMetaData.board, - "itemType": "UNIT", - "version": 2, - "category": ctrl.category, - "description": ctrl.questionMetaData.description, - "createdBy": window.context.user.id, - "channel": ecEditor.getContext('channel'), - "type": ctrl.category.toLowerCase(), // backward compatibility - "template": "NA", // backward compatibility - "template_id": "NA", // backward compatibility - }; - var dynamicOptions = [{"answer": true, "value": {"type": "text", "asset": "1"}}]; - var mtfoptions = [{ - "value": { - "type": "mixed", - "text": "इक", - "image": "", - "count": "", - "audio": "", - "resvalue": "इक", - "resindex": 0 - }, - "index": 0 - }]; - switch (ctrl.category) { - case 'MCQ': - metadata.options = dynamicOptions; - break; - case 'FTB': - metadata.answer = dynamicOptions; - break; - case 'MTF': - metadata.lhs_options = mtfoptions; - metadata.rhs_options = mtfoptions; - break; - default: - metadata.options = dynamicOptions; - break; - } - ctrl.qFormData = { - "request": { - "assessment_item": { - "objectType": "AssessmentItem", - "metadata": metadata - } - } - }; - - /*Save data and get response and dispatch event with response to questionbank plugin*/ - ctrl.saveQuestion(ctrl.assessmentId, ctrl.qFormData); - }; - - ctrl.extractHTML = function(htmlElement) { - var divElement= document.createElement('div'); - divElement.innerHTML= htmlElement; - return divElement.textContent || divElement.innerText; - } - - ctrl.genImpressionTelemetry = function(data) { - if (data) ecEditor.getService('telemetry').impression({ - "type": data.type, - "subtype": data.subtype, - "pageid": data.pageid, - "uri": encodeURIComponent(location.href), - "visits": { - 'objid': data.visits.objid, - 'objtype': data.visits.objtype - } - }) - } - - ctrl.generateTelemetry = function(data, event) { - if (data) ecEditor.getService('telemetry').interact({ - "type": data.type, - "id": data.id, - "pageid": 'question-creation-form', - "target": { - "id": data.target.id, - "ver": data.target.ver, - "type": data.target.type - }, - "plugin": { - "id": instance.manifest.id, - "ver": instance.manifest.ver - } - }) - } - ctrl.init(); - }]); - -//# sourceURL=question.js \ No newline at end of file diff --git a/editor/style.css b/editor/style.css index b585f73..27e8871 100644 --- a/editor/style.css +++ b/editor/style.css @@ -13,6 +13,7 @@ .qc-ngdialog-custome > .ngdialog-content { top: 0% !important; + font-family: Helvetica,sans-serif; } .item:hover { From 97e860edb821987986a31702e9b2dba1dfa0dd5f Mon Sep 17 00:00:00 2001 From: Jagadish Pujari Date: Tue, 17 Jul 2018 12:28:46 +0530 Subject: [PATCH 02/11] Issue #15 fix: Removed _proto --- editor/question-ctrl.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/editor/question-ctrl.js b/editor/question-ctrl.js index 5e3e7a3..f40e473 100644 --- a/editor/question-ctrl.js +++ b/editor/question-ctrl.js @@ -74,7 +74,7 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) "templateId": obj.editor.template }; var pluginInstance = $scope.createPluginInstance(obj.pluginID); - pluginInstance.__proto__.__proto__._data = {}; + pluginInstance._data = {}; $scope.unitPlugin = obj.pluginID; $scope.pluginVer = obj.ver; $scope.templateId = obj.editor.template; @@ -93,10 +93,9 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) pluginInstance.validateForm($scope.validatedForm); } - $scope.validatedForm = function(isFormValid){ + $scope.validatedForm = function(isFormValid,data){ if(isFormValid){ - var pluginInstance = $scope.createPluginInstance($scope.selectedTemplatePluginData.plugin.id); - $scope.questionCreationFormData = pluginInstance.__proto__.__proto__._data; + $scope.questionCreationFormData = data; $scope.setPreviewData(); if (!$scope.refreshPreview) { $scope.formIsValid(); From 4ca087ecec459e26abbad498848f291667975db6 Mon Sep 17 00:00:00 2001 From: Jagadish Pujari Date: Tue, 17 Jul 2018 23:32:51 +0530 Subject: [PATCH 03/11] Issue #18 fix: Fixed show templates --- editor/question-ctrl.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/editor/question-ctrl.js b/editor/question-ctrl.js index f40e473..3d0cb4e 100644 --- a/editor/question-ctrl.js +++ b/editor/question-ctrl.js @@ -41,7 +41,10 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) $scope.showTemplates = function() { $scope.templatesScreen = true; $scope.questionMetadataScreen = false; - var PluginsData = JSON.parse(localStorage.getItem("qs-plugins")); + var PluginsData = []; + ecEditor.dispatchEvent("org.ekstep.questionbank:getPlugins",function(pluginData){ + PluginsData = pluginData; + }); _.each(PluginsData, function(val, key) { // eslint-disable-line no-unused-vars if (val.contentType == "Plugin") { var pluginManifest = org.ekstep.pluginframework.pluginManager.getPluginManifest(val.identifier); From a620889cdab63c24da1225062cd080298898d147 Mon Sep 17 00:00:00 2001 From: Manoj Chandrashekar Date: Wed, 18 Jul 2018 00:33:52 +0530 Subject: [PATCH 04/11] Issue #18 fix: Topic edit fix --- editor/question-ctrl.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/editor/question-ctrl.js b/editor/question-ctrl.js index 3d0cb4e..05741b7 100644 --- a/editor/question-ctrl.js +++ b/editor/question-ctrl.js @@ -334,13 +334,13 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) if (questionData1.data.config.metadata.concepts) { $scope.Totalconcepts = questionData1.data.config.metadata.concepts.length; } - if (questionData1.data.config.metadata.topic) { - $scope.Totaltopics = questionData1.data.config.metadata.topic.length; + if (questionData.topic) { + $scope.Totaltopics = questionData.topic.length; } $scope.questionData.concepts = questionData1.data.config.metadata.concepts; - $scope.questionData.topic = questionData1.data.config.metadata.topic; + $scope.questionData.topic = questionData.topic; $scope.selectedConceptsData = questionData1.data.config.metadata.concepts; - $scope.selectedTopicsData = questionData1.data.config.metadata.topic; + $scope.selectedTopicsData = questionData.topic; $scope.questionData.questionDesc = questionData1.data.config.metadata.description; $scope.questionData.questionMaxScore = questionData1.data.config.metadata.max_score; $scope.conceptsCheck = true; From ced3c686d0f2e5d44891e0f141195e4c8ebc3d3c Mon Sep 17 00:00:00 2001 From: akshaya Date: Wed, 18 Jul 2018 10:16:18 +0530 Subject: [PATCH 05/11] Issue #18 fix: Edit title and level fields getting empty --- editor/question-ctrl.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor/question-ctrl.js b/editor/question-ctrl.js index 05741b7..60d74a9 100644 --- a/editor/question-ctrl.js +++ b/editor/question-ctrl.js @@ -173,9 +173,9 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) $scope.questionData.questionTitle = _.isUndefined($scope.questionData.questionTitle) ? $scope.questionCreationFormData.question.text : $scope.questionData.questionTitle; } $scope.questionData.questionTitle = $scope.extractHTML($scope.questionData.questionTitle); - $scope.questionMetaData.title = $scope.questionData.questionTitle; + $scope.questionMetaData.name = $scope.questionData.questionTitle; $scope.questionMetaData.medium = $scope.questionData.qcMedium; - $scope.questionMetaData.qlevel = $scope.questionData.qcLevel; + $scope.questionMetaData.level = $scope.questionData.qcLevel; $scope.questionMetaData.description = $scope.questionData.questionDesc; $scope.questionMetaData.max_score = $scope.questionData.questionMaxScore; $scope.questionMetaData.gradeLevel = $scope.questionData.qcGrade; From 68e5cee8e7d039c9e690fc053a109226d70dab29 Mon Sep 17 00:00:00 2001 From: akshaya Date: Wed, 18 Jul 2018 11:45:18 +0530 Subject: [PATCH 06/11] Issue #18 fix: level changed to qlevel --- editor/question-ctrl.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor/question-ctrl.js b/editor/question-ctrl.js index 60d74a9..d722621 100644 --- a/editor/question-ctrl.js +++ b/editor/question-ctrl.js @@ -155,7 +155,7 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) metaFormScope.isSubmit = false; $scope.questionData.questionTitle = metaFormScope.contentMeta.name; $scope.questionData.qcMedium = metaFormScope.contentMeta.medium; - $scope.questionData.qcLevel = metaFormScope.contentMeta.level; + $scope.questionData.qcLevel = metaFormScope.contentMeta.qlevel; $scope.questionData.questionDesc = metaFormScope.contentMeta.description; $scope.questionData.questionMaxScore = metaFormScope.contentMeta.max_score; $scope.questionData.qcGrade = metaFormScope.contentMeta.gradeLevel; @@ -175,7 +175,7 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) $scope.questionData.questionTitle = $scope.extractHTML($scope.questionData.questionTitle); $scope.questionMetaData.name = $scope.questionData.questionTitle; $scope.questionMetaData.medium = $scope.questionData.qcMedium; - $scope.questionMetaData.level = $scope.questionData.qcLevel; + $scope.questionMetaData.qlevel = $scope.questionData.qcLevel; $scope.questionMetaData.description = $scope.questionData.questionDesc; $scope.questionMetaData.max_score = $scope.questionData.questionMaxScore; $scope.questionMetaData.gradeLevel = $scope.questionData.qcGrade; From 1364e7a42b2c5e749251c3e2f97f0e2eeb5800d4 Mon Sep 17 00:00:00 2001 From: Jagadish Pujari Date: Wed, 18 Jul 2018 14:15:31 +0530 Subject: [PATCH 07/11] Issue #15 fix: Scope related issue fixed --- editor/question-ctrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor/question-ctrl.js b/editor/question-ctrl.js index 3d0cb4e..e67d77b 100644 --- a/editor/question-ctrl.js +++ b/editor/question-ctrl.js @@ -35,7 +35,7 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) } else { $scope.showTemplates(); } - EventBus.listeners['editor:form:data'] = undefined; + EventBus.listeners['editor:form:success'] = undefined; ecEditor.addEventListener('editor:form:success', $scope.saveMetaData); } $scope.showTemplates = function() { From cdf1a702b4d40b71c512b34e865a44e07d226c41 Mon Sep 17 00:00:00 2001 From: akshaya Date: Wed, 18 Jul 2018 16:17:42 +0530 Subject: [PATCH 08/11] Issue #18 fix: Question title and qlevel changes --- editor/question-ctrl.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/editor/question-ctrl.js b/editor/question-ctrl.js index d722621..eac3082 100644 --- a/editor/question-ctrl.js +++ b/editor/question-ctrl.js @@ -175,7 +175,7 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) $scope.questionData.questionTitle = $scope.extractHTML($scope.questionData.questionTitle); $scope.questionMetaData.name = $scope.questionData.questionTitle; $scope.questionMetaData.medium = $scope.questionData.qcMedium; - $scope.questionMetaData.qlevel = $scope.questionData.qcLevel; + $scope.questionMetaData.level = $scope.questionData.qcLevel; $scope.questionMetaData.description = $scope.questionData.questionDesc; $scope.questionMetaData.max_score = $scope.questionData.questionMaxScore; $scope.questionMetaData.gradeLevel = $scope.questionData.qcGrade; @@ -235,6 +235,8 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) var metadata = { "code": "NA", "name": $scope.questionMetaData.name, + "title": $scope.questionMetaData.name, + "qlevel": $scope.questionMetaData.level, "question": $scope.questionCreationFormData.question.text, "isShuffleOption" : $scope.questionData.isShuffleOption, "body": JSON.stringify(questionFormData), @@ -248,16 +250,10 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) "template": "NA", // backward compatibility "template_id": "NA", // backward compatibility "topic": $scope.questionMetaData.topic, - //"framework": "NCFCOPY" + //"framework": "mh_k-12_15" "framework": ecEditor.getContext('framework') }; - for (var key in $scope.questionMetaData) { - if ($scope.questionMetaData.hasOwnProperty(key)) { - metadata[key] = $scope.questionMetaData[key]; - } - } - var dynamicOptions = [{"answer": true, "value": {"type": "text", "asset": "1"}}]; var mtfoptions = [{ "value": { @@ -322,8 +318,8 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) $scope.questionData = questionData1; $scope.questionCreationFormData = questionData1.data.data; $scope.questionData.qcMedium = questionData1.data.config.metadata.medium; - $scope.questionData.questionTitle = questionData1.data.config.metadata.title; - $scope.questionData.qcLevel = questionData1.data.config.metadata.qlevel; + $scope.questionData.questionTitle = questionData.title; + $scope.questionData.qcLevel = questionData.qlevel; $scope.questionData.subject = questionData1.data.config.metadata.subject; $scope.questionData.board = questionData1.data.config.metadata.board; $scope.questionData.templateType = questionData1.data.config.layout; From 6f22317d42f74079b8a76c9bd6cba897467a9017 Mon Sep 17 00:00:00 2001 From: akshaya Date: Wed, 18 Jul 2018 16:38:46 +0530 Subject: [PATCH 09/11] Issue #18 fix: Question meta change --- editor/question-ctrl.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/editor/question-ctrl.js b/editor/question-ctrl.js index 57806c4..7521cea 100644 --- a/editor/question-ctrl.js +++ b/editor/question-ctrl.js @@ -227,16 +227,20 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) var metadataObj = $scope.questionMetaData; metadataObj.category = $scope.category; - // var metadataObj = { category: $scope.category, title: $scope.questionMetaData.name, medium: $scope.questionMetaData.medium, qlevel: $scope.questionMetaData.level, gradeLevel: $scope.questionMetaData.gradeLevel, concepts: $scope.questionMetaData.concepts, description: $scope.questionMetaData.description, max_score: $scope.questionMetaData.max_score, subject: $scope.questionMetaData.subject, board: $scope.questionMetaData.board }; - - data.config = { "metadata": metadataObj, "max_time": 0, "max_score": $scope.questionData.questionMaxScore, "partial_scoring": $scope.questionData.isPartialScore, "layout": $scope.questionData.templateType, "isShuffleOption" : $scope.questionData.isShuffleOption, "questionCount": $scope.questionCreationFormData.questionCount}; + // TODO: questionCount should be sent from unit template controllers. Currently it is hardcoded to 1. + data.config = { "metadata": metadataObj, "max_time": 0, "max_score": $scope.questionData.questionMaxScore, "partial_scoring": $scope.questionData.isPartialScore, "layout": $scope.questionData.templateType, "isShuffleOption" : $scope.questionData.isShuffleOption, "questionCount": 1}; data.media = $scope.questionCreationFormData.media; questionFormData.data = data; var metadata = { "code": "NA", "name": $scope.questionMetaData.name, "title": $scope.questionMetaData.name, + "medium": $scope.questionMetaData.medium, + "max_score": $scope.questionData.questionMaxScore, "qlevel": $scope.questionMetaData.level, + "gradeLevel": $scope.questionMetaData.gradeLevel, + "subject": $scope.questionMetaData.subject, + "board": $scope.questionMetaData.board, "question": $scope.questionCreationFormData.question.text, "isShuffleOption" : $scope.questionData.isShuffleOption, "body": JSON.stringify(questionFormData), From c51adc30c5942eae5215c61ac134f49d18c60260 Mon Sep 17 00:00:00 2001 From: Jagadish Pujari Date: Wed, 18 Jul 2018 16:41:35 +0530 Subject: [PATCH 10/11] Issue #15 fix: Metadata callback isFormValid checks --- editor/question-ctrl.js | 169 +++++++++++++++++++--------------------- 1 file changed, 82 insertions(+), 87 deletions(-) diff --git a/editor/question-ctrl.js b/editor/question-ctrl.js index 57806c4..c0fc788 100644 --- a/editor/question-ctrl.js +++ b/editor/question-ctrl.js @@ -205,94 +205,89 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) ecEditor.dispatchEvent("metadata:form:onsuccess", {target: '#questionMetaDataTemplate', form: frmScope.metaForm}); }; $scope.saveMetaData = function (event, object) { - var metaDataObject = object.formData.metaData; - for (var property in object.formData.metaData) { - if (metaDataObject[property]) { - $scope.questionMetaData[property] = metaDataObject[property]; - } - } - var questionFormData = {}; - var data = {}; // TODO: You have to get this from Q.Unit plugin(getData()) - data.plugin = $scope.selectedTemplatePluginData.plugin; - data.data = $scope.questionCreationFormData; - - var outRelations = []; - _.each($scope.questionMetaData.concepts, function(concept){ - outRelations.push({ - "endNodeId": concept.identifier, - "relationType": "associatedTo" - }) - }); - - var metadataObj = $scope.questionMetaData; - metadataObj.category = $scope.category; - - // var metadataObj = { category: $scope.category, title: $scope.questionMetaData.name, medium: $scope.questionMetaData.medium, qlevel: $scope.questionMetaData.level, gradeLevel: $scope.questionMetaData.gradeLevel, concepts: $scope.questionMetaData.concepts, description: $scope.questionMetaData.description, max_score: $scope.questionMetaData.max_score, subject: $scope.questionMetaData.subject, board: $scope.questionMetaData.board }; - - data.config = { "metadata": metadataObj, "max_time": 0, "max_score": $scope.questionData.questionMaxScore, "partial_scoring": $scope.questionData.isPartialScore, "layout": $scope.questionData.templateType, "isShuffleOption" : $scope.questionData.isShuffleOption, "questionCount": $scope.questionCreationFormData.questionCount}; - data.media = $scope.questionCreationFormData.media; - questionFormData.data = data; - var metadata = { - "code": "NA", - "name": $scope.questionMetaData.name, - "title": $scope.questionMetaData.name, - "qlevel": $scope.questionMetaData.level, - "question": $scope.questionCreationFormData.question.text, - "isShuffleOption" : $scope.questionData.isShuffleOption, - "body": JSON.stringify(questionFormData), - "itemType": "UNIT", - "version": 2, - "category": $scope.category, - "description": $scope.questionMetaData.description, - "createdBy": window.context.user.id, - "channel": ecEditor.getContext('channel'), - "type": $scope.category.toLowerCase(), // backward compatibility - "template": "NA", // backward compatibility - "template_id": "NA", // backward compatibility - "topic": $scope.questionMetaData.topic, - //"framework": "mh_k-12_15" - "framework": ecEditor.getContext('framework') - }; - - var dynamicOptions = [{"answer": true, "value": {"type": "text", "asset": "1"}}]; - var mtfoptions = [{ - "value": { - "type": "mixed", - "text": "इक", - "image": "", - "count": "", - "audio": "", - "resvalue": "इक", - "resindex": 0 - }, - "index": 0 - }]; - switch ($scope.category) { - case 'MCQ': - metadata.options = dynamicOptions; - break; - case 'FTB': - metadata.answer = dynamicOptions; - break; - case 'MTF': - metadata.lhs_options = mtfoptions; - metadata.rhs_options = mtfoptions; - break; - default: - metadata.options = dynamicOptions; - break; + if(object.isValid){ + var metaDataObject = object.formData.metaData; + for (var property in object.formData.metaData) { + if (metaDataObject[property]) { + $scope.questionMetaData[property] = metaDataObject[property]; + } + } + var questionFormData = {}; + var data = {}; // TODO: You have to get this from Q.Unit plugin(getData()) + data.plugin = $scope.selectedTemplatePluginData.plugin; + data.data = $scope.questionCreationFormData; + var outRelations = []; + _.each($scope.questionMetaData.concepts, function(concept){ + outRelations.push({ + "endNodeId": concept.identifier, + "relationType": "associatedTo" + }) + }); + var metadataObj = $scope.questionMetaData; + metadataObj.category = $scope.category; + data.config = { "metadata": metadataObj, "max_time": 0, "max_score": $scope.questionData.questionMaxScore, "partial_scoring": $scope.questionData.isPartialScore, "layout": $scope.questionData.templateType, "isShuffleOption" : $scope.questionData.isShuffleOption, "questionCount": $scope.questionCreationFormData.questionCount}; + data.media = $scope.questionCreationFormData.media; + questionFormData.data = data; + var metadata = { + "code": "NA", + "name": $scope.questionMetaData.name, + "title": $scope.questionMetaData.name, + "qlevel": $scope.questionMetaData.level, + "question": $scope.questionCreationFormData.question.text, + "isShuffleOption" : $scope.questionData.isShuffleOption, + "body": JSON.stringify(questionFormData), + "itemType": "UNIT", + "version": 2, + "category": $scope.category, + "description": $scope.questionMetaData.description, + "createdBy": window.context.user.id, + "channel": ecEditor.getContext('channel'), + "type": $scope.category.toLowerCase(), // backward compatibility + "template": "NA", // backward compatibility + "template_id": "NA", // backward compatibility + "topic": $scope.questionMetaData.topic, + "framework": ecEditor.getContext('framework') + }; + var dynamicOptions = [{"answer": true, "value": {"type": "text", "asset": "1"}}]; + var mtfoptions = [{ + "value": { + "type": "mixed", + "text": "इक", + "image": "", + "count": "", + "audio": "", + "resvalue": "इक", + "resindex": 0 + }, + "index": 0 + }]; + switch ($scope.category) { + case 'MCQ': + metadata.options = dynamicOptions; + break; + case 'FTB': + metadata.answer = dynamicOptions; + break; + case 'MTF': + metadata.lhs_options = mtfoptions; + metadata.rhs_options = mtfoptions; + break; + default: + metadata.options = dynamicOptions; + break; + } + $scope.qFormData = { + "request": { + "assessment_item": { + "objectType": "AssessmentItem", + "metadata": metadata, + "outRelations": outRelations + } + } + }; + /*Save data and get response and dispatch event with response to questionbank plugin*/ + $scope.saveQuestion($scope.assessmentId, $scope.qFormData); } - $scope.qFormData = { - "request": { - "assessment_item": { - "objectType": "AssessmentItem", - "metadata": metadata, - "outRelations": outRelations - } - } - }; - /*Save data and get response and dispatch event with response to questionbank plugin*/ - $scope.saveQuestion($scope.assessmentId, $scope.qFormData); }; $scope.saveQuestion = function (assessmentId, data) { ecEditor.getService('assessment').saveQuestionV3(assessmentId, data, function (err, resp) { From b06bcb10ba09bbcb4aeb643d4608975cc5607779 Mon Sep 17 00:00:00 2001 From: Jagadish Pujari Date: Wed, 18 Jul 2018 16:54:33 +0530 Subject: [PATCH 11/11] Issue #15 fix: Reverted code --- editor/question-ctrl.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/editor/question-ctrl.js b/editor/question-ctrl.js index c0fc788..fa7986b 100644 --- a/editor/question-ctrl.js +++ b/editor/question-ctrl.js @@ -225,13 +225,19 @@ angular.module('org.ekstep.question', ['org.ekstep.metadataform']) }); var metadataObj = $scope.questionMetaData; metadataObj.category = $scope.category; - data.config = { "metadata": metadataObj, "max_time": 0, "max_score": $scope.questionData.questionMaxScore, "partial_scoring": $scope.questionData.isPartialScore, "layout": $scope.questionData.templateType, "isShuffleOption" : $scope.questionData.isShuffleOption, "questionCount": $scope.questionCreationFormData.questionCount}; + // TODO: questionCount should be sent from unit template controllers. Currently it is hardcoded to 1. + data.config = { "metadata": metadataObj, "max_time": 0, "max_score": $scope.questionData.questionMaxScore, "partial_scoring": $scope.questionData.isPartialScore, "layout": $scope.questionData.templateType, "isShuffleOption" : $scope.questionData.isShuffleOption, "questionCount": 1}; data.media = $scope.questionCreationFormData.media; questionFormData.data = data; var metadata = { "code": "NA", "name": $scope.questionMetaData.name, "title": $scope.questionMetaData.name, + "medium": $scope.questionMetaData.medium, + "max_score": $scope.questionData.questionMaxScore, + "gradeLevel": $scope.questionMetaData.gradeLevel, + "subject": $scope.questionMetaData.subject, + "board": $scope.questionMetaData.board, "qlevel": $scope.questionMetaData.level, "question": $scope.questionCreationFormData.question.text, "isShuffleOption" : $scope.questionData.isShuffleOption,