sigd/app/Http/Controllers/DashboardAdaptasiController...

73 lines
2.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Services\DashboardAdaptationService;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class DashboardAdaptasiController extends Controller
{
protected $title = 'Dashboard Adaptasi';
// protected $template = 'modules.dashboard.adaptasi';
protected $route = 'modules.dashboard.adaptasi';
protected DashboardAdaptationService $adaptationService;
public function __construct(DashboardAdaptationService $adaptationService)
{
$this->adaptationService = $adaptationService;
}
public function aksi(Request $request)
{
$year = (int) $request->input('adaptationYear', date('Y'));
try {
$dashboardData = $this->adaptationService->getDashboardData($year);
return view('auth.dashboard-adaptation-aksi', [
'title' => $this->title,
'route' => $this->route,
'stats' => $dashboardData['stats'],
'charts' => $dashboardData['charts'],
'today' => Carbon::today()->translatedFormat('d F Y'),
]);
} catch(\Exception $e) {
Log::error('Error loading aksi mitigasi dashboard', [
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
]);
return back()->withErrors(['error' => 'Gagal memuat dashboard aksi mitigasi.']);
}
}
public function index(Request $request)
{
$year = (int) $request->input('adaptationYear', date('Y'));
try {
$dashboardData = $this->adaptationService->getDashboardData($year);
return view('auth.dashboard-adaptation', [
'title' => $this->title,
'route' => $this->route,
'selectedYear' => $dashboardData['adaptationYear'],
'tableData' => $dashboardData['tableData'], // ⬅️ collection biasa
'barData' => $dashboardData['barData'],
'realisasiData' => $dashboardData['realisasiData'],
'budgetData' => $dashboardData['budgetData'],
]);
} catch (\Exception $e) {
Log::error('Error loading dashboard adaptation data', [
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
]);
// optional: kasih feedback ke user biar nggak blank
return back()->withErrors(['error' => 'Gagal memuat dashboard adaptasi.']);
}
}
}