{{-- resources/views/superadmin/proactive/command/rules.blade.php --}} @extends('layouts.superadmin') @section('title', 'ProActive — قواعد القيادة') @section('page-title', 'قواعد القيادة (Rules)') @section('content') @php use Illuminate\Support\Facades\Route; /* ✅ safe_route داخل نفس الـView */ if (!function_exists('safe_route')) { function safe_route(string $name, array $params = [], bool $absolute = true, string $fallback = '#'): string { try { return Route::has($name) ? route($name, $params, $absolute) : $fallback; } catch (\Throwable $e) { return $fallback; } } } /* ✅ getter آمن object/array */ if (!function_exists('getv')) { function getv($src, string $key, $default = null) { if (is_array($src)) return array_key_exists($key,$src) ? $src[$key] : $default; if (is_object($src)) return isset($src->{$key}) ? $src->{$key} : $default; return $default; } } $qs = request()->query(); $q = fn($k,$d=null) => request()->get($k,$d); $view = (string)($view ?? $q('view','cards')); // cards|table $scope = (string)($scope ?? $q('scope','all')); // all|active|paused|system|custom $search = trim((string)($search ?? $q('search',''))); if(!in_array($view,['cards','table'],true)) $view='cards'; if(!in_array($scope,['all','active','paused','system','custom'],true)) $scope='all'; // items: rules list (Collection/Paginator/array) // Expected fields (مرن): // id, title, rule_key, description, level (info|warn|hard), scope (system|custom), // is_enabled, priority, when_json, action_json, created_at, updated_at, hits_7d, hits_30d $items = $items ?? collect(); $stats = $stats ?? [ 'total' => (int)($totalCount ?? (method_exists($items,'total') ? $items->total() : (method_exists($items,'count') ? $items->count() : (is_array($items)?count($items):0)))), 'active' => (int)($activeCount ?? 0), 'paused' => (int)($pausedCount ?? 0), 'system' => (int)($systemCount ?? 0), 'custom' => (int)($customCount ?? 0), ]; $rCommand = safe_route('superadmin.proactive.command', [], true, url('/superadmin/proactive/command')); $rRules = safe_route('superadmin.proactive.rules', [], true, url()->current()); $chip = fn($cls) => "px-2.5 py-1 rounded-xl border text-[11px] font-extrabold $cls"; $scopeBtn = function($key, $label, $count, $activeCls, $idleCls) use ($scope,$qs,$rRules){ $url = $rRules.'?'.http_build_query(array_merge($qs, ['scope'=>$key])); return ['url'=>$url,'cls'=>($scope===$key ? $activeCls : $idleCls),'label'=>$label,'count'=>$count]; }; $scopes = [ $scopeBtn('all','الكل', (int)($stats['total'] ?? 0), 'border-amber-400/40 bg-amber-500/15 text-amber-100', 'border-white/10 bg-white/5 text-white/80 hover:text-white hover:bg-white/10'), $scopeBtn('active','نشط', (int)($stats['active'] ?? 0), 'border-emerald-400/40 bg-emerald-500/15 text-emerald-100', 'border-white/10 bg-white/5 text-white/80 hover:text-white hover:bg-white/10'), $scopeBtn('paused','موقوف', (int)($stats['paused'] ?? 0), 'border-rose-400/40 bg-rose-500/15 text-rose-100', 'border-white/10 bg-white/5 text-white/80 hover:text-white hover:bg-white/10'), $scopeBtn('system','نظام', (int)($stats['system'] ?? 0), 'border-fuchsia-400/40 bg-fuchsia-500/15 text-fuchsia-100', 'border-white/10 bg-white/5 text-white/80 hover:text-white hover:bg-white/10'), $scopeBtn('custom','مخصص', (int)($stats['custom'] ?? 0), 'border-cyan-400/40 bg-cyan-500/15 text-cyan-100', 'border-white/10 bg-white/5 text-white/80 hover:text-white hover:bg-white/10'), ]; $lvlBadge = function($lvl) use ($chip){ $lvl = (string)$lvl; if($lvl==='hard') return $chip('border-rose-400/25 bg-rose-500/10 text-rose-100'); if($lvl==='warn') return $chip('border-amber-400/25 bg-amber-500/10 text-amber-100'); return $chip('border-cyan-400/25 bg-cyan-500/10 text-cyan-100'); // info }; $scopeBadge = function($s) use ($chip){ $s = (string)$s; if($s==='system') return $chip('border-fuchsia-400/25 bg-fuchsia-500/10 text-fuchsia-100'); if($s==='custom') return $chip('border-cyan-400/25 bg-cyan-500/10 text-cyan-100'); return $chip('border-white/10 bg-white/5 text-white/70'); }; $onBadge = function($on) use ($chip){ return $on ? $chip('border-emerald-400/25 bg-emerald-500/10 text-emerald-100') : $chip('border-rose-400/25 bg-rose-500/10 text-rose-100'); }; $short = function($txt,$n=150){ $t = trim((string)$txt); if(mb_strlen($t) <= $n) return $t; return mb_substr($t,0,$n).'…'; }; $hasItems = ($items instanceof \Illuminate\Support\Collection) ? $items->isNotEmpty() : (is_array($items) && count($items)>0); @endphp
{{-- HERO --}}
ProActive • محرك القواعد

