automation: establish an automation framework

This commit is contained in:
Iain Learmonth 2022-05-08 17:20:04 +01:00
parent 1b53bf451c
commit 8abe5d60fa
31 changed files with 586 additions and 274 deletions

View file

@ -0,0 +1,16 @@
{% extends "base.html.j2" %}
{% from 'bootstrap5/form.html' import render_form %}
{% from "tables.html.j2" import automation_logs_table %}
{% block content %}
<h1 class="h2 mt-3">Automation Job</h1>
<h2 class="h3">{{ automation.description }} ({{ automation.short_name }})</h2>
<div style="border: 1px solid #666;" class="p-3">
{{ render_form(form) }}
</div>
<h3>Logs</h3>
{{ automation_logs_table(automation.logs) }}
{% endblock %}

View file

@ -128,6 +128,12 @@
<span>Monitoring</span>
</h6>
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link{% if section == "automation" %} active{% endif %}"
href="{{ url_for("portal.automation.automation_list") }}">
Automation
</a>
</li>
<li class="nav-item">
<a class="nav-link{% if section == "alarm" %} active{% endif %}"
href="{{ url_for("portal.view_alarms") }}">

View file

@ -1,5 +1,5 @@
{% extends "base.html.j2" %}
{% from "tables.html.j2" import bridgeconfs_table, bridges_table,
{% from "tables.html.j2" import automations_table, bridgeconfs_table, bridges_table,
groups_table, mirrorlists_table, origins_table, origin_onion_table,
onions_table, proxies_table %}
@ -8,7 +8,9 @@
{% if new_link %}
<a href="{{ new_link }}" class="btn btn-success">Create new {{ item }}</a>
{% endif %}
{% if item == "bridge configuration" %}
{% if item == "automation" %}
{{ automations_table(items) }}
{% elif item == "bridge configuration" %}
{{ bridgeconfs_table(items) }}
{% elif item == "bridge" %}
{{ bridges_table(items) }}

View file

@ -26,6 +26,67 @@
<div class="alert alert-danger">Not implemented yet.</div>
{% endmacro %}
{% macro automations_table(automations) %}
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col">Description</th>
<th scope="col">Status</th>
<th scope="col">Enabled</th>
<th scope="col">Last Run</th>
<th scope="col">Next Run</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{% for automation in automations %}
<tr>
<td title="{{ automation.short_name }}">{{ automation.description }}</td>
<td title="{{ automation.state.name }}">
{% if automation.state.name == "IDLE" %}
🕰️
{% elif automation.state.name == "RUNNING" %}
🏃
{% else %}
💥
{% endif %}
</td>
<td>{% if automation.enabled %}✅{% else %}❌{% endif %}</td>
<td>{{ automation.last_run | format_datetime }}</td>
<td>{{ automation.next_run | format_datetime }}</td>
<td>
<a href="{{ url_for("portal.automation.automation_edit", automation_id=automation.id) }}" class="btn btn-primary btn-sm">View/Edit</a>
<a href="{{ url_for("portal.automation.automation_kick", automation_id=automation.id) }}" class="btn btn-success btn-sm">Kick Timer</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endmacro %}
{% macro automation_logs_table(logs) %}
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col">Log Created</th>
<th scope="col">Log</th>
</tr>
</thead>
<tbody>
{% for log in logs %}
<tr>
<td>{{ log.added | format_datetime }}</td>
<td>{{ log.logs }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endmacro %}
{% macro groups_table(groups) %}
<div class="table-responsive">
<table class="table table-striped table-sm">
@ -84,6 +145,8 @@
<td>
<a href="{{ url_for("portal.origin.origin_edit", origin_id=origin.id) }}"
class="btn btn-primary btn-sm">View/Edit</a>
<a href="{{ url_for("portal.origin.origin_destroy", origin_id=origin.id) }}"
class="btn btn-danger btn-sm">Destroy</a>
</td>
</tr>
{% endif %}