@extends('app.template') @section('title', 'Scan Logs - COLI') @php // The $scan variable should be passed from the controller // $scan->process is a JSON string containing the structured process log $processLog = []; if (isset($scan) && $scan->process) { $processLog = json_decode($scan->process, true); } // Function to get MermaidJS color and Bootstrap class for each status function getStatusInfo($status) { $status = strtolower($status); switch ($status) { case 'done': return [ 'mermaid' => 'green', 'badge' => 'success', 'label' => 'Done' ]; case 'error': return [ 'mermaid' => 'red', 'badge' => 'danger', 'label' => 'Error' ]; case 'running': return [ 'mermaid' => 'yellow', 'badge' => 'warning text-dark', 'label' => 'Running' ]; case 'stopped': case 'stoped': return [ 'mermaid' => 'gray', 'badge' => 'secondary', 'label' => 'Stopped' ]; case 'waiting': case 'pending': return [ 'mermaid' => 'blue', 'badge' => 'primary text-white', 'label' => 'Waiting' ]; default: return [ 'mermaid' => 'gray', 'badge' => 'secondary', 'label' => ucfirst($status) ]; } } // Recursive function to generate MermaidJS flowchart function renderMermaidTasks($tasks, &$nodes, &$edges, $parentId = null, &$counter = 1) { foreach ($tasks as $task) { $nodeId = 'T' . $counter++; $label = addslashes($task['name'] ?? 'Unnamed Task'); $status = $task['status'] ?? 'unknown'; $statusInfo = getStatusInfo($status); $color = $statusInfo['mermaid']; $nodes[] = "$nodeId([\"$label\"]):::status_$color"; if ($parentId) { $edges[] = "$parentId --> $nodeId"; } if (!empty($task['tasks'])) { renderMermaidTasks($task['tasks'], $nodes, $edges, $nodeId, $counter); } } } // Recursive function to flatten tasks for table display function flattenTasks($tasks, $parent = null, &$flat = [], $level = 0) { foreach ($tasks as $task) { $flat[] = [ 'name' => $task['name'] ?? 'Unnamed Task', 'status' => $task['status'] ?? 'unknown', 'output' => $task['output'] ?? '', 'error' => $task['error'] ?? '', 'level' => $level, 'command' => $task['command'] ?? '', ]; if (!empty($task['tasks'])) { flattenTasks($task['tasks'], $task, $flat, $level + 1); } } return $flat; } $nodes = []; $edges = []; $counter = 1; if (!empty($processLog)) { renderMermaidTasks($processLog, $nodes, $edges, null, $counter); $flatTasks = flattenTasks($processLog); } else { $flatTasks = []; } // Function to display Bootstrap badge for status function getStatusBadge($status) { $info = getStatusInfo($status); return '' . $info['label'] . ''; } // Recursive function to display all task logs (nested) function displayTaskLogs($tasks, $level = 0, &$idx = 1) { foreach ($tasks as $task) { echo ''; echo '' . $idx++ . ''; echo '' . e($task['name'] ?? 'Unnamed Task') . ''; echo ''; echo getStatusBadge($task['status'] ?? 'unknown'); echo ''; echo ''; if (env("ERROR_LOG") == "true") { $modalId = 'errorModal' . uniqid(); echo ''; // Error Modal echo ''; } else{ echo '-'; } echo ''; echo ''; if ((strtolower($task['status'] ?? '') === 'error') && !empty($task['error'])) { $modalId = 'errorModal' . uniqid(); echo ''; // Error Modal echo ''; } else { echo '-'; } echo ''; echo ''; if (!empty($task['command'])) { echo '' . $task['command'] . ''; } else { echo '-'; } echo ''; echo ''; // Loop children if (!empty($task['tasks'])) { displayTaskLogs($task['tasks'], $level + 1, $idx); } } } @endphp @section('content')

Scan Process Logs

Back to Scans
@if(empty($processLog)) @else {{-- Diagram Section --}}
Process Flow Diagram
Done Error Running Waiting Stopped
flowchart TD
@foreach($nodes as $node)
{!! $node !!}
@endforeach
@foreach($edges as $edge)
{!! $edge !!}
@endforeach

classDef status_green fill:#c6f6d5,stroke:#38a169,stroke-width:2px;
classDef status_red fill:#fed7d7,stroke:#e53e3e,stroke-width:2px;
classDef status_yellow fill:#fefcbf,stroke:#d69e2e,stroke-width:2px;
classDef status_gray fill:#e2e8f0,stroke:#718096,stroke-width:2px;
classDef status_blue fill:#bee3f8,stroke:#3182ce,stroke-width:2px;
                            
{{-- Table Section --}}
Task Log Details
@if(!empty($processLog)) @php $idx = 1; @endphp {!! displayTaskLogs($processLog, 0, $idx) !!} @else @endif
# Task Name Status Logging Error Command
No task logs found.
@endif
@endsection