قواعد القيادة — Rules

القواعد هي “قانون التشغيل”: متى نعتبر تأخير؟ متى نطلب إثبات؟ متى نصعّد؟ وكيف تتصرف المنظومة تلقائيًا.

إجمالي: {{ (int)($stats['total'] ?? 0) }} نشط: {{ (int)($stats['active'] ?? 0) }} موقوف: {{ (int)($stats['paused'] ?? 0) }} نظام: {{ (int)($stats['system'] ?? 0) }} مخصص: {{ (int)($stats['custom'] ?? 0) }}
{{-- FILTER --}}
تصفير
* Scope: {{ $scope }}.
{{-- SCOPES --}}
@foreach($scopes as $s) {{ $s['label'] }} ({{ (int)$s['count'] }}) @endforeach
{{-- INFO --}}
كيف نقرأ القاعدة؟
WHEN = شروط التفعيل (وقت/حالة/تكرار/منصة…)، و ACTION = ماذا نفعل (تنبيه/طلب إثبات/تصعيد/تجميد…)، و LEVEL = شدة القاعدة.
{{-- LIST --}} @if($hasItems) @if($view === 'cards')
@foreach($items as $r) @php $id = (int)getv($r,'id', 0); $title = (string)getv($r,'title', '— بدون عنوان —'); $key = (string)getv($r,'rule_key', getv($r,'key','')); $desc = (string)getv($r,'description', ''); $lvl = (string)getv($r,'level', 'info'); // info|warn|hard $sc = (string)getv($r,'scope', 'custom'); // system|custom $on = (int)getv($r,'is_enabled', 1) === 1; $prio = (int)getv($r,'priority', 0); $when = (string)getv($r,'when_json', getv($r,'when','')); $act = (string)getv($r,'action_json', getv($r,'action','')); $hits7 = (int)getv($r,'hits_7d', 0); $hits30= (int)getv($r,'hits_30d', 0); $updated = (string)getv($r,'updated_at', ''); @endphp
{{ $title }}
Key: {{ $key !== '' ? $key : '—' }}
{{ strtoupper($lvl) }} {{ strtoupper($sc) }} {{ $on ? 'مفعل' : 'موقوف' }}
الوصف
{{ $desc !== '' ? $short($desc, 160) : '—' }}
WHEN
{{ $when !== '' ? $short($when, 180) : '—' }}
ACTION
{{ $act !== '' ? $short($act, 180) : '—' }}
ID: {{ $id }} أولوية: {{ $prio }} 7d: {{ $hits7 }} 30d: {{ $hits30 }}
آخر تحديث: {{ $updated }}
@endforeach
@else
جدول القواعد
ملخّص سريع — التفاصيل في JSON.
@foreach($items as $r) @php $title = (string)getv($r,'title','—'); $key = (string)getv($r,'rule_key', getv($r,'key','—')); $lvl = (string)getv($r,'level','info'); $sc = (string)getv($r,'scope','custom'); $on = (int)getv($r,'is_enabled',1) === 1; $prio = (int)getv($r,'priority',0); $hits7 = (int)getv($r,'hits_7d',0); $upd = (string)getv($r,'updated_at',''); @endphp @endforeach
العنوان Key Level Scope الحالة أولوية Hits (7d) آخر تحديث
{{ $title }} {{ $key }} {{ strtoupper($lvl) }} {{ strtoupper($sc) }} {{ $on ? 'مفعل' : 'موقوف' }} {{ $prio }} {{ $hits7 }} {{ $upd }}
@if(isset($items) && method_exists($items,'links'))
{{ $items->links() }}
@endif
@endif @else
لا يوجد قواعد ضمن هذا الفلتر
جرّب تغيّر Scope أو كلمة البحث.
@endif
@endsection