using HTMX to load camers in list/detail views
parent
91b72ab9d9
commit
aab2168f92
|
@ -466,6 +466,19 @@ class EagleEyev3():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_camera_by_id(self, esn):
|
||||||
|
found_camera = None
|
||||||
|
for camera in self.cameras:
|
||||||
|
if camera.id == esn:
|
||||||
|
found_camera = camera
|
||||||
|
break
|
||||||
|
|
||||||
|
if found_camera == None:
|
||||||
|
camera = Camera()
|
||||||
|
|
||||||
|
logging.info(f"returning camera {camera} for search query {esn}")
|
||||||
|
return camera
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -490,7 +503,10 @@ class Device():
|
||||||
return self.status['connectionStatus'] == "online"
|
return self.status['connectionStatus'] == "online"
|
||||||
|
|
||||||
def is_offline(self):
|
def is_offline(self):
|
||||||
return self.status['connectionStatus'] == "deviceOffline" or self.status['connectionStatus'] == "bridgeOffline"
|
return self.status['connectionStatus'] == "deviceOffline" \
|
||||||
|
or self.status['connectionStatus'] == "bridgeOffline" \
|
||||||
|
or self.status['connectionStatus'] == "error"
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self.is_online():
|
if self.is_online():
|
||||||
|
|
49
app.py
49
app.py
|
@ -46,8 +46,17 @@ def index():
|
||||||
logging.info(f"{check['success']} - check get_current_user")
|
logging.info(f"{check['success']} - check get_current_user")
|
||||||
|
|
||||||
|
|
||||||
|
#logging.info(een.cameras)
|
||||||
|
|
||||||
|
|
||||||
|
# this call could get expensive
|
||||||
|
een.get_list_of_cameras()
|
||||||
|
|
||||||
|
#logging.info(een.cameras)
|
||||||
|
|
||||||
values = {
|
values = {
|
||||||
"current_user": een.current_user
|
"current_user": een.current_user,
|
||||||
|
"cameras": een.cameras
|
||||||
}
|
}
|
||||||
|
|
||||||
return render_template('index.html', template_values=values)
|
return render_template('index.html', template_values=values)
|
||||||
|
@ -68,7 +77,7 @@ def login_callback():
|
||||||
# use the include code parameter to complete login process
|
# use the include code parameter to complete login process
|
||||||
oauth_object = een.login_tokens(code)
|
oauth_object = een.login_tokens(code)
|
||||||
|
|
||||||
|
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,5 +90,41 @@ def logout():
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/cameras')
|
||||||
|
def cameras():
|
||||||
|
if 'een' in session:
|
||||||
|
een = session['een']
|
||||||
|
else:
|
||||||
|
een = EagleEyev3()
|
||||||
|
|
||||||
|
een.get_list_of_cameras()
|
||||||
|
|
||||||
|
values = {
|
||||||
|
"current_user": een.current_user,
|
||||||
|
"cameras": een.cameras
|
||||||
|
}
|
||||||
|
|
||||||
|
return render_template('cameras_partial.html', template_values=values)
|
||||||
|
|
||||||
|
@app.route('/camera/<esn>')
|
||||||
|
def camera_detail(esn=None):
|
||||||
|
if 'een' in session:
|
||||||
|
een = session['een']
|
||||||
|
else:
|
||||||
|
een = EagleEyev3()
|
||||||
|
|
||||||
|
camera = een.get_camera_by_id(esn)
|
||||||
|
|
||||||
|
values = {
|
||||||
|
"current_user": een.current_user,
|
||||||
|
"camera": camera,
|
||||||
|
"events": camera.get_list_of_events()
|
||||||
|
}
|
||||||
|
|
||||||
|
return render_template('camera_detail_partial.html', template_values=values)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host=een.server_host, port=een.server_port)
|
app.run(host=een.server_host, port=een.server_port)
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
|
@ -1,5 +1,4 @@
|
||||||
|
|
||||||
{% if "X-PJAX" not in request.headers %}
|
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
@ -10,7 +9,7 @@
|
||||||
|
|
||||||
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
|
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
|
||||||
{% block title %}
|
{% block title %}
|
||||||
<title>classifier.een.cloud</title>
|
<title>status.mcotton.space</title>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<!-- Bootstrap core CSS -->
|
<!-- Bootstrap core CSS -->
|
||||||
|
@ -61,14 +60,11 @@
|
||||||
|
|
||||||
|
|
||||||
<main role="main">
|
<main role="main">
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% if "X-PJAX" not in request.headers %}
|
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer class="text-muted">
|
<footer class="text-muted">
|
||||||
|
@ -88,35 +84,14 @@
|
||||||
|
|
||||||
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
|
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
|
||||||
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
|
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
|
||||||
<script src="/static/js/jquery.pjax.js"></script>
|
|
||||||
|
<script src="https://unpkg.com/htmx.org@1.9.2"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
$('#user_mode_toggle').on('click', function(event) {
|
|
||||||
event.stopPropagation();
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: '/api/v1/user_mode/toggle',
|
|
||||||
dataType: "text",
|
|
||||||
contentType : 'application/json',
|
|
||||||
success: function(data) {
|
|
||||||
//$('#labelModal-add').text('Saved');
|
|
||||||
//$('#labelModal').modal('hide');
|
|
||||||
location.reload();
|
|
||||||
},
|
|
||||||
error: function(data) {
|
|
||||||
console.log(data)
|
|
||||||
$('#labelModal-add').text('Failed');
|
|
||||||
//$('#labelModal').modal('hide');
|
|
||||||
//location.reload();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,4 +103,3 @@
|
||||||
{% endblock%}
|
{% endblock%}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
{% endif %}
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h3>{{ template_values['camera'].name }}</h3>
|
||||||
|
<img src="/static/placeholder.png" style="max-height:360px;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h3>Events</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -10,12 +10,16 @@
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
|
|
||||||
<div class="container text-center">
|
<div class="container text-center">
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6 offset-3">
|
|
||||||
<h1>Hello {{ template_values['current_user']['firstName'] }} {{ template_values['current_user']['lastName'] }}</h1>
|
<div class="row" id="camera_list">
|
||||||
</div>
|
{% include 'cameras_partial.html' %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue