Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treasure hunt (hopefully final) #22

Merged
merged 10 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/Poppins-Light.ttf
Binary file not shown.
7 changes: 6 additions & 1 deletion assets/styles/mask.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ body {
background-attachment: fixed;
text-align: center;
color: var(--light-gray);
font-family: Ubuntu, Roboto, Arial, Open Sans, sans-serif;
font-family: Poppins ,Ubuntu, Roboto, Arial, Open Sans, sans-serif;
}

div#page-container {
Expand Down Expand Up @@ -515,3 +515,8 @@ span.navbar-line {
display: none;
}
}

@font-face {
font-family: "Poppins";
src: url("/assets/Poppins-Light.ttf");
}
15 changes: 1 addition & 14 deletions routers/admin-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,7 @@ router.get('/edit-team', async (req, res) => {
return res.renderFile('admin/team-edit.njk', { team });
});

router.patch('/edit-team', [
body('id')
.isNumeric()
.trim()
.notEmpty().withMessage('No ID Provided'),
body('teamName')
.trim()
.notEmpty().withMessage('No Name Provided')
], async (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
const errorMessages = errors.array().map(error => error.msg);
throw new Error(errorMessages[0]);
}
router.patch('/edit-team', async (req, res) => {
const team = {
id: req.body.id,
name: req.body.teamName,
Expand Down
6 changes: 3 additions & 3 deletions routers/live-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ router.post('/get-riddle-question', (req, res) => {

router.post('/submit', async (req, res) => {
const attempted = req.team.questionsAttempted;
if (req.body.questionNo !== attempted) return res.status(420).send('Koi bkl hi hoga');
if (req.body.state !== req.team.status) return res.status(420).send('Koi bkl hi hoga');
if (req.body.questionNo !== attempted) return res.status(871).send('Koi bkl hi hoga');
if (req.body.state !== req.team.status) return res.status(871).send('Koi bkl hi hoga');
if (req.body.state === 'riddle-question') {
if (attempted + 1 >= ques) {
await dbh.updateTeamStatus({ _id: req.team._id, status: 'completed', questionNo: 6 });
Expand All @@ -91,7 +91,7 @@ router.post('/submit', async (req, res) => {
if (
req.team.order.map((o) =>
handlerContext.locations.find((l) => l._id === o.location)
)[attempted].code === req.body.answer
)[attempted].code.toLowerCase() === req.body.answer.toLowerCase()
) {
await dbh.updateTeamStatus({ _id: req.team._id, status: 'riddle-question', questionNo: req.body.questionNo });
return res.status(200).send('correct answer');
Expand Down
2 changes: 1 addition & 1 deletion templates/_base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
{% if not loggedIn %}
<a href="/login" class="dropbtn {{ 'active-page' if thispage === 'login' }}" target="_self">Login</a>
{% else %}
<a href="/logout" class="{% if 'logout' === thispage %}active-page {% endif %}{% if mongoless %}disabled {% endif %}" target="_self">Logout</a>
<a href="/logout" class="dropbtn {% if 'logout' === thispage %}'active-page' {% endif %}{% if mongoless %}'disabled' {% endif %}" target="_self">Logout</a>
{% endif %}
</div>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions templates/_form.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
</div>
{% endmacro %}

{% macro field(id, label, value, type = "text") %}
<div class="item field" {% if type == 'hidden' %} style="display: none;" {% endif %}>
<input type="{{type}}" required id="{{ id }}" {% if value %} value="{{ value }}" {% endif %}>
{% macro field(id, label, value, type = "text", autocomplete = true) %}
<div class="item field" {% if type == 'hidden' %} style="display: none;" {% endif %} >
<input type="{{type}}" required id="{{ id }}" {% if value %} value="{{ value }}" {% endif %} {{ 'autocomplete=off' if not autocomplete }}>
<label>{{ label }}</label>
</div>
{% endmacro %}
Expand Down
9 changes: 3 additions & 6 deletions templates/admin/_admin.njk
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{% extends '_base.njk' %}

{% set adminlinks = [{
href: 'admin/list-users',
name: 'Users'
},{
href: 'admin/quiz-master',
name: 'Quiz Portal'
href: 'live',
name: 'Teams'
}] %}

{% block navbar %}
Expand All @@ -25,7 +22,7 @@
<div style="height:80px;"></div>
<hr id="top-line"/>
{% for link in navlinks %}
<a href="/admin/{{ link.href }}" target="_self"><div class="lettuce{% if link.href == thispage %} active-page {% endif %}" >{{ link.name }}</div></a>
<a href="/{{ link.href }}" target="_self"><div class="lettuce{% if link.href == thispage %} active-page {% endif %}" >{{ link.name }}</div></a>
{% if not loop.last %}<hr class="minor"/>{% endif %}
{% endfor %}
</div>
Expand Down
8 changes: 6 additions & 2 deletions templates/admin/team-edit.njk
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@
async function update() {
event.preventDefault();
const data = getData();
console.log(data);
updateData = {
...data,
id: '{{ team._id }}'
}
console.log(updateData);
try {
const response = await axios.patch('/admin/edit-team', data);
const response = await axios.patch('/admin/edit-team', updateData);
if (response.status === 200) {
alert('Team updated successfully!');
window.location.href = '/live';
Expand Down
4 changes: 1 addition & 3 deletions templates/info/landing.njk
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@
<style>
#timer {
color: color-mix(in hsl, var(--dark-red) 50%, var(--error-red) 70%);
font-size: 2.5em;
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', fantasy, sans-serif;
font-size: 2em;
padding: 20px;
}

Expand Down Expand Up @@ -298,7 +297,6 @@
border-radius: 10px;
padding: 10px;
text-decoration: none;
/* font-family: Ubuntu, Roboto, Arial, Open Sans, sans-serif; */
background-color: var(--red);
color: var(--off-white);
}
Expand Down
37 changes: 21 additions & 16 deletions templates/live/interface.njk
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
</g>
</svg>
<br/>
<p style="font-size: 22px;">You have completed the treasure hunt. Head over to Gymkhana to grab your prizes!</p>
<p id="completed" style="font-size: 22px;">You have completed the treasure hunt. Head over to Gymkhana to grab your prizes!</p>
</div>
{% endcall %}
</div>
Expand Down Expand Up @@ -274,8 +274,8 @@
<h3>Question</h3>
<p id="location-question"></p>
</div>
{{ forms.field('locationcode', 'Location Code') }}
<button id="location-submit-button">Submit</button>
{{ forms.field('locationcode', 'Location Code', autocomplete = false) }}
<button id="location-submit-button" onclick="this.disabled = true">Submit</button>
{% endcall %}
</div>
<div id="riddle-form">
Expand All @@ -289,7 +289,7 @@
<label style="top: -8px;"></label>
<select name="riddleanswer" id="riddleanswer" style="height: 40px; font-size: 17px; font-weight: 400;"></select>
</div>
<button id="riddle-submit-button">Submit</button>
<button id="riddle-submit-button" onclick="this.disabled = true">Submit</button>
{% endcall %}
</div>
</div>
Expand Down Expand Up @@ -485,27 +485,27 @@
waiting = true;
waitMsg = 'Fetching Locations'
wait()
document.getElementById('location-question').textContent = await getLocationQuestion();
document.getElementById('location-question').innerHTML = await getLocationQuestion();
setTimeout(() => {
document.getElementById('waiting').style.display = 'none'
locationCode.style.display = 'block';
}, Math.floor(4 + Math.random()*3) * 1000);
}, 1000);
} else if (state === 'riddle-question') {
waiting = true;
waitMsg = 'Fetching Questions'
wait()
const riddleQuestion = await getRiddleQuestion();
console.log(riddleQuestion);
if (riddleQuestion) {
document.getElementById('riddle-question').textContent = riddleQuestion.question;
document.getElementById('riddle-question').innerHTML = riddleQuestion.question;
}
document.getElementById('riddleanswer').innerHTML = '<option value="" selected disabled hidden>Choose an answer</option>' + riddleQuestion.keywords.map((keyword, index) => {
return `<option value="${ index }">${ keyword }</option>`
}).join(' ')
setTimeout(() => {
document.getElementById('waiting').style.display = 'none'
riddleForm.style.display = 'block';
}, Math.floor(4 + Math.random()*3) * 1000);
}, 1000);
} else if (state === 'riddle-timeout') {
return await timeout();
}
Expand All @@ -526,7 +526,7 @@
const riddleQuestion = await getRiddleQuestion();
console.log(riddleQuestion);
if (riddleQuestion) {
document.getElementById('riddle-question').textContent = riddleQuestion.question;
document.getElementById('riddle-question').innerHTML = riddleQuestion.question;
}
riddleButton.disabled = true;
document.getElementById('riddleanswer').innerHTML = '<option value="" selected disabled hidden>Choose an answer</option>' + riddleQuestion.keywords.map((keyword, index) => {
Expand Down Expand Up @@ -578,7 +578,7 @@
setTimeout(() => {
document.getElementById('waiting').style.display = 'none'
document.getElementById('riddle-form').style.display = 'block';
}, Math.floor(4 + Math.random()*3) * 1000);
}, 1000);
await timeout();
}
else{
Expand All @@ -596,7 +596,6 @@
const response = await axios.post('/live/submit', {state: state, answer: state === 'location-code'? data.locationcode.trim() : data.riddleanswer, questionNo: attempted});
if (state === 'location-code') {
const locationButton = document.getElementById('location-submit-button');
locationButton.disabled = true;
const messageBox = document.getElementById("message-box");
messageBox.innerHTML = '<h2 class="correct">Correct Location!</h2>';
const messageCover = document.getElementById("message-cover");
Expand All @@ -610,7 +609,6 @@
}
else {
const riddleButton = document.getElementById('riddle-submit-button');
riddleButton.disabled = true;
const messageBox = document.getElementById("message-box");
messageBox.innerHTML = '<h2 class="correct">Correct Answer!</h2>';
const messageCover = document.getElementById("message-cover");
Expand All @@ -622,11 +620,18 @@
document.getElementById('locationcode').value= '';
riddleButton.disabled = false;
await renderForm();
}, 5000);
}, 3000);
}
}
catch ( e ) {
if (e.response.status === 786) console.log(e.response.data);
if (e.response.status === 786) {
state='completed';
document.getElementById('done').innerHTML = "Event Ended";
document.getElementById('completed').innerHTML = "Please head over to TSG";
document.querySelector("svg").style.display = "none";
document.getElementById('container').style.display = 'none';
document.getElementById('done-cover').style.display = 'flex';
}
else if ( e.response.status === 418 ) {
const riddleButton = document.getElementById('riddle-submit-button');
riddleButton.disabled = true;
Expand All @@ -641,9 +646,9 @@
state='completed';
document.getElementById('container').style.display = 'none';
document.getElementById('done-cover').style.display = 'flex';
}, 5000);
}, 3000);
}
else if ( e.response.status === 420 ) {
else if ( e.response.status === 871 ) {
localStorage.setItem('encountered-error', true);
location.reload();
}
Expand Down
Loading