From d404054887239779b3eb40b25499712562afa4f0 Mon Sep 17 00:00:00 2001 From: theRAD Date: Fri, 6 Mar 2026 04:58:29 +0200 Subject: [PATCH] feat: add admin settings panel and dashboard configurations --- src/app/Http/Controllers/AdminController.php | 52 ++++++++ src/app/Models/Setting.php | 39 ++++++ ...026_03_06_025530_create_settings_table.php | 35 ++++++ src/resources/views/admin/index.blade.php | 28 +++++ src/resources/views/admin/layout.blade.php | 112 ++++++++++++++++++ src/resources/views/admin/settings.blade.php | 54 +++++++++ src/resources/views/landing.blade.php | 8 ++ src/routes/web.php | 8 ++ 8 files changed, 336 insertions(+) create mode 100644 src/app/Http/Controllers/AdminController.php create mode 100644 src/app/Models/Setting.php create mode 100644 src/database/migrations/2026_03_06_025530_create_settings_table.php create mode 100644 src/resources/views/admin/index.blade.php create mode 100644 src/resources/views/admin/layout.blade.php create mode 100644 src/resources/views/admin/settings.blade.php diff --git a/src/app/Http/Controllers/AdminController.php b/src/app/Http/Controllers/AdminController.php new file mode 100644 index 0000000..d7c783b --- /dev/null +++ b/src/app/Http/Controllers/AdminController.php @@ -0,0 +1,52 @@ + 'target_margin', 'name' => 'Target Margin (%)', 'type' => 'integer', 'default' => 20, 'description' => 'Target gross margin percentage for alerts.'], + ['key' => 'low_stock_threshold', 'name' => 'Low Stock Warning', 'type' => 'integer', 'default' => 50, 'description' => 'Quantity at which a product is considered low stock.'], + ['key' => 'default_date_range', 'name' => 'Default Date Filter', 'type' => 'string', 'default' => 'YTD', 'description' => 'Default date range on load (e.g. YTD, All).'], + ]; + } else if ($dashboard === 'sales') { + $schema = [ + ['key' => 'monthly_target', 'name' => 'Monthly Sales Target', 'type' => 'integer', 'default' => 100000, 'description' => 'Overall monthly sales target.'], + ]; + } else { + abort(404); + } + + // Fetch current settings from DB + $settings = Setting::where('dashboard', $dashboard)->get()->keyBy('key'); + + return view('admin.settings', compact('dashboard', 'schema', 'settings')); + } + + public function updateSettings(Request $request, $dashboard) + { + $settingsData = $request->except('_token'); + + foreach ($settingsData as $key => $value) { + Setting::updateOrCreate( + ['dashboard' => $dashboard, 'key' => $key], + ['value' => $value] + ); + } + + return redirect()->back()->with('success', ucfirst($dashboard) . ' settings saved successfully!'); + } +} diff --git a/src/app/Models/Setting.php b/src/app/Models/Setting.php new file mode 100644 index 0000000..910e4fc --- /dev/null +++ b/src/app/Models/Setting.php @@ -0,0 +1,39 @@ +where('key', $key)->first(); + if (!$setting) { + return $default; + } + + switch ($setting->type) { + case 'boolean': + return filter_var($setting->value, FILTER_VALIDATE_BOOLEAN); + case 'integer': + return (int) $setting->value; + case 'json': + return json_decode($setting->value, true); + default: + return $setting->value; + } + } +} diff --git a/src/database/migrations/2026_03_06_025530_create_settings_table.php b/src/database/migrations/2026_03_06_025530_create_settings_table.php new file mode 100644 index 0000000..7f8da8c --- /dev/null +++ b/src/database/migrations/2026_03_06_025530_create_settings_table.php @@ -0,0 +1,35 @@ +id(); + $table->string('dashboard')->index(); // e.g., 'procurement', 'sales', 'global' + $table->string('key'); + $table->text('value')->nullable(); + $table->string('type')->default('string'); // string, boolean, integer, json + $table->string('name')->nullable(); // Human-readable name + $table->text('description')->nullable(); + $table->timestamps(); + + $table->unique(['dashboard', 'key']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('settings'); + } +}; diff --git a/src/resources/views/admin/index.blade.php b/src/resources/views/admin/index.blade.php new file mode 100644 index 0000000..84a76fd --- /dev/null +++ b/src/resources/views/admin/index.blade.php @@ -0,0 +1,28 @@ +@extends('admin.layout') + +@section('content') +
+

System Configuration Overview

+

Manage dashboard settings and globally defined parameters.

+
+ +
+ + +
+ +
+

Procurement Settings

+

Configure thresholds, margins, and default variables for the procurement module.

+
+ + +
+ +
+

Sales Settings (WIP)

+

Configure revenue targets and metric parameters for the upcoming sales dashboard.

+
+ +
+@endsection diff --git a/src/resources/views/admin/layout.blade.php b/src/resources/views/admin/layout.blade.php new file mode 100644 index 0000000..e036db9 --- /dev/null +++ b/src/resources/views/admin/layout.blade.php @@ -0,0 +1,112 @@ + + + + + + Admin Panel - Stargas Dashboards + @vite(['resources/css/app.css', 'resources/js/app.js']) + + + + + + +
+ + +
+
+
+ Stargas +
+

Admin Panel

+

System Configuration

+
+
+ +
+
+ +
+ + + + +
+ @if(session('success')) +
+ +
+

Success

+
{{ session('success') }}
+
+
+ @endif + + @yield('content') +
+
+ + diff --git a/src/resources/views/admin/settings.blade.php b/src/resources/views/admin/settings.blade.php new file mode 100644 index 0000000..2a264fe --- /dev/null +++ b/src/resources/views/admin/settings.blade.php @@ -0,0 +1,54 @@ +@extends('admin.layout') + +@section('content') +
+
+

{{ ucfirst($dashboard) }} Settings

+

Adjust constants and parameters specific to this dashboard.

+
+
+ +
+ @csrf + +
+ @foreach($schema as $field) + @php + // Retrieve existing value from DB or fallback to default + $currentValue = isset($settings[$field['key']]) ? $settings[$field['key']]->value : $field['default']; + @endphp + +
+ +

{{ $field['description'] }}

+ + @if($field['type'] === 'boolean') +
+ +
+ @else + + @endif +
+ @endforeach +
+ +
+ +
+
+@endsection diff --git a/src/resources/views/landing.blade.php b/src/resources/views/landing.blade.php index dc21d99..e8e822f 100644 --- a/src/resources/views/landing.blade.php +++ b/src/resources/views/landing.blade.php @@ -62,6 +62,14 @@
+ +
+ + + Settings + +
+
diff --git a/src/routes/web.php b/src/routes/web.php index 2a7a98a..e49fdfd 100644 --- a/src/routes/web.php +++ b/src/routes/web.php @@ -1,6 +1,7 @@ group(function () { + Route::get('/', [AdminController::class, 'index']); + Route::get('/settings/{dashboard}', [AdminController::class, 'dashboardSettings']); + Route::post('/settings/{dashboard}', [AdminController::class, 'updateSettings']); +}); + // Dashboard API endpoints Route::prefix('api/dashboard')->group(function () { Route::get('/summary', [DashboardController::class, 'summary']);