initialize project
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
<template>
|
||||
<div class="row col-md-10 col-md-offset-1">
|
||||
<div class="col-md-4">
|
||||
<h4>Voter's Information</h4><hr/>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item"><b>Student ID : </b>{{ data.user.student_id }}</li>
|
||||
<li class="list-group-item"><b>Name : </b>{{ data.user.name }}</li>
|
||||
<li class="list-group-item"><b>Course : </b>{{ data.user.course }}</li>
|
||||
<li class="list-group-item" v-if="data.election.status==1">
|
||||
<center>Election hasn't started yet</center>
|
||||
</li>
|
||||
<li class="list-group-item" v-if="data.election.status==2">
|
||||
<center>
|
||||
<router-link v-if="!hasVoted()" :to="{name: 'Vote'}" class="btn btn-info">
|
||||
Vote Now
|
||||
</router-link>
|
||||
<router-link v-else :to="{name: 'Result'}" class="btn btn-info">
|
||||
View Result
|
||||
</router-link>
|
||||
</center>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-if="hasVoted()">
|
||||
<hr/>
|
||||
<h4>Your votes information</h4><hr/>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item" v-for="result in data.result">
|
||||
<b>{{ getPosition(result.position_id) }} : </b>{{ getNominee(result.nominee_id) }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-8">
|
||||
<h4>Candidates Information</h4><hr/>
|
||||
<small>Click Picture to see details</small>
|
||||
<div class="panel panel-primary" v-for="position in data.positions">
|
||||
<div class="panel-heading">{{ position.name }}</div>
|
||||
<div class="panel-body table-responsive">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Name</th>
|
||||
<th>Partylist</th>
|
||||
<th>Course</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(nominee,i) in data.nominees" v-if="nominee.position_id==position.id">
|
||||
<td><img
|
||||
@click="view(i)"
|
||||
:src="data.storageURL+nominee.image"
|
||||
class="thumbnail"
|
||||
style="height: 60px;width: 60px;" />
|
||||
</td>
|
||||
<td>{{ nominee.name }}</td>
|
||||
<td>{{ getPartylist(nominee.partylist_id) }}</td>
|
||||
<td>{{ nominee.course }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<modal id="nominee-information-modal" aClass="primary">
|
||||
<modal-header>{{ header }}</modal-header>
|
||||
<modal-body>
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<img :src="data.storageURL+x.image" style="height: 150px; width: 150px" class="thumbnail"/>
|
||||
</div>
|
||||
<div class="col-md-9" style="margin-left: 5px;">
|
||||
<h3><strong><em>"{{ x.motto }}"</em></strong></h3>
|
||||
<b> Name : </b>{{ x.name }}<br/>
|
||||
<b> Course : </b>{{ x.course }}<br/>
|
||||
<b> Partylist : </b>{{ getPartylist(x.partylist_id) }}<br/><hr/>
|
||||
{{ x.description }}
|
||||
</div>
|
||||
</div>
|
||||
</modal-body>
|
||||
<modal-footer>
|
||||
<button data-dismiss="modal" class="btn btn-default">Close</button>
|
||||
</modal-footer>
|
||||
</modal>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default{
|
||||
created: function () {
|
||||
//console.log(this)
|
||||
},
|
||||
|
||||
data: function () {
|
||||
return {
|
||||
x: {}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
hasVoted: function () {
|
||||
return this.data.result.length > 0;
|
||||
},
|
||||
|
||||
getPartylist: function(id) {
|
||||
let partylists = this.data.partylists;
|
||||
for (var i in partylists)
|
||||
if (partylists[i]['id'] == id) return partylists[i]['name'];
|
||||
return 'No Partylist';
|
||||
},
|
||||
|
||||
getPosition: function (id) {
|
||||
let positions = this.data.positions;
|
||||
for (var i in positions)
|
||||
if (positions[i].id == id) return positions[i].name;
|
||||
return '';
|
||||
},
|
||||
|
||||
getNominee: function (id) {
|
||||
let nominees = this.data.nominees;
|
||||
for (var i in nominees)
|
||||
if (nominees[i]['id']==id) return nominees[i].name;
|
||||
return '';
|
||||
},
|
||||
|
||||
view: function (index) {
|
||||
this.x = this.data.nominees[index];
|
||||
this.util.showModal('#nominee-information-modal');
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
header: function () {
|
||||
return this.x.name+' for '+this.getPosition(this.x.position_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,168 @@
|
||||
<template>
|
||||
<div class="row col-md-10 col-md-offset-1">
|
||||
<div class="col-md-4">
|
||||
<h4>Positions</h4><hr/>
|
||||
<ul class="list-group">
|
||||
<router-link :key="position.id" v-for="position in data.positions" class="list-group-item" :class="{'active':position.id==position_id}" tag="li" :to="{query:{position_id:position.id}}" exact replace>
|
||||
{{ position.name }}
|
||||
</router-link>
|
||||
<li class="list-group-item">
|
||||
<center>
|
||||
<button class="btn btn-info" @click="refreshResults()">
|
||||
Refresh results <i class="fa fa-refresh"></i>
|
||||
</button>
|
||||
</center>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<h4>Results</h4><hr/>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">{{ getPosition(position_id) }} - Results as of : {{ last_update }}</div>
|
||||
<div class="panel-body">
|
||||
<div id="chart" style="height: 300px; width: 300px"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default{
|
||||
data: function () {
|
||||
return {
|
||||
results: [{
|
||||
"position_id": 6,
|
||||
"nominee_id": 1,
|
||||
"votes": 2
|
||||
}, {
|
||||
"position_id": 8,
|
||||
"nominee_id": 6,
|
||||
"votes": 2
|
||||
}, {
|
||||
"position_id": 7,
|
||||
"nominee_id": 5,
|
||||
"votes": 2
|
||||
}, {
|
||||
"position_id": 7,
|
||||
"nominee_id": 4,
|
||||
"votes": 1
|
||||
}, {
|
||||
"position_id": 6,
|
||||
"nominee_id": 2,
|
||||
"votes": 1
|
||||
}, {
|
||||
"position_id": 8,
|
||||
"nominee_id": 7,
|
||||
"votes": 1
|
||||
}]
|
||||
}
|
||||
},
|
||||
created: function () {
|
||||
this.refreshResults();
|
||||
this.$nextTick(function(){
|
||||
this.initChart();
|
||||
});
|
||||
},
|
||||
|
||||
watch: {
|
||||
position_id : function () {
|
||||
this.initChart();
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
refreshResults: function () {
|
||||
var vm = this;
|
||||
this.util.notify('Refreshing results', 'loading');
|
||||
axios.get(config.API+'election/result')
|
||||
.then(response=>{
|
||||
$.notifyClose();
|
||||
console.log(response)
|
||||
vm.data.results = response.data;
|
||||
vm.data.last_update= new Date();
|
||||
vm.initChart();
|
||||
})
|
||||
.catch(error=>{
|
||||
$.notifyClose();
|
||||
vm.util.showResult(error);
|
||||
})
|
||||
},
|
||||
|
||||
initChart: function () {
|
||||
$.plot($('#chart'), this.datas, {
|
||||
series: {
|
||||
pie: {
|
||||
show: true,
|
||||
innerRadius: 0.5
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
getPosition: function (id) {
|
||||
let positions = this.data.positions;
|
||||
for (var i in positions)
|
||||
if (id == positions[i]['id']) return positions[i]['name'];
|
||||
return '';
|
||||
},
|
||||
|
||||
getNominee: function (id) {
|
||||
let nominees = this.data.nominees;
|
||||
for (var i in nominees)
|
||||
if (id == nominees[i]['id']) return nominees[i]['name'];
|
||||
return '';
|
||||
},
|
||||
|
||||
getVotes: function (id) {
|
||||
let results = this.data.results;
|
||||
for (var i in results) {
|
||||
if (results[i]['nominee_id'] == id) return results[i]['votes'];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
last_update: function () {
|
||||
let x = this.data.last_update;
|
||||
return x.toDateString() +' '+x.toLocaleTimeString();
|
||||
},
|
||||
|
||||
position_id: function () {
|
||||
return this.$route.query.position_id ?
|
||||
this.$route.query.position_id :
|
||||
this.data.positions[0]['id'];
|
||||
},
|
||||
|
||||
datas: function () {
|
||||
//var results =
|
||||
var data = [];
|
||||
var nominees = this.data.nominees;
|
||||
for (var i in nominees) {
|
||||
if (nominees[i]['position_id']== this.position_id){
|
||||
let row = [];
|
||||
row['label'] = nominees[i]['name'];
|
||||
row['data'] = [[1, this.getVotes(nominees[i]['id'])]];
|
||||
data.push(row);
|
||||
}
|
||||
}
|
||||
/*let positions = this.data.positions;
|
||||
for (var i in positions) {
|
||||
if (positions[i]['id'] == this.position_id) {
|
||||
var row = [];
|
||||
row['label'] = this.getNominee()
|
||||
}
|
||||
}
|
||||
for (var i in results) {
|
||||
if (results[i]['position_id'] != this.position_id) continue;
|
||||
var row = [];
|
||||
row['label'] = this.getNominee(results[i]['nominee_id']);
|
||||
row['data'] = [[1, results[i]['votes']]];
|
||||
data.push(row);
|
||||
}*/
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,152 @@
|
||||
<template>
|
||||
<div class="row col-md-10 col-md-offset-1">
|
||||
<div class="col-md-4">
|
||||
<h4>Vote Information</h4><hr/>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item" v-for="position in data.positions">
|
||||
<b>{{ position.name }} : </b>{{ getName(position.id) }}
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<center>
|
||||
<button class="btn btn-success" @click="util.showModal('#vote-modal')">Submit Vote</button>
|
||||
<button class="btn btn-default" @click="reset()">Reset</button>
|
||||
</center>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<h4>Select Candidates</h4><hr/>
|
||||
<div class="panel panel-info" v-for="position in data.positions">
|
||||
<div class="panel-heading">{{ position.name }}</div>
|
||||
<div class="panel-body table-responsive">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Name</th>
|
||||
<th>Partylist</th>
|
||||
<th>Unit</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="nominee in data.nominees" v-if="nominee.position_id==position.id" @click="vote(position.id,nominee.id)">
|
||||
<td><input type="radio" :name="position.id" :id="nominee.id"/></td>
|
||||
<td>{{ nominee.name }}</td>
|
||||
<td>{{ getPartylist(nominee.partylist_id) }}</td>
|
||||
<td>{{ nominee.course }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<modal id="vote-modal">
|
||||
<modal-header>Vote</modal-header>
|
||||
<modal-body>
|
||||
<h3>Note: You can only vote once, so vote wisely.</h3>
|
||||
</modal-body>
|
||||
<modal-footer>
|
||||
<button class="btn btn-success" @click="submit()">Submit Vote</button>
|
||||
<button class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
</modal-footer>
|
||||
</modal>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default{
|
||||
created: function () {
|
||||
if (this.data.result.length > 0 || this.data.election.status != 2)
|
||||
this.$router.push({name: 'Voter Home'})
|
||||
for (var i in this.data.positions) {
|
||||
this.selected.push({
|
||||
position_id: this.data.positions[i]['id'],
|
||||
nominee_id: null,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
data: function () {
|
||||
return {
|
||||
selected: [],
|
||||
name: {}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
submit: function () {
|
||||
this.util.hideModal('#vote-modal');
|
||||
if (this.hasNullVote()) return;
|
||||
var vm = this;
|
||||
this.util.notify('Submitting your vote, please wait...', 'loading');
|
||||
let data = {};
|
||||
data['vote'] = this.selected;
|
||||
axios.post(config.API+'election/vote', data)
|
||||
.then(response=>{
|
||||
$.notifyClose();
|
||||
if (vm.util.showResult(response, 'success')){
|
||||
vm.data.result = response.data.result;
|
||||
vm.$router.push({name: 'Voter Home'});
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error=>{
|
||||
$.notifyClose();
|
||||
vm.util.showResult(error, 'error');
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
hasNullVote: function () {
|
||||
let selected = this.selected;
|
||||
for (var i in selected)
|
||||
if (selected[i]['nominee_id'] == null){
|
||||
this.util.notify('You must vote on all position', 'error');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
reset: function () {
|
||||
let selected = this.selected;
|
||||
for (var i in selected){
|
||||
$('#'+selected[i]['nominee_id']).selected(false);
|
||||
selected[i]['nominee_id'] = null;
|
||||
}
|
||||
},
|
||||
|
||||
vote: function (position_id, nominee_id) {
|
||||
$('#'+nominee_id).selected();
|
||||
for (var i in this.selected)
|
||||
if (this.selected[i]['position_id'] == position_id) {
|
||||
this.selected[i]['nominee_id'] = nominee_id;
|
||||
}
|
||||
},
|
||||
|
||||
getName: function (id) {
|
||||
let positions = this.data.positions;
|
||||
let selected = this.selected;
|
||||
for (var i in selected)
|
||||
if (selected[i]['position_id'] == id)
|
||||
return this.getNominee(selected[i]['nominee_id']);
|
||||
return '';
|
||||
},
|
||||
|
||||
getNominee: function (id) {
|
||||
let nominees = this.data.nominees;
|
||||
for (var i in nominees)
|
||||
if (nominees[i]['id'] == id) return nominees[i]['name'];
|
||||
},
|
||||
|
||||
getPartylist: function (id) {
|
||||
let partylists = this.data.partylists;
|
||||
for (var i in partylists)
|
||||
if (partylists[i]['id']==id) return partylists[i]['name'];
|
||||
return 'No Partylist';
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user