puppetboard/app: Reducing code redundancy for environment retreival and checking

Moving the envs variable out of the functions scope to the global scope,
this enables each function to reference and use these values.

Adding a new function check_env() to standardize the way to ensure that
the request environment exists, if it doesn't then abort with a 404.

This reduces 16 blocks of code and is in line with @daenney's suggestions
This commit is contained in:
Corey Hammerton
2015-11-07 20:06:48 -05:00
parent b628032c39
commit 46439055f8
3 changed files with 37 additions and 88 deletions

View File

@@ -42,7 +42,6 @@
</div>
<div class="four column row">
<div class="column">
<span>Global Metrics:</span>
</div>
<div class="column">
<h1 class="ui header darkblue no-margin-bottom">{{metrics['num_nodes']}}</h1>

View File

@@ -40,17 +40,15 @@
<a {% if endpoint == request.endpoint %} class="active item" {% else %} class="item" {% endif %}
href="{{ url_for(endpoint, env=current_env) }}">{{ caption }}</a>
{%- endfor %}
{% if envs|length > 0 %}
<div class="ui item dropdown">
Environments
<i class="dropdown icon"></i>
<div class="menu">
{% for env in envs %}
<a class="item {% if env == current_env %}active{% endif %}" href="{{url_for_environments(env)}}">{{env}}</a>
{% endfor %}
</div>
<div class="ui item dropdown">
Environments
<i class="dropdown icon"></i>
<div class="menu">
{% for env in envs %}
<a class="item {% if env == current_env %}active{% endif %}" href="{{url_for_environments(env)}}">{{env}}</a>
{% endfor %}
</div>
{% endif %}
</div>
<div class="item right"><a href="https://github.com/puppet-community/puppetboard" target="_blank">v0.1.0</a></div>
</div>
<div class="ui grid padding-bottom">