141 lines
5.3 KiB
PHP
141 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Dataset;
|
|
use App\Models\Master\Topik;
|
|
use App\Models\Master\Template;
|
|
use App\Models\Master\Group;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
protected $template = 'modules.dashboard';
|
|
protected $route = 'modules.dashboard';
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
/**
|
|
* Show the application dashboard.
|
|
*
|
|
* @return \Illuminate\Contracts\Support\Renderable
|
|
*/
|
|
public function dashboard()
|
|
{
|
|
$data['title'] = 'Dashboard';
|
|
$data['dataset'] = Dataset::orderBy('DatasetId','DESC')->limit(10)->get();
|
|
$data['group'] = Group::where('MsGroupId','!=',1)->get();
|
|
$data['classDataset'] = Dataset::class;
|
|
|
|
return view($this->template.'.dashboard',$data);
|
|
}
|
|
|
|
public function dataset($alias)
|
|
{
|
|
$data['title'] = 'Dashboard';
|
|
$data['dataset'] = Dataset::orderBy('DatasetId','DESC')->limit(10)->get();
|
|
$data['group'] = Group::where('MsGroupId','!=',1)->get();
|
|
$data['alias'] = $alias;
|
|
|
|
return view($this->template.'.dataset',$data);
|
|
}
|
|
|
|
public function grid(Request $request)
|
|
{
|
|
if(session('group_id') == 1){
|
|
$data = Dataset::orderBy('DatasetId','DESC')->limit(10)->get();
|
|
}else{
|
|
$data = Dataset::orderBy('DatasetId','DESC')->limit(10)->whereIn('created_by',[auth()->user()->id,1])->get();
|
|
}
|
|
// $data = User::with(['group'])->orderBy('id','DESC')->get();
|
|
$_data = [];
|
|
|
|
foreach ($data as $key => $row) {
|
|
|
|
$action = '';
|
|
$action .= '<div class="flex gap-3 justify-center items-center flex-row">';
|
|
$action .= '<a href="'.url('opendata/dataset/view/'.encode_id($row->DatasetId)).'" data-toggle="tooltip" title="Lihat Data" class="btn btn-sm btn-block bg-info"><i class="ri-eye-line text-white"></i></a>';
|
|
$action .= '</div>';
|
|
$status = '';
|
|
|
|
if($row->status == 1){
|
|
$status = '<small class="p-1 w-full bg-success text-white rounded" title="Aktif"><i class="ri-check-line"></i></small>';
|
|
}else{
|
|
$status = '<small class="p-1 w-full bg-danger text-white rounded" title="Tidak Aktif"><i class="ri-close-line"></i></small>';
|
|
}
|
|
|
|
$_data[] = [
|
|
'no' => $key+1,
|
|
'id' => encode_id($row->id),
|
|
'name' => @$row->name,
|
|
'publik' => @$row->publik,
|
|
'tahun' => @$row->tahun,
|
|
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
|
|
'instansi' => @$row->instansi->name,
|
|
'action' => @$action,
|
|
'status' => @$status,
|
|
];
|
|
|
|
}
|
|
|
|
// return response()->json($_data); // Return the data as a JSON response
|
|
return response()->json($_data);
|
|
|
|
}
|
|
|
|
public function datasetGrid($alias,Request $request)
|
|
{
|
|
if(session('group_id') == 1){
|
|
$data = Dataset::whereHas('instansi',function($query) use ($alias){
|
|
$query->where('parent','ilike','%'.$alias.'%');
|
|
})->orderBy('DatasetId','DESC')->get();
|
|
}else{
|
|
$data = Dataset::whereHas('instansi',function($query) use ($alias){
|
|
$query->where('parent','ilike','%'.$alias.'%');
|
|
})->orderBy('DatasetId','DESC')->whereIn('created_by',[auth()->user()->id,1])->get();
|
|
}
|
|
// $data = User::with(['group'])->orderBy('id','DESC')->get();
|
|
$_data = [];
|
|
|
|
foreach ($data as $key => $row) {
|
|
|
|
$action = '';
|
|
$action .= '<div class="flex gap-3 justify-center items-center flex-row">';
|
|
$action .= '<a href="'.url('opendata/dataset/view/'.encode_id($row->DatasetId)).'" data-toggle="tooltip" title="Lihat Data" class="btn btn-sm btn-block bg-info"><i class="ri-eye-line text-white"></i></a>';
|
|
$action .= '</div>';
|
|
$status = '';
|
|
|
|
if($row->status == 1){
|
|
$status = '<small class="p-1 w-full bg-success text-white rounded" title="Aktif"><i class="ri-check-line"></i></small>';
|
|
}else{
|
|
$status = '<small class="p-1 w-full bg-danger text-white rounded" title="Tidak Aktif"><i class="ri-close-line"></i></small>';
|
|
}
|
|
|
|
$_data[] = [
|
|
'no' => $key+1,
|
|
'id' => encode_id($row->id),
|
|
'name' => @$row->name,
|
|
'publik' => @$row->publik,
|
|
'tahun' => @$row->tahun,
|
|
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
|
|
'instansi' => @$row->instansi->name,
|
|
'action' => @$action,
|
|
'status' => @$status,
|
|
];
|
|
|
|
}
|
|
|
|
// return response()->json($_data); // Return the data as a JSON response
|
|
return response()->json($_data);
|
|
|
|
}
|
|
}
|