CODE MERGE : RV

This commit is contained in:
venkateswaran ubuntu 2023-10-19 17:22:11 +05:30
commit 287c859eaa
3 changed files with 130 additions and 45 deletions

View File

@ -49,6 +49,10 @@
<style>
p{
font-weight: 500;
}
/* Question Group Mark */
.text-qus-align{
display: inline-flex;
@ -110,7 +114,8 @@
.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 {border-top: 2px solid gray
; width: 100%;}
#sectionTitle:first-of-type {border:none;}
mjx-container[jax="CHTML"][display="true"] {
display: block;

View File

@ -48,6 +48,14 @@
<style>
#editPreview{
color: #7018d4;
}
#editPreview:hover {
color:#3399FF;
}
ul, #myUL {
list-style-type: none;
}
@ -373,7 +381,7 @@
<ul>
<li><a href="dashboard.html"><i class="fa fa-home" aria-hidden="true" style="font-size: 24px;"></i>&nbsp;&nbsp;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>&nbsp;&nbsp;Save</a></li>
<li><a id="editPreview" style="color: #730fd5;"><i class="fa fa-eye" aria-hidden="true" style="font-size: 24px;"></i>&nbsp;&nbsp;Preview</a></li>
<li><a id="editPreview" ><i class="fa fa-eye" aria-hidden="true" style="font-size: 24px;"></i>&nbsp;&nbsp;Preview</a></li>
</ul>
</div>
</div>
@ -603,7 +611,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
var 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

View File

@ -3,11 +3,38 @@ const cheerio = require('cheerio');
const Swal = require('sweetalert2')
const encode = require('./encode')
const path = require('path')
require('dotenv').config();
//Get the value from .env
const isEncrypted = process.env.ENCRYPTED;
// start the Autosave filename take the names in xml folder
////////
function getFilesInFolder(folderName) {
const xmlFilePath = path.join(__dirname, folderName);
try {
const fileNames = fs.readdirSync(xmlFilePath);
const xmlFiles = fileNames.filter((file) => file.endsWith('.xml'));
return xmlFiles;
} catch (error) {
console.error('Error reading folder:', error);
return [];
}
}
//XmlPath get from .env
const xmlPath_ = process.env.XML_FILE_PATH;
const folderName = `/${xmlPath_}`;
const filePaths = [];
const files = getFilesInFolder(folderName);
files.forEach((file) => {
const filePath = file;
filePaths.push(filePath);
});
////////
//end the autosave
function saveXmlToFile(xmlData, filePath) {
console.log(filePath);
// Check if the file path is provided
@ -38,67 +65,102 @@ function saveXmlToFile(xmlData, filePath) {
function savexml(UserFilename) {
// Get the XML string from localStorage
var xmlString = localStorage.getItem("xml");
//check Encrypted or not
var enc = "";
if (isEncrypted === 'YES') {
// Encrypt
enc = encode(xmlString);
}else{
enc = xmlString;
}
// Get the XML string from localStorage
var xmlString = localStorage.getItem("xml");
//XmlPath get from .env
const xmlPathenv=process.env.XML_FILE_PATH;
const xmlPath = path.join(__dirname, xmlPathenv)
// Get the json string from localStorage for set fileName
var jsonData = localStorage.getItem("json");
// Create a filename using on the subtitle
var xmlfilename = `${UserFilename}.xml`;
// var jsonfilename = `${UserFilename}.json`;
// file path where you want to save the XML file
// const xmlfilePath = process.cwd() + `/${xmlPath}` + xmlfilename;
const xmlfilePath = `${xmlPath}` + xmlfilename;
// const jsonfilePath = process.cwd() + '/xml/' + jsonfilename;
// Call the function to save the XML file
saveXmlToFile(enc, xmlfilePath);
//check Encrypted or not
var enc = "";
if (isEncrypted === 'YES') {
// Encrypt
enc = encode(xmlString);
} else {
enc = xmlString;
}
function promptBox(){
//XmlPath get from .env
const xmlPathenv = process.env.XML_FILE_PATH;
const xmlPath = path.join(__dirname, xmlPathenv)
// Get the json string from localStorage for set fileName
var jsonData = localStorage.getItem("json");
// Create a filename using on the subtitle
var xmlfilename = `${UserFilename}.xml`;
// var jsonfilename = `${UserFilename}.json`;
var jsonData = localStorage.getItem("json");
var jsonString = JSON.parse(jsonData);
var getTitle = jsonString.question_paper_title;
var RawFileName = removeHtmlTags(getTitle);
// console.log(RawFileName)
// file path where you want to save the XML file
// const xmlfilePath = process.cwd() + `/${xmlPath}` + xmlfilename;
const xmlfilePath = `${xmlPath}` + xmlfilename;
// const jsonfilePath = process.cwd() + '/xml/' + jsonfilename;
// Call the function to save the XML file
saveXmlToFile(enc, xmlfilePath);
}
function promptBox() {
var jsonData = localStorage.getItem("json");
var jsonString = JSON.parse(jsonData);
var getTitle = jsonString.question_paper_title;
var RawFileNam = removeHtmlTags(getTitle);
var RawFileName;
if (RawFileNam === "" || RawFileNam === null) {
const currentDate = new Date();
const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2, '0');
const day = String(currentDate.getDate()).padStart(2, '0');
let hours = currentDate.getHours();
let ampm = 'AM';
if (hours > 12) {
hours -= 12;
ampm = 'PM';
}
hours = String(hours).padStart(2, '0');
const minutes = String(currentDate.getMinutes()).padStart(2, '0');
// Create a formatted date-time string
const formattedDateTime = `${year}${month}${day}(${hours};${minutes}${ampm})`;
RawFileName = "untitled" +formattedDateTime;
} else {
RawFileName = RawFileNam
}
Swal.fire({
title: 'Enter Filename',
input: 'text',
inputValue: RawFileName,
showCancelButton: true,
showDenyButton: false,
denyButtonText: 'Overwrite',
confirmButtonText: 'Submit',
cancelButtonText: 'Cancel',
inputValidator: (value) => {
const entervalue =value+'.xml'
if (!value) {
return 'You need to enter Filename!'
}
else if (value){
const fileexists =fileexists(entervalue);
if(fileexists){
Swal.update({ showDenyButton: true });
return 'This file Name already exists'
}else {
Swal.update({ showDenyButton: false });
}
}
}
}).then((result) => {
console.log(result);
if (result.isConfirmed) {
const inputValue = result.value
savexml(inputValue)
}else if(result.isDenied){
savexml(RawFileName)
}
})
@ -114,5 +176,15 @@ function removeHtmlTags(inputString) {
return text;
}
//check filename is already exists or not
function fileexists(enteredfilename) {
var nextFilename
for (const files of filePaths) {
nextFilename = files;
if (nextFilename === enteredfilename) {
return true;
}
}
}