update tick game v1 and v2

pull/5/head
dev sp 2023-12-17 11:52:03 +00:00
parent d1e08b721a
commit b76cedd883
2 changed files with 209 additions and 181 deletions

View File

@ -4,7 +4,6 @@ import Layout from "../../layouts/Layout.astro";
<Layout title="">
<main>
<div>
<!-- bg-[url('/assets/background.jpg')] -->
<section class="bg-white bg-center bg-no-repeat bg-cover h-screen">
<div class="container mx-auto px-4">
<div class="flex flex-row place-content-between pt-6">
@ -15,28 +14,37 @@ import Layout from "../../layouts/Layout.astro";
<form id="contactForm">
<div id="itemForm" class="flex flex-row place-content-between">
<div class="flex flex-col gap-6 place-items-center">
<img id="image1" src="" alt="" draggable="false" class="select-none" />
<input onclick="checkResult('image1');" type="checkbox" id="a1" class="round-checkbox-input myCheckbox" value="a1"/>
<label for="a1" class="round-checkbox-label"></label>
<img id="image2" src="" alt="" draggable="false" class="select-none" />
<input onclick="checkResult('image2');" type="checkbox" id="a2" class="round-checkbox-input myCheckbox" value="a2"/>
<label for="a2" class="round-checkbox-label"></label>
<label for="a1" class="round-checkbox-label">
<img id="image1" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image1');" type="checkbox" id="a1" class="round-checkbox-input myCheckbox" value="a1"/>
<label for="a2" class="round-checkbox-label">
<img id="image2" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image2');" type="checkbox" id="a2" class="round-checkbox-input myCheckbox" value="a2"/>
</div>
<div class="flex flex-col gap-6 place-items-center">
<img id="image3" src="" alt="" draggable="false" class="select-none" />
<input onclick="checkResult('image3');" type="checkbox" id="a3" class="round-checkbox-input myCheckbox" value="a3"/>
<label for="a3" class="round-checkbox-label"></label>
<img id="image4" src="" alt="" draggable="false" class="select-none" />
<input onclick="checkResult('image4');" type="checkbox" id="a4" class="round-checkbox-input myCheckbox" value="a4"/>
<label for="a4" class="round-checkbox-label"></label>
<label for="a3" class="round-checkbox-label">
<img id="image3" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image3');" type="checkbox" id="a3" class="round-checkbox-input myCheckbox" value="a3"/>
<label for="a4" class="round-checkbox-label">
<img id="image4" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image4');" type="checkbox" id="a4" class="round-checkbox-input myCheckbox" value="a4"/>
</div>
<div class="flex flex-col gap-6 place-items-center">
<img id="image5" src="" alt="" draggable="false" class="select-none" />
<input onclick="checkResult('image5');" type="checkbox" id="a5" class="round-checkbox-input myCheckbox" value="a5"/>
<label for="a5" class="round-checkbox-label"></label>
<img id="image6" src="" alt="" draggable="false" class="select-none" />
<input onclick="checkResult('image6');" type="checkbox" id="a6" class="round-checkbox-input myCheckbox" value="a6"/>
<label for="a6" class="round-checkbox-label"></label>
<label for="a5" class="round-checkbox-label">
<img id="image5" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image5');" type="checkbox" id="a5" class="round-checkbox-input myCheckbox" value="a5"/>
<label for="a6" class="round-checkbox-label">
<img id="image6" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image6');" type="checkbox" id="a6" class="round-checkbox-input myCheckbox" value="a6"/>
</div>
</div>
<div class="flex flex-col place-items-center justify-center pt-8">
@ -50,6 +58,81 @@ import Layout from "../../layouts/Layout.astro";
</main>
</Layout>
<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;
document.getElementById("gameDescription").innerHTML = gameData.game_description;
const assetsURL = 'https://management.beanstalkedu.com/assets/';
for (let i = 1; i <= 6; i++) {
const imageId = `image${i}`;
document.getElementById(imageId).src = assetsURL + gameData[imageId];
}
});
function checkResult2(id) {
const checkbox = document.getElementById('a' + id.slice(-1));
const element = document.getElementById(id);
if (checkbox.checked) {
if (gameData[id.replace('image', 'a')] === true) {
element.classList.add('greenBorder');
} else {
element.classList.add('redBorder');
}
} else {
element.classList.remove('greenBorder', 'redBorder');
}
}
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() {
let userData = {
'status': 'published',
'user_id': 'tick-v1@beanstalkedu.com',
'game_name': gameName,
'game_open': formatedDateTime,
};
fetch(`https://management.beanstalkedu.com/items/game_result`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(userData)
})
.then(response => {
if (response.ok) {
document.getElementById('savedMessage').innerHTML = 'Saved Successfully';
} 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>
<!-- <script is:inline>
const params = new URLSearchParams(window.location.search);
const paramsID = params.get('id');
@ -67,28 +150,7 @@ import Layout from "../../layouts/Layout.astro";
document.getElementById("image5").src = assetsURL + gameData.image5;
document.getElementById("image6").src = assetsURL + gameData.image6;
});
// const saveButton = document.getElementById('saveButton');
// saveButton.addEventListener('click', function() {
// const checkboxes = document.querySelectorAll('.myCheckbox');
// const checkedValues = [];
// console.log(checkedValues)
// if(checkedValues == gameData.a1){
// console.log(gameData.a1)
// }
// checkboxes.forEach(function(checkbox) {
// if (checkbox.checked) {
// checkedValues.push(checkbox.value);
// // console.log(checkedValues);
// // console.log(gameData.a1)
// // let value1 = checkedValues = 'a1';
// }
// });
// // if(checkedValues == gameData.a1) {
// // console.log("Matched")
// // }
// // console.log('Checked Values:', checkedValues);
// })
function checkResult(id){
function checkResult2(id){
// console.log(gameData.a1)
// alert("Matched")
if(id == 'image1'){
@ -214,101 +276,42 @@ import Layout from "../../layouts/Layout.astro";
console.error('An error occurred', error);
});
}
// var checkBoxes = itemForm.querySelectorAll('input[type="checkbox"]');
// function getData() { // this function will get called when the save button is clicked
// result = [];
// console.log(result);
// checkBoxes.forEach(item => { // loop all the checkbox item
// if (item.checked) { //if the check box is checked
// let data = { // create an object
// item: item.value,
// selected: item.checked
// }
// console.log(data.selected);
// result.push(data); //stored the objects to result array
// }
// })
// };
document.addEventListener('DOMContentLoaded', function () {
const contactForm = document.getElementById('contactForm');
contactForm.addEventListener('submit', async function (event) {
event.preventDefault();
// const formData = {
// f1: result[0],
// f2: result[1],
// f3: result[2],
// f4: result[3],
// f5: result[4],
// f6: result[5]
// };
// console.log("Form Data", formData)
// try {
// const response = await fetch('https://management.beanstalkedu.com/items/game_result', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify(formData)
// });
// if (response.ok) {
// console.log('Form data submitted successfully');
// } else {
// console.error('Failed to submit form data');
// }
// } catch (error) {
// console.error('An error occurred:', error);
// }
});
});
</script>
</script> -->
<style>
@import url('https://fonts.googleapis.com/css2?family=Lobster&family=Quicksand:wght@500;700&display=swap');
body{
font-family: quicksand;
}
.greenBorder{
border: 4px solid green;
border: 4px solid #008000;
border-radius: 10%;
transition: border 0.5s, border-color 0.3s, transform 6s;
}
.redBorder{
border: 4px solid red;
border-radius: 10%;
}
#image1, #image2, #image3, #image4, #image5, #image6{
width: 200px;
/* border: 4px solid red;
border-radius: 5%; */
}
.round-checkbox-input {
display: none;
#image1, #image2, #image3, #image4, #image5, #image6, #image7, #image8, #image9{
width: 150px;
}
.round-checkbox-label {
display: inline-block;
width: 30px;
height: 30px;
border-radius: 10%;
background-color: #ccc;
border: 2px solid #007bff;
cursor: pointer;
position: relative;
transition: background-color 0.3s, border-color 0.3s, transform 0.3s;
}
.round-checkbox-input:checked + .round-checkbox-label {
background-color: #007bff;
border-color: #007bff;
transform: scale(1.2);
border-radius: 30%;
}
.round-checkbox-input:checked + .round-checkbox-label::after {
content: '\2713';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 40px;
color: white;
display: block;
}
</style>

