Add commands view and macros.html

Commands view has a scope sidebar with the content block filled with
command buttons (poweroff, wol, etc.)

This commit leaves scope create/delete/update buttons in the /scopes
view, which serves that purpose.

To avoid duplicating scope tree creation macro, an external macros.html
is created, this template can be imported. Future macros needed can be
written in there.
multi-ogserver
Jose M. Guisado 2021-06-16 10:30:39 +00:00 committed by OpenGnSys Support Team
parent 514fb84a56
commit 3667db8662
5 changed files with 73 additions and 45 deletions

View File

@ -0,0 +1,44 @@
{% extends 'base.html' %}
{% import "macros.html" as macros %}
{% block nav_scopes %}active{% endblock %}
{% block container %}
<form id="scopesForm">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
</form>
{{ super() }}
</form>
{% endblock %}
{% block sidebar %}
{{ macros.print_scopes_tree(scopes["scope"]) }}
{% endblock %}
{% block commands %}
<input class="btn btn-light" type="submit" value="{{ _('Power on (WoL)') }}"
form="scopesForm" formaction="{{ url_for('action_wol') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Power off') }}"
form="scopesForm" formaction="{{ url_for('action_poweroff') }}" formmethod="post">
<input class="btn btn-light" type="submit" value="{{ _('Reboot') }}"
form="scopesForm" formaction="{{ url_for('action_reboot') }}" formmethod="post">
<input class="btn btn-light" type="submit" value="{{ _('Refresh') }}"
form="scopesForm" formaction="{{ url_for('action_refresh') }}" formmethod="post">
<input class="btn btn-light" type="submit" value="{{ _('Hardware') }}"
form="scopesForm" formaction="{{ url_for('action_hardware') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Software') }}"
form="scopesForm" formaction="{{ url_for('action_software') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Start session') }}"
form="scopesForm" formaction="{{ url_for('action_session') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Restore Image') }}"
form="scopesForm" formaction="{{ url_for('action_image_restore') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Partition & Format') }}"
form="scopesForm" formaction="{{ url_for('action_setup_show') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Client details') }}"
form="scopesForm" formaction="{{ url_for('action_client_info') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Create image') }}"
form="scopesForm" formaction="{{ url_for('action_image_create') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Set boot mode') }}"
form="scopesForm" formaction="{{ url_for('action_mode') }}" formmethod="get">
{% endblock %}

View File

@ -0,0 +1,19 @@
{% macro print_scopes_tree(scopes) -%}
<ul class="list-group list-group-flush">
{% for scope in scopes %}
<li class="list-group-item state--{{ scope['state'] | lower }}">
<input class="form-check-input" type="checkbox" form="scopesForm"
value="{{ " ".join(scope["ip"]) }}"
name="{{ scope["name"] }}_{{ scope["id"] }}">
{{ scope["name"] }}
{% if "state" in scope %}
-- STATE: {{ scope["state"] }}
{% endif %}
{{ print_scopes_tree(scope["scope"]) }}
</li>
{% endfor %}
</ul>
{% endmacro %}

View File

@ -14,7 +14,7 @@
<a class="nav-link" href="{{ url_for('scopes') }}">{{ _('Scopes') }}</a>
</li>
<li class="nav-item {% if request.endpoint == "commands" %}active{% endif %}">
<a class="nav-link" href="#">{{ _('Commands') }}</a>
<a class="nav-link" href="{{ url_for('commands') }}">{{ _('Commands') }}</a>
</li>
<li class="nav-item {% if request.endpoint == "images" %}active{% endif %}">
<a class="nav-link" href="#">{{ _('Images') }}</a>

View File

@ -1,25 +1,8 @@
{% extends 'base.html' %}
{% import "macros.html" as macros %}
{% block nav_scopes %}active{% endblock %}
{% macro print_scopes_tree(scopes) -%}
<ul class="list-group list-group-flush">
{% for scope in scopes %}
<li class="list-group-item state--{{ scope['state'] | lower }}">
<input class="form-check-input" type="checkbox" form="scopesForm"
value="{{ " ".join(scope["ip"]) }}"
name="{{ scope["name"] }}_{{ scope["id"] }}">
{{ scope["name"] }}
{% if "state" in scope %}
-- STATE: {{ scope["state"] }}
{% endif %}
{{ print_scopes_tree(scope["scope"]) }}
</li>
{% endfor %}
</ul>
{% endmacro %}
{% block container %}
<form id="scopesForm">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
@ -29,36 +12,12 @@
{% endblock %}
{% block sidebar %}
{{ print_scopes_tree(scopes["scope"]) }}
{{ macros.print_scopes_tree(scopes["scope"]) }}
{% endblock %}
{% block commands %}
<input class="btn btn-light" type="submit" value="{{ _('Power on (WoL)') }}"
form="scopesForm" formaction="{{ url_for('action_wol') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Power off') }}"
form="scopesForm" formaction="{{ url_for('action_poweroff') }}" formmethod="post">
<input class="btn btn-light" type="submit" value="{{ _('Reboot') }}"
form="scopesForm" formaction="{{ url_for('action_reboot') }}" formmethod="post">
<input class="btn btn-light" type="submit" value="{{ _('Refresh') }}"
form="scopesForm" formaction="{{ url_for('action_refresh') }}" formmethod="post">
<input class="btn btn-light" type="submit" value="{{ _('Hardware') }}"
form="scopesForm" formaction="{{ url_for('action_hardware') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Software') }}"
form="scopesForm" formaction="{{ url_for('action_software') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Start session') }}"
form="scopesForm" formaction="{{ url_for('action_session') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Restore Image') }}"
form="scopesForm" formaction="{{ url_for('action_image_restore') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Partition & Format') }}"
form="scopesForm" formaction="{{ url_for('action_setup_show') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Client details') }}"
form="scopesForm" formaction="{{ url_for('action_client_info') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Add client') }}"
form="scopesForm" formaction="{{ url_for('action_client_add') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Create image') }}"
form="scopesForm" formaction="{{ url_for('action_image_create') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Set boot mode') }}"
form="scopesForm" formaction="{{ url_for('action_mode') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Add room') }}"
form="scopesForm" formaction="{{ url_for('action_room_add') }}" formmethod="get">
<input class="btn btn-light" type="submit" value="{{ _('Delete room') }}"

View File

@ -711,3 +711,9 @@ def action_room_delete():
for room in rooms]
form.room.choices = list(rooms)
return render_template('actions/delete_room.html', form=form)
@app.route('/commands/', methods=['GET'])
@login_required
def commands():
scopes, clients = get_scopes()
return render_template('commands.html', scopes=scopes, clients=clients)