kehadiran pengundi
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API\v1\Voter;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Util;
|
||||
use App\Voter;
|
||||
|
||||
class AttendanceController extends Controller
|
||||
{
|
||||
//
|
||||
public function __invoke(Request $request, $id)
|
||||
{
|
||||
$this->validateRequest($request, $id);
|
||||
$this->updateAttendance($request, $id);
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Kehadiran anda telah disahkan.'
|
||||
]);
|
||||
}
|
||||
|
||||
private function validateRequest($request, $id)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'name' => [
|
||||
'required',
|
||||
Rule::unique('voter')->ignore($id)->where(function($query){
|
||||
$query->where('election_id', Util::getCurrentElection());
|
||||
})
|
||||
],
|
||||
'no_kp' => [
|
||||
'required',
|
||||
Rule::unique('voter')->ignore($id)->where(function($query){
|
||||
$query->where('election_id', Util::getCurrentElection());
|
||||
})
|
||||
],
|
||||
|
||||
'unit' => 'required',
|
||||
|
||||
'no_anggota' => [
|
||||
'required',
|
||||
Rule::unique('voter')->ignore($id)->where(function($query){
|
||||
$query->where('election_id', Util::getCurrentElection());
|
||||
})
|
||||
],
|
||||
|
||||
'kehadiran' => 'required'
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
private function updateAttendance($request, $id)
|
||||
{
|
||||
$voter = $request->all();
|
||||
Voter::find($id)->update($voter);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -10,5 +10,5 @@ class Voter extends Authenticatable
|
||||
use HasApiTokens;
|
||||
|
||||
protected $table = 'voter';
|
||||
protected $fillable = ['name', 'no_kp', 'no_anggota','unit', 'election_id', 'alamat', 'telefon', 'saham', 'yuran'];
|
||||
protected $fillable = ['name', 'no_kp', 'no_anggota','unit', 'election_id', 'alamat', 'telefon', 'saham', 'yuran', 'kehadiran'];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddKehadiranToVoterTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('voter', function (Blueprint $table) {
|
||||
//
|
||||
$table->integer('kehadiran');
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('voter', function (Blueprint $table) {
|
||||
//
|
||||
$table->dropColumn('kehadiran');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,9 @@
|
||||
<a href="#">Jawatan</a>
|
||||
</router-link>
|
||||
|
||||
<router-link :to="{name: 'Manage Partylist'}" v-if="data.user.role==1" tag="li">
|
||||
<!-- <router-link :to="{name: 'Manage Partylist'}" v-if="data.user.role==1" tag="li">
|
||||
<a href="#">Manage Partylist</a>
|
||||
</router-link>
|
||||
</router-link> -->
|
||||
|
||||
<router-link :to="{name: 'Manage Voter'}" v-if="data.user.role==1" tag="li">
|
||||
<a href="#">Anggota Koperasi</a>
|
||||
@@ -32,6 +32,10 @@
|
||||
<a href="#">Calon</a>
|
||||
</router-link>
|
||||
|
||||
<router-link :to="{name: 'Kehadiran Calon'}" v-if="data.user.role==1" tag="li">
|
||||
<a href="#">Kehadiran</a>
|
||||
</router-link>
|
||||
|
||||
</ul>
|
||||
<ul class="nav navbar-right navbar-nav">
|
||||
<li class="dropdown">
|
||||
|
||||
@@ -3,134 +3,84 @@
|
||||
<div class="col-md-12">
|
||||
<h3 class="text-center">Pendaftaran Kehadiran</h3>
|
||||
<hr />
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item"><b>No. Kad Pengenalan : </b>{{ data.user.no_kp }}</li>
|
||||
<li class="list-group-item"><b>No. Anggota : </b>{{ data.user.no_anggota }}</li>
|
||||
<li class="list-group-item"><b>Nama : </b>{{ data.user.name }}</li>
|
||||
<li class="list-group-item"><b>Unit : </b>{{ data.user.unit }}</li>
|
||||
<li class="list-group-item" v-if="data.election.status == 1">
|
||||
<center><router-link :to="{ name: 'Maklumat Calon', query: { position_id: position_id } }"
|
||||
class="btn btn-primary">
|
||||
SAYA TERIMA
|
||||
</router-link></center>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
<div v-if="hasVoted()">
|
||||
<hr />
|
||||
<h4>Maklumat Undian</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>Maklumat Calon</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>Unit</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.unit }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<form @submit.prevent="edit()" id="edit_form">
|
||||
<div class="form-group">
|
||||
<label for="name">Nama : </label>
|
||||
<input type="text" name="name" class="form-control" readonly :value="data.user.name" required />
|
||||
</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> Unit : </b>{{ x.unit }}<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 class="form-group">
|
||||
<label for="no_kp">No. Kad Pengenalan :</label>
|
||||
<input type="text" name="no_kp" class="form-control" readonly :value="data.user.no_kp" required />
|
||||
</div>
|
||||
|
||||
</div> -->
|
||||
<div class="form-group">
|
||||
<label for="no_anggota">No. Anggota : </label>
|
||||
<input type="text" name="no_anggota" class="form-control" readonly :value="data.user.no_anggota" required />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="no_anggota">Unit : </label>
|
||||
<input type="text" name="unit" class="form-control" readonly :value="data.user.unit" required />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="role">Kehadiran :</label>
|
||||
<select class="form-control" id="kehadiran" name="kehadiran" value="" required>
|
||||
<option value="1">Fizikal</option>
|
||||
<option value="2">Maya</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p> <i>*Elaun akan diberikan setelah pengundi membuat pengesahan kehadiran</i></p>
|
||||
<p> <i>*Pendaftaran online sehingga jam 10 pagi</i></p>
|
||||
</div>
|
||||
|
||||
<center><input type="submit" value="SAYA TERIMA" class="btn btn-primary" v-if="data.election.status==1"/></center>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
export default {
|
||||
created: function () {
|
||||
//console.log(this)
|
||||
},
|
||||
|
||||
data: function () {
|
||||
return {
|
||||
x: {}
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
hasVoted: function () {
|
||||
return this.data.result.length > 0;
|
||||
},
|
||||
// refreshUser: function () {
|
||||
// var vm = this;
|
||||
// axios.get(config.API + 'voter/' + this.data.user.id)
|
||||
// .then(response => {
|
||||
// vm.data.user = response.data;
|
||||
// })
|
||||
// },
|
||||
|
||||
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);
|
||||
edit: function () {
|
||||
if (this.loading) return;
|
||||
this.loading = true;
|
||||
var vm = this;
|
||||
this.util.notify('Adding Attendance', 'loading');
|
||||
axios.put(config.API + 'attendance/' + this.data.user.id, $('#edit_form').serialize())
|
||||
.then(response => {
|
||||
$.notifyClose();
|
||||
vm.loading = false;
|
||||
if (vm.util.showResult(response, 'success')) {
|
||||
vm.refreshUser();
|
||||
vm.$router.push({ name: 'Voter Home' });
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
$.notifyClose();
|
||||
vm.loading = false;
|
||||
vm.util.showResult(error, 'error')
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -29,6 +29,11 @@ Route::prefix('v1')->group(function(){ //Version 1 of my Rest API
|
||||
Route::get('election/information', 'API\v1\Election\InformationController');
|
||||
Route::post('election/vote', 'API\v1\Election\VoteController')->middleware('isvoted');
|
||||
Route::get('election/result', 'API\v1\Election\ResultController')->middleware('has_voted');
|
||||
|
||||
});
|
||||
|
||||
Route::prefix('attendance')->group(function(){
|
||||
Route::put('{id}', 'API\v1\Voter\AttendanceController');
|
||||
});
|
||||
|
||||
//Admins API
|
||||
@@ -80,7 +85,7 @@ Route::prefix('v1')->group(function(){ //Version 1 of my Rest API
|
||||
Route::post('', 'API\v1\Voter\AddController');
|
||||
Route::get('', 'API\v1\Voter\GetController');
|
||||
Route::delete('{id}', 'API\v1\Voter\DeleteController');
|
||||
Route::put('{id}', 'API\v1\Voter\UpdateController');
|
||||
Route::put('{id}', 'API\v1\Voter\UpdateController');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user