mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Permit disabling utilization graph warning/danger thresholds
This commit is contained in:
@ -256,6 +256,21 @@ class RoleTable(BaseTable):
|
||||
# Prefixes
|
||||
#
|
||||
|
||||
class PrefixUtilizationColumn(UtilizationColumn):
|
||||
"""
|
||||
Extend UtilizationColumn to allow disabling the warning & danger thresholds for prefixes
|
||||
marked as fully utilized.
|
||||
"""
|
||||
template_code = """
|
||||
{% load helpers %}
|
||||
{% if record.pk and record.mark_utilized %}
|
||||
{% utilization_graph value warning_threshold=0 danger_threshold=0 %}
|
||||
{% elif record.pk %}
|
||||
{% utilization_graph value %}
|
||||
{% endif %}
|
||||
"""
|
||||
|
||||
|
||||
class PrefixTable(BaseTable):
|
||||
pk = ToggleColumn()
|
||||
prefix = tables.TemplateColumn(
|
||||
@ -300,7 +315,7 @@ class PrefixTable(BaseTable):
|
||||
|
||||
|
||||
class PrefixDetailTable(PrefixTable):
|
||||
utilization = UtilizationColumn(
|
||||
utilization = PrefixUtilizationColumn(
|
||||
accessor='get_utilization',
|
||||
orderable=False
|
||||
)
|
||||
|
@ -101,8 +101,9 @@
|
||||
<tr>
|
||||
<th scope="row">Utilization</th>
|
||||
<td>
|
||||
{% if object.marked_utilized %}
|
||||
{% utilization_graph 100 %}
|
||||
{% if object.mark_utilized %}
|
||||
{% utilization_graph 100 warning_threshold=0 danger_threshold=0 %}
|
||||
<small>(Marked fully utilized)</small>
|
||||
{% else %}
|
||||
{% utilization_graph object.get_utilization %}
|
||||
{% endif %}
|
||||
|
@ -4,39 +4,15 @@
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="progress">
|
||||
{% if utilization >= danger_threshold %}
|
||||
<div
|
||||
aria-valuemin="0"
|
||||
role="progressbar"
|
||||
aria-valuemax="100"
|
||||
class="progress-bar bg-danger"
|
||||
aria-valuenow="{{ utilization }}"
|
||||
style="width: {{ utilization }}%;"
|
||||
>
|
||||
{{ utilization }}%
|
||||
</div>
|
||||
{% elif utilization >= warning_threshold %}
|
||||
<div
|
||||
aria-valuemin="0"
|
||||
role="progressbar"
|
||||
aria-valuemax="100"
|
||||
aria-valuenow="{{ utilization }}"
|
||||
style="width: {{ utilization }}%;"
|
||||
class="progress-bar bg-warning"
|
||||
>
|
||||
{{ utilization }}%
|
||||
</div>
|
||||
{% else %}
|
||||
<div
|
||||
aria-valuemin="0"
|
||||
role="progressbar"
|
||||
aria-valuemax="100"
|
||||
class="progress-bar bg-success"
|
||||
aria-valuenow="{{ utilization }}"
|
||||
class="progress-bar {{ bar_class }}"
|
||||
style="min-width: 8%; width: {{ utilization }}%;"
|
||||
>
|
||||
{{ utilization }}%
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
@ -276,10 +276,17 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
|
||||
"""
|
||||
Display a horizontal bar graph indicating a percentage of utilization.
|
||||
"""
|
||||
if danger_threshold and utilization >= danger_threshold:
|
||||
bar_class = 'bg-danger'
|
||||
elif warning_threshold and utilization >= warning_threshold:
|
||||
bar_class = 'bg-warning'
|
||||
elif warning_threshold or danger_threshold:
|
||||
bar_class = 'bg-success'
|
||||
else:
|
||||
bar_class = 'bg-default'
|
||||
return {
|
||||
'utilization': utilization,
|
||||
'warning_threshold': warning_threshold,
|
||||
'danger_threshold': danger_threshold,
|
||||
'bar_class': bar_class,
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user