submit user data in all games

This commit is contained in:
Suvodip
2024-06-24 18:19:47 +05:30
parent d7a2533f43
commit 79f158380c
84 changed files with 569 additions and 2563 deletions

View File

@@ -3,7 +3,7 @@ import Layout from "../../layouts/Layout.astro";
---
<Layout title="">
<main>
<div>
<div class="specific">
<section class="bg-white bg-center bg-no-repeat bg-cover h-screen">
<div class="shadow-md">
<div class="container mx-auto px-4 flex flex-row place-content-between pt-6">
@@ -17,7 +17,6 @@ import Layout from "../../layouts/Layout.astro";
<button><img src="/assets/svg/cancel.svg" alt=""></button>
</div>
</div>
<!-- <input onclick="saveUserData();" class="bg-blue-700 px-8 py-2 rounded-lg shadow-lg font-bold text-white cursor-pointer" type="submit" value="Submit"> -->
</div>
@@ -83,20 +82,17 @@ import Layout from "../../layouts/Layout.astro";
</form>
</div>
</section>
<section class="">
<div class="container mx-auto px-4 flex flex-row place-content-between">
<p>All rights reserved. Copyright@akademy.interakto2024</p>
</div>
</section>
</div>
</div>
</main>
</Layout>
<script is:inline>
const params = new URLSearchParams(window.location.search);
const paramsID = params.get('id');
const gameId = params.get('id');
const userId = params.get('userid');
let startTime = Date.now();
let gameData = null;
fetch(`https://game-du.teachertrainingkolkata.in/items/game_tick_variant1/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`)
fetch(`https://game-du.teachertrainingkolkata.in/items/game_tick_variant1/${encodeURIComponent(gameId)}?filter[status][_eq]=published`)
.then(res => res.json())
.then(data => {
gameData = data.data;
@@ -147,14 +143,12 @@ import Layout from "../../layouts/Layout.astro";
let url = window.location.href;
let urlSplit = url.split('/');
let gameName = urlSplit[3] + '-' + urlSplit[4];
let formatedDateTime;
window.onload = function () {
let currentTime = new Date();
formatedDateTime = currentTime.toLocaleString();
};
function saveUserData() {
const endTime = Date.now();
const timeDifference = endTime - startTime;
const timeDifferenceInSeconds = timeDifference / 1000;
// Get checkbox values and corresponding elements
const checkboxes = ['a1', 'a2', 'a3', 'a4', 'a5', 'a6'];
const checkboxValues = checkboxes.map(id => {
@@ -174,16 +168,16 @@ import Layout from "../../layouts/Layout.astro";
totalPoints += 1;
}
});
// Move the userData object creation inside the saveUserData function if needed
let userData = {
'user': 'tick-v1@beanstalkedu.com',
'game_name': gameName,
'starts': formatedDateTime,
'score': totalPoints, // Include the totalPoints in the userData
'gameName': gameName,
'gameID': gameId,
'userId': userId,
'gameTime': timeDifferenceInSeconds,
'score': totalPoints,
};
console.log(userData);
fetch(`https://2016.dev2-cs.siliconpin.com/save/`, {
fetch(`https://phaser-game-api.s38.siliconpin.com/save-data`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
@@ -210,157 +204,6 @@ import Layout from "../../layouts/Layout.astro";
});
});
</script>
<!-- <script is:inline>
const params = new URLSearchParams(window.location.search);
const paramsID = params.get('id');
fetch(`https://management.beanstalkedu.com/items/game_tick_variant1/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`)
.then(res => res.json())
.then(data => {
gameData = data.data;
// console.log(gameData);
document.getElementById("gameDescription").innerHTML = gameData.game_description;
const assetsURL = 'https://management.beanstalkedu.com/assets/';
document.getElementById("image1").src = assetsURL + gameData.image1;
document.getElementById("image2").src = assetsURL + gameData.image2;
document.getElementById("image3").src = assetsURL + gameData.image3;
document.getElementById("image4").src = assetsURL + gameData.image4;
document.getElementById("image5").src = assetsURL + gameData.image5;
document.getElementById("image6").src = assetsURL + gameData.image6;
});
function checkResult2(id){
// console.log(gameData.a1)
// alert("Matched")
if(id == 'image1'){
if( gameData.a1 == true){
var element = document.getElementById(id);
element.classList.add("greenBorder");
// console.log('Value True')
} else{
var element = document.getElementById(id);
element.classList.add("redBorder");
// console.log('Value False')
}
};
if(id == 'image2'){
if(gameData.a2 == true){
var element = document.getElementById(id);
element.classList.add("greenBorder");
// console.log('Value True')
} else{
var element = document.getElementById(id);
element.classList.add("redBorder");
// console.log('Value False')
}
};
if(id == 'image3'){
if(gameData.a3 == true){
var element = document.getElementById(id);
element.classList.add("greenBorder");
// console.log('Value True')
} else{
var element = document.getElementById(id);
element.classList.add("redBorder");
// console.log('Value False')
}
};
if(id == 'image4'){
if(gameData.a4 == true){
var element = document.getElementById(id);
element.classList.add("greenBorder");
// console.log('Value True')
} else{
var element = document.getElementById(id);
element.classList.add("redBorder");
// console.log('Value False')
}
};
if(id == 'image5'){
if(gameData.a5 == true){
var element = document.getElementById(id);
element.classList.add("greenBorder");
// console.log('Value True')
} else{
var element = document.getElementById(id);
element.classList.add("redBorder");
// console.log('Value False')
}
};
if(id == 'image6'){
if(gameData.a6 == true){
var element = document.getElementById(id);
element.classList.add("greenBorder");
// console.log('Value True')
} else{
var element = document.getElementById(id);
element.classList.add("redBorder");
// console.log('Value False')
}
}
};
let url = window.location.href;
let urlSplit = url.split('/')
let gameName = urlSplit[3] +`-`+ urlSplit[4];
let formatedDateTime;
window.onload = function () {
let currentTime = new Date();
formatedDateTime = currentTime.toLocaleString();
// console.log(formatedDateTime);
// Create userData object inside the onload event
let userData = {
'f2': formatedDateTime,
};
// console.log(userData); // Now, f1 and f2 should have values
};
function generateShortUniqueID(length) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
result += characters.charAt(randomIndex);
}
return result;
}
const shortUniqueID = generateShortUniqueID(10); // Change 10 to the desired length
// console.log(shortUniqueID);
function saveUserData() {
// Move the userData object creation inside the saveUserData function if needed
let userData = {
'status' : 'published',
'user_id': 'tick-v1@beanstalkedu.com',
'game_name': gameName,
'game_open': formatedDateTime,
};
fetch(`https://2016.dev2-cs.siliconpin.com/save/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(userData)
})
.then(response => {
if (response.ok) {
document.getElementById('savedMessage').innerHTML = 'Saved Successfully';
// console.log('Data Saved', response);
} else {
// console.log('Something Wrong', response);
}
})
.catch(error => {
console.error('An error occurred', error);
});
}
document.addEventListener('DOMContentLoaded', function () {
const contactForm = document.getElementById('contactForm');
contactForm.addEventListener('submit', async function (event) {
event.preventDefault();
});
});
</script> -->
<style>
@import url('https://fonts.googleapis.com/css2?family=Lobster&family=Quicksand:wght@500;700&display=swap');
body{