update
parent
f19ab0def1
commit
324a7f8768
|
|
@ -4,12 +4,38 @@ namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Models\Master\Instansi;
|
use App\Models\Master\Instansi;
|
||||||
|
use App\Models\Master\Template;
|
||||||
use App\Models\Dataset;
|
use App\Models\Dataset;
|
||||||
use App\Models\Dataset\DatasetTable45;
|
use App\Models\Dataset\DatasetTable45;
|
||||||
use App\Models\Dataset\DatasetTable47;
|
use App\Models\Dataset\DatasetTable47;
|
||||||
|
|
||||||
class AjaxController extends Controller
|
class AjaxController extends Controller
|
||||||
{
|
{
|
||||||
|
function getResourceData(Request $request){
|
||||||
|
$_data = [];
|
||||||
|
|
||||||
|
$keyId = decode_id($request->id);
|
||||||
|
$instansi = Instansi::find($keyId);
|
||||||
|
$resource = json_decode($instansi->resource_data);
|
||||||
|
|
||||||
|
$data = Template::whereIn('MsTemplateId',$resource)->count();
|
||||||
|
|
||||||
|
if(@$data != 0){
|
||||||
|
$data = Template::whereIn('MsTemplateId',$resource)->get();
|
||||||
|
}else{
|
||||||
|
$data = Template::all();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
$filename = pathinfo($value->template_url, PATHINFO_FILENAME);
|
||||||
|
|
||||||
|
$_data[$key]['id'] = encode_id($value->MsTemplateId);
|
||||||
|
$_data[$key]['name'] = $filename.' - '.$value->name;
|
||||||
|
$_data[$key]['excel'] = asset($value->template_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(['data' => $_data,'status' => true]);
|
||||||
|
}
|
||||||
function getInstansi($type){
|
function getInstansi($type){
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@
|
||||||
<?php
|
<?php
|
||||||
$filename = pathinfo($dataTemplate->template_url, PATHINFO_FILENAME);
|
$filename = pathinfo($dataTemplate->template_url, PATHINFO_FILENAME);
|
||||||
?>
|
?>
|
||||||
<option {{ in_array(encode_id($dataTemplate->MsTemplateId), $selectedResources) ? 'selected' : '' }} value="{{encode_id($dataTemplate->MsTemplateId)}}">{{$filename}} - {{$dataTemplate->name}}</option>
|
<option {{ in_array($dataTemplate->MsTemplateId, $selectedResources) ? 'selected' : '' }} value="{{$dataTemplate->MsTemplateId}}">{{$filename}} - {{$dataTemplate->name}}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
@error('resource_data')
|
@error('resource_data')
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
<div class="grid lg:grid-cols-1 gap-3">
|
<div class="grid lg:grid-cols-1 gap-3">
|
||||||
<div class="">
|
<div class="">
|
||||||
<label class="mb-3 required">Instansi</label>
|
<label class="mb-3 required">Instansi</label>
|
||||||
<select name="instansi_id" required class="form-input instansi_id select2 @error('instansi_id') is-invalid @enderror" id="">
|
<select name="instansi_id" required class="form-input instansi_id select2 @error('instansi_id') is-invalid @enderror" id="instansi_id">
|
||||||
<option value="">-</option>
|
<option value="">-</option>
|
||||||
@foreach($instansi as $dataInstansi)
|
@foreach($instansi as $dataInstansi)
|
||||||
<option {{@$item->instansi_id == $dataInstansi->MsInstansiId ? 'selected' : ''}} value="{{encode_id($dataInstansi->MsInstansiId)}}">{{$dataInstansi->name}}</option>
|
<option {{@$item->instansi_id == $dataInstansi->MsInstansiId ? 'selected' : ''}} value="{{encode_id($dataInstansi->MsInstansiId)}}">{{$dataInstansi->name}}</option>
|
||||||
|
|
@ -31,14 +31,14 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="">
|
<div class="">
|
||||||
<label class="mb-3 required">Resource Data</label>
|
<label class="mb-3 required">Resource Data</label>
|
||||||
<select name="template_id" required class="form-input template_id select2 @error('template_id') is-invalid @enderror" id="">
|
<select name="template_id" required class="form-input template_id select2 @error('template_id') is-invalid @enderror" id="template_id">
|
||||||
<option value="">-</option>
|
{{-- <option value="">-</option> --}}
|
||||||
@foreach($template as $dataTemplate)
|
{{-- @foreach($template as $dataTemplate)
|
||||||
<?php
|
<?php
|
||||||
$filename = pathinfo($dataTemplate->template_url, PATHINFO_FILENAME);
|
// $filename = pathinfo($dataTemplate->template_url, PATHINFO_FILENAME);
|
||||||
?>
|
?>
|
||||||
<option {{@$item->template_id == $dataTemplate->MsTemplateId ? 'selected' : ''}} data-template="{{asset($dataTemplate->template_url)}}" value="{{encode_id($dataTemplate->MsTemplateId)}}">{{ $filename }} - {{$dataTemplate->name}}</option>
|
<option {{@$item->template_id == $dataTemplate->MsTemplateId ? 'selected' : ''}} data-template="{{asset($dataTemplate->template_url)}}" value="{{encode_id($dataTemplate->MsTemplateId)}}">{{ $filename }} - {{$dataTemplate->name}}</option>
|
||||||
@endforeach
|
@endforeach --}}
|
||||||
</select>
|
</select>
|
||||||
@error('template_id')
|
@error('template_id')
|
||||||
<span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
|
<span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
|
||||||
|
|
@ -99,6 +99,74 @@
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
@section('js')
|
@section('js')
|
||||||
|
<script>
|
||||||
|
function clear(elementId) {
|
||||||
|
$('#' + elementId).empty();
|
||||||
|
$('#' + elementId).select2();
|
||||||
|
}
|
||||||
|
$('select').on("select2:selecting", function(e) {
|
||||||
|
var selectorOrigin = this.id;
|
||||||
|
var id = e.params.args.data.id;
|
||||||
|
|
||||||
|
|
||||||
|
if(selectorOrigin=='instansi_id'){
|
||||||
|
$('#loading-spinner').show();
|
||||||
|
clear('template_id');
|
||||||
|
selector = 'template_id';
|
||||||
|
url_to = 'getResourceData';
|
||||||
|
getSelect(id, selector, url_to);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function getSelect(id, selectTo, urlTo, selected = "") {
|
||||||
|
id = id;
|
||||||
|
var base_url = "{{url('/')}}";
|
||||||
|
//alert(id);
|
||||||
|
destino = "#" + selectTo;
|
||||||
|
console.log(id);
|
||||||
|
valor = $('#' + id).find(":selected").val();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "GET",
|
||||||
|
url: base_url + '/' + urlTo,
|
||||||
|
data: {
|
||||||
|
id: id
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.done(function(msg) {
|
||||||
|
obj = msg.data;
|
||||||
|
|
||||||
|
if (obj.length > 0) {
|
||||||
|
//Clear the current options
|
||||||
|
$(destino).empty();
|
||||||
|
|
||||||
|
if(selectTo=='template_id'){
|
||||||
|
$(destino).append('<option value="">-PILIH RESOURCE DATA-</option>').select2("val", "0");
|
||||||
|
|
||||||
|
$.each(obj, function(index) {
|
||||||
|
value = obj[index].id;
|
||||||
|
text = obj[index].name;
|
||||||
|
excel = obj[index].excel;
|
||||||
|
$(destino).append('<option data-template="'+excel+'" value=' + value + '>' + text + '</option>');
|
||||||
|
});
|
||||||
|
console.log(selected)
|
||||||
|
if (selected) {
|
||||||
|
$(destino).val(selected).trigger('change');
|
||||||
|
selected = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if(selectTo=='template_id'){
|
||||||
|
$(destino).empty().append('<option value="0">-PILIH RESOURCE DATA-</option>').select2("val", "0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$('#loading-spinner').hide();
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
const input = document.getElementById('tag-input');
|
const input = document.getElementById('tag-input');
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ use App\Http\Controllers\AjaxController;
|
||||||
|
|
||||||
Route::get('getPenduduk/{tahun}',[AjaxController::class,'getPenduduk'])->name('getPenduduk');
|
Route::get('getPenduduk/{tahun}',[AjaxController::class,'getPenduduk'])->name('getPenduduk');
|
||||||
Route::get('getTimbulan/{tahun}',[AjaxController::class,'getTimbulan'])->name('getTimbulan');
|
Route::get('getTimbulan/{tahun}',[AjaxController::class,'getTimbulan'])->name('getTimbulan');
|
||||||
|
Route::get('getResourceData',[AjaxController::class,'getResourceData'])->name('getResourceData');
|
||||||
|
|
||||||
Route::name('dashboard.')->prefix('dashboard')->group(function () {
|
Route::name('dashboard.')->prefix('dashboard')->group(function () {
|
||||||
Route::get('/',[HomeController::class,'dashboard'])->name('dashboard');
|
Route::get('/',[HomeController::class,'dashboard'])->name('dashboard');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue