Merge branch 'dev' of bitbucket.org:venbainformationtechnology/projectb into dev

This commit is contained in:
aadhavan 2023-12-11 12:36:03 +05:30
commit 9bc8c93824
3 changed files with 146 additions and 75 deletions

View File

@ -489,35 +489,102 @@ color: #1d3557 !important;
//Preview edit button //Preview edit button
document.getElementById("editlink").href = "addform.html?filename=" + xmlFileName; document.getElementById("editlink").href = "addform.html?filename=" + xmlFileName;
// Function to load XML from a file //XmlPath get from .env
function loadXML(xmlFileName) {
// const decode = require('./decode');
// Function to load XML from a file
function loadXML(xmlFileName) {
//XmlPath get from .env
const xmlPathenv=configObject.XML_FILE_PATH.trim(); const xmlPathenv=configObject.XML_FILE_PATH.trim();
// const xmlPathenv=process.env.XML_FILE_PATH;
const xmlPath =path.join(__dirname,xmlPathenv); const xmlPath =path.join(__dirname,xmlPathenv);
// console.log(xmlFileName)
return new Promise((resolve, reject) => { // console.log('xmlFileName', xmlFileName);
fs.readFile(`${xmlPath}`+xmlFileName, 'utf8', (error, data) => {
if (error) { var decodeData ="";
reject(error); var encodedXmlFilePath = `${xmlPath}${xmlFileName}`;
} else {
if (isEncrypted === 'YES') { var jsonDecodeData = "";
var decodeData = decode(data); var jsonFileName = xmlFileName.split('.xml');
resolve(decodeData); var encodedJsonFilePath = `${xmlPath}${jsonFileName[0]}_answer.json`;
xml2json(decodeData);
} else { // console.log('encodedJsonFilePath', encodedJsonFilePath);
resolve(data);
xml2json(data); var filelist = findFile(encodedJsonFilePath);
} const decode = require('./decode');
MathJax.typeset(); if(filelist !== false)
} {
}); //JSON File Read Function
}); fs.readFile(encodedJsonFilePath, 'utf8', (error, data) => {
} if (error) {
</script> console.error('Error reading file:', error);
} else {
if (isEncrypted === 'YES') {
jsonDecodeData = decode(encodedJsonFilePath);
localStorage.setItem('json_Decode_Data_For_Mcq_Crt_Ans', jsonDecodeData);
} else{
jsonDecodeData = data;
localStorage.setItem('json_Decode_Data_For_Mcq_Crt_Ans', jsonDecodeData);
console.log('jsonDecodeData', jsonDecodeData);
}
}
});
}
setTimeout(function() {
fs.readFile(`${xmlPath}${xmlFileName}`, 'utf8', (error, data) => {
if (error) {
console.error('Error reading file:', error);
} else {
if (isEncrypted === 'YES') {
// decrypt function call go to decode.js
decodeData = decode(encodedXmlFilePath);
} else{
decodeData = data;
}
console.log('jsonDecodeData : ', jsonDecodeData);
xml2json(decodeData);
}
});
}, 1000);
}
// Function for Finding the JSON File in the folder
function findFile(filePath) {
try {
const stats = fs.statSync(filePath);
if (stats.isFile()) {
// File exists
// console.log(`File found at: ${filePath}`);
return true;
} else {
// console.error(`Path is not a file: ${filePath}`);
return false;
}
} catch (err) {
// console.error(`File not found: ${filePath}`);
return false;
}
}
</script>

View File

@ -1299,41 +1299,43 @@ $('#workarea_math').click(function(){
console.log('called'); console.log('called');
$('#workarea_math').css('margin-bottom', '240px'); $('#workarea_math').css('margin-bottom', '240px');
localStorage.setItem('workAreaMath', true); localStorage.setItem('workAreaMath', true);
}); });
$(document).on("click", function (event) { $(document).on("click", function (event) {
// console.log('Clicked element id:', event.target.id); // console.log('Clicked element id:', event.target.id);
// console.log('Clicked element:', event.target); // console.log('Clicked element:', event.target);
const targetElement = event.target; const targetElement = event.target;
var tragetedId = event.target.id.startsWith("ML"); var tragetedId = event.target.id.startsWith("ML");
const classList = Array.from(event.target.classList); const classList = Array.from(event.target.classList);
const hasMLKClass = classList.some(className => className.startsWith("MLK") || className.startsWith("row") || className.startsWith("left") || className.startsWith("ML") || className.startsWith("action")); const hasMLKClass = classList.some(className => className.startsWith("MLK") || className.startsWith("row") || className.startsWith("left") || className.startsWith("ML") || className.startsWith("action"));
const isSvgElement = targetElement.closest('svg') || targetElement.closest('i'); const isSvgElement = targetElement.closest('svg') || targetElement.closest('i');
// console.log('svg',isSvgElement); // console.log('svg',isSvgElement);
// console.log(hasMLKClass); // console.log(hasMLKClass);
if (event.target.id !== 'workarea_math' && tragetedId == false && hasMLKClass == false && isSvgElement == null) { if (event.target.id !== 'workarea_math' && tragetedId == false && hasMLKClass == false && isSvgElement == null) {
// console.log('Inside if'); // console.log('Inside if');
var value = localStorage.getItem('workAreaMath'); var value = localStorage.getItem('workAreaMath');
if (value === 'true') { if (value === 'true') {
// console.log('Value:', value); // console.log('Value:', value);
$('#workarea_math').css('margin-bottom', '0px'); $('#workarea_math').css('margin-bottom', '0px');
localStorage.removeItem('workAreaMath'); localStorage.removeItem('workAreaMath');
} else { } else {
// $('#workarea_math').css('margin-bottom', '190px'); // $('#workarea_math').css('margin-bottom', '190px');
// console.log('Value is not true'); // console.log('Value is not true');
}
} }
}
}); });
var ids = document.getElementById('workarea_math'); var ids = document.getElementById('workarea_math');
//clear the string from the workarea and a fileds
function clearMessage() { function clearMessage() {
var val = document.getElementById('messages') ; var val = document.getElementById('messages') ;
if(val !== null){ if(val !== null){
@ -1465,7 +1467,9 @@ var previewbutton = document.getElementById("editPreview");
function editPreview() { function editPreview() {
var title_id = localStorage.getItem('JSON_FOR_EMPTY_QUESTION'); var title_id = localStorage.getItem('JSON_FOR_EMPTY_QUESTION');
var count = ""; var count = "";//XmlPath get from .env
// const decode = require('./decode');
if(title_id !== '' && title_id !== null) if(title_id !== '' && title_id !== null)
{ {
var parsedArray = JSON.parse(title_id); var parsedArray = JSON.parse(title_id);
@ -1550,22 +1554,22 @@ var previewbutton = document.getElementById("editPreview");
// Function for Finding the JSON File in the folder // Function for Finding the JSON File in the folder
function findFile(filePath) { function findFile(filePath) {
try { try {
const stats = fs.statSync(filePath); const stats = fs.statSync(filePath);
if (stats.isFile()) { if (stats.isFile()) {
// File exists // File exists
// console.log(`File found at: ${filePath}`); // console.log(`File found at: ${filePath}`);
return true; return true;
} else { } else {
// console.error(`Path is not a file: ${filePath}`); // console.error(`Path is not a file: ${filePath}`);
return false; return false;
} }
} catch (err) { } catch (err) {
// console.error(`File not found: ${filePath}`); // console.error(`File not found: ${filePath}`);
return false; return false;
} }
} }
@ -1587,7 +1591,7 @@ function loadXML(xmlFileName) {
// console.log('encodedJsonFilePath', encodedJsonFilePath); // console.log('encodedJsonFilePath', encodedJsonFilePath);
var filelist = findFile(encodedJsonFilePath); var filelist = findFile(encodedJsonFilePath);
const decode = require('./decode');
if(filelist !== false) if(filelist !== false)
{ {
//JSON File Read Function //JSON File Read Function

View File

@ -432,9 +432,9 @@ function validateFile(input) {
const allowedExtensions = ["xml"]; const allowedExtensions = ["xml"];
const fileExtension = file.name.split(".").pop().toLowerCase(); const fileExtension = file.name.split(".").pop().toLowerCase();
if (!allowedExtensions.includes(fileExtension)) { if (!allowedExtensions.includes(fileExtension)) {
alert('Invalid file type. Only xml files are allowed.') alert('Invalid file type. Only xml files are allowed.')
input.value = ""; input.value = "";
return; return;
} }
} }
@ -460,19 +460,19 @@ function validateFile(input) {
function downloadFile(filename) { function downloadFile(filename) {
console.log(xmlPath); // console.log(xmlPath);
const xmlFilePath = `${xmlPath}${filename}`; const xmlFilePath = `${xmlPath}${filename}`;
console.log(xmlFilePath) // console.log(xmlFilePath)
const xmlFileNameParts = filename.split('.xml'); const xmlFileNameParts = filename.split('.xml');
const xmlBaseName = xmlFileNameParts[0]; const xmlBaseName = xmlFileNameParts[0];
const jsonFileName = `${xmlBaseName}_answer.json`; const jsonFileName = `${xmlBaseName}_answer.json`;
const jsonFilePath = `${xmlPath}${jsonFileName}`; const jsonFilePath = `${xmlPath}${jsonFileName}`;
console.log(jsonFilePath); // console.log(jsonFilePath);
var fileList = findFile(jsonFilePath); var fileList = findFile(jsonFilePath);
console.log(fileList) // console.log(fileList)
// const downloadsPath = process.env.DOWNLOAD_XML_FILE_PATH; // const downloadsPath = process.env.DOWNLOAD_XML_FILE_PATH;
@ -480,18 +480,18 @@ console.log(fileList)
// const isEncrypted = process.env.ENCRYPTED; // const isEncrypted = process.env.ENCRYPTED;
const downloadsPath = configObject.DOWNLOAD_XML_FILE_PATH.trim(); const downloadsPath = configObject.DOWNLOAD_XML_FILE_PATH.trim();
console.log(downloadsPath,'downloadpath'); // console.log(downloadsPath,'downloadpath');
const isEncrypted = configObject.ENCRYPTED.trim(); const isEncrypted = configObject.ENCRYPTED.trim();
const filePathToSave = path.join(downloadsPath, filename); const filePathToSave = path.join(downloadsPath, filename);
const jsonFilePathToSave = path.join(downloadsPath, jsonFileName); const jsonFilePathToSave = path.join(downloadsPath, jsonFileName);
console.log(filePathToSave); // console.log(filePathToSave);
console.log(jsonFilePathToSave); // console.log(jsonFilePathToSave);
if(isEncrypted == 'YES'){ if(isEncrypted == 'YES'){
console.log('isEncrypted'); // console.log('isEncrypted');
// XML File // XML File
@ -510,7 +510,7 @@ if(fileList !== false)
} }
else{ else{
console.log('isEncrypted NOT'); // console.log('isEncrypted NOT');
// //Download XML FIle // //Download XML FIle
// console.log(xmlFilePath); // console.log(xmlFilePath);