feat: add admin settings panel and dashboard configurations

This commit is contained in:
theRAD
2026-03-06 04:58:29 +02:00
parent d705160b55
commit d404054887
8 changed files with 336 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Setting;
class AdminController extends Controller
{
public function index()
{
return view('admin.index');
}
public function dashboardSettings($dashboard)
{
// Define available settings per dashboard here for simplicity
$schema = [];
if ($dashboard === 'procurement') {
$schema = [
['key' => '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!');
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
protected $fillable = [
'dashboard',
'key',
'value',
'type',
'name',
'description',
];
/**
* Get a setting value, returning the provided default if not found.
*/
public static function getValue($dashboard, $key, $default = null)
{
$setting = self::where('dashboard', $dashboard)->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;
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('settings', function (Blueprint $table) {
$table->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');
}
};

View File

@@ -0,0 +1,28 @@
@extends('admin.layout')
@section('content')
<div class="mb-8">
<h2 class="text-2xl font-bold text-white tracking-tight">System Configuration Overview</h2>
<p class="text-slate-400 mt-2">Manage dashboard settings and globally defined parameters.</p>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<a href="/admin/settings/procurement" class="glass rounded-xl p-6 group transition-all duration-300 hover:border-red-500/50 hover:bg-white/5 block">
<div class="w-12 h-12 rounded-lg bg-red-500/20 text-red-500 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 3h2l.4 2M7 13h10l4-8H5.4M7 13L5.4 5M7 13l-2.293 2.293c-.63.63-.184 1.707.707 1.707H17m0 0a2 2 0 100 4 2 2 0 000-4zm-8 2a2 2 0 11-4 0 2 2 0 014 0z"/></svg>
</div>
<h3 class="text-lg font-bold text-white mb-2">Procurement Settings</h3>
<p class="text-sm text-slate-400">Configure thresholds, margins, and default variables for the procurement module.</p>
</a>
<a href="/admin/settings/sales" class="glass rounded-xl p-6 group transition-all duration-300 hover:border-orange-500/50 hover:bg-white/5 block">
<div class="w-12 h-12 rounded-lg bg-orange-500/20 text-orange-500 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
</div>
<h3 class="text-lg font-bold text-slate-300 mb-2">Sales Settings (WIP)</h3>
<p class="text-sm text-slate-500">Configure revenue targets and metric parameters for the upcoming sales dashboard.</p>
</a>
</div>
@endsection

View File

@@ -0,0 +1,112 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Panel - Stargas Dashboards</title>
@vite(['resources/css/app.css', 'resources/js/app.js'])
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
body {
background: linear-gradient(135deg, #0a0a0a 0%, #1a0a0a 30%, #0d0d0d 60%, #0a0a0a 100%);
min-height: 100vh;
font-family: 'Inter', sans-serif;
}
.glass {
background: rgba(255, 255, 255, 0.04);
backdrop-filter: blur(12px);
border: 1px solid rgba(227, 25, 55, 0.12);
}
.stargas-accent {
background: linear-gradient(90deg, #E31937, #FFD700, #E31937);
height: 2px;
}
.fade-in {
animation: fadeIn 0.5s ease-out forwards;
}
@keyframes fadeIn {
to { opacity: 1; transform: translateY(0); }
from { opacity: 0; transform: translateY(10px); }
}
/* Nav links hover glow */
.nav-link.active {
background: rgba(227, 25, 55, 0.15);
border-right: 3px solid #E31937;
color: white;
}
.nav-link:hover:not(.active) {
background: rgba(255, 255, 255, 0.05);
color: #fca5a5;
}
</style>
</head>
<body class="text-white antialiased flex flex-col min-h-screen">
<!-- Stargas Accent Line -->
<div class="stargas-accent"></div>
<!-- Header -->
<header class="glass sticky top-0 z-50 border-b border-white/5">
<div class="max-w-[1600px] mx-auto px-6 py-3 flex items-center justify-between">
<div class="flex items-center gap-4">
<img src="/images/stargas-logo.svg" alt="Stargas" class="h-10">
<div class="border-l border-white/10 pl-4">
<h1 class="text-lg font-bold tracking-tight text-red-400">Admin Panel</h1>
<p class="text-xs text-slate-400">System Configuration</p>
</div>
</div>
<div class="flex items-center gap-4">
<a href="/" class="px-3 py-2 text-xs font-medium rounded-lg bg-white/5 hover:bg-white/10 transition-colors border border-white/10 flex items-center gap-1.5 text-slate-300">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/></svg>
Hub
</a>
</div>
</div>
</header>
<div class="flex-1 flex max-w-[1600px] w-full mx-auto">
<!-- Sidebar Navigation -->
<aside class="w-64 glass border-x-0 border-y-0 border-r border-white/5 flex-shrink-0 pt-8">
<nav class="space-y-1">
<div class="px-6 mb-4">
<h3 class="text-xs font-semibold text-slate-500 uppercase tracking-wider">Dashboards</h3>
</div>
<a href="/admin" class="nav-link flex items-center gap-3 px-6 py-3 text-sm font-medium text-slate-400 transition-colors {{ request()->is('admin') ? 'active' : '' }}">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"/></svg>
Overview
</a>
<a href="/admin/settings/procurement" class="nav-link flex items-center gap-3 px-6 py-3 text-sm font-medium text-slate-400 transition-colors {{ request()->is('admin/settings/procurement') ? 'active' : '' }}">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 3h2l.4 2M7 13h10l4-8H5.4M7 13L5.4 5M7 13l-2.293 2.293c-.63.63-.184 1.707.707 1.707H17m0 0a2 2 0 100 4 2 2 0 000-4zm-8 2a2 2 0 11-4 0 2 2 0 014 0z"/></svg>
Procurement
</a>
<a href="/admin/settings/sales" class="nav-link flex items-center gap-3 px-6 py-3 text-sm font-medium text-slate-400 transition-colors {{ request()->is('admin/settings/sales') ? 'active' : '' }}">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
Sales (WIP)
</a>
</nav>
</aside>
<!-- Main Content Area -->
<main class="flex-1 p-8 fade-in opacity-0">
@if(session('success'))
<div class="mb-6 p-4 rounded-lg bg-green-500/10 border border-green-500/30 flex items-start gap-3 fade-in">
<svg class="w-5 h-5 text-green-400 shrink-0 mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
<div>
<h4 class="text-sm font-medium text-green-400">Success</h4>
<div class="mt-1 text-sm text-green-400/80">{{ session('success') }}</div>
</div>
</div>
@endif
@yield('content')
</main>
</div>
</body>
</html>

View File

@@ -0,0 +1,54 @@
@extends('admin.layout')
@section('content')
<div class="mb-8 flex items-center justify-between">
<div>
<h2 class="text-2xl font-bold text-white tracking-tight">{{ ucfirst($dashboard) }} Settings</h2>
<p class="text-slate-400 mt-2">Adjust constants and parameters specific to this dashboard.</p>
</div>
</div>
<form action="/admin/settings/{{ $dashboard }}" method="POST" class="glass rounded-2xl p-8 max-w-3xl border-t-4 border-t-red-700">
@csrf
<div class="space-y-6">
@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
<div class="border-b border-white/5 pb-6 last:border-0 last:pb-0">
<label for="{{ $field['key'] }}" class="block text-sm font-semibold text-slate-200 mb-1">
{{ $field['name'] }}
</label>
<p class="text-xs text-slate-500 mb-3">{{ $field['description'] }}</p>
@if($field['type'] === 'boolean')
<div class="flex items-center gap-3">
<label class="relative inline-flex items-center cursor-pointer">
<input type="hidden" name="{{ $field['key'] }}" value="0">
<input type="checkbox" name="{{ $field['key'] }}" id="{{ $field['key'] }}" value="1" class="sr-only peer" {{ $currentValue ? 'checked' : '' }}>
<div class="w-11 h-6 bg-white/10 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-red-500/50 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-red-600"></div>
</label>
</div>
@else
<input type="{{ $field['type'] === 'integer' ? 'number' : 'text' }}"
name="{{ $field['key'] }}"
id="{{ $field['key'] }}"
value="{{ $currentValue }}"
class="w-full bg-white/5 border border-white/10 rounded-lg px-4 py-2 text-sm text-white focus:border-red-500 focus:outline-none focus:ring-1 focus:ring-red-500/30 transition-colors"
>
@endif
</div>
@endforeach
</div>
<div class="mt-8 pt-6 border-t border-white/10 flex items-center justify-end">
<button type="submit" class="px-6 py-2.5 text-sm font-semibold rounded-lg bg-red-700 hover:bg-red-600 border border-red-500/50 transition-colors shadow-lg shadow-red-900/20 text-white flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"/></svg>
Save Changes
</button>
</div>
</form>
@endsection

View File

@@ -62,6 +62,14 @@
<!-- Stargas Accent Line --> <!-- Stargas Accent Line -->
<div class="stargas-accent"></div> <div class="stargas-accent"></div>
<!-- Admin Link -->
<div class="absolute top-6 right-6 z-50 fade-in">
<a href="/admin" class="flex items-center gap-2 px-3 py-2 rounded-lg bg-white/5 hover:bg-white/10 transition-colors border border-white/10 text-xs font-medium text-slate-400 hover:text-white" title="Admin Control Panel">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
Settings
</a>
</div>
<main class="max-w-[1200px] mx-auto px-6 py-16"> <main class="max-w-[1200px] mx-auto px-6 py-16">
<!-- Hero Section --> <!-- Hero Section -->

View File

@@ -1,6 +1,7 @@
<?php <?php
use App\Http\Controllers\DashboardController; use App\Http\Controllers\DashboardController;
use App\Http\Controllers\AdminController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::get('/', function() { Route::get('/', function() {
@@ -9,6 +10,13 @@
Route::get('/procurement', [DashboardController::class, 'index']); Route::get('/procurement', [DashboardController::class, 'index']);
// Admin endpoints
Route::prefix('admin')->group(function () {
Route::get('/', [AdminController::class, 'index']);
Route::get('/settings/{dashboard}', [AdminController::class, 'dashboardSettings']);
Route::post('/settings/{dashboard}', [AdminController::class, 'updateSettings']);
});
// Dashboard API endpoints // Dashboard API endpoints
Route::prefix('api/dashboard')->group(function () { Route::prefix('api/dashboard')->group(function () {
Route::get('/summary', [DashboardController::class, 'summary']); Route::get('/summary', [DashboardController::class, 'summary']);