Added a hacky solution to allow users to be able to set a number of reports that they wish to display on the reports panel on the node page

This commit is contained in:
stack72
2014-05-16 16:37:16 -05:00
parent bfdc778a81
commit 81c71607ae
5 changed files with 22 additions and 6 deletions

View File

@@ -21,7 +21,7 @@ from pypuppetdb import connect
from puppetboard.forms import QueryForm from puppetboard.forms import QueryForm
from puppetboard.utils import ( from puppetboard.utils import (
get_or_abort, yield_or_stop, get_or_abort, yield_or_stop,
ten_reports, jsonprint ten_reports, limit_reports, jsonprint
) )
@@ -173,12 +173,13 @@ def node(node_name):
""" """
node = get_or_abort(puppetdb.node, node_name) node = get_or_abort(puppetdb.node, node_name)
facts = node.facts() facts = node.facts()
reports = ten_reports(node.reports()) reports = limit_reports(node.reports(), app.config['REPORTS_COUNT'])
return render_template( return render_template(
'node.html', 'node.html',
node=node, node=node,
facts=yield_or_stop(facts), facts=yield_or_stop(facts),
reports=yield_or_stop(reports)) reports=yield_or_stop(reports),
reports_count=app.config['REPORTS_COUNT'])
@app.route('/reports') @app.route('/reports')

View File

@@ -9,3 +9,4 @@ DEV_LISTEN_PORT = 5000
UNRESPONSIVE_HOURS = 2 UNRESPONSIVE_HOURS = 2
ENABLE_QUERY = True ENABLE_QUERY = True
LOGLEVEL = 'info' LOGLEVEL = 'info'
REPORTS_COUNT = 10

View File

@@ -95,9 +95,13 @@
</script> </script>
{%- endmacro %} {%- endmacro %}
{% macro reports_table(reports, nodename, condensed=False, hash_truncate=False, show_conf_col=True, show_agent_col=True, show_host_col=True) -%}
{% macro reports_table(reports, nodename, reports_count, condensed=False, hash_truncate=False, show_conf_col=True, show_agent_col=True, show_host_col=True) -%}
<div class="ui info message"> <div class="ui info message">
Only showing the last ten reports.
Only showing the last {{reports_count}} reports.
</div> </div>
<table class='ui table basic {% if condensed %}compact{% endif %}'> <table class='ui table basic {% if condensed %}compact{% endif %}'>
<thead> <thead>

View File

@@ -28,7 +28,7 @@
</div> </div>
<div class='row'> <div class='row'>
<h1>Reports</h1> <h1>Reports</h1>
{{ macros.reports_table(reports, node.name, condensed=True, hash_truncate=True, show_conf_col=False, show_agent_col=False, show_host_col=False)}} {{ macros.reports_table(reports, node.name, reports_count, condensed=True, hash_truncate=True, show_conf_col=False, show_agent_col=False, show_host_col=False)}}
</div> </div>
</div> </div>
<div class='column'> <div class='column'>

View File

@@ -39,6 +39,16 @@ def ten_reports(reports):
yield report yield report
def limit_reports(reports, limit):
"""Helper to yield a number of from the reports generator.
This is an ugly solution at best...
"""
for count, report in enumerate(reports):
if count == limit:
raise StopIteration
yield report
def yield_or_stop(generator): def yield_or_stop(generator):
"""Similar in intent to get_or_abort this helper will iterate over our """Similar in intent to get_or_abort this helper will iterate over our
generators and handle certain errors. generators and handle certain errors.