CODE MERGE : RV
This commit is contained in:
commit
287c859eaa
@ -49,6 +49,10 @@
|
|||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
p{
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
/* Question Group Mark */
|
/* Question Group Mark */
|
||||||
.text-qus-align{
|
.text-qus-align{
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
@ -110,7 +114,8 @@
|
|||||||
.text-des{ margin-left: 20px;margin-top: 0px;} /* Change there aadhavan top-6px*/
|
.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{display:flex;margin-top: 0%;margin-left: 45px;} /* Change there aadhavan 10px*/
|
||||||
.text-option-align p{ margin:0; }
|
.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;}
|
#sectionTitle:first-of-type {border:none;}
|
||||||
mjx-container[jax="CHTML"][display="true"] {
|
mjx-container[jax="CHTML"][display="true"] {
|
||||||
display: block;
|
display: block;
|
||||||
|
|||||||
12
addform.html
12
addform.html
@ -48,6 +48,14 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
|
#editPreview{
|
||||||
|
color: #7018d4;
|
||||||
|
}
|
||||||
|
#editPreview:hover {
|
||||||
|
color:#3399FF;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
ul, #myUL {
|
ul, #myUL {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
@ -373,7 +381,7 @@
|
|||||||
<ul>
|
<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="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 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" style="color: #730fd5;"><i class="fa fa-eye" aria-hidden="true" style="font-size: 24px;"></i> Preview</a></li>
|
<li><a id="editPreview" ><i class="fa fa-eye" aria-hidden="true" style="font-size: 24px;"></i> Preview</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -603,7 +611,7 @@
|
|||||||
|
|
||||||
const url = new URL(window.location.href);// Get the URL of the current page for JSON
|
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 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
|
var xmlPath ="" //get the xml filepath in .env file local variable
|
||||||
|
|
||||||
|
|||||||
156
savexml.js
156
savexml.js
@ -3,11 +3,38 @@ const cheerio = require('cheerio');
|
|||||||
const Swal = require('sweetalert2')
|
const Swal = require('sweetalert2')
|
||||||
const encode = require('./encode')
|
const encode = require('./encode')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
|
|
||||||
//Get the value from .env
|
//Get the value from .env
|
||||||
const isEncrypted = process.env.ENCRYPTED;
|
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) {
|
function saveXmlToFile(xmlData, filePath) {
|
||||||
console.log(filePath);
|
console.log(filePath);
|
||||||
// Check if the file path is provided
|
// Check if the file path is provided
|
||||||
@ -38,67 +65,102 @@ function saveXmlToFile(xmlData, filePath) {
|
|||||||
|
|
||||||
|
|
||||||
function savexml(UserFilename) {
|
function savexml(UserFilename) {
|
||||||
|
|
||||||
// Get the XML string from localStorage
|
|
||||||
var xmlString = localStorage.getItem("xml");
|
|
||||||
|
|
||||||
//check Encrypted or not
|
// Get the XML string from localStorage
|
||||||
var enc = "";
|
var xmlString = localStorage.getItem("xml");
|
||||||
if (isEncrypted === 'YES') {
|
|
||||||
// Encrypt
|
|
||||||
enc = encode(xmlString);
|
|
||||||
}else{
|
|
||||||
enc = xmlString;
|
|
||||||
}
|
|
||||||
|
|
||||||
//XmlPath get from .env
|
//check Encrypted or not
|
||||||
const xmlPathenv=process.env.XML_FILE_PATH;
|
var enc = "";
|
||||||
const xmlPath = path.join(__dirname, xmlPathenv)
|
if (isEncrypted === 'YES') {
|
||||||
// Get the json string from localStorage for set fileName
|
// Encrypt
|
||||||
var jsonData = localStorage.getItem("json");
|
enc = encode(xmlString);
|
||||||
|
} else {
|
||||||
// Create a filename using on the subtitle
|
enc = xmlString;
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
// file path where you want to save the XML file
|
||||||
var jsonString = JSON.parse(jsonData);
|
// const xmlfilePath = process.cwd() + `/${xmlPath}` + xmlfilename;
|
||||||
var getTitle = jsonString.question_paper_title;
|
|
||||||
var RawFileName = removeHtmlTags(getTitle);
|
const xmlfilePath = `${xmlPath}` + xmlfilename;
|
||||||
// console.log(RawFileName)
|
// 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({
|
Swal.fire({
|
||||||
title: 'Enter Filename',
|
title: 'Enter Filename',
|
||||||
input: 'text',
|
input: 'text',
|
||||||
inputValue: RawFileName,
|
inputValue: RawFileName,
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
|
showDenyButton: false,
|
||||||
|
denyButtonText: 'Overwrite',
|
||||||
confirmButtonText: 'Submit',
|
confirmButtonText: 'Submit',
|
||||||
cancelButtonText: 'Cancel',
|
cancelButtonText: 'Cancel',
|
||||||
inputValidator: (value) => {
|
inputValidator: (value) => {
|
||||||
|
const entervalue =value+'.xml'
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return 'You need to enter Filename!'
|
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) => {
|
}).then((result) => {
|
||||||
|
console.log(result);
|
||||||
if (result.isConfirmed) {
|
if (result.isConfirmed) {
|
||||||
|
|
||||||
const inputValue = result.value
|
const inputValue = result.value
|
||||||
savexml(inputValue)
|
savexml(inputValue)
|
||||||
|
}else if(result.isDenied){
|
||||||
|
savexml(RawFileName)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -114,5 +176,15 @@ function removeHtmlTags(inputString) {
|
|||||||
return text;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user