From b12d4bebe1bca247349ea6107f34a116c9b27cca Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Wed, 21 May 2025 15:40:29 -0700 Subject: [PATCH] update/add year to car assets --- src/public/scripts/assetManager.js | 30 ++++++++++++++++++++++++++++++ src/router/user.js | 3 +++ src/views/partials/assetModify.ejs | 21 +++++++++++++++++++++ src/views/partials/createAsset.ejs | 15 +++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/src/public/scripts/assetManager.js b/src/public/scripts/assetManager.js index 16bbc37..b0eee0b 100644 --- a/src/public/scripts/assetManager.js +++ b/src/public/scripts/assetManager.js @@ -85,6 +85,8 @@ function lockAsset(assetId, icon) { document.getElementById(`${key}-${assetId}`).disabled = true; }); + if (icon === "Car" || icon === "Motorcycle") document.getElementById(`year-${assetId}`).disabled = true; + document.getElementById(`save-${assetId}`).disabled = true; document.getElementById(`save-${assetId}`).classList.remove("cursor-pointer"); document.getElementById(`save-${assetId}`).classList.add("cursor-not-allowed"); @@ -105,6 +107,8 @@ function unlockAsset(assetId, icon) { document.getElementById(`${key}-${assetId}`).disabled = false; }); + if (icon === "Car" || icon === "Motorcycle") document.getElementById(`year-${assetId}`).disabled = false; + document.getElementById(`save-${assetId}`).disabled = false; document.getElementById(`save-${assetId}`).classList.remove("cursor-not-allowed"); document.getElementById(`save-${assetId}`).classList.add("cursor-pointer"); @@ -133,6 +137,8 @@ function autoOpenCreate() { * @param {string} assetId */ function selectIcon(selectedIcon, assetId="") { + toggleYear(selectedIcon.value, assetId); + document.getElementById(`dropdown-icon-button${assetId != "" ? "-" : ""}${assetId}`).value = selectedIcon.value; document.getElementById(`icon${assetId != "" ? "-" : ""}${assetId}`).value = selectedIcon.value @@ -144,5 +150,29 @@ function selectIcon(selectedIcon, assetId="") { `; } +/** + * toggleYear shows or hides year input + * @param {string} type of asset + */ +function toggleYear(type, assetId="") { + if (type === "Car" || type === "Motorcycle") { + if (assetId) { + document.getElementById(`year-${assetId}`).disabled = false; + document.getElementById(`year-modify-${assetId}`).style.display = 'block'; + } else { + document.getElementById('year-input').disabled = false; + document.getElementById('year-create').style.display = 'block'; + } + } else { + if (assetId) { + document.getElementById(`year-${assetId}`).disabled = true; + document.getElementById(`year-modify-${assetId}`).style.display = 'none'; + } else { + document.getElementById('year-input').disabled = true; + document.getElementById('year-create').style.display = 'none'; + } + } +} + resetRadio(); autoOpenCreate(); diff --git a/src/router/user.js b/src/router/user.js index d5d70c3..4665a7e 100644 --- a/src/router/user.js +++ b/src/router/user.js @@ -26,6 +26,7 @@ const getAssetSchema = (type) => { icon: joi.string().alphanum().required(), name: joi.string().alphanum().min(3).max(30).required(), value: joi.number().min(0).required(), + year: joi.number().min(1900).max(new Date().getFullYear()), purchaseDate: joi.date().required(), description: joi.string().max(240).min(0), id: joi.string().alphanum(), // May be passed when updating existing asset @@ -627,6 +628,7 @@ module.exports = (middleware, users, plans, assets) => { newAsset.value = newAsset.quantity * newAsset.price; newAsset.name = `${newAsset.ticker} Stock`; } + if (type == "other" && newAsset.year != "") newAsset.year = parseInt(newAsset.year); newAsset.value = parseFloat(newAsset.value); newAsset.icon = type == "stock" ? "Stock" : type == "saving" ? "Coins" : newAsset.icon; @@ -673,6 +675,7 @@ module.exports = (middleware, users, plans, assets) => { update.value = update.quantity * update.price; update.name = `${update.ticker} Stock`; } + if (type == "other" && update.year != "") update.year = parseInt(update.year); update.value = parseFloat(update.value); delete update.id; delete update.userId; diff --git a/src/views/partials/assetModify.ejs b/src/views/partials/assetModify.ejs index 4e4ffbf..b455aa1 100644 --- a/src/views/partials/assetModify.ejs +++ b/src/views/partials/assetModify.ejs @@ -120,6 +120,27 @@ value="<%= asset.value %>" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm disabled:border-gray-200 disabled:bg-gray-50 disabled:text-gray-500 disabled:shadow-none" > + +
+ style="display: none;" + <% } %> + > + + +
<% } else { %> +
+ + +
+