Suppress 0s in monitoring pane rows

Do not set value to 0 and do not add rows without non-zero value.
Also fix javascript in template to avoid coloring 'No items to display.'

With the following rules:
$ openstack congress policy rule create action 'warning(x) :- blah(x)'
$ openstack congress policy rule create classification 'blah(x) :- error(x)'

Monitoring pane pre-patch shows rows of zero warning/error
screenshot: https://imagebin.ca/v/3VXCVtZxXYUQ

rows suppressed post-patch.
screenshot: https://imagebin.ca/v/3VXX9g34QOGf

Closes-Bug: 1708294

Change-Id: I56adc4da430e3e1e15bd31c42fe3f7bce996dcd0
This commit is contained in:
Eric Kao 2017-08-02 15:25:00 -07:00
parent 791ad086ea
commit becbd719cd
2 changed files with 12 additions and 8 deletions

View File

@ -98,8 +98,10 @@ def get_policy_violations_data(request):
row.set_policy_details(policy)
for t in tables:
rows = congress.policy_rows_list(request, policy['name'], t)
row.set_value(t, len(rows))
violations_table.append(row)
if len(rows) > 0:
row.set_value(t, len(rows))
if row.get('error') or row.get('warning'):
violations_table.append(row)
return violations_table

View File

@ -31,16 +31,18 @@
{{ monitoring_table.render }}
</div>
<script type="text/javascript">
// color none 0 errors/warnings red/yellow
// color non-zero errors/warnings red/yellow
table_rows = document.getElementById("monitoring").childNodes[5];
num_rows = (table_rows.childNodes.length - 1)/2;
for (i = 0; i < num_rows; i++) {
row = table_rows.childNodes[1 + 2*i];
if (row.childNodes[1].innerHTML.trim() != "-") {
row.childNodes[1].style.backgroundColor = "rgba(255, 0, 0, 0.5)";
}
if (row.childNodes[2].innerHTML.trim() != "-") {
row.childNodes[2].style.backgroundColor = "rgba(255, 255, 0, 0.5)";
if (row.className != "odd empty") { // ignore the row indicating no items
if (row.childNodes[1].innerHTML.trim() != "-") {
row.childNodes[1].style.backgroundColor = "rgba(255, 0, 0, 0.5)";
}
if (row.childNodes[2].innerHTML.trim() != "-") {
row.childNodes[2].style.backgroundColor = "rgba(255, 255, 0, 0.5)";
}
}
}
</script>