Skip to content

Commit

Permalink
change: sort and collapse stats
Browse files Browse the repository at this point in the history
  • Loading branch information
ulcuber committed Dec 2, 2024
1 parent c6a7acd commit 025e3d5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions resources/views/bootstrap-5/logs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<a href="{{ route('log-viewer::logs.show', [$prefix, $date]) }}" class="btn btn-sm btn-info">
<i class="bi bi-eye"></i>
</a>
<a href="{{ route('log-viewer::logs.stats', [$prefix, $date]) }}" class="btn btn-sm btn-warning">
<i class="bi bi-calculator"></i>
</a>
<a href="{{ route('log-viewer::logs.download', [$prefix, $date]) }}" class="btn btn-sm btn-success">
<i class="bi bi-download"></i>
</a>
Expand Down
24 changes: 22 additions & 2 deletions resources/views/bootstrap-5/stats.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,29 @@
</ul>
<ul class="list-group list-group-flush">
@foreach ($context as $dottedKey => $values)
@php
$valuesCount = count($values);
$collapsable = $valuesCount > 3;
$collapseId = "values-list-{$dottedKey}";
@endphp
<li class="list-group-item d-flex justify-content-between flex-wrap">
<span>{{ $dottedKey }}</span>
<ul class="list-group list-group-flush">
<span>
{{ $dottedKey }}
@if ($collapsable)
<a
class="btn btn-sm btn-light"
role="button"
data-bs-toggle="collapse"
href="#{{ $collapseId }}"
aria-expanded="false"
aria-controls="{{ $collapseId }}"
>
<span class="badge text-bg-primary rounded-pill">{{ $valuesCount }}</span>
<i class="bi bi-chevron-down"></i>
</a>
@endif
</span>
<ul id="{{ $collapseId }}" class="list-group list-group-flush @if ($collapsable) collapse @endif">
@foreach ($values as $value => $info)
<li class="list-group-item">
<span class="badge text-bg-primary rounded-pill">{{ $info['count'] }}</span>
Expand Down
9 changes: 9 additions & 0 deletions src/Http/Controllers/LogViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public function stats(Request $request, string $prefix, string $date): View
$context[$dottedKey] = [];
}

if (is_array($value)) {
// empty array could not be flattened
$value = '';
}

if (isset($context[$dottedKey][$value])) {
$context[$dottedKey][$value]['count']++;
} else {
Expand All @@ -169,6 +174,10 @@ public function stats(Request $request, string $prefix, string $date): View
}
}

foreach ($context as $dottedKey => &$values) {
$values = collect($values)->sortByDesc('count')->all();
}

return $this->view($request, 'stats', compact('level', 'log', 'search', 'levels', 'stats', 'context'));
}

Expand Down

0 comments on commit 025e3d5

Please sign in to comment.