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

Added functionality of updating results for events for first rank #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
56 changes: 54 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ app.set('view engine', 'ejs');
app.engine('html', require('ejs').renderFile);

app.use('/', express.static(__dirname + '/'));

app.use(express.static('public'));
app.use(express.urlencoded({ extended: true }));

Expand Down Expand Up @@ -42,6 +41,59 @@ connection.connect(function (error) {
}
});


var resultsUpdate = (req, res) => {

var firstPlace = req.body.firstPlace;

var secondPlace = "";
if(secondPlace != undefined){
secondPlace = req.body.secondPlace;
}

var thirdPlace = "";
if(thirdPlace != undefined){
thirdPlace = req.body.thirdPlace;
}

var eventId = req.body.eventCode;

var insertQuery = "INSERT INTO winners VALUES ('"+ eventId +"', '"+ firstPlace +"', '1')";
connection.query(insertQuery, (err, res) => {
if(!err){
log("Updated results");
}else{
log("Update error");
}
});

// var insertQuery = "INSERT INTO winners(eventId, candidateId) VALUES ('"+ eventId +"', '"+ candidateId +"')";
// connection.query(insertQuery, (err, res) => {
// if(!err){
// log("Updated results");
// }else{
// log("Update error");
// }
// });

return res.redirect('/' + eventId + '/eventResults');
}

app.post('/resultsUpdate', resultsUpdate);

app.get('/:eventCode/eventResults', (req, res) => {
var selectionQuery = "SELECT * FROM candidates WHERE candidateId IN (SELECT candidateId FROM registers WHERE eventCode = '"+ req.params.eventCode +"')";

connection.query(selectionQuery, (err, result) => {
if(!err){
res.render('eventResults.html', {winners: result, eventId: req.params.eventCode});
}else{
log(err);
throw err;
}
});
});

app.get('/event/:eventCode', (req, res) => {
var selectionQuery = "SELECT * FROM events WHERE eventId = '"+ req.params.eventCode +"'";
connection.query(selectionQuery, (err, result) => {
Expand All @@ -55,7 +107,7 @@ app.get('/event/:eventCode', (req, res) => {
});

app.get('/manageEvent', (req, res) => {
var selectionQuery = "SELECT * FROM events order by eventDate";
var selectionQuery = "SELECT * FROM events ORDER BY eventDate";
connection.query(selectionQuery, (err, result) => {
if (err) {
log(err);
Expand Down
1 change: 1 addition & 0 deletions public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ input[type="submit"] {
border-radius: 4px;
cursor: pointer;
display: block;
font-size: medium;
}

/* When moving the mouse over the submit button, add a darker green color */
Expand Down
38 changes: 30 additions & 8 deletions public/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Results</title>
<link rel="stylesheet" href="../css/styles.css">
<script src="../include/js/timer.js"></script>
</head>
<body>
<body onload="">
<div class="row">
<div class="col3">
<img src="/images/quest_logo.png" alt="" width=80 height=80>
Expand All @@ -27,13 +28,34 @@ <h2 style="text-align:center">JNTUH COLLEGE OF ENGINEERING HYDERABAD</h2>
</div>
</div>

<div align="center" class="row">
<% for (const i in events) { %>
<h2><%=events[i].eventId %></h2>
<h2><%=events[i].eventName %></h2>
<h2><%=events[i].eventDate %></h2>
<h2><%=events[i].eventTime %></h2>
<% } %>
<br>
<div class="row" style="background-color: white;">

<h2><%=events[0].eventId %></h2>
<h2><%=events[0].eventName %></h2>
<h2><%=events[0].eventDate %></h2>
<h2><%=events[0].eventTime %></h2>
</div>


<div class="cardContainer" width="100%">
<a href="/manageCandidateOnEvent" class="center">
<div class="card col3">
<img src="/images/quest_logo.png" alt="Avatar" width="70%">
<div class="container">
<h4><b>Manage Candidate</b></h4>
</div>
</div>
</a>

<a href="/<%= events[0].eventId %>/eventResults" class="center">
<div class="card col3">
<img src="/images/quest_logo.png" alt="Avatar" width="70%">
<div class="container">
<h4><b>Update winners </b></h4>
</div>
</div>
</a>
</div>
</body>
</html>
70 changes: 70 additions & 0 deletions public/eventResults.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Results</title>
<link rel="stylesheet" href="../css/styles.css">
</head>
<body onload="">
<div class="row">
<div class="col3">
<img src="/images/quest_logo.png" alt="" width=80 height=80>
</div>
<div class="col3" align="center">
<h1 style="text-align:center">
QUEST - <script>document.write(new Date().getFullYear())</script>
<br>
</h1>
<h4 style="text-align:center">DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING</h4>
<h2 style="text-align:center">JNTUH COLLEGE OF ENGINEERING HYDERABAD</h2>

</div>

<div class="col3">
<img src="/images/jntuhlogo.png" alt="" width=120 height=120>
</div>
</div>

<br>

<h2 style="text-align: center;"><u>UPDATE RESULTS</u></h2>
<div class="formContainer">
<div class="w3-container">
<form action="/resultsUpdate" method="POST">

<label for="eventCode">Event</label>
<input type="text" id="eventCode" name="eventCode" readonly value="<%= eventId%>"/>

<label for="firstPlace">First place</label>
<select id="firstPlace" name="firstPlace" required>
<option>--SELECT--</option>
<% for (const i in winners) { %>
<option value="<%= winners[i].candidateId %>"> <%= winners[i].candidateName + " -- " + winners[i].candidateContact %> </option>
<% } %>
</select>

<label for="secondPlace">Second place</label>
<select id="secondPlace" name="secondPlace">
<option>--SELECT--</option>
<% for (const i in winners) { %>
<option value="<%= winners[i].candidateId %>"> <%= winners[i].candidateName + " -- " + winners[i].candidateContact %> </option>
<% } %>
</select>

<label for="thirdPlace">Third place</label>
<select id="thirdPlace" name="thirdPlace">
<option>--SELECT--</option>
<% for (const i in winners) { %>
<option value="<%= winners[i].candidateId %>"> <%= winners[i].candidateName + " -- " + winners[i].candidateContact %> </option>
<% } %>
</select>

<input type="submit" id="submitData" value="Update Results">

</form>
</div>
</div>
</body>
</html>
30 changes: 30 additions & 0 deletions public/include/js/timer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function countdownTimer(lastDate){
// Set the date we're counting down to
var countDownDate = new Date(lastDate).getTime();

// Update the count down every 1 second
var x = setInterval(function() {

// Get today's date and time
var now = new Date().getTime();

// Find the distance between now and the count down date
var distance = countDownDate - now;

// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

// Display the result in the element with id="demo"
document.getElementById("countdown-timer").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";

// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
}
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h1 style="text-align:center">
<h4 style="text-align:center">DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING</h4>
<h2 style="text-align:center">JNTUH COLLEGE OF ENGINEERING HYDERABAD</h2>

<h4 style="text-align:center"><%= fest[0].festDateFrom %></h4>
<!-- <h4 style="text-align:center"><%= fest[0].festDateFrom %></h4> -->

</div>

Expand Down
52 changes: 0 additions & 52 deletions public/studentresults.html

This file was deleted.