From c7cc56897ad7d0adc645822bde7da68e87711b8c Mon Sep 17 00:00:00 2001 From: Galexion Date: Wed, 24 May 2023 12:19:35 -0400 Subject: [PATCH] More Updates --- public/javascript/user.js | 75 ++++++++++++++++++++++++++++++------- public/stylesheets/user.css | 9 +++++ routes/api.js | 12 ++++++ views/index.ejs | 2 +- views/user.ejs | 7 +++- 5 files changed, 89 insertions(+), 16 deletions(-) diff --git a/public/javascript/user.js b/public/javascript/user.js index 002fd28..6394b94 100644 --- a/public/javascript/user.js +++ b/public/javascript/user.js @@ -24,17 +24,17 @@ clearStorageBtn.addEventListener('click', () => { }); function startBanBtnEventListener(status) { -// Get the Ban Button Element -const banBtn = document.getElementById('banButton'); + // Get the Ban Button Element + const banBtn = document.getElementById('banButton'); -// Add a click Event Listener to the Ban button. -banBtn.addEventListener('click', () => { - if(status === 0) { - getuserbanned(aime_card_id) - } else { - getuserunbanned(aime_card_id) - } -}); + // Add a click Event Listener to the Ban button. + banBtn.addEventListener('click', () => { + if (status === 0) { + getuserbanned(aime_card_id) + } else { + getuserunbanned(aime_card_id) + } + }); } // Get the cookie string const cookieString = document.cookie; @@ -110,7 +110,7 @@ if (userdata.ban_state !== 0) { let banButton = document.createElement('button'); banButton.id = "banButton"; banButton.innerHTML = "let me in... LET ME INnNnNnNnNnNnNnNnN"; - + document.getElementById('BanUserArea').append(banButton); startBanBtnEventListener(1) // unban user } else { @@ -215,7 +215,7 @@ async function userPlayLogFormatter(div, loadMoreButton) { scoreDiv.innerHTML = `
-

${song.name.str || ""} ||

+

${song.name.str} || ${new Date(score.user_play_date)}

`; /* Score Jacket Image */ @@ -266,7 +266,7 @@ async function userPlayLogFormatter(div, loadMoreButton) { /* Full Combo */ /* Full Sync */ /* Player Placement */ - + /* Side note: Can't Do Any of this without the Image Assets / Information, So Moving on for now */ /* setting stuff up */ scoreDiv.setAttribute("class", "score-grid"); @@ -347,6 +347,32 @@ async function userAreaStatusFormatter(div) { div.appendChild(areaWrapper) } +/* Memorial Image Renderer */ +async function userImageFormatter(div) { + let memorialImageList = await imageList(); // get image list + let imageInfoDiv = document.getElementById("image-info-header-div"); + imageInfoDiv.innerHTML = ""; + console.log("Attempting to search list with EXT_ID " + ext_id.toString()) + for (var i = 0; i < memorialImageList.length; i++) { // for each name in the array + let imageName = memorialImageList[i] + console.log(imageName) + if (imageName.startsWith(ext_id.toString())) { // Check if the External ID matches the ID within the photo at the beginning + let memorialImage = document.createElement('img'); + memorialImage.classList.add('memorialImage'); + memorialImage.addEventListener("error", function () { + this.src = "assets/icon/UI_Icon_000000.png"; + }); + memorialImage.src = "images/" + imageName + '.jpg'; + imageInfoDiv.append(memorialImage) + } + } + if(imageInfoDiv.innerHTML == "") { + let error = document.createElement('h3'); + error.innerText = "No Images Memorialised." + imageInfoDiv.append(error) + } +} + //===================================================================== // Now Exiting: User Data ////////////// Now Entering: Nested Div Hell //===================================================================== @@ -361,6 +387,8 @@ const showContent = (contentNumber) => { if (div === contentDiv) { if (contentNumber === 2) { // If the ContentNumber is set to the PlayLog, Go to the userPlayLogFormatter Function userPlayLogFormatter(div) + } else if (contentNumber === 4) { + userImageFormatter(div) } else if (contentNumber === 6) { userAreaStatusFormatter(div) } @@ -497,4 +525,23 @@ async function mapsMetadata() { } catch (error) { console.error(error); } -} \ No newline at end of file +} + +async function imageList() { + const url = "/api/getmemorialimagelist"; + + try { + const response = await fetch(url, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }); + + const data = await response.json(); + return data + } catch (error) { + console.error(error); + } +} + diff --git a/public/stylesheets/user.css b/public/stylesheets/user.css index b304d13..b37e9c9 100644 --- a/public/stylesheets/user.css +++ b/public/stylesheets/user.css @@ -36,6 +36,15 @@ font-size: 2em; } +.memorialImage { + width: 90%; + padding-bottom: 5px; + margin-left: auto; + margin-right: auto; + height: auto; + display: block; +} + @media screen and (max-width: 768px) { #user-profile-wrapper { display: inline-block; diff --git a/routes/api.js b/routes/api.js index 3317ffe..38168ed 100644 --- a/routes/api.js +++ b/routes/api.js @@ -2,6 +2,7 @@ var express = require('express'); var router = express.Router(); var fetch = require('cross-fetch'); const sqlite3 = require('sqlite3').verbose(); +const fs = require('fs') var config = require('../config.json'); let db = new sqlite3.Database(config.DXMemorialImageDirectory + '\\db.sqlite'); @@ -121,4 +122,15 @@ let db = new sqlite3.Database(config.DXMemorialImageDirectory + '\\db.sqlite'); } }); }); + +router.get('/getmemorialimagelist/', function (req,res,next) { + let ext = ".jpg"; + // Use fs.readdirSync() to get the file names synchronously + const files = fs.readdirSync(config.DXMemorialImageDirectory); + // Filter the files by extension and create an array of names + const imageNames = files.filter(file => file.endsWith(ext)).map(file => file.slice(0, -ext.length)); + // Create and return a JSON object with the image names + res.send(imageNames); +}); + module.exports = router; \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index 2a718bc..982f7ec 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -6,7 +6,7 @@
Total Users Registered: <%= params.totalUsers %>

Please Input your 20 Digit Access Code.

- +
diff --git a/views/user.ejs b/views/user.ejs index 038124f..3732155 100644 --- a/views/user.ejs +++ b/views/user.ejs @@ -42,9 +42,14 @@

Please Wait, Obtaining Scores...

+