Skip to content

Commit

Permalink
Enhanced PDF generation with detailed carbohydrate count and added Ex…
Browse files Browse the repository at this point in the history
…ercise Plan section in printPdf.js
  • Loading branch information
StarOne01 committed May 5, 2024
1 parent 00eb8b7 commit 0d4f7b8
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 84 deletions.
7 changes: 4 additions & 3 deletions assets/js/ExScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const showSuggestionsEx = (i) => {
}
};

const addInput = (e) => {
var addInput = (e) => {

for(const Selecteday of Exdays) {
if (ExDb[Selecteday][`${e.target.id.substring(0, e.target.id.length - 3)}`].length >
Expand Down Expand Up @@ -103,9 +103,9 @@ const addInput = (e) => {
});
for (let lea = 0; lea < 3; lea++) {
let htm1 = "";
htm1 = `<table width='100%'>`;
htm1 = `<table width='100%'>`;
for (let j = 0; j < e.target.value; j++) {
htm1 += `<input class='In${j}' style='margin:10px;' type='text'/>`;
htm1 += `<input class='In${j}' data-lim='${e.target.value}' style='margin:10px;' type='text'/>`;
}

htm1 += "</table>";
Expand All @@ -116,6 +116,7 @@ const addInput = (e) => {
`#${Selecteday}Tbl #${e.target.id.substring(0, e.target.id.length - 3)}Tr`
)
.appendChild(newTd1);
newTd1.classList.add(`${e.target.id.substring(0, e.target.id.length - 3)}SubTd`);
}

});
Expand Down
3 changes: 3 additions & 0 deletions assets/js/domGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const selectedItemsList = document.getElementsByClassName("selectedItems");
var timeInput = document.querySelectorAll("input[type='time']");
const body = document.body;

const getBothBtn = document.getElementById("getBothBtn");
const getExBtn =document.getElementById("getExBtn");

const trItems = document.querySelectorAll("#foodTable tr");

const trItemsData = document.querySelectorAll("#DataTable tr");
Expand Down
16 changes: 13 additions & 3 deletions assets/js/eventListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,13 @@ setOrderBtn.addEventListener("click", (e) => {
const newDiv = document.createElement("div");
newDiv.innerHTML = `<label for="${order[i].textContent
.split(" ")
.join("")}" onchange='addInput(e)'>${order[i].textContent}</label><br />
.join("")}" '>${order[i].textContent}</label><br />
<label>Varience:</label>
<input id="${order[i].textContent
.split(" ")
.join("")}Var" type="number" class="varient"> <br>
<input
type="search"
onchange='addInput(this)'
list="itemListEx"
id='${order[i].textContent.split(" ").join("")}'
placeholder="Search items..."
Expand All @@ -242,7 +241,7 @@ setOrderBtn.addEventListener("click", (e) => {
.addEventListener("click", addSelectedEx);
const userInputEx = document.querySelectorAll("[list='itemListEx']");
console.log(userInputEx);
document.getElementById(`${order[i].textContent.split(" ").join("")}Var`).addEventListener("change", addInput);
document.getElementById(`${order[i].textContent.split(" ").join("")}Var`).addEventListener("change", (e)=> addInput(e));
userInputEx.forEach((j) => {
j.addEventListener("keyup", (k) => {
showSuggestionsEx(k.target);
Expand Down Expand Up @@ -304,3 +303,14 @@ DayExChks.forEach((i) => {
});

AlldayEx.addEventListener("click", CheckAllEx);
getPDFBtn.addEventListener("click", (e) => {
printPdf(e,0);
});

getExBtn.addEventListener("click", (e) => {
printPdf(e,1);
});

getBothBtn.addEventListener("click", (e) => {
printPdf(e,2);
});
225 changes: 147 additions & 78 deletions assets/js/printPdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,14 @@
* Represents an event listener for the "getPDFBtn" button click.
* @param {Event} e - The click event object.
*/
getPDFBtn.addEventListener("click", (e) => {

function printPdf(e, i) {


e.preventDefault();
const nameval = document.getElementById("client_name").value;
const clientid = document.getElementById("membership_id").value;
console.log(goal)
const dayOne = [
["Day 1", "Exercise", "Rep", "Sets", "Rest"],
];
const dayTwo = [
["Day 1", "Exercise", "Rep", "Sets", "Rest"],
];
const dayThree = [
["Day 1", "Exercise", "Rep", "Sets", "Rest"],
];
const dayFour = [
["Day 1", "Exercise", "Rep", "Sets", "Rest"],
];
const dayFive = [
["Day 1", "Exercise", "Rep", "Sets", "Rest"],
];
const daySix = [
["Day 1", "Exercise", "Rep", "Sets", "Rest"],
];
const daySeven = [
["Day 1", "Exercise", "Rep", "Sets", "Rest"],
];
const tableLayout = [
{ text: "Column 1", width: "*" },
{ text: "Column 2" },
{ text: "Column 3", alignment: "right" },
];

const table2Content = dayTwo.map((row) => {
return tableLayout.map((column, index) => {
return { text: row[index] };
});
});

const table3Content = dayThree.map((row) => {
return tableLayout.map((column, index) => {
return { text: row[index] };
});
});

const table4Content = dayFour.map((row) => {
return tableLayout.map((column, index) => {
return { text: row[index] };
});
});

const table5Content = dayFive.map((row) => {
return tableLayout.map((column, index) => {
return { text: row[index] };
});
});

const table6Content = daySix.map((row) => {
return tableLayout.map((column, index) => {
return { text: row[index] };
});
});

const table7Content = daySeven.map((row) => {
return tableLayout.map((column, index) => {
return { text: row[index] };
});
});

const table1Content = dayOne.map((row) => {
return tableLayout.map((column, index) => {
return { text: row[index] };
});
});


const canvasy = document.getElementById("foo");
const imageData = canvasy.toDataURL();
//docDefinition
Expand Down Expand Up @@ -394,20 +327,108 @@ getPDFBtn.addEventListener("click", (e) => {
}
];

//widths: [85, 103, 93, 93, 93],
let exerciseTable = [
{
margin: [0, 20, 0, 0],
text: "Exercise Plan",
style: 'header',
},
{
];


let DaysEx = {

Day1: {
margin: [0, 10, 0, 0],
table: {
headerRows: 1,
widths: [55, 55, 55, 55, 55],
widths: [85, 103, 93, 93, 93],
body: [
[
{ text: "Day", bold: true },
{ text: "Day 1", bold: true },
{ text: "Exercise", bold: true },
{ text: "Rep", bold: true },
{ text: "Sets", bold: true },
{ text: "Rest", bold: true },
],
],
},
},

Day2: {
margin: [0, 10, 0, 0],
table: {
widths: [85, 103, 93, 93, 93],
body: [
[
{ text: "Day 2", bold: true },
{ text: "Exercise", bold: true },
{ text: "Rep", bold: true },
{ text: "Sets", bold: true },
{ text: "Rest", bold: true },
],
],
},
},

Day3: {
margin: [0, 10, 0, 0],
table: {
widths: [85, 103, 93, 93, 93],
body: [
[
{ text: "Day 3", bold: true },
{ text: "Exercise", bold: true },
{ text: "Rep", bold: true },
{ text: "Sets", bold: true },
{ text: "Rest", bold: true },
],
],
},
},


Day4: {
margin: [0, 10, 0, 0],
table: {
widths: [85, 103, 93, 93, 93],
body: [
[
{ text: "Day 4", bold: true },
{ text: "Exercise", bold: true },
{ text: "Rep", bold: true },
{ text: "Sets", bold: true },
{ text: "Rest", bold: true },
],
],
},
},


Day5: {
margin: [0, 10, 0, 0],
table: {
widths: [85, 103, 93, 93, 93],
body: [
[
{ text: "Day 5", bold: true },
{ text: "Exercise", bold: true },
{ text: "Rep", bold: true },
{ text: "Sets", bold: true },
{ text: "Rest", bold: true },
],
],
},
},


Day6: {
margin: [0, 10, 0, 0],
table: {
widths: [85, 103, 93, 93, 93],
body: [
[
{ text: "Day 6", bold: true },
{ text: "Exercise", bold: true },
{ text: "Rep", bold: true },
{ text: "Sets", bold: true },
Expand All @@ -416,7 +437,50 @@ getPDFBtn.addEventListener("click", (e) => {
],
},
},
];


Day7: {
margin: [0, 10, 0, 0],
table: {
widths: [85, 103, 93, 93, 93],
body: [
[
{ text: "Day 7", bold: true },
{ text: "Exercise", bold: true },
{ text: "Rep", bold: true },
{ text: "Sets", bold: true },
{ text: "Rest", bold: true },
],
],
},
},
}





for (const daysL in ExDb) {
let jo = 0;
for (const x in ExDb[daysL]) {
DaysEx[daysL].table.body.push([{ text: x, bold: true }, { layout: 'lightHorizontalLines', table: { body: [] } }, { layout: 'lightHorizontalLines', table: { body: [] } }, { layout: 'lightHorizontalLines', table: { body: [] } }, { layout: 'lightHorizontalLines', table: { body: [] } }]);
let lim = Number(document.querySelectorAll(`#${daysL}Tbl .${x}SubTd .In0`)[0].getAttribute('data-lim'));
for (const y in ExDb.Day1[x]) {
DaysEx[daysL].table.body[1 + jo][1].table.body.push([ExDb.Day1[x][y]])
}
for (let i = 0; i < lim; i++) {
DaysEx[daysL].table.body[1 + jo][2].table.body.push([document.querySelectorAll(`#${daysL}Tbl .${x}SubTd .In${i}`)[0].value])
DaysEx[daysL].table.body[1 + jo][3].table.body.push([document.querySelectorAll(`#${daysL}Tbl .${x}SubTd .In${i}`)[1].value])
DaysEx[daysL].table.body[1 + jo][4].table.body.push([document.querySelectorAll(`#${daysL}Tbl .${x}SubTd .In${i}`)[2].value])

}
jo++;
}

exerciseTable.push(DaysEx[daysL]);
}




let remarks = [
Expand Down Expand Up @@ -447,10 +511,15 @@ getPDFBtn.addEventListener("click", (e) => {





if(i === 0 || i===2) {
DataDef.content.push(foodTable);
}
if(i === 1 || i===2) {
DataDef.content.push(exerciseTable);
}
DataDef.content.push(remarks);
DataDef.styles = style;

pdfMake.createPdf(DataDef).download(`${nameval}-Diet.pdf`);
});
};

0 comments on commit 0d4f7b8

Please sign in to comment.