Skip to content
Snippets Groups Projects
Commit f42fcda2 authored by Ömer Kinik's avatar Ömer Kinik
Browse files

Upload New File

parent cd80ba4f
Branches main
No related tags found
No related merge requests found
vote.html 0 → 100644
<!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>Vote</title>
<script src="https://unpkg.com/vue@next"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<!-- import for vuetify-->
<link href="https://cdn.jsdelivr.net/npm/vuetify@latest/dist/vuetify.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/vuetify@latest"></script>
<style>
.voteConfirmation {
color: green;
font-weight: bold;
margin: 10px;
}
.big-button {
font-size: large;
padding: 20px 20px;
margin-top: 400px;
}
.my-heading {
font-size: 1.5rem;
font-weight: 500;
}
</style>
</head>
<body>
<div id="app">
<v-app>
<v-container>
<v-row justify="center">
<v-col cols="12" sm="8" md="6">
<v-btn v-if="showStartVotingButton" block color="primary" @click="startTheVote"
class="big-button">
Start Voting</v-btn>
</v-col>
</v-row>
<v-row>
<v-col cols="12" sm="6" md="4" v-for="persona in persons"
:key="persona.firstName + persona.lastName" class="mb-3">
<v-card>
<v-card-title>
<div justify="center" class="my-heading">{{ persona.firstName }} {{
persona.lastName }}</div>
</v-card-title>
<v-card-actions>
<v-btn block color="success" @click="castVote(persona)">Vote</v-btn>
</v-card-actions>
</v-card>
</v-col>
</v-row>
</v-container>
<div v-if="votedPerson" class="voteConfirmation">Your vote for {{votedPerson}} has been counted, votes left:
{{voteLimit - voteCount}}</div>
<v-container>
<v-bottom-navigation grow>
<v-btn @click="goToPage('index.html')">
Create a person
</v-btn>
<v-btn @click="goToPage('vote.html')">
Vote
</v-btn>
<v-btn @click="goToPage('vote_results.html')">
Vote results
</v-btn>
</v-bottom-navigation>
</v-container>
</v-app>
</div>
<script>
const vuetify = Vuetify.createVuetify();
let app = Vue.createApp({
data() {
return {
persons: [],
voteCount: 0,
voteLimit: 1,
person: {
firstName: '',
lastName: ''
},
winner: '',
votedPerson: null,
showStartVotingButton: true
}
},
methods: {
async startTheVote() {
const response = await axios.get('http://127.0.0.1:8000/persons')
this.persons = response.data
setVoteLimit = parseInt(prompt("Set the vote limit please"))
this.voteLimit = setVoteLimit
this.showStartVotingButton = false;
},
async findPersonWithMostVotes() {
const response = await axios.get('http://127.0.0.1:8000/vote')
const data = response.data
let maxVotes = -1
let personWithMaxVotes = ''
for (person of data) {
if (person.Stimmzahl > maxVotes) {
maxVotes = person.Stimmzahl
personWithMaxVotes = person.person
}
}
this.winner = personWithMaxVotes
},
async castVote(person) {
const personToVote = {
firstName: person.firstName,
lastName: person.lastName
}
axios.post('http://127.0.0.1:8000/vote', personToVote)
this.voteCount++
this.votedPerson = personToVote.firstName + " " + personToVote.lastName
if (this.voteCount >= this.voteLimit) {
await this.findPersonWithMostVotes()
this.votedPerson = ''
alert("Voting is complete, you will be redirected to the results page")
window.location.href = 'vote_results.html'
return
}
},
goToPage(page) {
window.location.href = page;
}
}
})
app.use(vuetify);
app.mount('#app')
</script>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment