Commit 935276dc by Farendi Giotivano R.P

ganti kelompok

parent 63fa1098
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api; namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Controllers\GetDataApiController;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class DosenController extends Controller class DosenController extends Controller
...@@ -16,30 +17,37 @@ class DosenController extends Controller ...@@ -16,30 +17,37 @@ class DosenController extends Controller
$total_count = 0; $total_count = 0;
$incomplete_results = true; $incomplete_results = true;
$items = array(); $items = [];
if (empty($getDosen)) {
if ($getDosen->isEmpty()) {
$items = array(); $items = array();
} else { } else {
$no = 0; $no = 0;
foreach ($getDosen as $item) { foreach ($getDosen['data'] as $key => $item) {
$items[$item->id]['nm_sdm'] = $item->nm_sdm;
$items[$item->id]['nm_sdm'] = $item->prodi; if(str_contains(strtolower($item['nm_sdm']), strtolower($keyword))){
$items[$item->id]['nm_sdm'] = $item->nidn; $itemData = [
'id' => encrypt($item['id_sdm'].'_'.$item['nm_sdm'].'_'.$item['nidn']),
'full_name' => $item['nm_sdm'],
'description' => $item['prodi'],
'nidn' => $item['nidn'],
];
$items[] = $itemData;
$total_count = $total_count + 1; $total_count = $total_count + 1;
} }
} }
}
$data = [ $data = [
'total_count' => $total_count, 'total_count' => $total_count,
'incomplete_results' => false,
'items' => $items, 'items' => $items,
]; ];
//dd($data); //dd($data);
return response()->json($data); return response($data, 200);
} }
} }
...@@ -71,6 +71,7 @@ class KelompokController extends Controller ...@@ -71,6 +71,7 @@ class KelompokController extends Controller
$getDosen = GetDataApiController::getDosen(); $getDosen = GetDataApiController::getDosen();
$periode = Periode::query()->where('status', 1)->first(); $periode = Periode::query()->where('status', 1)->first();
$data = [ $data = [
'title' => $title, 'title' => $title,
'dosen' => $getDosen['data'], 'dosen' => $getDosen['data'],
...@@ -140,7 +141,7 @@ class KelompokController extends Controller ...@@ -140,7 +141,7 @@ class KelompokController extends Controller
'created_user' => Auth::user()->id 'created_user' => Auth::user()->id
]); ]);
return redirect()->intended(route('mahasiswa.kelompok.createnew', ['id' => encrypt($kel->kelompok_id)]))->with('success', 'Berhasil membuat elompok!'); return redirect()->intended(route('mahasiswa.kelompok.createnew', ['id' => encrypt($kel->kelompok_id)]))->with('success', 'Berhasil membuat Kelompok!');
} }
/** /**
......
...@@ -36,11 +36,8 @@ ...@@ -36,11 +36,8 @@
<label class="col-sm-2 col-form-label">Dosen Pembimbing</label> <label class="col-sm-2 col-form-label">Dosen Pembimbing</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="hidden" name="periode" value="{{ $periode['periode_id'] }}" > <input type="hidden" name="periode" value="{{ $periode['periode_id'] }}" >
<select class="form-select select2" name="dosen"> <select class="form-select" id="selectDosen" name="dosen">
<option selected>Pilih Dosen</option>
@foreach($dosen as $item)
<option value="{{ encrypt($item['id_sdm'].'_'.$item['nm_sdm'].'_'.$item['nidn']) }}">{{ $item['nm_sdm'].' - '.$item['prodi']}}</option>
@endforeach
</select> </select>
</div> </div>
</div> </div>
...@@ -65,7 +62,64 @@ ...@@ -65,7 +62,64 @@
@section('js') @section('js')
<script> <script>
$(document).ready(function() { $(document).ready(function() {
$(".select2").select2();
$("#selectDosen").select2({
ajax: {
url: "{{ route('api.getDosen') }}",
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, params) {
// parse the results into the format expected by Select2
// since we are using custom formatting functions we do not need to
// alter the remote JSON data, except to indicate that infinite
// scrolling can be used
params.page = params.page || 1;
return {
results: data.items,
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: true
},
placeholder: 'Pilih Dosen Pembimbing',
minimumInputLength: 1,
templateResult: formatRepo,
templateSelection: formatRepoSelection
}); });
});
function formatRepo (repo) {
if (repo.loading) {
return repo.text;
}
var $container = $(
"<div class='select2-result-repository clearfix'>" +
"<div class='select2-result-repository__meta'>" +
"<div class='select2-result-repository__title'></div>" +
"<div class='select2-result-repository__description'></div>" +
"</div>" +
"</div>"
);
$container.find(".select2-result-repository__title").text(repo.full_name);
$container.find(".select2-result-repository__description").text(repo.description);
return $container;
}
function formatRepoSelection (repo) {
return repo.full_name || repo.text;
}
</script> </script>
@endsection @endsection
...@@ -248,39 +248,5 @@ ...@@ -248,39 +248,5 @@
} }
function formatRepo (repo) {
if (repo.loading) {
return repo.text;
}
var $container = $(
"<div class='select2-result-repository clearfix'>" +
"<div class='select2-result-repository__avatar'><img src='" + repo.owner.avatar_url + "' /></div>" +
"<div class='select2-result-repository__meta'>" +
"<div class='select2-result-repository__title'></div>" +
"<div class='select2-result-repository__description'></div>" +
"<div class='select2-result-repository__statistics'>" +
"<div class='select2-result-repository__forks'><i class='fa fa-flash'></i> </div>" +
"<div class='select2-result-repository__stargazers'><i class='fa fa-star'></i> </div>" +
"<div class='select2-result-repository__watchers'><i class='fa fa-eye'></i> </div>" +
"</div>" +
"</div>" +
"</div>"
);
$container.find(".select2-result-repository__title").text(repo.full_name);
$container.find(".select2-result-repository__description").text(repo.description);
$container.find(".select2-result-repository__forks").append(repo.forks_count + " Forks");
$container.find(".select2-result-repository__stargazers").append(repo.stargazers_count + " Stars");
$container.find(".select2-result-repository__watchers").append(repo.watchers_count + " Watchers");
return $container;
}
function formatRepoSelection (repo) {
return repo.full_name || repo.text;
}
</script> </script>
@endsection @endsection
<?php <?php
use App\Http\Controllers\Api\DosenController;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
...@@ -17,3 +18,7 @@ use Illuminate\Support\Facades\Route; ...@@ -17,3 +18,7 @@ use Illuminate\Support\Facades\Route;
Route::middleware('auth:sanctum')->get('/user', function (Request $request) { Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user(); return $request->user();
}); });
Route::group(['namespace' => 'Api'], function () {
Route::get('getDosen', [DosenController::class, 'getDosen'])->name('api.getDosen');
});
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