From 563fa502d13727d035f4dbab977d1db16acbbf22 Mon Sep 17 00:00:00 2001 From: knighthawk4227 Date: Wed, 14 May 2025 21:47:50 -0700 Subject: [PATCH] progress bar on dashboard & number formatting --- src/auth/forgotPass.js | 1 + src/public/scripts/random.js | 15 ++++ src/router/user.js | 13 +++- src/views/dashboard.ejs | 109 +++------------------------- src/views/partials/dashboardBox.ejs | 34 +++++++++ 5 files changed, 70 insertions(+), 102 deletions(-) create mode 100644 src/public/scripts/random.js create mode 100644 src/views/partials/dashboardBox.ejs diff --git a/src/auth/forgotPass.js b/src/auth/forgotPass.js index 698a500..85dd678 100644 --- a/src/auth/forgotPass.js +++ b/src/auth/forgotPass.js @@ -65,6 +65,7 @@ module.exports = (users) => { } }); + //Reset link verifies information from user and checks token router.post('/resetLink', async (req, res) => { const { token, password, confirmPassword, } = req.body; const passwordSchema = joi.object({ diff --git a/src/public/scripts/random.js b/src/public/scripts/random.js new file mode 100644 index 0000000..6539f64 --- /dev/null +++ b/src/public/scripts/random.js @@ -0,0 +1,15 @@ +document.addEventListener("DOMContentLoaded", () => { + const number = document.querySelectorAll(".planGoal"); + number.forEach(value => { + num = parseFloat(value.textContent); + if (num >= 999999) { + value.textContent = (num /= 1000000).toFixed(2) + "M"; + console.log(value.textContent); + } else if (num > 999) { + value.textContent = (num /= 1000).toFixed(2) + "K"; + } else { + return num; + } + }); +}); + diff --git a/src/router/user.js b/src/router/user.js index e4511ad..4b67b48 100644 --- a/src/router/user.js +++ b/src/router/user.js @@ -55,6 +55,12 @@ const getAssetSchema = (type) => { return assetSchema; } +/** + * Function takes in a number and formats it to currency + * @param {integer} + * @returns nuber formatted in currency + */ + /** * @param {function} middleware handler * @param {MongoClient.collection} users db collection @@ -71,6 +77,7 @@ module.exports = (middleware, users, plans, assets) => { router.use(middleware); router.get('/home', async (req, res) => { + let user = req.session.user._id; // if no session with geoData if (!req.session.geoData) { req.session.geoData = { @@ -78,8 +85,10 @@ module.exports = (middleware, users, plans, assets) => { toCurrencyRates: [], }; } - - res.render('dashboard', { user: req.user, geoData: req.session.geoData }); + let planSchema = await plans.find({ userId: new ObjectId(user) }).project({ + name: 1, retirementAssets: 1, progress: 1, _id: 1, + }).toArray(); + res.render('dashboard', { user: req.user, geoData: req.session.geoData, plans: planSchema, }); return res.status(status.Ok); }); diff --git a/src/views/dashboard.ejs b/src/views/dashboard.ejs index 86539d0..449e446 100644 --- a/src/views/dashboard.ejs +++ b/src/views/dashboard.ejs @@ -1,7 +1,7 @@ <%- include("./partials/fileHeader") %> <%- include("./partials/header") %> -
+
- -
- - - - - -
-
- -
- - - -
-

- Retirement goal

-

- $53k

-
-
-

- Make this percent bar or graph or - something -  than lastweek -

-
-
-
-
-

- Retirement goal

-

- $53k

-
-
-

- Make this percent bar or graph or - something -  than last - week -

-
-
-
- - - - - - - - - - - - - - - - - - - - - - - -
-
-
-

- Retirement goal

-

- $53k

-
-
-

- Make this percent bar or - graph or something -  than last - week -

-
-
-
-
-
-
-
+
+
+ <% plans.forEach(plan=> { %> + <%- include('./partials/dashboardBox.ejs', {plan: plan}) %> + <% }); %> +
+
- <%- include("./partials/navBar") %> <%- include("./partials/scriptLoader") %> <%- include("./partials/footer") %> + diff --git a/src/views/partials/dashboardBox.ejs b/src/views/partials/dashboardBox.ejs new file mode 100644 index 0000000..60ceca1 --- /dev/null +++ b/src/views/partials/dashboardBox.ejs @@ -0,0 +1,34 @@ +