PREVIEW_CHANGES CREATE_PREVIEW : AADHAVAN
This commit is contained in:
parent
d7396137f4
commit
0b379fb7f9
@ -2,6 +2,44 @@
|
||||
function QuestionPaperPreview(jsonData){
|
||||
// The provided JSON data
|
||||
// console.log(jsonData)
|
||||
|
||||
// start Remove <p> tag
|
||||
|
||||
var jsonDat = jsonData;
|
||||
// Remove <p> tags only with <br> tags
|
||||
function removeEmptyPTags(htmlString) {
|
||||
var tempdiv = document.createElement('div');
|
||||
tempdiv.innerHTML = htmlString;
|
||||
var paragraphs = tempdiv.querySelectorAll('p');
|
||||
|
||||
paragraphs.forEach(function(paragraph) {
|
||||
if (paragraph.innerHTML.trim() === '<br>') {
|
||||
paragraph.remove();
|
||||
}
|
||||
});
|
||||
|
||||
return tempdiv.innerHTML;
|
||||
}
|
||||
// Recursive function to modify HTML content in an object
|
||||
function modifyHTMLProperties(obj) {
|
||||
for (var key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
if (typeof obj[key] === 'string') {
|
||||
// If the property is a string, modify it
|
||||
obj[key] = removeEmptyPTags(obj[key]);
|
||||
} else if (typeof obj[key] === 'object') {
|
||||
// If the property is an object, recursively modify its properties
|
||||
modifyHTMLProperties(obj[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
modifyHTMLProperties(jsonDat);
|
||||
|
||||
//end Remove <p> tag
|
||||
|
||||
|
||||
|
||||
function convertToLatex(text, mathstatus) {
|
||||
// Parse mathstatus into a boolean
|
||||
const mathStatusBoolean = JSON.parse(mathstatus);
|
||||
@ -25,59 +63,82 @@ function convertToLatex(text, mathstatus) {
|
||||
let questionPaper = "";
|
||||
|
||||
|
||||
function CheakQnType(question, questionIndex, depth) {
|
||||
function CheakQnType(question, questionIndex, depth,nested) {
|
||||
const questionType = question.question_type;
|
||||
|
||||
if (questionType) {
|
||||
processQuestion(question, questionIndex, depth);
|
||||
processQuestion(question, questionIndex, depth,nested);
|
||||
}else {
|
||||
GroupQuestion(question, questionIndex, depth);
|
||||
}
|
||||
|
||||
}
|
||||
let count =0
|
||||
function processQuestion(question, questionIndex, depth) {
|
||||
const questionText = question.question;
|
||||
var count1 =0
|
||||
function processQuestion(question, questionIndex, depth,nested) {
|
||||
const questionTex = question.question;
|
||||
const questionText = questionTex.replace('<p>', '<p id="question_Text">');
|
||||
const questionDescription = question.question_description;
|
||||
const mathstatus = question.is_math_enabled;
|
||||
|
||||
const questionMark = question.marks;
|
||||
const multipleAnswer =question.question_sub_type; // this gives true or false to chaeck multiple answers or not
|
||||
// Add appropriate indentation for nested questions
|
||||
const questionIndentation = " ".repeat(depth + 1);
|
||||
count++
|
||||
questionPaper += `<div class="text-qus-align">${questionIndentation}${count}) ${convertToLatex(questionText, mathstatus)}${questionIndentation}</div><div class="text-des">${convertToLatex(questionDescription, mathstatus)}</div>`;
|
||||
if (nested == 1) {// this adds the inside the questionGroup
|
||||
count1++
|
||||
questionPaper += `<div class="text-qus-align">${questionIndentation}${count}.${count1}) ${convertToLatex(questionText, mathstatus)}${questionIndentation}</div><p id="question-mark">Marks :${questionMark}</p><div class="text-des">${convertToLatex(questionDescription, mathstatus)}</div>`;
|
||||
} else {
|
||||
count++
|
||||
questionPaper += `<div class="text-qus-align">${questionIndentation}${count}) ${convertToLatex(questionText, mathstatus)}${questionIndentation}</div><p id="question-mark">Marks :${questionMark}</p><div class="text-des">${convertToLatex(questionDescription, mathstatus)}</div>`;
|
||||
}
|
||||
|
||||
// If it's an MCQ question, add choices
|
||||
if (question.question_type === "group") {
|
||||
const answers = question.answers;
|
||||
const alphabetOptions = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // Define the alphabet options
|
||||
|
||||
for (let i = 0; i < answers.length; i += 2) {
|
||||
for (let i = 0; i < answers.length; i++) { // change the i +=2 aadhavan
|
||||
const optionA = alphabetOptions[i];
|
||||
const optionB = alphabetOptions[i + 1];
|
||||
// const optionB = alphabetOptions[i + 1];
|
||||
|
||||
const answerA = answers[i] ? `${optionA}. ${convertToLatex(answers[i].choice_name, mathstatus)}` : '';
|
||||
const answerB = answers[i + 1] ? `${optionB}. ${convertToLatex(answers[i + 1].choice_name, mathstatus)}` : '';
|
||||
|
||||
questionPaper += `<div class="text-option-align">${questionIndentation}${answerA.padEnd(10)} ${answerB}</div>\n`;
|
||||
// const answerB = answers[i + 1] ? `${optionB}. ${convertToLatex(answers[i + 1].choice_name, mathstatus)}` : '';
|
||||
if (multipleAnswer == 'false') {
|
||||
questionPaper += `<div class="text-option-align"><input type="radio" name="answer" value="A"> ${questionIndentation}${answerA.padEnd(10)}</div>`;
|
||||
}else{
|
||||
questionPaper += `<div class="text-option-align"><input type="checkbox" name="answer" value="A"> ${questionIndentation}${answerA.padEnd(10)}</div>`;
|
||||
}
|
||||
// questionPaper += `<div class="text-option-align">${questionIndentation}${answerA.padEnd(10)}</div>`;
|
||||
// questionPaper += `<div class="text-option-align">${questionIndentation}${answerA.padEnd(10)} ${answerB}</div>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function GroupQuestion(question, questionIndex, depth) {
|
||||
questionPaper += `${question.group_title}`;
|
||||
questionPaper += `${question.group_description}`;
|
||||
|
||||
const questionGroupSetP = `${question.group_title}`;
|
||||
const questionGroupmodify =questionGroupSetP.replace('<p>', '<p id="question-Group-Id">')
|
||||
count++
|
||||
questionPaper += `<div class="text-qus-align" style="margin-left:-1px">${count}) ${questionGroupmodify}</div>`
|
||||
|
||||
questionPaper += `<div class="group_marks"><p id="group_marks">Marks : ${question.group_marks} </p></div>`;
|
||||
questionPaper += `<div class="group_attempt_any"><p id="group_attempt_any">Attempt Any : ${question.group_attempt_any} </p></div>`;
|
||||
|
||||
questionPaper += `<div style="margin-left:20px">${question.group_description}</div>`;
|
||||
const nestedQuestions = question.questions;
|
||||
// Process nested questions in the same way
|
||||
count1 =0
|
||||
nestedQuestions.forEach((nestedQuestion) => {
|
||||
// processQuestion(nestedQuestion, questionIndex, depth);
|
||||
CheakQnType(nestedQuestion,questionIndex,depth);
|
||||
const nested =1;
|
||||
|
||||
CheakQnType(nestedQuestion,questionIndex,depth,nested);
|
||||
});
|
||||
}
|
||||
|
||||
// Function to recursively convert JSON to a formatted question paper
|
||||
function convertJSONToQuestionPaper(data, depth = 0, sectionIndex = 1, questionIndex = 1) {
|
||||
const sections = data.sections;
|
||||
|
||||
console.log(sections);
|
||||
// Extract the heading information
|
||||
const questionPaperTitle = data.question_paper_title;
|
||||
const questionPaperDescription = data.question_paper_description;
|
||||
@ -87,17 +148,24 @@ function convertJSONToQuestionPaper(data, depth = 0, sectionIndex = 1, questionI
|
||||
// Wrap the heading elements in <div> elements with CSS for centering
|
||||
questionPaper += `<div style="text-align: center; font-weight: bolder; "><h1>${questionPaperTitle}</h1></div>`;
|
||||
questionPaper += `<div style="text-align: center;"><h5>${questionPaperDescription}</h5></div>`;
|
||||
questionPaper += "<br><br><br>"; // Add a newline for separation
|
||||
// questionPaper += "<br><br><br>"; // Add a newline for separation
|
||||
|
||||
// Process each section
|
||||
sections.forEach((section, sectionIndex) => {
|
||||
const sectionTitle = section.section_title;
|
||||
const modifiedSectionTitle = sectionTitle.replace('<p>', '<p id="sectionTitle">');//add the id for Section Title
|
||||
|
||||
const sectionAttempt = `<p id="sectionAttempt">Attempt Any : ${section.section_attempt_any}</p>`;
|
||||
const sectionMark = `<p id="sectionMark">Marks: ${section.section_marks}</p>`;
|
||||
const sectionDescription = section.section_description;
|
||||
const questions = section.questions;
|
||||
|
||||
// Add appropriate indentation for nested sections
|
||||
const indentation = " ".repeat(depth);
|
||||
questionPaper += `${indentation}${sectionTitle}${indentation}${sectionDescription}`;
|
||||
|
||||
// questionPaper += `${indentation}${sectionTitle}${sectionAttempt}${sectionMark}${indentation}${sectionDescription}`;
|
||||
questionPaper += `${indentation}${modifiedSectionTitle}${sectionMark}${sectionAttempt}${indentation}${sectionDescription}`;
|
||||
|
||||
|
||||
// Process each question in the section
|
||||
questions.forEach((question, questionIndex) => {
|
||||
@ -108,6 +176,7 @@ function convertJSONToQuestionPaper(data, depth = 0, sectionIndex = 1, questionI
|
||||
});
|
||||
|
||||
// Return the formatted question paper
|
||||
// console.log(questionPaper);
|
||||
return questionPaper;
|
||||
}
|
||||
|
||||
|
||||
@ -49,8 +49,53 @@
|
||||
|
||||
|
||||
<style>
|
||||
/* Question Group Mark */
|
||||
.text-qus-align{
|
||||
display: inline-flex;
|
||||
}
|
||||
.group_attempt_any{
|
||||
display: inline-flex;
|
||||
float: right;
|
||||
margin-right: 40px;
|
||||
}
|
||||
.group_marks{
|
||||
display: inline-flex;
|
||||
float: right;
|
||||
}
|
||||
|
||||
|
||||
/* Questions Mark */
|
||||
#question_Text{
|
||||
display: inline-block;
|
||||
margin-right: 10px;
|
||||
}
|
||||
#question-mark{
|
||||
display: inline-block;
|
||||
margin-right: 10px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
/* Section SectionAttempt SectionMark */
|
||||
#sectionTitle{
|
||||
display: inline-block;
|
||||
margin-right: 10px;
|
||||
}
|
||||
#sectionAttempt{
|
||||
display: inline-block;
|
||||
margin-right: 40px;
|
||||
float: right;
|
||||
}
|
||||
#sectionMark{
|
||||
display: inline-block;
|
||||
margin-right: 10px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
/* End the this */
|
||||
|
||||
mjx-math{
|
||||
margin-top: 10px;
|
||||
}
|
||||
/* Center the heading */
|
||||
#heading {
|
||||
text-align: center;
|
||||
@ -60,11 +105,13 @@
|
||||
.MathJax.CtxtMenu_Attached_0{
|
||||
display: contents !important;
|
||||
}
|
||||
.text-qus-align{ display:flex;margin-left: -10px; }
|
||||
.text-qus-align{margin-left: -16px;padding-right: 250px; }
|
||||
.text-qus-align p{ margin:0; }
|
||||
.text-des{ margin-left: 20px;margin-top: 6px;}
|
||||
.text-option-align{display:flex;margin-top: 10px;}
|
||||
.text-des{ margin-left: 20px;margin-top: 0px;} /* Change there aadhavan top-6px*/
|
||||
.text-option-align{display:flex;margin-top: 0%;margin-left: 45px;} /* Change there aadhavan 10px*/
|
||||
.text-option-align p{ margin:0; }
|
||||
#sectionTitle {border-top: 2px solid gray; width: 100%;}
|
||||
#sectionTitle:first-of-type {border:none;}
|
||||
mjx-container[jax="CHTML"][display="true"] {
|
||||
display: block;
|
||||
text-align: center;
|
||||
@ -107,7 +154,9 @@
|
||||
text-align: right;
|
||||
margin-bottom: -32px;
|
||||
}
|
||||
|
||||
p{
|
||||
margin-bottom: auto;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -220,6 +269,7 @@
|
||||
<script src="decode.js"></script>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
const fs = require('fs');
|
||||
const path =require('path');
|
||||
@ -260,11 +310,10 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
33
addform.html
33
addform.html
@ -354,7 +354,7 @@
|
||||
<ul>
|
||||
<li><a href="dashboard.html"><i class="fa fa-home" aria-hidden="true" style="font-size: 24px;"></i> Home</a></li>
|
||||
<li><a href="#" class="myBtn" onclick="saveFile()" id="SaveButton"><i class="fa fa-floppy-o" aria-hidden="true" style="font-size: 20px;"></i> Save</a></li>
|
||||
<li><a id="editPreview" href=""><i class="fa fa-eye" aria-hidden="true" style="font-size: 24px;"></i> Preview</a></li>
|
||||
<li><a id="editPreview" style="color: #730fd5;"><i class="fa fa-eye" aria-hidden="true" style="font-size: 24px;"></i> Preview</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -585,7 +585,7 @@
|
||||
|
||||
const url = new URL(window.location.href);// Get the URL of the current page for JSON
|
||||
const params = new URLSearchParams(url.search);// Create a URLSearchParams object from the query string
|
||||
const FileName = params.get('filename');// Get the value of a specific parameter
|
||||
var FileName = params.get('filename');// Get the value of a specific parameter
|
||||
|
||||
var xmlPath ="" //get the xml filepath in .env file local variable
|
||||
|
||||
@ -639,8 +639,33 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
});
|
||||
|
||||
|
||||
//EditPreview
|
||||
document.getElementById("editPreview").href = "QuestionPreview.html?filename=" + FileName;
|
||||
//EditPreview and Create Previe
|
||||
var previewbutton = document.getElementById("editPreview");
|
||||
previewbutton.addEventListener("click", async () => {
|
||||
if (FileName) {
|
||||
previewbutton.href = "QuestionPreview.html?filename=" + FileName;
|
||||
} else {
|
||||
const saveButton = document.getElementById('SaveButton');
|
||||
if (saveButton) {
|
||||
saveButton.click();
|
||||
setTimeout(function() {
|
||||
var popupInput = document.getElementById("swal2-input");
|
||||
var submitButton = document.querySelector(".swal2-confirm.swal2-styled");
|
||||
submitButton.addEventListener("click", function() {
|
||||
FileName = popupInput.value;
|
||||
FileName += ".xml"
|
||||
if(FileName){
|
||||
var anchorElement = document.getElementById("editPreview");
|
||||
if (anchorElement) {
|
||||
anchorElement.click();
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// Function to load XML from a file
|
||||
function loadXML(xmlFileName) {
|
||||
|
||||
@ -12,20 +12,20 @@ body {
|
||||
padding: 0;
|
||||
color: #6d6d6d;
|
||||
font-family: 'Rubik', sans-serif;
|
||||
font-weight: 400;
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
font-size: 16px;
|
||||
line-height: 28px;
|
||||
line-height: 28px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
|
||||
p {
|
||||
|
||||
font-weight: 400;
|
||||
font-weight: 500;/* Change this into 400 aadhavan */
|
||||
font-style: normal;
|
||||
font-family: 'Rubik', sans-serif;
|
||||
color: #6d6d6d;
|
||||
color: #6d6d6d;
|
||||
}
|
||||
h1,
|
||||
h2,
|
||||
|
||||
@ -218,7 +218,7 @@ function json2xml() {
|
||||
// Serialize the XML to a string
|
||||
var xmlString = new XMLSerializer().serializeToString(xmlDoc);
|
||||
|
||||
console.log(xmlString);
|
||||
// console.log(xmlString);
|
||||
localStorage.setItem("xml", xmlString);
|
||||
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ function saveXmlToFile(xmlData, filePath) {
|
||||
});
|
||||
localStorage.clear();
|
||||
|
||||
window.location.href = 'dashboard.html';
|
||||
// window.location.href = 'dashboard.html';
|
||||
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ function promptBox(){
|
||||
var jsonString = JSON.parse(jsonData);
|
||||
var getTitle = jsonString.question_paper_title;
|
||||
var RawFileName = removeHtmlTags(getTitle);
|
||||
console.log(RawFileName)
|
||||
// console.log(RawFileName)
|
||||
|
||||
Swal.fire({
|
||||
title: 'Enter Filename',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user