Commit 2138bc35 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

automation view integrated

parent c96b9edd
{% extends 'logged_layout.html' %}
{% block title %} HPC&A IoT - Automation {% endblock %}
{% block header %}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
{% endblock %}
{% block location %}
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/applications">Applications</a>
<p class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"> &nbsp;-&nbsp; </p>
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/application/{{ app[1] }}">{{ app[0] }}</a>
{% endblock %}
{% block body %}
<!-- Page content -->
<div class="container-fluid mt--7">
<!-- Table -->
<div class="row">
<div class="col">
<div class="card shadow">
<div class="card-header bg-transparent">
<h3 class="mb-0">Automation</h3>
</div>
<div class="card-body">
{% if alert_list %}
<table class="table">
<thead>
<th> Name </th>
<th> Statement </th>
<th> </th>
</thead>
<tbody>
{% for a in automations %}
<tr>
<th> {{ a[3] }} </th>
<th> {{ a[4] }} </th>
<th> <a href="javascript:void(0)" onclick="return remove_automation('{{ a[0] }}', '{{ a[2] }}');"> <span class="fa fa-remove"</span> </a> </th>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<center><p> There are no automations for the given application.</p> </center>
{% endif %}
<br>
<div class="col-lg-4">
<a href="/application/{{ app[1] }}/new-automation"><button class="btn btn-primary" type="submit">New Automation</button></a>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript">
function remove_automation(id, devid) {
$.ajax({
url:"/application/{{ app[1] }}/remove-automation?id="+id+"&devid="+devid,
type:"get",
success: function() {
location.reload();
}
});
}
</script>
{% endblock %}
...@@ -40,36 +40,6 @@ def index(): ...@@ -40,36 +40,6 @@ def index():
else: else:
return render_template('new/public/login.html', users_signup=app.config['USERS_SIGNUP']) return render_template('new/public/login.html', users_signup=app.config['USERS_SIGNUP'])
@app.route('/chart-update')
def chart_update():
if 'name' in session:
day_chart_values = md.get_user_data_count_per_hour_period(session['name'], 11)[1]
day_chart_values = [x[0] for x in day_chart_values]
day_chart_labels = [misc.local_hour(x) for x in range(11,-1,-1)]
day_chart = [day_chart_labels, day_chart_values]
week_chart_values = md.get_user_data_count_per_day_period(session['name'], 6)[1]
week_chart_values = [x[0] for x in week_chart_values]
week_chart_labels = [misc.local_weekday(x) for x in range(6,-1,-1)]
week_chart = [week_chart_labels, week_chart_values]
return "[{}, {}]".format(day_chart, week_chart)
else:
return '', 401
@app.route('/recent-activity')
def recent_activity():
if 'name' in session:
recent_activity = md.get_recent_activity(session['name'])[1]
ra = ''
for r in recent_activity:
ra += '<tr><th scope="row">'+r[1]+'</th><th>'+r[2]+'</th><th>'+r[0]+'</th><th>'+str(r[3])+'</th></tr>'
return ra, 200
else:
return '', 401
@app.route('/register', methods=['GET', 'POST']) @app.route('/register', methods=['GET', 'POST'])
def register(): def register():
if request.method == 'GET': if request.method == 'GET':
...@@ -310,6 +280,37 @@ def application_device_download_csv(appkey, devid): ...@@ -310,6 +280,37 @@ def application_device_download_csv(appkey, devid):
return redirect(utl_for('login')) return redirect(utl_for('login'))
@app.route('/chart-update')
def chart_update():
if 'name' in session:
day_chart_values = md.get_user_data_count_per_hour_period(session['name'], 11)[1]
day_chart_values = [x[0] for x in day_chart_values]
day_chart_labels = [misc.local_hour(x) for x in range(11,-1,-1)]
day_chart = [day_chart_labels, day_chart_values]
week_chart_values = md.get_user_data_count_per_day_period(session['name'], 6)[1]
week_chart_values = [x[0] for x in week_chart_values]
week_chart_labels = [misc.local_weekday(x) for x in range(6,-1,-1)]
week_chart = [week_chart_labels, week_chart_values]
return "[{}, {}]".format(day_chart, week_chart)
else:
return '', 401
@app.route('/recent-activity')
def recent_activity():
if 'name' in session:
recent_activity = md.get_recent_activity(session['name'])[1]
ra = ''
for r in recent_activity:
ra += '<tr><th scope="row">'+r[1]+'</th><th>'+r[2]+'</th><th>'+r[0]+'</th><th>'+str(r[3])+'</th></tr>'
return ra, 200
else:
return '', 401
@app.route('/new-app') @app.route('/new-app')
def new_app(): def new_app():
if 'name' in session: if 'name' in session:
...@@ -795,6 +796,17 @@ def application_alert_remove(appkey): ...@@ -795,6 +796,17 @@ def application_alert_remove(appkey):
return redirect(url_for('login')) return redirect(url_for('login'))
@app.route('/application/<appkey>/automation')
def application_automation(appkey):
if 'name' in session:
ap = ad.get(appkey)
ats = nfs.get_automation_list(appkey)
return render_template('new/public/automation.html', automations=ats[1], app=ap[1])
else:
return redirect(url_for('login'))
@app.route('/alerts') @app.route('/alerts')
def alerts(): def alerts():
if 'name' in session: if 'name' in session:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment