Skip to content

Commit

Permalink
Added table data population logic to printPdf.js and fetch images fro…
Browse files Browse the repository at this point in the history
…m the cloud and add i to the pdf
  • Loading branch information
StarOne01 committed Jun 1, 2024
1 parent bf41fca commit e8001f0
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 188 deletions.
3 changes: 3 additions & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
margin: 5px;
}

#pdfStatus {
display: none;
}

* {
margin: 0;
Expand Down
21 changes: 21 additions & 0 deletions assets/js/ExScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,19 @@ var addInput = (e) => {

const addSelectedEx = (e) => {
e.preventDefault();



const selectedOption = document.getElementById(
`${e.target.id.substring(0, e.target.id.length - 3)}`
).value;
if (`${e.target.id.substring(0, e.target.id.length - 3)}` === "HIIT") {
if(Number(selectedOption) > 304) {
toastBody.textContent = "HIIT can't be more than 304";
toastBootstrap.show();
return;
}
}
document.getElementById(
`${e.target.id.substring(0, e.target.id.length - 3)}`
).value = "";
Expand Down Expand Up @@ -172,11 +182,17 @@ const addSelectedEx = (e) => {
document
.getElementById(`${e.target.id.substring(0, e.target.id.length - 3)}Ul`)
.appendChild(newListItem);

if (`${e.target.id.substring(0, e.target.id.length - 3)}` === "HIIT") {
HIITItems[selectedOption] = setDays;
}

setDays.forEach((da) => {
ExDb[da][`${e.target.id.substring(0, e.target.id.length - 3)}`].push(
selectedOption
);
console.log(ExDb);

document.querySelector(
`#${da}Tbl #${e.target.id.substring(0, e.target.id.length - 3)}TblR`
).innerHTML = "";
Expand Down Expand Up @@ -233,6 +249,11 @@ const addSelectedEx = (e) => {
});
});
e.target.parentNode.remove();

if (`${e.target.id.substring(0, e.target.id.length - 3)}` === "HIIT") {
delete HIITItems[e.target.getAttribute("data-item")];
}

});
});
};
5 changes: 5 additions & 0 deletions assets/js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @summary Contains variables and data structures for the foodSuggester application.
* @since 0.0.1
*/


let weight = 0;
let height = 0;
let age = 0;
Expand Down Expand Up @@ -35,6 +37,9 @@ let nutriDataTime = [
[0, 0, 0, 0,],
]

let HIITItems = {
};

let nutriData = [
0,0,0,0
]
Expand Down
1 change: 1 addition & 0 deletions assets/js/domGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample);
const fileInputs = document.querySelectorAll('input[type="file"]');
const applyBtn = document.getElementById('applyBtn')
const toastBody = document.getElementById("toastBody");
const pdfStatus = document.getElementById("pdfStatus");
const BMRH = document.getElementById("resultBMR");
const userNature = document.getElementById("youAre");
const wakeUp = document.getElementById("wakeUpI");
Expand Down
99 changes: 1 addition & 98 deletions assets/js/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,104 +504,7 @@ const exSessions = {
'301',
'302',
'303',
'304',
'305',
'306',
'307',
'308',
'309',
'310',
'311',
'312',
'313',
'314',
'315',
'316',
'317',
'318',
'319',
'320',
'321',
'322',
'323',
'324',
'325',
'326',
'327',
'328',
'329',
'330',
'331',
'332',
'333',
'334',
'335',
'336',
'337',
'338',
'339',
'340',
'341',
'342',
'343',
'344',
'345',
'346',
'347',
'348',
'349',
'350',
'351',
'352',
'353',
'354',
'355',
'356',
'357',
'358',
'359',
'360',
'361',
'362',
'363',
'364',
'365',
'366',
'367',
'368',
'369',
'370',
'371',
'372',
'373',
'374',
'375',
'376',
'377',
'378',
'379',
'380',
'381',
'382',
'383',
'384',
'385',
'386',
'387',
'388',
'389',
'390',
'391',
'392',
'393',
'394',
'395',
'396',
'397',
'398',
'399',
'400',
'401']
'304']
,
WarmupM: [
"Arm circles",
Expand Down
15 changes: 11 additions & 4 deletions assets/js/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ const firebaseConfig = {
const app = initializeApp(firebaseConfig);

const storage = getStorage(app);
function goPdf(e, mode) {
let [DataDef, name,PhNo] = printPdf(e,mode);
///*
async function goPdf(e, mode) {
pdfStatus.style.display = "block";
pdfStatus.textContent = "Generating PDF...";
let [DataDef, name,PhNo] = await printPdf(e,mode);
/*
pdfStatus.textContent = "Uploading PDF...";
const storageRef = ref(storage, "ClientPdfs/"+ name); // Replace with your desired storage path
pdfMake.createPdf(DataDef)
.getBlob((blob) => {
Expand All @@ -30,6 +33,7 @@ pdfMake.createPdf(DataDef)
console.log('Uploaded PDF blob to Firebase Storage!');
getDownloadURL(snapshot.ref).then(async(downloadURL) => {
console.log('File available at', downloadURL);
pdfStatus.textContent = "PDF Uploaded!";
var raw = downloadURL;
var myHeaders = new Headers();
Expand All @@ -41,6 +45,8 @@ pdfMake.createPdf(DataDef)
headers: myHeaders,
body: raw
};
pdfStatus.textContent = "Generating Short URL...";
fetch("https://api.apilayer.com/short_url/hash", requestOptions)
.then(response => response.text())
Expand All @@ -49,14 +55,15 @@ pdfMake.createPdf(DataDef)
link.target = "_blank";
let short = result.split('"')[7];
console.log(short)
pdfStatus.textContent = "Short URL Generated!, redirecing to Whatsapp";
link.href = "https://wa.me/91"+PhNo+"?text="+ ((((short).split(':').join('%3A')).split('/',).join('%2F')).split('?').join('%3F')).split('&').join('%26');
link.click();
})
.catch(error => console.log('error', error));
});
});
};
});//*/
});*/
}
// Initialize the blob and name variables
getPDFBtn.addEventListener("click",(e) => goPdf(e,0));
Expand Down
Loading

0 comments on commit e8001f0

Please sign in to comment.