From b59e46713c8b9ad99f016af167d8484268ff7090 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 22 Jan 2024 16:51:42 +0530 Subject: [PATCH] XML_CHANGES : RV --- addform.html | 50 ++++++++++++++++++++++----- json2html.js | 2 +- json2xml.js | 47 +++++++++---------------- xml2json.js | 22 ++++++------ xml2json_for_Questionpaper_preview.js | 15 ++++---- 5 files changed, 76 insertions(+), 60 deletions(-) diff --git a/addform.html b/addform.html index 0e5faf4..32791b0 100644 --- a/addform.html +++ b/addform.html @@ -1139,7 +1139,7 @@ async function convertToLatex(text, mathstatus) {
- +
@@ -1451,8 +1451,8 @@ var inputElement2 = document.getElementById('questionTitleValue'); var innerDivElement = inputElement2.querySelector('.jodit-workplace').querySelector('.jodit-wysiwyg'); innerDivElement.addEventListener("keyup", function(event) { - console.log('JoditworkPlaceId : ', event.target.id); - console.log('content : ',innerDivElement.innerHTML); + // console.log('JoditworkPlaceId : ', event.target.id); + // console.log('content : ',innerDivElement.innerHTML); json2nav(); clearSidebarWrapper(); @@ -1468,6 +1468,27 @@ html2json(); }) +function matchnum(event){ + +var charcode; +charcode = event.which || event.keyCode; +if(charcode>= 48 && charcode <= 57)return true; //only numbers +return false; + +} + +let innerDivElement = document.getElementById('Max_Marks'); +console.log(innerDivElement) +innerDivElement.addEventListener("keyup", function(event) { + +json2nav(); +clearSidebarWrapper(); +navpane(); +check_Remove_Empty_Question('Max_Marks'); + +}); + + @@ -1898,6 +1919,14 @@ var checkchoicequestona= 0; var questionIncrement = 1; +$(document).ready(function(){ +array_of_Id.push('Max_Marks') +console.log(array_of_Id); +const arrayString = JSON.stringify(array_of_Id); +collect_Empty_Question_Id(arrayString, 'Max_Marks'); +}) + + //Function for Create a New Section in the Question Paper function addSection(title = false, description = false, random_no = false, section_uuid = false, section_marks = false, sectionDispalyMarks = false, sectionAttemptAny = false, scrollval = false) @@ -2429,7 +2458,7 @@ function addQuestionGroup(idObj)
Attempt Any :
- +
@@ -4475,8 +4504,13 @@ function collect_Empty_Question_Id(arrayString, ID) { if(input_text_value !== null) { // console.log("ikl"); - if (input_text_value.className == 'QuestionTextIdSet') { - attrId =input_text_value.innerHTML; + if (input_text_value.className == 'QuestionTextIdSet' || ID == 'Max_Marks') { + + if(ID == 'Max_Marks'){ + attrId =input_text_value.innerHTML; + }else{ + attrId =input_text_value.value; + } // console.log('attrId QuestionTextIdSet : ', attrId); } else { const previousElement = input_text_value.previousElementSibling; @@ -4549,7 +4583,7 @@ function check_Empty_Question() attrId =elementid; } else { var value = '' - if(getMathFiled == 'textQuestiontitleMath_'){ + if(getMathFiled == 'textQuestiontitleMath_' || Id == "Max_Marks"){ value = elementid.value; }else{ value = previousElement.querySelector('.jodit-workplace').querySelector('.jodit-wysiwyg').innerHTML; @@ -4617,7 +4651,7 @@ function check_Remove_Empty_Question(IdToRemove , DeleteElement=0) { if (newVariableWithoutNumbers == 'removeAndCloneQroupQuestion_') { attrId= 'choice'; } else if(DeleteElement != 1){ - if(newVariableWithoutNumbers == 'QuestionTextIdSet_' || newVariableWithoutNumbers == 'QuestionChoiceId_' || newVariableWithoutNumbers == 'Questions_Group_id_' || newVariableWithoutNumbers == 'textQuestiontitleMath_'){ + if(newVariableWithoutNumbers == 'QuestionTextIdSet_' || newVariableWithoutNumbers == 'QuestionChoiceId_' || newVariableWithoutNumbers == 'Questions_Group_id_' || newVariableWithoutNumbers == 'textQuestiontitleMath_' || IdToRemove == "Max_Marks"){ attrId = input_text_value.value; }else{ const previousElement = input_text_value.previousElementSibling; diff --git a/json2html.js b/json2html.js index 6a6ebb6..3a7530d 100644 --- a/json2html.js +++ b/json2html.js @@ -62,7 +62,7 @@ function jsonToHtml(jsonData) { var sectionMarks = section.section_marks; var sectionUUID = section.attributes.Id; var sectionDispalyMarks = section.section_display_marks; - var sectionAttemptAny = section.section_attempt_any; + var sectionAttemptAny = section.attributes.AttemptAny; var SectionObj = { diff --git a/json2xml.js b/json2xml.js index 0492eea..3a80528 100644 --- a/json2xml.js +++ b/json2xml.js @@ -62,28 +62,24 @@ function json2xml() { doc, element } = createStandaloneXMLNode('Question', { - "xsi:type": (question['question_type'] == 'text' ? 'DescriptiveQuestion' : 'MultiChoiceQuestion'), + // "xsi:type": (question['question_type'] == 'text' ? 'DescriptiveQuestion' : 'MultiChoiceQuestion'), 'Id': (question['question_type'] == 'text' ? question['text_question_uuid'] : question['choice_question_uuid']), - 'type': (question['question_type'] == 'text' ? 'Descriptive' : 'Mcq'), + 'Type': (question['question_type'] == 'text' ? 'Descriptive' : 'MCQ'), 'No': (question['question_id'] ? question['question_id'] : question['questionChoiceId']), 'DisplayMarks': (question['display_marks'] === true ? 'true' : 'false'), }, ''); - // if (question['question_id'] !== undefined) { - // var questionChoiceId =createElementWithText(doc, element, 'Text', question['question_id']) - // } else { - // // If question['question_id'] is undefined, create a new variable - // var questionIdSet = createElementWithText(doc, element , 'Text', question['questionChoiceId']) - // } - var questionTitle = createElementWithText(doc, element, 'Text', question['question']); - questionTitle.setAttribute('xsi:type',(question['is_math_enabled2'] === true ? 'Math' : '')); + if(question['is_math_enabled2'] === true){ + questionTitle.setAttribute('Type',(question['is_math_enabled2'] === true ? 'Math' : '')); + } var questionDesc = createElementWithText(doc, element, 'Subtext', question['question_description']); - questionDesc.setAttribute('xsi:type',(question['is_math_enabled'] === true ? 'Math' : '')); + if(question['is_math_enabled'] === true){ + questionDesc.setAttribute('Type',(question['is_math_enabled'] === true ? 'Math' : '')); + } var marks = createElementWithText(doc, element, 'Marks', question['marks']); - // var display_marks = createElementWithText(doc, element, 'DispalyMarks', (question['display_marks'] === true ? 'true' : 'false'), {}); if (question['question_type'] == 'group') { // console.log(question); @@ -95,7 +91,9 @@ function json2xml() { var id = createElementWithText(doc, choiceElement, 'Id', question['answers'][choice]['choice_uuid'], {}); var no = createElementWithText(doc, choiceElement, 'No', question['answers'][choice]['no'], {}); var text = createElementWithText(doc, choiceElement, 'Text', question['answers'][choice]['choice_name'], {}); - text.setAttribute('xsi:type',(question['answers'][choice]['is_math_enabled'] === true ? 'Math' : 'Text')); + if(question['answers'][choice]['is_math_enabled'] === true){ + text.setAttribute('Type',(question['answers'][choice]['is_math_enabled'] === true ? 'Math' : '')); + } } // choicesElement.appendChild(); @@ -113,35 +111,24 @@ function json2xml() { doc, element } = createStandaloneXMLNode('Question', { - 'xsi:type': 'QuestionGroup', + // 'xsi:type': 'QuestionGroup', 'Id': singleQuestion['group_uuid'], 'Type': 'QuestionGroup', 'No': (singleQuestion['question_id'] ? singleQuestion['question_id'] : '' ), - 'Order': 0, 'DisplayMarks':(singleQuestion['group_display_marks'] === true ? 'true' : 'false' ), - 'AttemptAny':(singleQuestion['group_attempt_any'] ? singleQuestion['group_attempt_any'] : '' ), + ...(singleQuestion['group_attempt_any'] !== '' ? {'AttemptAny': singleQuestion['group_attempt_any']} : {}) }, ''); - // var groupQuestionElement = createElementWithText(xmlDoc, sectionElement, 'Question', '', { - // 'xsi:type': 'QuestionGroup', - // 'Id': singleQuestion['group_uuid'], - // 'Type': 'QuestionGroup', - // 'No': singleQuestion['group_title'], - // 'Order': 0 - // }); - // var groupQuestionId = createElementWithText(doc, element, 'Text', singleQuestion['question_id']); var groupQuestionTitle = createElementWithText(doc, element, 'Text', singleQuestion['group_title']); var groupQuestionDesc = createElementWithText(doc, element, 'Subtext', singleQuestion['group_description']); var groupQuestionMarks = createElementWithText(doc, element, 'Marks', singleQuestion['group_marks']); - // var groupQuestionDisplayMarks = createElementWithText(doc, element, 'DisplayMarks', (singleQuestion['group_display_marks'] === true ? 'true' : 'false' )); - // var groupQuestionAttemptAny = createElementWithText(doc, element, 'AttemptAny', singleQuestion['group_attempt_any'] ); var groupQuestionItemsElement = createElementWithText(doc, element, 'Items', ''); //gather questions data inside question group if (singleQuestion['questions'].length != 0) { var tempGroupQuestions = singleQuestion['questions']; - console.log(tempGroupQuestions); + // console.log(tempGroupQuestions); //looping each questions indise question group and attach it to group items node for (gquestion in tempGroupQuestions) { var singleGQuestion = tempGroupQuestions[gquestion]; @@ -201,14 +188,12 @@ function json2xml() { // console.log(tempSection); var sectionElement = createElementWithText(xmlDoc, rootItemsElement, 'Question', '', { - 'xsi:type': 'QuestionPaperSection', + // 'xsi:type': 'QuestionPaperSection', 'Id': tempSection['section_uuid'], 'Type': 'Section', 'No': sectionNumber, - 'Order': 0, 'DisplayMarks':(tempSection['section_display_marks'] === true ? 'true' : 'false'), - 'AttemptAny':(tempSection['section_attempt_any'] ? tempSection['section_attempt_any'] : '' ), - + ...(tempSection['section_attempt_any'] !== '' ? {'AttemptAny': tempSection['section_attempt_any']} : {}), }); var sectionTitle = createElementWithText(xmlDoc, sectionElement, 'Text', tempSection['section_title']); diff --git a/xml2json.js b/xml2json.js index 4c60c06..2b0ccc6 100644 --- a/xml2json.js +++ b/xml2json.js @@ -126,12 +126,9 @@ function getQuestionsNodes(questionNode,type) function getQuestionGroupNodes(questionGroup) { var questionGroupObj = {}; - // questionGroupObj['question_id'] = (questionGroup.childNodes[0].firstChild !== null ? questionGroup.childNodes[0].firstChild.nodeValue : ""); questionGroupObj['group_title'] = (questionGroup.childNodes[0].firstChild !== null ? questionGroup.childNodes[0].firstChild.nodeValue : ""); questionGroupObj['group_description'] = (questionGroup.childNodes[1].firstChild !== null ? questionGroup.childNodes[1].firstChild.nodeValue : ""); questionGroupObj['group_marks'] = (questionGroup.childNodes[2].firstChild !== null ? questionGroup.childNodes[2].firstChild.nodeValue : ""); - // questionGroupObj['group_display_marks'] = questionGroup.childNodes[4].firstChild.nodeValue; - // questionGroupObj['group_attempt_any'] = (questionGroup.childNodes[5].firstChild !== null ? questionGroup.childNodes[5].firstChild.nodeValue : ""); questionGroupObj['attributes'] = getAttributesOfXMLNode(questionGroup); questionGroupObj['questions'] = []; //handle questions @@ -140,13 +137,13 @@ function getQuestionGroupNodes(questionGroup) for(let q = 0; q < questionList.length ;q++) { - var questionType = questionList[q].getAttribute("xsi:type"); - if(questionType == 'DescriptiveQuestion') + var questionType = questionList[q].getAttribute("Type"); + if(questionType == 'Descriptive') { // console.log(questionList[q]); questionGroupObj['questions'].push(getQuestionsNodes(questionList[q],1)); } - else if(questionType == 'MultiChoiceQuestion') + else if(questionType == 'MCQ') { // console.log(questionList[q]); questionGroupObj['questions'].push(getQuestionsNodes(questionList[q],2)); @@ -208,13 +205,13 @@ jsonObj['sections'] = []; //check weather quesiotn or question grup // console.log('QUESTION :' + j ); // console.log(questionList[j]); - var questionType = questionList[j].getAttribute("xsi:type"); + var questionType = questionList[j].getAttribute("Type"); // console.log(questionType); - if(questionType == 'DescriptiveQuestion') + if(questionType == 'Descriptive') { tempObj['questions'].push(getQuestionsNodes(questionList[j],1)); } - else if(questionType == 'MultiChoiceQuestion') + else if(questionType == 'MCQ') { tempObj['questions'].push(getQuestionsNodes(questionList[j],2)); } @@ -227,10 +224,11 @@ jsonObj['sections'] = []; } var jsonData = JSON.stringify(jsonObj); - // console.log('Xml to Json Conversion '); - console.log('jsonData : ', jsonData); - // console.log(jsonObj); jsonToHtml(jsonObj); + + // console.log('Xml to Json Conversion '); + // console.log('jsonData : ', jsonData); + // console.log(jsonObj); // console.log(jsonToHtml(jsonObj)) // localStorage.removeItem('json_Decode_Data_For_Mcq_Crt_Ans'); diff --git a/xml2json_for_Questionpaper_preview.js b/xml2json_for_Questionpaper_preview.js index 5b23383..e3cd81f 100644 --- a/xml2json_for_Questionpaper_preview.js +++ b/xml2json_for_Questionpaper_preview.js @@ -98,13 +98,13 @@ function getQuestionGroupNodes(questionGroup) for(let q = 0; q < questionList.length ;q++) { - var questionType = questionList[q].getAttribute("xsi:type"); + var questionType = questionList[q].getAttribute("Type"); console.log(questionType); - if(questionType == 'DescriptiveQuestion') + if(questionType == 'Descriptive') { questionGroupObj['questions'].push(getQuestionsNodes(questionList[q],1)); } - else if(questionType == 'MultiChoiceQuestion') + else if(questionType == 'MCQ') { questionGroupObj['questions'].push(getQuestionsNodes(questionList[q],2)); } @@ -121,7 +121,7 @@ function getQuestionGroupNodes(questionGroup) //busi logic start var xmlString = xmlData; -const parser = new DOMParser(); +const parser = new DOMParser(); // Parse the XML string into an XML document const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); @@ -129,7 +129,6 @@ const jsonObj = {}; jsonObj['question_paper_title'] = xmlDoc.getElementsByTagName("Title")[0] && xmlDoc.getElementsByTagName("Title")[0].childNodes[0] ? xmlDoc.getElementsByTagName("Title")[0].childNodes[0].nodeValue : null; jsonObj['question_paper_description'] = xmlDoc.getElementsByTagName("Subtitle")[0] && xmlDoc.getElementsByTagName("Subtitle")[0].childNodes[0] ? xmlDoc.getElementsByTagName("Subtitle")[0].childNodes[0].nodeValue : null; -//get attributes of root/question paper element jsonObj['attributes'] = getAttributesOfXMLNode(xmlDoc.documentElement); jsonObj['sections'] = []; @@ -158,13 +157,13 @@ jsonObj['sections'] = []; //check weather quesiotn or question grup // console.log('QUESTION :' + j ); // console.log(questionList[j]); - var questionType = questionList[j].getAttribute("xsi:type"); + var questionType = questionList[j].getAttribute("Type"); // console.log(questionType); - if(questionType == 'DescriptiveQuestion') + if(questionType == 'Descriptive') { tempObj['questions'].push(getQuestionsNodes(questionList[j],1)); } - else if(questionType == 'MultiChoiceQuestion') + else if(questionType == 'MCQ') { tempObj['questions'].push(getQuestionsNodes(questionList[j],2)); }