Commit ecf51406 authored by jeremystretch's avatar jeremystretch
Browse files

Permit disabling utilization graph warning/danger thresholds

parent bf56145a
......@@ -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 %}
......
{% if utilization == 0 %}
<div class="progress align-items-center justify-content-center">
<div class="progress align-items-center justify-content-center">
<span class="w-100 text-center">{{ utilization }}%</span>
</div>
</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 }}%;"
<div class="progress">
<div
role="progressbar"
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="{{ utilization }}"
class="progress-bar {{ bar_class }}"
style="min-width: 8%; width: {{ utilization }}%;"
>
{{ 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 }}"
style="min-width: 8%;width: {{ utilization }}%;"
>
{{ utilization }}%
</div>
{% endif %}
</div>
{% endif %}
\ No newline at end of file
</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,
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment