A free open source IT asset/license management system
Quick fix for alert menu 1001 queries
snipe546c8ce7d5c4
diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.phpindex 3dfc388a9e..195c2e4611 100644--- a/app/Helpers/Helper.php+++ b/app/Helpers/Helper.php@@ -775,11 +775,11 @@ class Helperpublic static function checkLowInventory(){$alert_threshold = \App\Models\Setting::getSettings()->alert_threshold;- $consumables = Consumable::withCount('consumableAssignments as consumable_assignments_count')->whereNotNull('min_amt')->get();+ $consumables = Consumable::withCount('consumableAssignments as consumables_users_count')->whereNotNull('min_amt')->get();$accessories = Accessory::withCount('checkouts as checkouts_count')->whereNotNull('min_amt')->get();- $components = Component::whereNotNull('min_amt')->get();+ $components = Component::withCount('assets as sum_unconstrained_assets')->whereNotNull('min_amt')->get();$asset_models = AssetModel::where('min_amt', '>', 0)->withCount(['availableAssets', 'assets'])->get();- $licenses = License::where('min_amt', '>', 0)->get();+ $licenses = License::withCount('availCount as licenses_available')->where('min_amt', '>', 0)->get();$items_array = [];$all_count = 0;diff --git a/resources/views/blade/alert-menu.blade.php b/resources/views/blade/alert-menu.blade.phpnew file mode 100644index 0000000000..73e81a9814--- /dev/null+++ b/resources/views/blade/alert-menu.blade.php@@ -0,0 +1,90 @@+@props([+ 'snipeSettings' => \App\Models\Setting::getSettings(),+])++@if ($snipeSettings->show_alerts_in_menu=='1')+<!-- Tasks: style can be found in dropdown.less -->+<?php+ $alert_items = \App\Helpers\Helper::checkLowInventory();+ $deprecations = \App\Helpers\Helper::deprecationCheck()+?>++<li class="dropdown tasks-menu">+ <a href="#" class="dropdown-toggle" data-toggle="dropdown">+ <x-icon type="alerts" />+ <span class="sr-only">{{ trans('general.alerts') }}</span>+ @if(count($alert_items) + count($deprecations))+ <span class="label label-danger">{{ count($alert_items) + count($deprecations)}}</span>+ @endif+ </a>+ <ul class="dropdown-menu">++ @if ((count($alert_items) + count($deprecations)) > 0)++ @can('superadmin')+ @if($deprecations)+ @foreach ($deprecations as $key => $deprecation)+ @if ($deprecation['check'])+ <li class="header alert-warning">{!! $deprecation['message'] !!}</li>+ @endif+ @endforeach+ @endif+ @endcan++ @if($alert_items)+ <li class="header">+ {{ trans_choice('general.quantity_minimum', count($alert_items)) }}+ </li>+ <li>+ <!-- inner menu: contains the actual data -->+ <ul class="menu">++ @if (count($alert_items) <= 50)+ @for($i = 0; count($alert_items) > $i; $i++)+++ <!-- Task item -->+ <li>+ <a href="{{ route($alert_items[$i]['type'].'.show', $alert_items[$i]['id'])}}">+ <h2 class="task_menu">{{ $alert_items[$i]['name'] }}+ <small class="pull-right">+ {{ $alert_items[$i]['remaining'] }} {{ trans('general.remaining') }}+ </small>+ </h2>+ <div class="progress xs">+ <div class="progress-bar progress-bar-yellow"+ style="width: {{ $alert_items[$i]['percent'] }}%"+ role="progressbar"+ aria-valuenow="{{ $alert_items[$i]['percent'] }}"+ aria-valuemin="0"+ aria-valuemax="100">+ <span class="sr-only">+ {{ $alert_items[$i]['percent'] }}%+ </span>+ </div>+ </div>+ </a>+ </li>++ <!-- end task item -->+ @endfor+ @endif+ </ul>+ </li>+ @endif+ @else+ <li class="header">+ {{ trans_choice('general.quantity_minimum', 0) }}+ </li>++ @endif+ {{-- <li class="footer">--}}+ {{-- <a href="#">{{ trans('general.tasks_view_all') }}</a>--}}+ {{-- </li>--}}+ </ul>+</li>++@if (!$slot->isEmpty())+ {{ $slot }}+@endif+@endif\ No newline at end of filediff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.phpindex 0b148650f2..dbdb697f05 100644--- a/resources/views/layouts/default.blade.php+++ b/resources/views/layouts/default.blade.php@@ -1145,79 +1145,7 @@@endcan@can('admin')- <!-- Tasks: style can be found in dropdown.less -->- <?php $alert_items = ($snipeSettings->show_alerts_in_menu=='1') ? Helper::checkLowInventory() : [];- $deprecations = Helper::deprecationCheck()- ?>-- <li class="dropdown tasks-menu">- <a href="#" class="dropdown-toggle" data-toggle="dropdown">- <x-icon type="alerts" />- <span class="sr-only">{{ trans('general.alerts') }}</span>- @if(count($alert_items) + count($deprecations))- <span class="label label-danger">{{ count($alert_items) + count($deprecations)}}</span>- @endif- </a>- <ul class="dropdown-menu">-- @if ((count($alert_items) + count($deprecations)) > 0)-- @can('superadmin')- @if($deprecations)- @foreach ($deprecations as $key => $deprecation)- @if ($deprecation['check'])- <li class="header alert-warning">{!! $deprecation['message'] !!}</li>- @endif- @endforeach- @endif- @endcan-- @if($alert_items)- <li class="header">- {{ trans_choice('general.quantity_minimum', count($alert_items)) }}- </li>- <li>- <!-- inner menu: contains the actual data -->- <ul class="menu">- @for($i = 0; count($alert_items) > $i; $i++)- <!-- Task item -->- <li>- <a href="{{ route($alert_items[$i]['type'].'.show', $alert_items[$i]['id'])}}">- <h2 class="task_menu">{{ $alert_items[$i]['name'] }}- <small class="pull-right">- {{ $alert_items[$i]['remaining'] }} {{ trans('general.remaining') }}- </small>- </h2>- <div class="progress xs">- <div class="progress-bar progress-bar-yellow"- style="width: {{ $alert_items[$i]['percent'] }}%"- role="progressbar"- aria-valuenow="{{ $alert_items[$i]['percent'] }}"- aria-valuemin="0"- aria-valuemax="100">- <span class="sr-only">- {{ $alert_items[$i]['percent'] }}%- </span>- </div>- </div>- </a>- </li>- <!-- end task item -->- @endfor- </ul>- </li>- @endif- @else- <li class="header">- {{ trans_choice('general.quantity_minimum', 0) }}- </li>-- @endif-{{-- <li class="footer">--}}-{{-- <a href="#">{{ trans('general.tasks_view_all') }}</a>--}}-{{-- </li>--}}- </ul>- </li>+ <x-alert-menu />@endcan