View File

@ -4,7 +4,6 @@ import Layout from "../../layouts/Layout.astro";
<Layout title="">
<main>
<div>
<!-- bg-[url('/assets/background.jpg')] -->
<section class="bg-white bg-center bg-no-repeat bg-cover h-screen">
<div class="container mx-auto px-4">
<div class="flex flex-row place-content-between pt-6">
@ -15,45 +14,52 @@ import Layout from "../../layouts/Layout.astro";
<form id="contactForm">
<div id="" class="flex flex-row place-content-between">
<div class="flex flex-col gap-6 place-items-center">
<!-- <img id="image1" src="" alt="" draggable="false" class="select-none" /> -->
<input onclick="checkResult2('image1');" type="checkbox" id="a1" class="round-checkbox-input myCheckbox" value="a1"/>
<label for="a1" class="round-checkbox-label">
<img id="image1" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image1');" type="checkbox" id="a1" class="round-checkbox-input myCheckbox" value="a1"/>
<img id="image2" src="" alt="" draggable="false" class="select-none" />
<label for="a2" class="round-checkbox-label">
<img id="image2" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image2');" type="checkbox" id="a2" class="round-checkbox-input myCheckbox" value="a2"/>
<label for="a2" class="round-checkbox-label"></label>
<img id="image3" src="" alt="" draggable="false" class="select-none" />
<label for="a3" class="round-checkbox-label">
<img id="image3" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image3');" type="checkbox" id="a3" class="round-checkbox-input myCheckbox" value="a3"/>
<label for="a3" class="round-checkbox-label"></label>
</div>
<div class="flex flex-col gap-6 place-items-center">
<img id="image4" src="" alt="" draggable="false" class="select-none" />
<label for="a4" class="round-checkbox-label">
<img id="image4" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image4');" type="checkbox" id="a4" class="round-checkbox-input myCheckbox" value="a4"/>
<label for="a4" class="round-checkbox-label"></label>
<img id="image5" src="" alt="" draggable="false" class="select-none" />
<label for="a5" class="round-checkbox-label">
<img id="image5" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image5');" type="checkbox" id="a5" class="round-checkbox-input myCheckbox" value="a5"/>
<label for="a5" class="round-checkbox-label"></label>
<img id="image6" src="" alt="" draggable="false" class="select-none" />
<label for="a6" class="round-checkbox-label">
<img id="image6" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image6');" type="checkbox" id="a6" class="round-checkbox-input myCheckbox" value="a6"/>
<label for="a6" class="round-checkbox-label"></label>
</div>
<div class="flex flex-col gap-6 place-items-center">
<img id="image7" src="" alt="" draggable="false" class="select-none" />
<label for="a7" class="round-checkbox-label">
<img id="image7" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image7');" type="checkbox" id="a7" class="round-checkbox-input myCheckbox" value="a7"/>
<label for="a7" class="round-checkbox-label"></label>
<img id="image8" src="" alt="" draggable="false" class="select-none" />
<label for="a8" class="round-checkbox-label">
<img id="image8" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image8');" type="checkbox" id="a8" class="round-checkbox-input myCheckbox" value="a8"/>
<label for="a8" class="round-checkbox-label"></label>
<img id="image9" src="" alt="" draggable="false" class="select-none" />
<label for="a9" class="round-checkbox-label">
<img id="image9" src="" alt="" draggable="false" class="select-none" />
</label>
<input onclick="checkResult2('image9');" type="checkbox" id="a9" class="round-checkbox-input myCheckbox" value="a9"/>
<label for="a9" class="round-checkbox-label"></label>
</div>
</div>
<div class="flex flex-col justify-center place-items-center pt-8">
@ -69,6 +75,81 @@ import Layout from "../../layouts/Layout.astro";
<script is:inline>
const params = new URLSearchParams(window.location.search);
const paramsID = params.get('id');
fetch(`https://management.beanstalkedu.com/items/game_tick_variant2/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`)
.then(res => res.json())
.then(data => {
gameData = data.data;
document.getElementById("gameDescription").innerHTML = gameData.game_description;
const assetsURL = 'https://management.beanstalkedu.com/assets/';
for (let i = 1; i <= 9; i++) {
const imageId = `image${i}`;
document.getElementById(imageId).src = assetsURL + gameData[imageId];
}
});
function checkResult2(id) {
const checkbox = document.getElementById('a' + id.slice(-1));
const element = document.getElementById(id);
if (checkbox.checked) {
if (gameData[id.replace('image', 'a')] === true) {
element.classList.add('greenBorder');
} else {
element.classList.add('redBorder');
}
} else {
element.classList.remove('greenBorder', 'redBorder');
}
}
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() {
let userData = {
'status': 'published',
'user_id': 'tick-v2@beanstalkedu.com',
'game_name': gameName,
'game_open': formatedDateTime,
};
fetch(`https://management.beanstalkedu.com/items/game_result`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(userData)
})
.then(response => {
if (response.ok) {
document.getElementById('savedMessage').innerHTML = 'Saved Successfully';
} 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>
<!-- <script is:inline>
const params = new URLSearchParams(window.location.search);
const paramsID = params.get('id');
fetch(`https://management.beanstalkedu.com/items/game_tick_variant2/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`)
.then(res => res.json())
.then(data => {
@ -200,7 +281,6 @@ import Layout from "../../layouts/Layout.astro";
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-v2@beanstalkedu.com',
@ -231,54 +311,14 @@ import Layout from "../../layouts/Layout.astro";
const contactForm = document.getElementById('contactForm');
contactForm.addEventListener('submit', async function (event) {
event.preventDefault();
// const formData = {
// f1: result[0],
// f2: result[1],
// f3: result[2],
// f4: result[3],
// f5: result[4],
// f6: result[5]
// };
// console.log("Form Data", formData)
// try {
// const response = await fetch('https://management.beanstalkedu.com/items/game_result', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify(formData)
// });
// if (response.ok) {
// console.log('Form data submitted successfully');
// } else {
// console.error('Failed to submit form data');
// }
// } catch (error) {
// console.error('An error occurred:', error);
// }
});
});
</script>
</script> -->
<style>
@import url('https://fonts.googleapis.com/css2?family=Lobster&family=Quicksand:wght@500;700&display=swap');
/* body{
font-family: quicksand;
animation: fadeInAnimation ease 6s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
@keyframes fadeInAnimation {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
} */
.greenBorder{
border: 4px solid #008000;
border-radius: 10%;
/* transform:scale3d(0.5, 1, 1.7); */
transition: border 0.5s, border-color 0.3s, transform 6s;
}
.redBorder{
@ -287,37 +327,22 @@ import Layout from "../../layouts/Layout.astro";
}
#image1, #image2, #image3, #image4, #image5, #image6, #image7, #image8, #image9{
width: 150px;
/* border: 4px solid red;
border-radius: 5%; */
}
/* .round-checkbox-input {
display: none;
} */
.round-checkbox-label {
display: inline-block;
/* width: 30px; */
/* height: 30px; */
/* border-radius: 10%; */
/* background-color: #ccc; */
/* border: 2px solid #007bff; */
cursor: pointer;
position: relative;
transition: background-color 0.3s, border-color 0.3s, transform 0.3s;
}
.round-checkbox-input:checked + .round-checkbox-label {
/* background-color: #007bff; */
/* border-color: #007bff; */
transform: scale(1.2);
border-radius: 30%;
}
.round-checkbox-input:checked + .round-checkbox-label::after {
/* content: '\2713'; */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 40px;
/* color: white; */
display: block;
}
</style>