Commit 3124c62f by Farendi Giotivano R.P

buku ajar, dashboard, update

parent 5009c008
......@@ -3,20 +3,35 @@
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\Biodata;
use App\Models\User\BukuAjar;
use App\Repositories\User\BukuAjarRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Alert;
use Exception;
use Crypt;
use Validator;
class BukuAjarController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
private $bukuajarRepo;
public function __construct(BukuAjarRepository $bukuajarRepo)
{
$this->bukuajarRepo = $bukuajarRepo;
}
public function index()
{
//
$data = 'Buku Ajar';
return view('user.bukuajar.index');
$menu = 'bukuajar';
$bukuajar = $this->bukuajarRepo->get(['rDosen']);
$data = [
'bukuajar' => $bukuajar,
'menu' => $menu
];
return view('user.bukuajar.index', $data);
}
/**
......@@ -27,7 +42,14 @@ class BukuAjarController extends Controller
public function create()
{
//
return view('user.bukuajar.create');
$menu = 'bukuajar';
$edit = false;
$data = [
'menu' => $menu,
'edit' => $edit
];
return view('user.bukuajar.create', $data);
}
/**
......@@ -39,6 +61,24 @@ class BukuAjarController extends Controller
public function store(Request $request)
{
//
$data = $request->except('_token');
Validator::make($data, BukuAjar::RULES, BukuAjar::ERROR_MESSAGES)->validate();
try {
$biodata = Biodata::query()->where('nidn', $request->nidn)->firstOrFail();
$data['userid_created'] = Auth::user()->id;
$data['userid_updated'] = Auth::user()->id;
//dd($data);
$bukuajar = $this->bukuajarRepo->store($data);
} catch (Exception $ex) {
return redirect()->back()->withInput();
}
$data = [
'bukuajar' => $bukuajar->id,
];
return redirect()->route('bukuajar.index', $data);
}
/**
......@@ -61,6 +101,24 @@ class BukuAjarController extends Controller
public function edit($id)
{
//
$menu = 'unitbisnis';
$edit = true;
try {
$menu = 'unitbisnis';
$bukuajar = $this->bukuajarRepo->findId(null, $id);
$data = [
'menu' => $menu,
'edit' => $edit,
'bukuajar' => $bukuajar,
];
return view('user.bukuajar.create', $data);
} catch (Exception $ex) {
return redirect()->back();
}
}
/**
......@@ -73,6 +131,25 @@ class BukuAjarController extends Controller
public function update(Request $request, $id)
{
//
$data = $request->except('_token');
Validator::make($data, BukuAjar::RULES, BukuAjar::ERROR_MESSAGES)->validate();
try {
$biodata = Biodata::query()->where('nidn', $request->nidn)->firstOrFail();
$data['userid_updated'] = auth()->user()->id;
$bukuajar = $this->bukuajarRepo->findId(null, decrypt($id));
//dd($bukuajar);
$this->bukuajarRepo->update($data, $bukuajar);
} catch (Exception $ex) {
return redirect()->back()->withInput();
}
$data = [
'bukuajar' => $bukuajar->id,
];
return redirect()->route('bukuajar.index', $data);
}
/**
......@@ -84,5 +161,11 @@ class BukuAjarController extends Controller
public function destroy($id)
{
//
$model = $this->bukuajarRepo->findId(null, Crypt::decrypt($id));
$this->bukuajarRepo->destroy($model);
Alert::success('Data berhasil dihapus')->persistent('Ok');
return redirect()->route('bukuajar.index');
}
}
<?php
namespace App\Models\User;
use App\Models\Biodata;
use App\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Model;
class BukuAjar extends Model
{
use UuidTrait;
public $incrementing = false;
protected $table = 'bukuajar';
protected $keyType = 'string';
protected $fillable = [
'id', 'nidn', 'kategori', 'judul', 'isbn', 'jumlah_hal', 'penerbit', 'url', 'userid_created', 'userid_updated', 'created_at', 'updated_at',
];
public const RULES = [
'kategori' => 'required',
'judul' => 'required',
'isbn' => 'required',
'jumlah_hal' => 'required',
'penerbit' => 'required',
'url' => 'required',
];
public const ERROR_MESSAGES = [
'kategori' => 'Kategori tidak boleh kosong',
'judul' => 'Judul tidak boleh kosong',
'isbn' => 'ISBN tidak boleh kosong',
'jumlah_hal' => 'Jumlah Halaman tidak boleh kosong',
'penerbit' => 'Penerbit tidak boleh kosong',
'url' => 'URL tidak boleh kosong',
];
public function rDosen()
{
return $this->belongsTo(Biodata::class, 'nidn', 'nidn');
}
}
<?php
namespace App\Repositories\User;
use App\Models\User\BukuAjar;
use App\Repositories\Repository;
class BukuAjarRepository extends Repository
{
protected $model;
public function __construct(BukuAjar $model)
{
$this->model = $model;
}
public function get($with = null, $search = null, $id = null)
{
return $this->model->when($with, function ($query) use ($with) {
return $query->with($with);
})
->when($search, function ($query) use ($search) {
return $query->where('search', $search);
})
->when($id, function ($query) use ($id) {
return $query->where('id', $id);
})
->get();
}
}
......@@ -32,3 +32,5 @@
<link href="{{ url('theme/plugins/noUiSlider/custom-nouiSlider.css') }}" rel="stylesheet" type="text/css">
<link href="{{ url('theme/plugins/bootstrap-range-Slider/bootstrap-slider.css') }}" rel="stylesheet" type="text/css">
<link href="{{ url('theme/assets/css/components/custom-carousel.css') }}" rel="stylesheet" type="text/css" />
......@@ -50,7 +50,10 @@
<a class="" href="user_profile.html"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg> My Profile</a>
</div>
<div class="dropdown-item">
<a class="" href="auth_login.html"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-log-out"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path><polyline points="16 17 21 12 16 7"></polyline><line x1="21" y1="12" x2="9" y2="12"></line></svg> Sign Out</a>
<a href="{{ route('logout') }}" onclick="event.preventDefault();document.getElementById('logout-form').submit();" ><i data-feather="log-out"></i>Logout</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
@csrf
</form>
</div>
</div>
</div>
......
......@@ -18,130 +18,36 @@
<div class="col-xl-12 col-lg-12 col-sm-12 layout-spacing">
<div class="widget-content widget-content-area br-6">
<div class="table-responsive mb-4 mt-4">
<a href="{{ url('bukuajar/create') }}" class="btn btn-primary mb-2"><i data-feather="file-plus"></i> Tambah</a>
<table id="zero-config" class="table table-hover" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
<th>No</th>
<th>Judul</th>
<th>Kategori</th>
<th>Penerbit</th>
<th>Nama Dosen</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
@php $no = 1; @endphp
@foreach($bukuajar as $value)
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>$170,750</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$86,000</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>Edinburgh</td>
<td>22</td>
<td>2012/03/29</td>
<td>$433,060</td>
</tr>
<tr>
<td>Airi Satou</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>33</td>
<td>2008/11/28</td>
<td>$162,700</td>
</tr>
<tr>
<td>Brielle Williamson</td>
<td>Integration Specialist</td>
<td>New York</td>
<td>61</td>
<td>2012/12/02</td>
<td>$372,000</td>
</tr>
<tr>
<td>Herrod Chandler</td>
<td>Sales Assistant</td>
<td>San Francisco</td>
<td>59</td>
<td>2012/08/06</td>
<td>$137,500</td>
</tr>
<tr>
<td>Rhona Davidson</td>
<td>Integration Specialist</td>
<td>Tokyo</td>
<td>55</td>
<td>2010/10/14</td>
<td>$327,900</td>
</tr>
<tr>
<td>Colleen Hurst</td>
<td>Javascript Developer</td>
<td>San Francisco</td>
<td>39</td>
<td>2009/09/15</td>
<td>$205,500</td>
</tr>
<tr>
<td>Sonya Frost</td>
<td>Software Engineer</td>
<td>Edinburgh</td>
<td>23</td>
<td>2008/12/13</td>
<td>$103,600</td>
</tr>
<tr>
<td>Jena Gaines</td>
<td>Office Manager</td>
<td>London</td>
<td>30</td>
<td>2008/12/19</td>
<td>$90,560</td>
</tr>
<tr>
<td>Quinn Flynn</td>
<td>Support Lead</td>
<td>Edinburgh</td>
<td>22</td>
<td>2013/03/03</td>
<td>$342,000</td>
</tr>
<tr>
<td>Charde Marshall</td>
<td>Regional Director</td>
<td>San Francisco</td>
<td>36</td>
<td>2008/10/16</td>
<td>$470,600</td>
</tr>
<tr>
<td>Haley Kennedy</td>
<td>Senior Marketing Designer</td>
<td>London</td>
<td>43</td>
<td>2012/12/18</td>
<td>$313,500</td>
<td>{{$no++}}</td>
<td>Judul : {{$value->judul}}<br>ISBN : {{$value->isbn}}<br>Jumlah Halaman : {{$value->jumlah_hal}}</td>
<td>{{$value->kategori}}</td>
<td>{{$value->penerbit}}</td>
<td>{{$value->rDosen->name}}</td>
<td>
<a href="{{ url('bukuajar/'.$value->id.'/edit') }}" class="btn btn-warning mb-2"><i data-feather="edit"></i> Edit</a> |
<button class="btn btn-danger mb-2 delete" data-id="{{ $value->id }}" data-file="{{$value->id}}"><i data-feather="trash-2"></i> Delete</button>
{{ Form::open(['url'=>route('bukuajar.destroy', [Crypt::encrypt($value->id)]), 'method'=>'delete', 'id' => $value->id, 'style' => 'display: none;']) }}
{{ csrf_field() }}
{{ Form::close() }}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
......@@ -167,5 +73,29 @@
"lengthMenu": [10, 20, 50],
"pageLength": 10
});
var url = "{{ route('bukuajar.index') }}";
$("body").on("click", ".delete", function (e) {
e.preventDefault();
var id = $(this).data('id');
Swal.fire({
title: "Apakah Anda Yakin?",
text: "Anda akan menghapus data ini!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No"
}).then((result) => {
if (result.value) {
Swal.close();
$("#"+id).submit();
} else if (result.dismiss === Swal.DismissReason.cancel) {
Swal.fire('Dibatalkan', 'Data batal dihapus', 'error');
}
});
});
</script>
@endsection
......@@ -46,22 +46,15 @@ Route::middleware(['auth:sanctum', 'verified'])->group(function () {
Route::resource('/fasilitas', FasilitasController::class);
Route::resource('/kekayaanintelek', KekayaanIntelController::class);
Route::resource('/kontrakkerja', KontrakKerjaController::class);
Route::resource('/penelitiansumber', PenelitianSumberDanaController::class);
Route::get('/penelitiansumber/next-form/{id}', [PenelitianSumberDanaController::class, 'nextForm'])->name('penelitiansumber.next-form');
Route::get('/penelitiansumber/edit-anggota/{id}', [PenelitianSumberDanaController::class, 'editAnggota'])->name('penelitiansumber.edit-anggota');
Route::post('/penelitiansumber/simpan-anggota/{id}', [PenelitianSumberDanaController::class, 'simpanAnggota'])->name('penelitiansumber.simpan-anggota');
Route::post('/penelitiansumber/delete-anggota', [PenelitianSumberDanaController::class, 'deleteAnggota'])->name('penelitiansumber.delete-anggota');
Route::post('/penelitiansumber/cek-simpan-anggota', [PenelitianSumberDanaController::class, 'cekSimpanAnggota'])->name('penelitiansumber.cek-simpan-anggota');
Route::resource('/penelitiasing', PenelitiAsingController::class);
Route::resource('/publikasiartikel', PublikasiArtikelController::class);
Route::resource('/publikasijurnal', PublikasiJurnalController::class);
Route::get('/publikasijurnal/next-form/{id}', [PublikasiJurnalController::class, 'nextForm'])->name('publikasijurnal.next-form');
Route::get('/publikasijurnal/edit-anggota/{id}', [PublikasiJurnalController::class, 'editAnggota'])->name('publikasijurnal.edit-anggota');
Route::post('/publikasijurnal/simpan-anggota/{id}', [PublikasiJurnalController::class, 'simpanAnggota'])->name('publikasijurnal.simpan-anggota');
Route::post('/publikasijurnal/delete-anggota', [PublikasiJurnalController::class, 'deleteAnggota'])->name('publikasijurnal.delete-anggota');
Route::resource('/penyelenggaraseminar', PenyelenggaraanSeminarController::class);
Route::resource('/stafpendukung', StafPendukungController::class);
Route::resource('/unitbisnis', UnitBisnisController::class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment