From 95c461c6efd182baae7fe71fd45e4512fa5ebcfe Mon Sep 17 00:00:00 2001 From: Prashanth <67097277+StarOne01@users.noreply.github.com> Date: Wed, 29 May 2024 15:48:10 +0000 Subject: [PATCH] Add HIIT Function --- assets/js/ExScript.js | 7 +- assets/js/exercise.js | 402 ++++++++++++++++++++++++++++++++++++++++++ assets/js/firebase.js | 5 +- assets/js/printPdf.js | 60 +++++++ 4 files changed, 466 insertions(+), 8 deletions(-) diff --git a/assets/js/ExScript.js b/assets/js/ExScript.js index b1450bb..433d121 100644 --- a/assets/js/ExScript.js +++ b/assets/js/ExScript.js @@ -30,9 +30,6 @@ const filterOptionsEx = (userInputValueEx, targ) => { }; const showSuggestionsEx = (i) => { - if (i.id === "HIIT") { - return; - } const userInputValue = i.value; const filteredOptions = filterOptionsEx(userInputValue, i.id); dataListEx.innerHTML = ""; @@ -124,9 +121,6 @@ var addInput = (e) => { const addSelectedEx = (e) => { e.preventDefault(); - if (`${e.target.id.substring(0, e.target.id.length - 3)}` === "HIIT") { - return; - } const selectedOption = document.getElementById( `${e.target.id.substring(0, e.target.id.length - 3)}` ).value; @@ -211,6 +205,7 @@ const addSelectedEx = (e) => { } ); }); + console.log(ExDb) let delet = document.querySelectorAll(".delet"); delet.forEach((i) => { diff --git a/assets/js/exercise.js b/assets/js/exercise.js index 00562dc..dbc5842 100644 --- a/assets/js/exercise.js +++ b/assets/js/exercise.js @@ -201,6 +201,408 @@ const exSessions = { "Kneeling Side Plank", "Stability Ball Sit Up", ], + HIITM:['001', + '002', + '003', + '004', + '005', + '006', + '007', + '008', + '009', + '010', + '011', + '012', + '013', + '014', + '015', + '016', + '017', + '018', + '019', + '020', + '021', + '022', + '023', + '024', + '025', + '026', + '027', + '028', + '029', + '030', + '031', + '032', + '033', + '034', + '035', + '036', + '037', + '038', + '039', + '040', + '041', + '042', + '043', + '044', + '045', + '046', + '047', + '048', + '049', + '050', + '051', + '052', + '053', + '054', + '055', + '056', + '057', + '058', + '059', + '060', + '061', + '062', + '063', + '064', + '065', + '066', + '067', + '068', + '069', + '070', + '071', + '072', + '073', + '074', + '075', + '076', + '077', + '078', + '079', + '080', + '081', + '082', + '083', + '084', + '085', + '086', + '087', + '088', + '089', + '090', + '091', + '092', + '093', + '094', + '095', + '096', + '097', + '098', + '099', + '100', + '101', + '102', + '103', + '104', + '105', + '106', + '107', + '108', + '109', + '110', + '111', + '112', + '113', + '114', + '115', + '116', + '117', + '118', + '119', + '120', + '121', + '122', + '123', + '124', + '125', + '126', + '127', + '128', + '129', + '130', + '131', + '132', + '133', + '134', + '135', + '136', + '137', + '138', + '139', + '140', + '141', + '142', + '143', + '144', + '145', + '146', + '147', + '148', + '149', + '150', + '151', + '152', + '153', + '154', + '155', + '156', + '157', + '158', + '159', + '160', + '161', + '162', + '163', + '164', + '165', + '166', + '167', + '168', + '169', + '170', + '171', + '172', + '173', + '174', + '175', + '176', + '177', + '178', + '179', + '180', + '181', + '182', + '183', + '184', + '185', + '186', + '187', + '188', + '189', + '190', + '191', + '192', + '193', + '194', + '195', + '196', + '197', + '198', + '199', + '200', + '201', + '202', + '203', + '204', + '205', + '206', + '207', + '208', + '209', + '210', + '211', + '212', + '213', + '214', + '215', + '216', + '217', + '218', + '219', + '220', + '221', + '222', + '223', + '224', + '225', + '226', + '227', + '228', + '229', + '230', + '231', + '232', + '233', + '234', + '235', + '236', + '237', + '238', + '239', + '240', + '241', + '242', + '243', + '244', + '245', + '246', + '247', + '248', + '249', + '250', + '251', + '252', + '253', + '254', + '255', + '256', + '257', + '258', + '259', + '260', + '261', + '262', + '263', + '264', + '265', + '266', + '267', + '268', + '269', + '270', + '271', + '272', + '273', + '274', + '275', + '276', + '277', + '278', + '279', + '280', + '281', + '282', + '283', + '284', + '285', + '286', + '287', + '288', + '289', + '290', + '291', + '292', + '293', + '294', + '295', + '296', + '297', + '298', + '299', + '300', + '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'] + , WarmupM: [ "Arm circles", "Squats", diff --git a/assets/js/firebase.js b/assets/js/firebase.js index 4eb7d8a..3eacc73 100644 --- a/assets/js/firebase.js +++ b/assets/js/firebase.js @@ -18,7 +18,7 @@ const app = initializeApp(firebaseConfig); const storage = getStorage(app); function goPdf(e, mode) { let [DataDef, name,PhNo] = printPdf(e,mode); - const storageRef = ref(storage, "ClientPdfs/"+ name); // Replace with your desired storage path + /* const storageRef = ref(storage, "ClientPdfs/"+ name); // Replace with your desired storage path pdfMake.createPdf(DataDef) .getBlob((blob) => { if (blob) { @@ -55,10 +55,11 @@ pdfMake.createPdf(DataDef) }); }); }; -}); +});*/ } // Initialize the blob and name variables getPDFBtn.addEventListener("click",(e) => goPdf(e,0)); getExBtn.addEventListener("click",(e) => goPdf(e,1)); getBothBtn.addEventListener("click",(e) => goPdf(e,2)); + \ No newline at end of file diff --git a/assets/js/printPdf.js b/assets/js/printPdf.js index 0beb9f2..24a9d49 100644 --- a/assets/js/printPdf.js +++ b/assets/js/printPdf.js @@ -4,6 +4,44 @@ * @param {Event} e - The click event object. */ +function fetchAndConvert(item) { + // URL of the image you want to fetch + console.log(item) + var imageUrl = "https://starone01.github.io/foodSuggester/assets/HIIT/"+item+".jpg"; + + // Create a new Image object + var img = new Image(); + + // Set crossOrigin property to anonymous to allow for cross-origin requests + img.crossOrigin = "anonymous"; + + // Set the src attribute of the image to the image URL + img.src = imageUrl; + + // Once the image is loaded, convert it to base64 + img.onload = function() { + // Create a canvas element + var canvas = document.createElement('canvas'); + canvas.width = img.width; + canvas.height = img.height; + + // Get the canvas context + var ctx = canvas.getContext('2d'); + + // Draw the image onto the canvas + ctx.drawImage(img, 0, 0); + + // Get the base64 representation of the image + return canvas.toDataURL('image/jpeg'); // Change 'image/jpeg' to the desired format + // Store the base64 image data in a variable or use it as needed + console.log("Base64 Image Data:", base64ImageData); + }; + + // If there's an error loading the image + img.onerror = function() { + console.error("Error loading image:", imageUrl); + }; +} function printPdf(e, i) { @@ -518,6 +556,27 @@ function printPdf(e, i) { , ]; + let HIITImgs = { + margin: [20, 30, 0, 0], + columns: [] + } + + for (const daysL in ExDb) { + if(ExDb[daysL].hasOwnProperty('HIIT')) + for (const x of ExDb[daysL]['HIIT']) { + console.log(daysL + " - " + x) + + HIITImgs.columns.push([ + { + margin: [0, 20, 0, 0], + image: fetchAndConvert(x), + height: 150, + width: 150 + }, + ]) + } +} + let style = { defaultStyle: { @@ -539,6 +598,7 @@ let nameO = `${nameval}-${PhNo}//${nameval}-${PhNo}_${dateDb[0]}-${dateDb[1]}-${ } if(i === 1 || i===2) { DataDef.content.push(exerciseTable); + DataDef.content.push(HIITImgs); nameO += "-Workout" }